Jump to content
  • Advertisement
Sign in to follow this  
Frequency

OpenGL Question of efficiency - binding textures

This topic is 4552 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

Sorry for the very terse post, but it's a simple question with a (hopefully) simple answer that is not easily found with a search engine. If one were to do something like this: unsigned int id; glGenTextures(1, &id); // load a texture here glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id); Would this cost much more than binding the texture once, or will OpenGL immediately recognize this repeat and act accordingly? If it will needlessly complicate my graphics engine I don't want to separate binding and drawing (in the event of using the same tex to draw many things) but if it's a large matter of efficiency, it'll have to be so. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The most efficient way to do that, is do the following:

unsigned int *id[numTextures];

glBindTexture(....,id[0] );
glBindTexture(....,id[1]);
.
.
.
and put that code in your Init method. then at any given time you can access any one of those textures.

Share this post


Link to post
Share on other sites
Quote:
Original post by Frequency
Would this cost much more than binding the texture once, or will OpenGL immediately recognize this repeat and act accordingly?


Depends on the driver, the spec doesn't mandate it at all.
Your best bet when rendering is to sort by texture anyways (well, after any shaders), as such you shouldn't need to rebind like that

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Depends on the driver, the spec doesn't mandate it at all.
Your best bet when rendering is to sort by texture anyways (well, after any shaders), as such you shouldn't need to rebind like that


HMMM I'm guessing I do my rendering a lot differently and a lot worse than you do. When an object request a texture be drawn, say a textured rectangle, the Graphics object just does it on the spot and it's revealed when I swap buffers (using SDL). Is the recommended way to do rendering having the Graphics object keep a laundry list (of things that need to be rendered, where, and how) and do it in a rendering phase at the end of the game loop?

EDIT: Oh, and I'll probably just put myself in a situation where I'll be rebinding textures right now and see if it's enough of a performance hit to worry about it. Thanks for the heads up.

Share this post


Link to post
Share on other sites

static int boundtexes[numtextureunits];

if(id != boundtexes[layerid])
{
/*
take case of the active layer
*/


//bind texture
glBindTexture(GL_TEXTURE_2D,id);
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!