fixed gles/gles2 renderer creation fail on Android when default major/minor version doesn't match
authorCarniBlood
Thu, 19 Dec 2013 06:01:18 +0900
changeset 8256bcfb214c2950
parent 8255 49af9be342cd
child 8257 a1563cbde7a5
fixed gles/gles2 renderer creation fail on Android when default major/minor version doesn't match
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/opengles/SDL_render_gles.c	Tue Feb 25 10:04:49 2014 -0800
     1.2 +++ b/src/render/opengles/SDL_render_gles.c	Thu Dec 19 06:01:18 2013 +0900
     1.3 @@ -279,15 +279,24 @@
     1.4      GLES_RenderData *data;
     1.5      GLint value;
     1.6      Uint32 windowFlags;
     1.7 +    int profileMask, majorVersion, minorVersion;
     1.8 +
     1.9 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
    1.10 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
    1.11 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
    1.12  
    1.13      SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    1.14      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
    1.15      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    1.16  
    1.17      windowFlags = SDL_GetWindowFlags(window);
    1.18 -    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
    1.19 +    if (!(windowFlags & SDL_WINDOW_OPENGL) ||
    1.20 +        profileMask != SDL_GL_CONTEXT_PROFILE_ES || majorVersion != 1 || minorVersion != 1) {
    1.21          if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
    1.22              /* Uh oh, better try to put it back... */
    1.23 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
    1.24 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
    1.25 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
    1.26              SDL_RecreateWindow(window, windowFlags);
    1.27              return NULL;
    1.28          }
     2.1 --- a/src/render/opengles2/SDL_render_gles2.c	Tue Feb 25 10:04:49 2014 -0800
     2.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Thu Dec 19 06:01:18 2013 +0900
     2.3 @@ -1740,15 +1740,24 @@
     2.4      Uint32 windowFlags;
     2.5      GLint window_framebuffer;
     2.6      GLint value;
     2.7 +    int profileMask, majorVersion, minorVersion;
     2.8 +
     2.9 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
    2.10 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
    2.11 +    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
    2.12  
    2.13      SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    2.14      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    2.15      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
    2.16  
    2.17      windowFlags = SDL_GetWindowFlags(window);
    2.18 -    if (!(windowFlags & SDL_WINDOW_OPENGL)) {
    2.19 +    if (!(windowFlags & SDL_WINDOW_OPENGL) ||
    2.20 +        profileMask != SDL_GL_CONTEXT_PROFILE_ES || majorVersion != 2 || minorVersion != 0) {
    2.21          if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
    2.22              /* Uh oh, better try to put it back... */
    2.23 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
    2.24 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
    2.25 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
    2.26              SDL_RecreateWindow(window, windowFlags);
    2.27              return NULL;
    2.28          }