glIsEnabled() and performance question
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
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
(edit: These internal server errors are getting annoying! 4 so far on just this post)
-------------------
Realm Games Company
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.
Keep track of the state yourself. This is cheaper than both redundant state changes and querying current state.
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.
Because the state is stored server-side, meaning it is quite likely to reside in video memory. Video reads are uberslow because of the way the pipeline is set up, and they cause stalling.
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
That is BS.
OpenGL knows vry well what states are enabled/disabled, and I am sure the driver checks wether or not a certain state is enabled or not, and if you try to enable a state that is already enabled, it will just return.
Height Map Editor | Eternal Lands | Fast User Directory
OpenGL knows vry well what states are enabled/disabled, and I am sure the driver checks wether or not a certain state is enabled or not, and if you try to enable a state that is already enabled, it will just return.
Height Map Editor | Eternal Lands | Fast User Directory
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
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
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?
Obviously, the check is done for both Enable and Disable.
Height Map Editor | Eternal Lands | Fast User Directory
Height Map Editor | Eternal Lands | Fast User Directory
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement