Jump to content
  • Advertisement
Sign in to follow this  
lanhaiou

OpenGL is glBindTexture() not efficency ?

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

Hello,

I am trying to write a tile based 2D game using openGL, and I'm new to openGL..
I heard that glBindTexture() is not efficency and we'd better to bind texture only one time and drawing all the staff using this texture(this texture

constains all the tiles we need).
so I have 2 questions, could anybody help? thanks very much!
1\ Is this description above right ?
2\ Is the following Game logic the right way to rendering a game with good efficency?
if not, could I have some indication? thanks?

/* this render() is called every 30 millisecond to render the game.
there may be about 2000 tiles need to be rendered one time. */

render()
{
glEnable2D;
/*this texture contains all the tiles needed in the game*/
glBindTexture(GL_TEXTURE_2D, mTexture);

glClear();
for(...)// the drawing loop to draw all the staff
{
/* draw the needed tiles from the same texture */
glBegin();
//drawing...
glEnd();
}
SwapBuffers();
glDisable2D;
}

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
glBindTexture will likely cause a pipeline stall at the next draw call. Insofar, glBindTexture is not inefficient itself, but using it too often is. I say "likely" because it is possible that it does not cause a stall, depending on the hardware (but you have to assume the worst case, not the best case).

On the other hand, glBegin/glEnd is not efficient for drawing thousands of tiles (i.e. single quads) either.

What you want to do ideally is bind a texture once, bind a vertex buffer, and draw your 2000 quads with one call to glDrawElements. Even using a plain old vertex array (i.e. not a buffer object) would be much preferrable, because it's much more efficient for the GL to upload that block of data.

Share this post


Link to post
Share on other sites
Thank you very much !smile.png


glBindTexture will likely cause a pipeline stall at the next draw call. Insofar, glBindTexture is not inefficient itself, but using it too often is. I say "likely" because it is possible that it does not cause a stall, depending on the hardware (but you have to assume the worst case, not the best case).

On the other hand, glBegin/glEnd is not efficient for drawing thousands of tiles (i.e. single quads) either.

What you want to do ideally is bind a texture once, bind a vertex buffer, and draw your 2000 quads with one call to glDrawElements. Even using a plain old vertex array (i.e. not a buffer object) would be much preferrable, because it's much more efficient for the GL to upload that block of data.

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!