Function Latency

I’m just wondering. Obviously any call is going to take some time, but do calls like glEnable/Disable, glMatrixMode() and glPush/PopMatrix() take enough time to warrant serious optimizations in the parts of my code where I call them?

I ask because I just now discovered that you could switch projection matrices between drawing calls and achieve “layered” effects, and so I’ll be needing to push the projection matrix and switch it from a perspective to an ortho one and such alot from now on, plus for convenience sake all my texture drawing functions call glEnable(GL_TEXTURE_2D) at the start and glDisable(GL_TEXTURE_2D) at the end–so I want to know if this is an area I should overhaul when I get to the optimization phase.

[This message has been edited by Omaha (edited 10-31-2001).]

You want to glEnable/glDisable as little as possible because it can cause geometry to be flushed through the graphics pipeline. The state change also requires a whole bunch of validation.

So if you always have lighting on, enable it in some intialization code rather than in your main loop. Ditto for any other glEnable.

So only enable texturing once and bind different textures when you need them. To get hardcore into optimizing, you would sort your objects by texture and render all objects with the same texture at once.

SL