Reputation: 9873
I'm using gDEBugger to try to improve the performance of my openGL code (which is currently so excruciatingly bad that I won't even tell you its fps rate). I'm doing the tutorial step by step (using the debugger to find for openGL errors, etc.), and right now I'm identifying redundant state changes. I'm somewhat unsure whether changing the code to avoid them is really a good idea.
For example:
glClearAccum(0 , 0 , 0 , 0);
and glClearColor(0.0, 0.0, 0.0, 0.0);
. These are understandably redundant, but can I rely on that in all circumstances? If some openGL implementation doesn't guarantee this initial state, it's safer to make the calls even though they're redundant in most cases.glDrawBuffer(GL_BACK);
when drawing the scene for the first time.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
is also reported to be redundant. I realise I'm calling it repeatedly with the same parameters; that's because the call is placed between glEnable(GL_TEXTURE_2D);
and glDisable(GL_TEXTURE_2D);
, and texturing is enabled only briefly while the texturing calls are done. Would it hurt performance to have texturing enabled permanently? If I stick with enabling texturing temporarily, is it ok to call glTextEnvf
just once during initialization, or will that fail since texturing is disabled at that point? Or does that depend on the openGL implementation?Upvotes: 2
Views: 1014
Reputation: 6139
glClearAccum(0 , 0 , 0 , 0);
and glClearColor(0.0, 0.0, 0.0, 0.0);
are redundant when you draw the whole screen every frame (which you probably do), and they are quite heavy. There is no point clearing the framebuffer, just draw over the last frame.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
sets a flag and should work all the time. It shouldn't be expensive however.
Upvotes: 0
Reputation: 35943
For the initialization code, if you look at the man page for each particular function, it will tell you what the default value is, and that is guaranteed by the spec. That said, the initialization code shouldn't matter at all, because it's only run once at the beginning, and each call you make might have a delay of a microsecond. It's not worth worrying about these things during initialization.
For glTexEnvf, the state is not reset when you disable texturing. glEnable(GL_TEXTURE_2D) has no effect on any of the other textureing functions, it just determines whether to not to sample the texture during a draw call. You don't have to enable texturing to set a texture parameter.
For example, the following code is valid:
//textures disabled
glTexEnvf(some_texture_state);
for(i=0;i<10;i++){
glEnable(GL_TEXTURE_2D)
//draw some stuff with textures and "some_texture_state"
glDisable(GL_TEXTURE_2D)
//draw some stuff without texturing
}
Upvotes: 1