OSX PBuffer problems

Started by gregorypierce, January 23, 2005, 03:19:53

Previous topic - Next topic

gregorypierce

So I'm testing out my Swing adapter on OSX and I'm getting an error when creating the PBuffer:

Quote
5 [main] ERROR TestPBuffer  - Adpater error
org.lwjgl.LWJGLException: Could not allocate Pbuffer
   at org.lwjgl.opengl.MacOSXDisplay.nCreatePbuffer(Native Method)
   at org.lwjgl.opengl.MacOSXDisplay.createPbuffer(MacOSXDisplay.java:421)
   at org.lwjgl.opengl.Pbuffer.createPbuffer(Pbuffer.java:187)
   at org.lwjgl.opengl.Pbuffer.<init>(Pbuffer.java:180)
   at com.sojournermobile.client.TestPBuffer.<init>(TestPBuffer.java:80)

Has anyone actually gotten PBuffers to work on OSX? I thought it might be related to some other issue, but its happening in the native code itself, bubbling up from the PBuffer constructor call

           pbuffer = new Pbuffer( width, height, new PixelFormat(), null, null );

Chman

PBuffers don't work on MacOS X :oops:

Chman

gregorypierce

Quote from: "Chman"PBuffers don't work on MacOS X :oops:

Chman


Ah, that would do it :)

gregorypierce

I'll see if I can sort out what's wrong with them. Code looks good to me and I know that other people have been using pbuffers (WoW uses them) so there should be some way to get them to work properly.

elias

They work here on our G5 dual thingie with OS X 10.3. Notice that 10.2 doesn't support them.

- elias

gregorypierce

Found the problems with pbuffer. OSX GL_TEXTURE_2D requires that each side be a power of two. If you do say a 512x256 resolution, it will render just fine. One of the folks at iDevgames reported that setting the format to GL_TEXTURE_RECTANGLE_EXT will allow those 640x480 resolutions and similar. I went into the .m file and changed that and import <Opengl/glext.h> and rebuilt and the pbuffer gets created fine now.

NSOpenGLPixelBuffer *pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT textureInternalFormat:GL_RGBA textureMaxMipMapLevel:0 pixelsWide:width pixelsHigh:height];

elias

This is an extension, can we be sure it's always present?

- elias

gregorypierce

Quote from: "elias"This is an extension, can we be sure it's always present?

- elias

No, but here is a strategy we can take.

If the dimensions are power of 2, use GL_TEXTURE_2D. If they aren't power of two then the creation is going to fail anyways so try to use the extension. For Swing components or other resizable GUI things we won't have much choice anyways. The iDevgames folks say it won't work on the Rage128. I have no idea what still uses the Rage 128 though. In any event, it should be a sound approach since it would die anyways :)

elias

Ok. Can you create (and test) a patch to be applied then?

- elias

spasi

I'd like to recommend the following:

- If isPOT(width) && isPOT(height) then use GL_TEXTURE_2D.
- Else if either EXT_texture_rectangle or NV_texture_rectangle is available (query GLContext for this) then use GL_TEXTURE_RECTANGLE_EXT (GL_TEXTURE_RECTANGLE_NV has the same value).
- Else throw an exception with a meaningful message.

It will work on anything >= Radeon 7000 and GeForce 2.

princec

Also ARB_texture_non_power_of_two.

Cas :)

gregorypierce

Quote from: "elias"Ok. Can you create (and test) a patch to be applied then?

- elias

I'll add it to my calendar for this weekend.

gregorypierce

This patch has been coded and tested and will be going into CVS tonight. There are some other 'issues' with using GL_TEXTURE_RECTANGLE_EXT that I'm learning about right now - they aren't things that we need to worry about in this particular case though.

spasi

Just remembered, there's also the ARB_texture_rectangle one. :)

gregorypierce

Quote from: "spasi"Just remembered, there's also the ARB_texture_rectangle one. :)

NSOpenGLPixelBuffer can only be coerced into one of the following formats:

textureTarget

- (unsigned long)textureTarget
Returns the texture target of the receiver, one of GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, or GL_TEXTURE_RECTANGLE_EXT.
Availability

Available in Mac OS X v10.3 and later.


OSX PBuffers only go in those formats so we've only got 2 real choices in this situation: GL_TEXTURE_2D and GL_TEXTURE_RECTANGLE_EXT... unless we fake PBuffers with them not being PBuffers but insteal GLViews that are just never drawn to the screen, in which case the dimensions can be non power of 2 with no issues.