Jump to content
  • Advertisement
Sign in to follow this  
Mantear

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Jason Petrasko
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?


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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Mantear
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.


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!