glBindTexture

dave05
Unregistered
 
Post: #1
Currently in my code, the way it's structured, when I draw the same sprite 8 times in a row, for example, I call glBindTexture every single one of those 8 times.

ie, here is the routine that i call

Code:
void    OGL_DrawImageInRectWithOriginRotation(
                GLuint img, CGRect imgRect, int centerX, int centerY, int rotation)
{
    glPushMatrix();
        
        glTranslatef(centerX, centerY, 0);
        glRotatef(rotation,0,0,1);
        
        glBindTexture( GL_TEXTURE_2D, img );
        
        glBegin(GL_QUADS);
            
            glTexCoord2f(    0.0f,    0.0f);
            glVertex2i(    imgRect.origin.x,    imgRect.origin.y );
            
            glTexCoord2f(    1.0f,    0.0f);
            glVertex2i(    imgRect.size.width+imgRect.origin.x,
                        imgRect.origin.y);
            
            glTexCoord2f(    1.0f,    1.0f);
            glVertex2i(    imgRect.size.width+imgRect.origin.x,
                        imgRect.size.height+imgRect.origin.y);
            
            glTexCoord2f(    0.0f,    1.0f);
            glVertex2i(    imgRect.origin.x,
                        imgRect.size.height+imgRect.origin.y);
        glEnd();
    
    glPopMatrix();
}

now, I was just wondering if it's faster to draw repeatedly without rebinding.. ie, should I create a separate function that does the binding, then draw several quads before binding the next sprite...?
Quote this message in a reply
Member
Posts: 28
Joined: 2005.04
Post: #2
dave05 Wrote:Currently in my code, the way it's structured, when I draw the same sprite 8 times in a row, for example, I call glBindTexture every single one of those 8 times.
...
now, I was just wondering if it's faster to draw repeatedly without rebinding.. ie, should I create a separate function that does the binding, then draw several quads before binding the next sprite...?

I am going to say of course it would be faster, less calls to glBindTexture, but I have no idea how much overhead there is, so how much of a speed hit? I have no idea. You will have to use OpenGL Profiler to find out.

Remember optimization is cool, but it takes a good programmer to know when and where to optimize, if calling glBindTexture a million times, creates litteraly no overhead, then dont bother the time it will take you to re-implement that. Stick to the expensive places first, and toss in a nice
Code:
#warning glBindTexture is being called a lot, possible optimization here
to get a nice little flag every time you build. Just my 2cents.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #3
throwing all those state calls will slow you down. If you've got all your GL wrapped up in good OOP, it shouldn't be a problem to cache that part of the state. Another thing I like to cache is the current context. I know in NSGL (not sure about here) -makeCurrentContext is ghastly slow.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #4
Oh yeah, and besides, if you've got a good rendering pipeline, you can coalesce all those immediate mode calls into a single vertex array and get lots and lots of speed up.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ...) throws GL errors ravuya 1 6,069 Nov 2, 2006 12:06 AM
Last Post: ravuya
  glBindTexture with ALPHA sux on NVIDIA Cards !? hgore69 1 3,132 Mar 12, 2005 01:35 PM
Last Post: OneSadCookie