PDA

View Full Version : PBuffers and setTextureImageToPBuffer:colorBuffer:


Marjock
2006.07.15, 06:12 AM
Hey all,

I'm using NSOpenGL to try and set up a PBuffer in my game for things like water reflections.

I have successfully set up the PBuffer, and can successfully change between the PBuffer context and NSOpenGLView's context.

However, when I go to use what has been drawn to the PBuffer as a texture for my On Screen context (NSOpenGLView's context), I am told that I have an "Invalid Context State"

The code I use is the following:

[pBufferContext setTextureImageToPixelBuffer:pBuffer
colorBuffer:GL_FRONT];

Googling reveals this page: http://developer.apple.com/documentation/GraphicsImaging/Reference/CGL_OpenGL/Reference/reference.html

Which states the following:

Invalid context state. This error occurs when a context state is inspected for readiness to switch renderers. To be in a valid state, a context be in render mode and have an attribute stack depth of 0, and a modelview, projection, and texture stack depth of 1.

Using glGetIntegerv, I've ascertained that my Attribute Stack Depth is zero and my modelview, projection and texture stack depths are all one.

It seems that that only leaves the possibility that the context is not in "Render Mode".
I don't know what it means for a context to be in Render Mode, so I am unable to check/correct that situation.

So, can anybody help me with a definition/check of/for "Render Mode" or suggest any other possibilities that might be causing an invalid context state?

Thanks heaps,
Mark

OneSadCookie
2006.07.15, 06:38 AM
Crikey, you don't want to be switching renderers!

I'd suggest that something completely different is wrong with your code. Have you looked at the various pieces of Apple PBuffer sample code? Have you read the explanatory message sent to the mac-opengl mailing list "when they first became available" (read, about 6 months later)?

Marjock
2006.07.16, 01:10 AM
Through use of commenting, I have discovered the problem is caused by this line in my texture loading code (for loading textures *other* than the pBuffer one)

gluBuild2DMipMaps(GL_TEXTURE_2D, GL_RGBA, natbounds.right, natbounds.top, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);

When that line is not there the PBuffer thing works fine. (Although none of my other textures work).

Any ideas as to why that might be causing problems?

When it comes to the PBuffer, I assigned anything to do with Mip Map levels as being zero. I don't think it's referring to the Mip Map levels of any of my other textures, though? (and changing the value to what I estimated my Mip Map levels to be for my 512x512 PBuffer didn't help).

Thanks.

-Mark

Marjock
2006.07.16, 04:28 AM
Okay, it's not just mipmaps. Even if I use glTexImage2D I get the problem.

-Mark

Marjock
2006.07.16, 05:19 AM
Okay, the problem is now fixed. It seems I was binding my PBuffer texture in the PBuffer context, when I should have been binding it in NSOpenGLView's context, which is where I make my CGLTexImagePBuffer/setTextureImageToPixelBuffer call.

It works now, anyway. :-)

-Mark