[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 7642303214c66577
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
     1.1 --- a/src/render/opengles/SDL_glesfuncs.h	Fri Aug 16 09:20:33 2013 -0700
     1.2 +++ b/src/render/opengles/SDL_glesfuncs.h	Fri Aug 16 13:37:27 2013 -0300
     1.3 @@ -1,6 +1,6 @@
     1.4  SDL_PROC(void, glBindTexture, (GLenum, GLuint))
     1.5  SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
     1.6 -SDL_PROC(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
     1.7 +SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
     1.8  SDL_PROC(void, glClear, (GLbitfield))
     1.9  SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
    1.10  SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
    1.11 @@ -8,11 +8,11 @@
    1.12  SDL_PROC(void, glDisable, (GLenum))
    1.13  SDL_PROC(void, glDisableClientState, (GLenum array))
    1.14  SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
    1.15 -SDL_PROC(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
    1.16 +SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
    1.17  SDL_PROC(void, glEnable, (GLenum))
    1.18  SDL_PROC(void, glEnableClientState, (GLenum))
    1.19  SDL_PROC(void, glFinish, (void))
    1.20 -SDL_PROC(void, glGenFramebuffersOES, (GLsizei, GLuint *))
    1.21 +SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *))
    1.22  SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
    1.23  SDL_PROC(GLenum, glGetError, (void))
    1.24  SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
    1.25 @@ -30,13 +30,13 @@
    1.26  SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
    1.27  SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
    1.28  SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
    1.29 -SDL_PROC(void, glBindFramebufferOES, (GLenum, GLuint))
    1.30 -SDL_PROC(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
    1.31 -SDL_PROC(GLenum, glCheckFramebufferStatusOES, (GLenum))
    1.32 +SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
    1.33 +SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
    1.34 +SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
    1.35  SDL_PROC(void, glPushMatrix, (void))
    1.36  SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat))
    1.37  SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat))
    1.38  SDL_PROC(void, glPopMatrix, (void))
    1.39 -SDL_PROC(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
    1.40 +SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
    1.41  
    1.42  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/render/opengles/SDL_render_gles.c	Fri Aug 16 09:20:33 2013 -0700
     2.2 +++ b/src/render/opengles/SDL_render_gles.c	Fri Aug 16 13:37:27 2013 -0300
     2.3 @@ -96,7 +96,7 @@
     2.4      GLES_CreateRenderer,
     2.5      {
     2.6       "opengles",
     2.7 -     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
     2.8 +     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ),
     2.9       1,
    2.10       {SDL_PIXELFORMAT_ABGR8888},
    2.11       0,
    2.12 @@ -113,8 +113,10 @@
    2.13      } current;
    2.14  
    2.15  #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
    2.16 +#define SDL_PROC_OES SDL_PROC
    2.17  #include "SDL_glesfuncs.h"
    2.18  #undef SDL_PROC
    2.19 +#undef SDL_PROC_OES
    2.20      SDL_bool GL_OES_framebuffer_object_supported;
    2.21      GLES_FBOList *framebuffers;
    2.22      GLuint window_framebuffer;
    2.23 @@ -191,10 +193,15 @@
    2.24              return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \
    2.25          } \
    2.26      } while ( 0 );
    2.27 +#define SDL_PROC_OES(ret,func,params) \
    2.28 +    do { \
    2.29 +        data->func = SDL_GL_GetProcAddress(#func); \
    2.30 +    } while ( 0 );    
    2.31  #endif /* _SDL_NOGETPROCADDR_ */
    2.32  
    2.33  #include "SDL_glesfuncs.h"
    2.34  #undef SDL_PROC
    2.35 +#undef SDL_PROC_OES
    2.36      return 0;
    2.37  }
    2.38  
    2.39 @@ -465,12 +472,17 @@
    2.40          }
    2.41      }
    2.42  
    2.43 -    texture->driverdata = data;
    2.44 +    
    2.45      if (texture->access == SDL_TEXTUREACCESS_TARGET) {
    2.46 -       data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
    2.47 +        if (!renderdata->GL_OES_framebuffer_object_supported) {
    2.48 +            SDL_free(data);
    2.49 +            return SDL_SetError("GL_OES_framebuffer_object not supported");
    2.50 +        }
    2.51 +        data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
    2.52      } else {
    2.53 -       data->fbo = NULL;
    2.54 +        data->fbo = NULL;
    2.55      }
    2.56 +    
    2.57  
    2.58      renderdata->glGetError();
    2.59      renderdata->glEnable(GL_TEXTURE_2D);
    2.60 @@ -503,8 +515,11 @@
    2.61  
    2.62      result = renderdata->glGetError();
    2.63      if (result != GL_NO_ERROR) {
    2.64 +        SDL_free(data);
    2.65          return GLES_SetError("glTexImage2D()", result);
    2.66      }
    2.67 +    
    2.68 +    texture->driverdata = data;
    2.69      return 0;
    2.70  }
    2.71  
    2.72 @@ -602,6 +617,10 @@
    2.73      GLenum status;
    2.74  
    2.75      GLES_ActivateRenderer(renderer);
    2.76 +    
    2.77 +    if (!data->GL_OES_framebuffer_object_supported) {
    2.78 +        return SDL_SetError("Can't enable render target support in this renderer");
    2.79 +    }
    2.80  
    2.81      if (texture == NULL) {
    2.82          data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);