LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: gregorypierce on January 23, 2005, 03:19:53

Title: OSX PBuffer problems
Post by: gregorypierce on January 23, 2005, 03:19:53
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 );

Title: OSX PBuffer problems
Post by: Chman on January 23, 2005, 10:34:56
PBuffers don't work on MacOS X :oops:

Chman
Title: OSX PBuffer problems
Post by: gregorypierce on January 23, 2005, 16:05:25
Quote from: "Chman"PBuffers don't work on MacOS X :oops:

Chman


Ah, that would do it :)
Title: OSX PBuffer problems
Post by: gregorypierce on January 23, 2005, 17:35:39
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.
Title: OSX PBuffer problems
Post by: elias on January 23, 2005, 19:17:41
They work here on our G5 dual thingie with OS X 10.3. Notice that 10.2 doesn't support them.

- elias
Title: OSX PBuffer problems
Post by: gregorypierce on January 23, 2005, 19:24:02
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];

Title: OSX PBuffer problems
Post by: elias on January 23, 2005, 20:32:27
This is an extension, can we be sure it's always present?

- elias
Title: OSX PBuffer problems
Post by: gregorypierce on January 23, 2005, 22:58:43
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 :)
Title: OSX PBuffer problems
Post by: elias on January 24, 2005, 08:47:38
Ok. Can you create (and test) a patch to be applied then?

- elias
Title: OSX PBuffer problems
Post by: spasi on January 24, 2005, 10:50:31
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.
Title: OSX PBuffer problems
Post by: princec on January 24, 2005, 11:13:56
Also ARB_texture_non_power_of_two.

Cas :)
Title: OSX PBuffer problems
Post by: gregorypierce on January 24, 2005, 16:45:56
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.
Title: OSX PBuffer problems
Post by: gregorypierce on January 28, 2005, 20:37:56
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.
Title: OSX PBuffer problems
Post by: spasi on January 29, 2005, 10:18:00
Just remembered, there's also the ARB_texture_rectangle one. :)
Title: OSX PBuffer problems
Post by: gregorypierce on January 31, 2005, 04:50:18
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.