PDA

View Full Version : whitch one is faster???



ARES
01-11-2002, 11:00 AM
which one is better and which one is faster?
you don't know if GL_DEPTH_TEST is enabled before and after the // ....


1:

glDisable(GL_DEPTH_TEST);

// ....

glEnable(GL_DEPTH_TEST);

2:

glPushAttrib( GL_DEPTH_BUFFER_BIT );
glDisable(GL_DEPTH_TEST);

// ....

glPopAttrib();

3:

if ( glIsEnabled( GL_DEPTH_TEST ) == TRUE )
glDisable(GL_DEPTH_TEST);

// ....

if ( glIsEnabled( GL_DEPTH_TEST ) == FALSE )
glEnable(GL_DEPTH_TEST);

lobstah
01-11-2002, 11:54 AM
As for speed:
Unless you make one of these sets of calls thousands of times times, it may not be measureable.

As for which is better, I would prefer to use 1.

I use push atribute when I'm pushing many attributes.

Hope this helps.

lobstah...

Bob
01-11-2002, 12:20 PM
4:



#define disabled 0
#define enabled 1

...

int depthbuffer = disabled;

...


if(depthbuffer == disabled)
{
glEnable(GL_DEPTH_BUFER);
depthbuffer = enabled;
}

if(depthbuffer == enabled)
{
glDisable(GL_DEPTH_BUFER);
depthbuffer = disabled;
}

This is what you should do. Mirror the state you need in local variables so you don't have to do rendurant state changed, pushing/popping states, or query states.

Anyways, worrying about things like this is the last thing you should do. Trust me, if you worry about it too much, you will never even get your projects half done.

Nutty
01-11-2002, 12:51 PM
IF you want extreme speed make sure everything you render is red. cos Red comes 1st in RGBA, so it pipes out to the hardware faster.

Nutty http://www.opengl.org/discussion_boards/ubb/wink.gif

01-11-2002, 01:48 PM
pushing and poping attributes is slow

Tolga Dalman
01-11-2002, 09:21 PM
bob, it is up to the opengl implementation, to check, whether a state is enable or not (if changing a state is in fact slower than checking).
i would do it the 1st way. as lobstah stated, pushing and poping do only make sense, if there are many states to switch.

good luck!
Tolga.

zed
01-11-2002, 10:56 PM
method 4 (bobs) is quickest
all the other 3 are far slower

harsman
01-12-2002, 05:50 AM
Tolga, yes the implementation can check for redundant state changes internally, but most implementations don't. It's considered bad style to do redundant state changes and relying on the driver to sort it out. All this is covered in the FAQ (http://www.opengl.org/developers/faqs/technical/performance.htm#perf0040) btw.

Jambolo
01-13-2002, 02:14 PM
Well, it's a matter of opinion. I consider it bad design when a library's user is forced to keep track of the library's state in order to avoid making redundant state changes.

[This message has been edited by Jambolo (edited 01-13-2002).]

dorbie
01-14-2002, 01:27 AM
Thanks for the input Jambolo, of course it's up to the implementor to do this. The problem is that to do the test slows down a raw glEnable glDisable when the application KNOWS what it is doing.

What you are saying Jambolo is that someone doing

glDisable(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);

should see a minimal performance impact at the expense of someone doing

glDisable(GL_DEPTH_TEST);

That's an option for implementors, but better programmers may object in principal to slowing down their single glDisable(GL_DEPTH_TEST); call.

OpenGL has nothing to say about which choice the implementor makes, and with some implementations it may have almost no impact either way.