Jump to content
  • Advertisement
Sign in to follow this  
thorpe

OpenGL Is it expensive to change OpenGL state?

This topic is 5150 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

How expensive is it to change the OpenGL state by calls to glTexParameter, glEnable, glTexEnv and so forth. Are they just logical states which doesn't change any internal structure until rendering starts (and change is needed) or can some of these functions be time-consuming at the moment you call them?

Share this post


Link to post
Share on other sites
Advertisement
In general, yes it is expensive, and you should avoid unnecessary state changes as much as possible. A good way to do this is to sort batches by state and render them in that order.

In practice different state changes will take different amounts of time, and this will vary depending on drivers and hardware. Do some profiling and you should be able to find out which changes are most expensive on your hardware at least.

Share this post


Link to post
Share on other sites
There is a cost in some cases, but I've found that it's actually usually an extremely slight cost. As long as you do what benjamin_bunny suggested, and even if you don't, you should be fine. Don't sacrifice visual quality in order to reduce the number of state changes.

Share this post


Link to post
Share on other sites
From my practical experience with the Nvidia drivers, changing soem states, such as enabling/disabling textures have no noticeable penalty.

Share this post


Link to post
Share on other sites
I have a rendering system that uses q3-style shaders which means lots of shader stages with different states. 10k triangles with 5-10 stages without any state management, just plain trianglepushing, wasn't very efficient. Sorting by shader and drawing all triangles for a stage at a time improved the speed about 100%.

This was perhaps a slightly extreme situation, but state changes should be considered very expensive. Especially calls to glBindTexture(), if you would consider that a state change.

But as has already been mentioned the best way to find out is to run a profiler and see for yourself.

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!