Dabbler
Dabbler

Reputation: 9873

Eliminating redundant (?) openGL calls

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:

Upvotes: 2

Views: 1014

Answers (2)

unexpectedvalue
unexpectedvalue

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

Tim
Tim

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

Related Questions