Improve window recreation logic in OpenGL* renderers
authorGabriel Jacobo
Thu, 27 Feb 2014 20:21:46 -0300
changeset 826470d4dc60aa01
parent 8263 e22c4959e385
child 8265 1ed54c57d6c7
Improve window recreation logic in OpenGL* renderers
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Wed Feb 26 16:27:03 2014 -0800
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Thu Feb 27 20:21:46 2014 -0300
     1.3 @@ -32,8 +32,12 @@
     1.4  #include <OpenGL/OpenGL.h>
     1.5  #endif
     1.6  
     1.7 +/* To prevent unnecessary window recreation, 
     1.8 + * these should match the defaults selected in SDL_GL_ResetAttributes 
     1.9 + */
    1.10 +
    1.11  #define RENDERER_CONTEXT_MAJOR 2
    1.12 -#define RENDERER_CONTEXT_MINOR 0
    1.13 +#define RENDERER_CONTEXT_MINOR 1
    1.14  
    1.15  /* OpenGL renderer implementation */
    1.16  
    1.17 @@ -389,13 +393,14 @@
    1.18      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
    1.19      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
    1.20      
    1.21 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    1.22 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    1.23 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    1.24 -
    1.25      window_flags = SDL_GetWindowFlags(window);
    1.26      if (!(window_flags & SDL_WINDOW_OPENGL) ||
    1.27 -        profile_mask != SDL_GL_CONTEXT_PROFILE_CORE || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
    1.28 +        profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
    1.29 +        
    1.30 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
    1.31 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    1.32 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    1.33 +
    1.34          if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
    1.35              /* Uh oh, better try to put it back... */
    1.36              SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
     2.1 --- a/src/render/opengles/SDL_render_gles.c	Wed Feb 26 16:27:03 2014 -0800
     2.2 +++ b/src/render/opengles/SDL_render_gles.c	Thu Feb 27 20:21:46 2014 -0300
     2.3 @@ -26,6 +26,10 @@
     2.4  #include "SDL_opengles.h"
     2.5  #include "../SDL_sysrender.h"
     2.6  
     2.7 +/* To prevent unnecessary window recreation, 
     2.8 + * these should match the defaults selected in SDL_GL_ResetAttributes 
     2.9 + */
    2.10 +
    2.11  #define RENDERER_CONTEXT_MAJOR 1
    2.12  #define RENDERER_CONTEXT_MINOR 1
    2.13  
    2.14 @@ -288,13 +292,14 @@
    2.15      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
    2.16      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
    2.17  
    2.18 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    2.19 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    2.20 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    2.21 -
    2.22      windowFlags = SDL_GetWindowFlags(window);
    2.23      if (!(windowFlags & SDL_WINDOW_OPENGL) ||
    2.24          profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
    2.25 +
    2.26 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    2.27 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    2.28 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    2.29 +
    2.30          if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
    2.31              /* Uh oh, better try to put it back... */
    2.32              SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
     3.1 --- a/src/render/opengles2/SDL_render_gles2.c	Wed Feb 26 16:27:03 2014 -0800
     3.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Thu Feb 27 20:21:46 2014 -0300
     3.3 @@ -28,6 +28,9 @@
     3.4  #include "../../video/SDL_blit.h"
     3.5  #include "SDL_shaders_gles2.h"
     3.6  
     3.7 +/* To prevent unnecessary window recreation, 
     3.8 + * these should match the defaults selected in SDL_GL_ResetAttributes 
     3.9 + */
    3.10  #define RENDERER_CONTEXT_MAJOR 2
    3.11  #define RENDERER_CONTEXT_MINOR 0
    3.12  
    3.13 @@ -1749,13 +1752,14 @@
    3.14      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
    3.15      SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
    3.16  
    3.17 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    3.18 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    3.19 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    3.20 -
    3.21      windowFlags = SDL_GetWindowFlags(window);
    3.22      if (!(windowFlags & SDL_WINDOW_OPENGL) ||
    3.23          profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
    3.24 +        
    3.25 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    3.26 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
    3.27 +        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
    3.28 +
    3.29          if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
    3.30              /* Uh oh, better try to put it back... */
    3.31              SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);