OpenGL - glBindTexture - premature optimization?

I saw a code example (especially in iOS GL projects) where the current GL texture name is cached and the comparison is done before glBindTexture is called. The goal is to avoid unnecessary calls to glBindTexture.

eg.

if (textureName != cachedTextureName) { glBindTexture(GL_TEXTURE_2D, textureName); cachedTextureName = textureName; } 

This approach requires ALL glBindTexture calls to be handled similarly, preferably through a wrapper. But the inclusion of third-party code makes this problem problematic, and is also another thing to remember.

Q. Is this a useful optimization? Or is the OpenGL implementation smart enough to ignore calls to glBlindTexture where the texture name has not changed?

Thanks.

+4
source share
1 answer

This is not called in the specification as far as I have seen. In practice, it turns out that many implementations actually do some processing if you retype the same texture as the relative drop in performance, if you don't check the current texture. I would recommend using the test, if possible, just to make sure that the implementation details do not adversely affect your program.

Generally speaking, it’s very useful to ignore OpenGL startup with your own state handling, so that you can query for a state, such as related texture or active matrices, without calling glGet , which will be almost always slower than your custom processing.This also allows you to disable invalid behavior and generally simplifies your program.

+3
source

All Articles