Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Managing opengl state

This topic is 3051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys

My engine keeps track of almost all OpenGL state. This allows me to skip redundant state changes. It also has stacks to revert state. My goal is to do use this system as much as possible and use OpenGL only when it's absolutely needed.

The issue with openGL state, is that sometimes you have to bind an object before you can change its state. This becomes a problem when you have wrapped up these things into classes.
f.e I have a texture class that has a SetFilter() method. Internally, this method must make sure that the texture that is managed by my object is bound and that the desired filter is configured. Some ways to do it:

1. If I do this directly by using OpenGL calls, OpenGL will be out of sync with the states I kept track of in my engine. I can fix this by calling a Force() method I have made. It automaticly sets all the states to the values that are in my engine (I can call force for different groups of states like: texture, depth, rasterizer etc).
2. I can push my old texture state to a stack I made. Then I can set my texture and call OpenGL to set the filter. Finally, I will pop() again to restore the original texture.
3. I can also exit the SetFilter() routine if the texture is not bound. This is the most efficient option because it forces the programmer to "group" state changes, but it's less convenient, because he has to bind every texture before he can change it (using my engine's routines ofcourse). This makes the whole OOP structure of my code a bit decieving.

Which of these approaches would you pick? Any other ones you can think of?


P.S: I DO NOT want to use glPushAttrib/glPopAttrib because AFAIK it's deprecated in OpenGL 3.x.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!