# glBindTexture() cost

This topic is 4097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings, I have a situation where I'm unsure of where to put a call to glBindTexture(). I can either put it within a display list that will get called a bunch of times, or I can put it outside the display list and get called an order of magnitude or two less. Which would be better? Also, if I attempt to re-bind an already bound texture, how much time does that take? Is the driver smart enough to know the texture is already bound and not do anything? Thanks.

##### Share on other sites
I suppose your question makes me ask one in return: If you could not include the glBindTexture() in the display list, then why would you want it there anyway?

The way you present the question feels like a no-brainer. Don't put it in if you don't have too. Also, in regards to the intelligence of drivers- Its often easiest as a programmer to assume: All code I can't see is poor quality.

##### Share on other sites
Quote:
 Original post by Jason PetraskoI suppose your question makes me ask one in return: If you could not include the glBindTexture() in the display list, then why would you want it there anyway?

I would want it there if: a) calling glBindTexture() on the texture that is already bound causes nothing to happen (the driver recognizes that the texture I'm trying to bind is the current one and does nothing) and b) having the call to glBindTexture() within a display list is faster than calling it outside of a display list. Lots of 'if's that I don't have any answers to. I've ran my program both ways, but the performance looks to be the same (I'm not stressing the system at all, though).

It would also be nice to be able to include it within the display list so I don't have to remember to check/bind the texture outside of the display list every time.

##### Share on other sites
Point B is a very good point, and one that never came to mind. I wonder if any OpenGL gurus have something to say about that.

##### Share on other sites
If you really want to use display lists and worried about performance related to (b), just benchmark it.

The simplest solution is to keep a global parameter. Call it
GLuint CurrentlyBoundTexture;

if(CurrentlyBoundTexture != TheTextureIWantToBind){   CurrentlyBoundTexture = TheTextureIWantToBind;   glBindTexture(...., CurrentlyBoundTexture);}

##### Share on other sites
Quote:
 Original post by MantearAlso, if I attempt to re-bind an already bound texture, how much time does that take? Is the driver smart enough to know the texture is already bound and not do anything? Thanks.

I suspect this depends on individual implementations but when I've benchmarked double binding a texture it cost a lot less than binding 2 different textures but it still cost as much as other gl state changes. I'm guessing it checks if the textures is already bound but it has to ask the gpu rather than keeping a local copy so it checks but it won't take very many double binds before checking yourself will pay off.

1. 1
2. 2
Rutin
18
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 9
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013665
×