Jump to content
  • Advertisement
Sign in to follow this  
virvelvinden

OpenGL glBindTexture, quick performance question

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

if i make two glBindTexture calls with the exact same parameters, does the second call take less time than the first? Or even better, does the second call get ignored? The reason i'm asking is that i'm ordering my game objects by texture to minimize the number of glBindTexture calls, and i'm just curious whether or not OpenGL voids all those identical calls or not.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by virvelvinden
if i make two glBindTexture calls with the exact same parameters, does the second call take less time than the first? Or even better, does the second call get ignored?

Implementation dependent.

Quote:

The reason i'm asking is that i'm ordering my game objects by texture to minimize the number of glBindTexture calls, and i'm just curious whether or not OpenGL voids all those identical calls or not.

Don't worry about this. Just make sure that your geometry is sorted by texture (and by shaders, and by other expensive states), and try to avoid too many small batches. The driver will take care of everything else.

Share this post


Link to post
Share on other sites
Here is an idea, and I am wondering about this, say you have access to texture arrays, and could get by using all the 16 texture units, you could possibly bind the textures once for the entire app, and just load all the required textures you need into the arrays... Anyone done this?

Share this post


Link to post
Share on other sites

if(currentlyBoundTextureID != theTextureYouWantToBind)
{
currentlyBoundTextureID = theTextureYouWantToBind;
glBindTexture(X, currentlyBoundTextureID);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Yann L

Don't worry about this. Just make sure that your geometry is sorted by texture (and by shaders, and by other expensive states)


I don't understand! With sorted, do you mean sorted in respect to rendering order? I mean, that things with the same texture gets rendered together?


Original post by V-man
if(currentlyBoundTextureID != theTextureYouWantToBind)
{
currentlyBoundTextureID = theTextureYouWantToBind;
glBindTexture(X, currentlyBoundTextureID);
}



exactly, this is what I mean. what I don't get is if it's necessary!

Share this post


Link to post
Share on other sites
>>exactly, this is what I mean. what I don't get is if it's necessary!

if u want optimal performance it is

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
>>exactly, this is what I mean. what I don't get is if it's necessary!

if u want optimal performance it is

Not really. If your engine is correctly designed, then such a check is neither required nor will it make a noticeable difference.

You will have to batch your geometry according to certain state changes, in a certain order. The primary sort key is the most heavy state change (usually shader programs), the secondary key the second most heavy state change, etc. So if you minimize the number of batches to render per frame, you will rarely have to call glBindTexture with the same value consecutively. It does happen, but it usually doesn't have a noticeable effect on performance. Other state changes in modern engines are much more critical (eg. changing large pools of uniforms, or similar).

Share this post


Link to post
Share on other sites
yada yada ;)
i hear what you're saying
but instead of texture changes insert shader programs etc in the question, ie its cheaper to do it yourself (no calls to the driver) which is what the OP was asking I think, ie the OP I assume has not written a masterful scenegraph that mirrors the state + batches the geometry in a nice order.

hmmm OT i dont think i even 'sort' batches any more, i just set a 'light '+ call all meshs in order by material (ok its sorting by batch ;). but its certainly changed then 5 years ago when u had to watch vert counts

Quote:
you could possibly bind the textures once for the entire app, and just load all the required textures you need into the arrays... Anyone done this

its possible, with me i have fixed units bound
A/dir/spot light shadowmap
B/point light shadowmap
C/environmentmap
D/skybox
E/projected light texture
F/3d noise texture
G/3d noise texture2

thus theyre out of bounds personally i just stick those in 9-16 + just do normamap/diffusemap etc myself on the same units.. eg tex0 == diffuse 1 == normalmap. I dont try + stick another diffusemap in tex4 (as then the shader is not setup ie u have to change uniforms)

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!