Sign in to follow this  
LonelyStar

OpenGL Drawing objects in texture-use-order=better performance

Recommended Posts

Hi everbody, Would my application benefit from drawing all objects in the order, so that objects using the same texture are drawn directly after each other? Would OpenGL bother, if I do a unnsessary texture bind like: glBindTexture(Text1); Draw(Object1); glBindTexture(Text1); Draw(Object2); Thanks! Nathan

Share this post


Link to post
Share on other sites
yes yes yes (picture scene from when harry met sally here)... :)

[edit] though the entire point to this is that you dont have to do the extra texture setting [/edit]

Share this post


Link to post
Share on other sites
Wether or not glBindTexture() would actually bother going through the redundant Texture Setting is entirely up to the driver. Most current drivers probably do include some sort of redundancy check. I did some simple tests a while back (nothing fancy) comparing a single glBindTexture() to multiple redundant calls for each object and really didn't see much of a difference in frame rate. (Using a Fx5500)

HOWEVER

Just because this one test turned out okay does NOT mean that you should just let it slide. Drivers can be an unpredictable bunch, and it's ALWAYS better to handel things like this on your own, so that you know it will act the same no matter what system someone is using. Usually simply tracking the last used texture is sufficent:


GLuint lastTexID = -1;

void MyTextureBind( GLuint texID )
{
if(lastTexID != texID)
{
glBindTexture(texID);
lastTexID = texID;
}
}



Calling a function like this in place of glBindTexture() ensures that you don't get any redundant texture sets. This is especially effective if your render queue is already sorted by texture.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this