glBindTexture, quick performance question

Started by
6 comments, last by zedz 15 years, 9 months ago
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.
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.
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?
if(currentlyBoundTextureID != theTextureYouWantToBind){   currentlyBoundTextureID = theTextureYouWantToBind;   glBindTexture(X, currentlyBoundTextureID);}
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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!
>>exactly, this is what I mean. what I don't get is if it's necessary!

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

This topic is closed to new replies.

Advertisement