Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

v_d_d

glIsEnabled() and performance question

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

Is it faster to call glIsEnabled() to get the state of a certain feature before calling glEnable() or glDisable()? Ex: if(glIsEnabled(GL_TEXTURE_2D)) { glDisable(GL_TEXTURE_2D); } else { // already disabled // do nothing, (just to show the logic) } // rest of code follows

Share this post


Link to post
Share on other sites
Advertisement
OpenGL really doesn''t like it when you try to enable something that''s already enabled. This can lead to a big performance hit. I''m not sure about glIsEnabled(), but judging by the information I have, it would make sense. The only true way to find out is to test it your self. You could also keep track of what''s been enabled or disabled yourself.

(edit: These internal server errors are getting annoying! 4 so far on just this post)

-------------------
Realm Games Company

Share this post


Link to post
Share on other sites
I think actually that querying the state machine is very, very slow, and that OpenGL doesn''t like it too much... I think the performance would drop if you were doing it this way.

Share this post


Link to post
Share on other sites
quote:

I think actually that querying the state machine is very, very slow, and that OpenGL doesn''t like it too much... I think the performance would drop if you were doing it this way.



I don''t agree at all. Why would querying a variable cause something to lag?
You''re not changing anything. It''s ridiculous to me.

Share this post


Link to post
Share on other sites
Any sane video driver will keep a local cache of the current GL state. How complete that state cache is, depends on the driver.

I wasn''t entirely sure how current drivers handle the issue, so I just checked it. I compiled a ''glIsEnabled(GL_TEXTURE_2D)'' command, and stepped through the nvogl driver ASM. Driver used is the newest Detonator under NT4 (GeForce 4 Ti 4600).

The driver first goes through a rather large compare/branch sequence (probably from a switch statement, checking the argument of glIsEnabled), and finally retrieves the state from a locally cached system RAM state table (indexed by the currently active texture unit). It doesn''t look like the most efficient implementation possible (keeping track of the state yourself is going to be faster), but it certainly isn''t slow, and it won''t read back from the hardware.

/ Yann

Share this post


Link to post
Share on other sites
Yann, what about enabling a state when it is already enabled? Does it do something like the glIsEnabled() before trying to enable it, or does it just go through all the process of enabling the state?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!