Browse Source

gles2: Major renderer optimization. Work in progress!

This moves all the rendering to a command list that is flushed to the GL as
necessary, making most common activities upload a single vertex buffer per
frame and dramatically reducing state changes. In pathological cases,
like Emscripten running on iOS's Safari, performance can go from a dozen
draw calls killing your performance to 1000 draw calls running smoothly.

This is work in progress, and not ready to ship. Among other things, it has
a hardcoded array that isn't checked for overflow. But the basic idea is
sound!
Ryan C. Gordon 7 years ago
parent
commit
0d3275297d

+ 1 - 0
src/render/opengles2/SDL_gles2funcs.h

@@ -75,6 +75,7 @@ SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
 SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
 SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
 SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))
 SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))
 SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *))
 SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *))
+SDL_PROC(void, glDeleteBuffers, (GLsizei, GLuint *))
 SDL_PROC(void, glBindBuffer, (GLenum, GLuint))
 SDL_PROC(void, glBindBuffer, (GLenum, GLuint))
 SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum))
 SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum))
 SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *))
 SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *))

File diff suppressed because it is too large
+ 422 - 369
src/render/opengles2/SDL_render_gles2.c


+ 14 - 14
src/render/opengles2/SDL_shaders_gles2.c

@@ -69,13 +69,13 @@ static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
     precision mediump float; \
     precision mediump float; \
     uniform sampler2D u_texture; \
     uniform sampler2D u_texture; \
-    uniform vec4 u_modulation; \
+    uniform vec4 u_color; \
     varying vec2 v_texCoord; \
     varying vec2 v_texCoord; \
     \
     \
     void main() \
     void main() \
     { \
     { \
         gl_FragColor = texture2D(u_texture, v_texCoord); \
         gl_FragColor = texture2D(u_texture, v_texCoord); \
-        gl_FragColor *= u_modulation; \
+        gl_FragColor *= u_color; \
     } \
     } \
 ";
 ";
 
 
@@ -83,7 +83,7 @@ static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
     precision mediump float; \
     precision mediump float; \
     uniform sampler2D u_texture; \
     uniform sampler2D u_texture; \
-    uniform vec4 u_modulation; \
+    uniform vec4 u_color; \
     varying vec2 v_texCoord; \
     varying vec2 v_texCoord; \
     \
     \
     void main() \
     void main() \
@@ -92,7 +92,7 @@ static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
         gl_FragColor = abgr; \
         gl_FragColor = abgr; \
         gl_FragColor.r = abgr.b; \
         gl_FragColor.r = abgr.b; \
         gl_FragColor.b = abgr.r; \
         gl_FragColor.b = abgr.r; \
-        gl_FragColor *= u_modulation; \
+        gl_FragColor *= u_color; \
     } \
     } \
 ";
 ";
 
 
@@ -100,7 +100,7 @@ static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
     precision mediump float; \
     precision mediump float; \
     uniform sampler2D u_texture; \
     uniform sampler2D u_texture; \
-    uniform vec4 u_modulation; \
+    uniform vec4 u_color; \
     varying vec2 v_texCoord; \
     varying vec2 v_texCoord; \
     \
     \
     void main() \
     void main() \
@@ -110,7 +110,7 @@ static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
         gl_FragColor.r = abgr.b; \
         gl_FragColor.r = abgr.b; \
         gl_FragColor.b = abgr.r; \
         gl_FragColor.b = abgr.r; \
         gl_FragColor.a = 1.0; \
         gl_FragColor.a = 1.0; \
-        gl_FragColor *= u_modulation; \
+        gl_FragColor *= u_color; \
     } \
     } \
 ";
 ";
 
 
@@ -118,7 +118,7 @@ static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
 static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
     precision mediump float; \
     precision mediump float; \
     uniform sampler2D u_texture; \
     uniform sampler2D u_texture; \
-    uniform vec4 u_modulation; \
+    uniform vec4 u_color; \
     varying vec2 v_texCoord; \
     varying vec2 v_texCoord; \
     \
     \
     void main() \
     void main() \
@@ -126,7 +126,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
         vec4 abgr = texture2D(u_texture, v_texCoord); \
         vec4 abgr = texture2D(u_texture, v_texCoord); \
         gl_FragColor = abgr; \
         gl_FragColor = abgr; \
         gl_FragColor.a = 1.0; \
         gl_FragColor.a = 1.0; \
-        gl_FragColor *= u_modulation; \
+        gl_FragColor *= u_color; \
     } \
     } \
 ";
 ";
 
 
@@ -163,7 +163,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
 "uniform sampler2D u_texture;\n"                                \
 "uniform sampler2D u_texture;\n"                                \
 "uniform sampler2D u_texture_u;\n"                              \
 "uniform sampler2D u_texture_u;\n"                              \
 "uniform sampler2D u_texture_v;\n"                              \
 "uniform sampler2D u_texture_v;\n"                              \
-"uniform vec4 u_modulation;\n"                                  \
+"uniform vec4 u_color;\n"                                  \
 "varying vec2 v_texCoord;\n"                                    \
 "varying vec2 v_texCoord;\n"                                    \
 "\n"                                                            \
 "\n"                                                            \
 
 
@@ -185,7 +185,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
 "\n"                                                            \
 "\n"                                                            \
 "    // That was easy. :) \n"                                   \
 "    // That was easy. :) \n"                                   \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
-"    gl_FragColor *= u_modulation;\n"                           \
+"    gl_FragColor *= u_color;\n"                           \
 "}"                                                             \
 "}"                                                             \
 
 
 #define NV12_SHADER_BODY                                        \
 #define NV12_SHADER_BODY                                        \
@@ -205,7 +205,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
 "\n"                                                            \
 "\n"                                                            \
 "    // That was easy. :) \n"                                   \
 "    // That was easy. :) \n"                                   \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
-"    gl_FragColor *= u_modulation;\n"                           \
+"    gl_FragColor *= u_color;\n"                           \
 "}"                                                             \
 "}"                                                             \
 
 
 #define NV21_SHADER_BODY                                        \
 #define NV21_SHADER_BODY                                        \
@@ -225,7 +225,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
 "\n"                                                            \
 "\n"                                                            \
 "    // That was easy. :) \n"                                   \
 "    // That was easy. :) \n"                                   \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
 "    gl_FragColor = vec4(rgb, 1);\n"                            \
-"    gl_FragColor *= u_modulation;\n"                           \
+"    gl_FragColor *= u_color;\n"                           \
 "}"                                                             \
 "}"                                                             \
 
 
 /* YUV to ABGR conversion */
 /* YUV to ABGR conversion */
@@ -284,13 +284,13 @@ static const Uint8 GLES2_FragmentSrc_TextureExternalOESSrc_[] = " \
     #extension GL_OES_EGL_image_external : require\n\
     #extension GL_OES_EGL_image_external : require\n\
     precision mediump float; \
     precision mediump float; \
     uniform samplerExternalOES u_texture; \
     uniform samplerExternalOES u_texture; \
-    uniform vec4 u_modulation; \
+    uniform vec4 u_color; \
     varying vec2 v_texCoord; \
     varying vec2 v_texCoord; \
     \
     \
     void main() \
     void main() \
     { \
     { \
         gl_FragColor = texture2D(u_texture, v_texCoord); \
         gl_FragColor = texture2D(u_texture, v_texCoord); \
-        gl_FragColor *= u_modulation; \
+        gl_FragColor *= u_color; \
     } \
     } \
 ";
 ";
 
 

Some files were not shown because too many files changed in this diff