How expensive is calling glBindTexture2D multiple times?


This may be a really stupid question, but I was just wondering something. If I draw a tesselated surface and each patch has a texture associated with it, how expensive is it to call glBindTexture2D for each patch, even if the texture associated with different patches is the same? If the surface for example is a brick wall, then all the patches would have the same texture associated with it (i.e. bricks), so it should only be nesecary to call glBindTexture once. The reason why every patch would have a reference to a texture is because one of the patches might use a different one, say to simulate a hole in the wall or something. So is calling glBindTexture multiple times while rendering expensive?

Hope this made sense

Unnecessary calls should always be avoided. Texture bindings can be expensive. Don’t know if it’s cheaper to “rebind” a texture, but it’s still costs. You should keep track of the texture states yourself. For example, when you bind a texture, store it’s id in a local variable, and when binding a texture again, check the current id with the id you want to bind. Another way is to sort every primitive by texture. That is, first draw everything with one texture id, then draw everything wither another texture id, and so on. This way you will bind a texture only once.

[This message has been edited by Bob (edited 12-19-2002).]