View Full Version : A very simple performance question...
03-13-2001, 08:02 AM
Which of the following code snippets is faster and why?
// Method 1
GLboolean texEnabled = glIsEnabled(GL_TEXTURE_2D);
// Method 2
03-13-2001, 08:10 AM
You should do your own function shadowing.
Make a wrapper for glEnable(GL_TEXTURE_2D) like enableTexture2D(), which you just (*allways*) call and then it checks it's own variables too see whether Texture2D is enabled or not.
03-13-2001, 08:16 AM
Performance is key here, I need to know if manually detecting the enabled state with glIsEnabled(GL_TEXTURE_2D) and then reseting it when I am done is faster or slower than simply wrapping my code with the glPushAttrib(GL_ENABLE_BIT)/glPopAttrib() calls.
Your answer leads me to believe that you think the manual detection method is quicker since your enableTexture2D() function would use the manual method.
Is this true? Is manual detection quicker?
[This message has been edited by pleopard (edited 03-13-2001).]
03-13-2001, 08:32 AM
I could be mistaken about this, but I would think the first method would be slower. Why do I think this? Generally getting info back on GL states is slower than actually setting the states. Isaack's suggestion would probably be faster than both of them as you will be keeping track of the state of GL_TEXTURE_2D yourself and not having to query OpenGL for it.
03-13-2001, 10:07 AM
the fastest method is to store it yourself.. is written in the performance spec of nvidia, cause opengl stores the bits in big trees ( much bits, wich can be on or off ), and it takes longer to search as in your case just search with a simple mov eax,texture_is_enabled
so do it yourself.. its fastest..
ill back up what daveperman,isaackrasmussen saiz both methods are less than optimal
03-13-2001, 11:33 AM
Both methods are very bad.
*Never* use OpenGL queries in any app that needs to be high-performance. IsEnabled, GetIntegerv, GetFloatv, etc., never call them inside your rendering loop.
*Never* use PushAttrib/PopAttrib in any app that needs to be high-performance, either. In most implementations, in fact, PushAttrib and PopAttrib will be much slower than the queries.
Redundant state changes are bad, and the best way to deal with them is to shadow OpenGL state inside your application. The same goes for saving/restoring OpenGL state. It is far better for your app to keep track of whether texturing is enabled or disabled than to need to ask.
03-13-2001, 01:25 PM
Hey thanks folks, that is what I needed to know. Judging by your comments, I believe that my best approach will be to implement my own OpenGL state manager and implement it as a singleton. That will give me the centralized state control point that I am giving up (from OpenGL) with the queries and push/pop calls.
Paul H. Leopard
03-13-2001, 11:19 PM
What is about transforms.Should I avoid Get(any matrix) and keep track of all transforms ?
You should avoid glGet of ANY kind. Let it be states or matrices, always avoid them if possible.
For transformations, I keep a copy of the matrices for fast access. I compose my own transformation matrices and upload them with glLoadMatrix/glMultMatrix. I.e. I do not use glRotatef or anything like that.
Just how slow are these functions? If I have, say, 1000 objects in a scene, and push and pop a state for each of them, how much time per frame would this take? Same for gets. Are we talking about a 1-2% slowdown on a 500MHz machine, or something worse?
of course this is all relative but i believe i got about a 15% increase from removing all my push/pop/get statements
[This message has been edited by zed (edited 03-20-2001).]
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.