Fixed bug #1026
authorSam Lantinga
Wed, 19 Jan 2011 23:56:16 -0800
changeset 5053b5b42be9333c
parent 5052 4cb4b18cbae3
child 5054 8af42aba8e17
Fixed bug #1026

Vittorio Giovara 2010-07-16 19:09:28 PDT

i was reading SDL_renderer_gles and i noticed that every time we there
is some gl call the gl state is modified with a couple of
glEnableClientState()/glDisableClientState.
While this is completely fine for desktops systems, this is a major
performace kill on mobile devices, right where opengles is
implemented.
Normal practice in this case is to update the glstate once, keep it
always the same and disable/enable other states only in very special
occasions.

On the web there's plenty of documentation (on the top of my head
http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW5
) and i personally tried this.
I modified my code and got a 10 fps boost, then modified SDL_render_gles and
shifted from 40 fps to 50 fps alone -- considering that i started from ~30fps i
got an 80% performance increase with this technique.

I have attached a dif of my changes, hope that it will be included in
mainstream.
src/video/SDL_renderer_gles.c
     1.1 --- a/src/video/SDL_renderer_gles.c	Wed Jan 19 23:47:50 2011 -0800
     1.2 +++ b/src/video/SDL_renderer_gles.c	Wed Jan 19 23:56:16 2011 -0800
     1.3 @@ -324,6 +324,9 @@
     1.4      data->glDisable(GL_CULL_FACE);
     1.5      data->updateSize = SDL_TRUE;
     1.6  
     1.7 +    data->glEnableClientState(GL_VERTEX_ARRAY);
     1.8 +    data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     1.9 +    
    1.10      return renderer;
    1.11  }
    1.12  
    1.13 @@ -690,9 +693,7 @@
    1.14          vertices[2*i+1] = (GLshort)points[i].y;
    1.15      }
    1.16      data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.17 -    data->glEnableClientState(GL_VERTEX_ARRAY);
    1.18      data->glDrawArrays(GL_POINTS, 0, count);
    1.19 -    data->glDisableClientState(GL_VERTEX_ARRAY);
    1.20      SDL_stack_free(vertices);
    1.21  
    1.22      return 0;
    1.23 @@ -719,7 +720,6 @@
    1.24          vertices[2*i+1] = (GLshort)points[i].y;
    1.25      }
    1.26      data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.27 -    data->glEnableClientState(GL_VERTEX_ARRAY);
    1.28      if (count > 2 && 
    1.29          points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
    1.30          /* GL_LINE_LOOP takes care of the final segment */
    1.31 @@ -728,7 +728,6 @@
    1.32      } else {
    1.33          data->glDrawArrays(GL_LINE_STRIP, 0, count);
    1.34      }
    1.35 -    data->glDisableClientState(GL_VERTEX_ARRAY);
    1.36      SDL_stack_free(vertices);
    1.37  
    1.38      return 0;
    1.39 @@ -748,7 +747,6 @@
    1.40                      (GLfloat) renderer->b * inv255f,
    1.41                      (GLfloat) renderer->a * inv255f);
    1.42  
    1.43 -    data->glEnableClientState(GL_VERTEX_ARRAY);
    1.44      for (i = 0; i < count; ++i) {
    1.45          const SDL_Rect *rect = rects[i];
    1.46          GLshort minx = rect->x;
    1.47 @@ -768,7 +766,6 @@
    1.48          data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.49          data->glDrawArrays(GL_LINE_LOOP, 0, 4);
    1.50      }
    1.51 -    data->glDisableClientState(GL_VERTEX_ARRAY);
    1.52  
    1.53      return 0;
    1.54  }
    1.55 @@ -787,7 +784,6 @@
    1.56                      (GLfloat) renderer->b * inv255f,
    1.57                      (GLfloat) renderer->a * inv255f);
    1.58  
    1.59 -    data->glEnableClientState(GL_VERTEX_ARRAY);
    1.60      for (i = 0; i < count; ++i) {
    1.61          const SDL_Rect *rect = rects[i];
    1.62          GLshort minx = rect->x;
    1.63 @@ -807,7 +803,6 @@
    1.64          data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.65          data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    1.66      }
    1.67 -    data->glDisableClientState(GL_VERTEX_ARRAY);
    1.68  
    1.69      return 0;
    1.70  }
    1.71 @@ -950,12 +945,8 @@
    1.72          texCoords[7] = maxv;
    1.73  
    1.74          data->glVertexPointer(2, GL_SHORT, 0, vertices);
    1.75 -        data->glEnableClientState(GL_VERTEX_ARRAY);
    1.76          data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    1.77 -        data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    1.78          data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    1.79 -        data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    1.80 -        data->glDisableClientState(GL_VERTEX_ARRAY);
    1.81      }
    1.82  
    1.83      data->glDisable(GL_TEXTURE_2D);