Skip to main content
gamedev.net
🔒 Locked

glBindTexture, quick performance question

Started by virvelvinden Jul 6, 2008 at 9:41 AM 6 replies 3.7k views
Original Post
virvelvinden
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? 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.
Yann L
Yann L
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.
MARS_999
MARS_999
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?
V-man
V-man
if(currentlyBoundTextureID != theTextureYouWantToBind){   currentlyBoundTextureID = theTextureYouWantToBind;   glBindTexture(X, currentlyBoundTextureID);}
virvelvinden
virvelvinden
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!
zedz
zedz
>>exactly, this is what I mean. what I don't get is if it's necessary!

if u want optimal performance it is
Yann L
Yann L
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).
zedz
zedz
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)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.