# HG changeset patch # User Sam Lantinga # Date 1295510176 28800 # Node ID b5b42be9333cece413f31c602a64d2113c774081 # Parent 4cb4b18cbae3a45f0bfe1ab1356024e2113eb993 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. diff -r 4cb4b18cbae3 -r b5b42be9333c src/video/SDL_renderer_gles.c --- a/src/video/SDL_renderer_gles.c Wed Jan 19 23:47:50 2011 -0800 +++ b/src/video/SDL_renderer_gles.c Wed Jan 19 23:56:16 2011 -0800 @@ -324,6 +324,9 @@ data->glDisable(GL_CULL_FACE); data->updateSize = SDL_TRUE; + data->glEnableClientState(GL_VERTEX_ARRAY); + data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); + return renderer; } @@ -690,9 +693,7 @@ vertices[2*i+1] = (GLshort)points[i].y; } data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glEnableClientState(GL_VERTEX_ARRAY); data->glDrawArrays(GL_POINTS, 0, count); - data->glDisableClientState(GL_VERTEX_ARRAY); SDL_stack_free(vertices); return 0; @@ -719,7 +720,6 @@ vertices[2*i+1] = (GLshort)points[i].y; } data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glEnableClientState(GL_VERTEX_ARRAY); if (count > 2 && points[0].x == points[count-1].x && points[0].y == points[count-1].y) { /* GL_LINE_LOOP takes care of the final segment */ @@ -728,7 +728,6 @@ } else { data->glDrawArrays(GL_LINE_STRIP, 0, count); } - data->glDisableClientState(GL_VERTEX_ARRAY); SDL_stack_free(vertices); return 0; @@ -748,7 +747,6 @@ (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - data->glEnableClientState(GL_VERTEX_ARRAY); for (i = 0; i < count; ++i) { const SDL_Rect *rect = rects[i]; GLshort minx = rect->x; @@ -768,7 +766,6 @@ data->glVertexPointer(2, GL_SHORT, 0, vertices); data->glDrawArrays(GL_LINE_LOOP, 0, 4); } - data->glDisableClientState(GL_VERTEX_ARRAY); return 0; } @@ -787,7 +784,6 @@ (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - data->glEnableClientState(GL_VERTEX_ARRAY); for (i = 0; i < count; ++i) { const SDL_Rect *rect = rects[i]; GLshort minx = rect->x; @@ -807,7 +803,6 @@ data->glVertexPointer(2, GL_SHORT, 0, vertices); data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } - data->glDisableClientState(GL_VERTEX_ARRAY); return 0; } @@ -950,12 +945,8 @@ texCoords[7] = maxv; data->glVertexPointer(2, GL_SHORT, 0, vertices); - data->glEnableClientState(GL_VERTEX_ARRAY); data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); - data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); - data->glDisableClientState(GL_VERTEX_ARRAY); } data->glDisable(GL_TEXTURE_2D);