Possible Duplicate:
Making redundant OpenGL calls
Let’s say I have an Image class that has a method called draw that draws a part of the image on the screen, and also stores a handle to a 2d texture that contains the actual image data.
Is it OK to implement the draw() method like this?
// ix, iy, w and h specify which part of the image to draw
void Image::draw(int x, int y, int ix, int iy, int w, int h)
{
glBindTexture(GL_TEXTURE_2D, m_textureHandle);
//and then draw the specified part of the image
}
My main concern here is the call to glBindTexture. Is it correct to assume that if the texture is already bound, this call won’t result in some kind of a performance hit?
Having worked on some implementatioins (drivers) for OpenGL, OpenVG and similar, the glBindTexture really just stores the m_textureHandle in some “good place” inside the “current context”. It is not a difficult thing to do, and shouldn’t “cost much”.
If you are trying to save every last cycle of execution, by all means add a variable to determine if you have already bound your texture, and only do it if needed. But in general, I would be very surprised if you can’t save 5-10x the amount of time by doing other clever stuff.