How to reset all OpenGL state

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

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?

No. Please say it when you need advice for GL ES and not the regular GL.

… or just post your question to the OpenGL ES forum:

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

Even in desktop GL, PushAttrib can’t save all of the state. For example, which attribute does FRAMEBUFFER_BINDING push with?

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.

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.