[Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally
authorGabriel Jacobo <gabomdq@gmail.com>
Fri, 16 Aug 2013 13:37:27 -0300
changeset 7642 303214c66577
parent 7641 0cd36d20df2b
child 7643 bae07d884b52
[Bug 2042] OpenGL ES renderer tries to load OES functions unconditionally Also, fail more gracefully when creating texture to avoid double free errors.
src/render/opengles/SDL_glesfuncs.h
src/render/opengles/SDL_render_gles.c
--- a/src/render/opengles/SDL_glesfuncs.h	Fri Aug 16 09:20:33 2013 -0700
+++ b/src/render/opengles/SDL_glesfuncs.h	Fri Aug 16 13:37:27 2013 -0300
@@ -1,6 +1,6 @@
 SDL_PROC(void, glBindTexture, (GLenum, GLuint))
 SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
-SDL_PROC(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
+SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
 SDL_PROC(void, glClear, (GLbitfield))
 SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
 SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
@@ -8,11 +8,11 @@
 SDL_PROC(void, glDisable, (GLenum))
 SDL_PROC(void, glDisableClientState, (GLenum array))
 SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
-SDL_PROC(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
 SDL_PROC(void, glEnable, (GLenum))
 SDL_PROC(void, glEnableClientState, (GLenum))
 SDL_PROC(void, glFinish, (void))
-SDL_PROC(void, glGenFramebuffersOES, (GLsizei, GLuint *))
+SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *))
 SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
 SDL_PROC(GLenum, glGetError, (void))
 SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
@@ -30,13 +30,13 @@
 SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
 SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
 SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
-SDL_PROC(void, glBindFramebufferOES, (GLenum, GLuint))
-SDL_PROC(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
-SDL_PROC(GLenum, glCheckFramebufferStatusOES, (GLenum))
+SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
+SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
+SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
 SDL_PROC(void, glPushMatrix, (void))
 SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat))
 SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat))
 SDL_PROC(void, glPopMatrix, (void))
-SDL_PROC(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
+SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/render/opengles/SDL_render_gles.c	Fri Aug 16 09:20:33 2013 -0700
+++ b/src/render/opengles/SDL_render_gles.c	Fri Aug 16 13:37:27 2013 -0300
@@ -96,7 +96,7 @@
     GLES_CreateRenderer,
     {
      "opengles",
-     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ),
      1,
      {SDL_PIXELFORMAT_ABGR8888},
      0,
@@ -113,8 +113,10 @@
     } current;
 
 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#define SDL_PROC_OES SDL_PROC
 #include "SDL_glesfuncs.h"
 #undef SDL_PROC
+#undef SDL_PROC_OES
     SDL_bool GL_OES_framebuffer_object_supported;
     GLES_FBOList *framebuffers;
     GLuint window_framebuffer;
@@ -191,10 +193,15 @@
             return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \
         } \
     } while ( 0 );
+#define SDL_PROC_OES(ret,func,params) \
+    do { \
+        data->func = SDL_GL_GetProcAddress(#func); \
+    } while ( 0 );    
 #endif /* _SDL_NOGETPROCADDR_ */
 
 #include "SDL_glesfuncs.h"
 #undef SDL_PROC
+#undef SDL_PROC_OES
     return 0;
 }
 
@@ -465,12 +472,17 @@
         }
     }
 
-    texture->driverdata = data;
+    
     if (texture->access == SDL_TEXTUREACCESS_TARGET) {
-       data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
+        if (!renderdata->GL_OES_framebuffer_object_supported) {
+            SDL_free(data);
+            return SDL_SetError("GL_OES_framebuffer_object not supported");
+        }
+        data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
     } else {
-       data->fbo = NULL;
+        data->fbo = NULL;
     }
+    
 
     renderdata->glGetError();
     renderdata->glEnable(GL_TEXTURE_2D);
@@ -503,8 +515,11 @@
 
     result = renderdata->glGetError();
     if (result != GL_NO_ERROR) {
+        SDL_free(data);
         return GLES_SetError("glTexImage2D()", result);
     }
+    
+    texture->driverdata = data;
     return 0;
 }
 
@@ -602,6 +617,10 @@
     GLenum status;
 
     GLES_ActivateRenderer(renderer);
+    
+    if (!data->GL_OES_framebuffer_object_supported) {
+        return SDL_SetError("Can't enable render target support in this renderer");
+    }
 
     if (texture == NULL) {
         data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);