PDA

View Full Version : How to reset all OpenGL state



anime.igala.net
08-20-2008, 05:20 AM
Hello all,

I have a programe that has many functions. Each function is written by a person. So I don't know what did they do with the OpenGL state in these functions (glEnable, glDisable ...).

When I draw my scene I would like to reset all state of OpenGL machine to default value. How can I do that?

Thanks

skynet
08-20-2008, 05:41 AM
The answer ist to instruct these persons to restore the state they are changing after they have done their part. glPushAttrib() anf glPopAttrib() will help them.
Alternativly, _you_ can call glPushAttrib(GL_ALL_ATTRIB_BITS) before you call any of these functions and glPopAtrib() when they return. But this can be easily become a performance bottleneck if done many times per frame.

anime.igala.net
08-20-2008, 06:55 AM
The answer ist to instruct these persons to restore the state they are changing after they have done their part. glPushAttrib() anf glPopAttrib() will help them.
Alternativly, _you_ can call glPushAttrib(GL_ALL_ATTRIB_BITS) before you call any of these functions and glPopAtrib() when they return. But this can be easily become a performance bottleneck if done many times per frame.

OpenGL ES does not have this function. Can we do the same thing with other functions?

ZbuffeR
08-20-2008, 07:24 AM
No. Please say it when you need advice for GL ES and not the regular GL.

overlay
08-20-2008, 08:35 AM
... or just post your question to the OpenGL ES forum:

http://www.khronos.org/message_boards/viewforum.php?f=19

arekkusu
08-20-2008, 11:59 AM
Even in desktop GL, PushAttrib can't save all of the state. For example, which attribute does FRAMEBUFFER_BINDING push with?

Korval
08-20-2008, 04:16 PM
which attribute does FRAMEBUFFER_BINDING push with?

It's an object; it doesn't need a PushAttrib. If you need a certain FBO bound, you bind it yourself. Simple.

arekkusu
08-20-2008, 09:59 PM
Textures are objects too. And the binding for each target push/pops. But not for framebuffer or renderbuffer objects.

If you need to restore the FBO that was bound before you called some library function (or equivalently, before your middleware implementation returns to a client) then you need to GetInteger and re-bind it yourself.

The point here is that middleware layers already can't rely on push/pop for state management.

Same story goes for program object binding, XFB buffer bindings, and uniform buffer binding.