Binding textures


One of the optimiazions which can be done to speed up rendering is to sort the objects with respect to texture. Fewer the texture changes faster the rendering is.

Lets assume the following scenario:

glBindTexture( GL_TEXTURE_2D, 1 );

glBindTexture( GL_TEXTURE_2D, 1 );

Will the second glBindTexture impact the performace ? Will the OGL notice that the texture 1 is already binded and needs no binding ? Or should I take care of checking what texture has been previously binded and prevent calling glBindTexture ?

Thx in advance

The call alone is slower than a simple if-statement!
All those state changing OpenGL entrypoints need to do error checking on the parameters before they can advance to compare current state with desired state, that costs more than your if-statements required to check if the texture object id has changed.
So yes, depending on the amount of geometry in your drawing calls, this could have a measurable impact.

Thank you Relic!