Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 29 Aug 2013 15:02:32 -0300
changeset 7723aea98cc3e696
parent 7722 ea5565d856a8
child 7724 54c06b0f65d9
Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1

SDL_GL_CONTEXT_EGL = 1 is now internally treated as profile_mask = SDL_GL_CONTEXT_PROFILE_ES
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/video/SDL_video.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11window.c
     1.1 --- a/src/render/opengles/SDL_render_gles.c	Thu Aug 29 14:03:44 2013 -0300
     1.2 +++ b/src/render/opengles/SDL_render_gles.c	Thu Aug 29 15:02:32 2013 -0300
     1.3 @@ -280,7 +280,7 @@
     1.4      GLint value;
     1.5      Uint32 windowFlags;
     1.6  
     1.7 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
     1.8 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
     1.9      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
    1.10      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    1.11  
     2.1 --- a/src/render/opengles2/SDL_render_gles2.c	Thu Aug 29 14:03:44 2013 -0300
     2.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Thu Aug 29 15:02:32 2013 -0300
     2.3 @@ -1628,7 +1628,7 @@
     2.4      Uint32 windowFlags;
     2.5      GLint window_framebuffer;
     2.6  
     2.7 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
     2.8 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
     2.9      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    2.10      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
    2.11  
     3.1 --- a/src/video/SDL_video.c	Thu Aug 29 14:03:44 2013 -0300
     3.2 +++ b/src/video/SDL_video.c	Thu Aug 29 15:02:32 2013 -0300
     3.3 @@ -477,26 +477,21 @@
     3.4      _this->gl_config.multisamplesamples = 0;
     3.5      _this->gl_config.retained_backing = 1;
     3.6      _this->gl_config.accelerated = -1;  /* accelerated or not, both are fine */
     3.7 +    _this->gl_config.profile_mask = 0;
     3.8  #if SDL_VIDEO_OPENGL
     3.9      _this->gl_config.major_version = 2;
    3.10      _this->gl_config.minor_version = 1;
    3.11 -    _this->gl_config.use_egl = 0;
    3.12  #elif SDL_VIDEO_OPENGL_ES
    3.13      _this->gl_config.major_version = 1;
    3.14      _this->gl_config.minor_version = 1;
    3.15 -#if SDL_VIDEO_OPENGL_EGL    
    3.16 -    _this->gl_config.use_egl = 1;
    3.17 -#endif    
    3.18 +    _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    3.19  #elif SDL_VIDEO_OPENGL_ES2
    3.20      _this->gl_config.major_version = 2;
    3.21      _this->gl_config.minor_version = 0;
    3.22 -#if SDL_VIDEO_OPENGL_EGL    
    3.23 -    _this->gl_config.use_egl = 1;
    3.24 -#endif
    3.25 -    
    3.26 +    _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;   
    3.27  #endif
    3.28      _this->gl_config.flags = 0;
    3.29 -    _this->gl_config.profile_mask = 0;
    3.30 +    
    3.31      _this->gl_config.share_with_current_context = 0;
    3.32  
    3.33      _this->current_glwin_tls = SDL_TLSCreate();
    3.34 @@ -2516,7 +2511,12 @@
    3.35          _this->gl_config.minor_version = value;
    3.36          break;
    3.37      case SDL_GL_CONTEXT_EGL:
    3.38 -        _this->gl_config.use_egl = value;
    3.39 +        /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
    3.40 +        if (value != 0) {
    3.41 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
    3.42 +        } else {
    3.43 +            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
    3.44 +        };
    3.45          break;
    3.46      case SDL_GL_CONTEXT_FLAGS:
    3.47          if( value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
    3.48 @@ -2686,8 +2686,14 @@
    3.49              return 0;
    3.50          }
    3.51      case SDL_GL_CONTEXT_EGL:
    3.52 +        /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
    3.53          {
    3.54 -            *value = _this->gl_config.use_egl;
    3.55 +            if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
    3.56 +                *value = 1;
    3.57 +            }
    3.58 +            else {
    3.59 +                *value = 0;
    3.60 +            }
    3.61              return 0;
    3.62          }
    3.63      case SDL_GL_CONTEXT_FLAGS:
     4.1 --- a/src/video/x11/SDL_x11opengl.c	Thu Aug 29 14:03:44 2013 -0300
     4.2 +++ b/src/video/x11/SDL_x11opengl.c	Thu Aug 29 15:02:32 2013 -0300
     4.3 @@ -210,36 +210,31 @@
     4.4      /* Initialize extensions */
     4.5      X11_GL_InitExtensions(_this);
     4.6      
     4.7 -    /* If SDL_GL_CONTEXT_EGL has been changed to 1, and there's 
     4.8 -     * no GLX_EXT_create_context_es2_profile extension switch over to X11_GLES functions  */
     4.9 -    if (_this->gl_config.use_egl == 1) {
    4.10 -        if (_this->gl_data->HAS_GLX_EXT_create_context_es2_profile) {
    4.11 -            /* We cheat a little bit here by using GLX instead of EGL 
    4.12 -             * to improve our chances of getting hardware acceleration */
    4.13 -            _this->gl_config.use_egl = 0;
    4.14 -            _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
    4.15 -        } else {
    4.16 +    /* If we need a GL ES context and there's no  
    4.17 +     * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions  
    4.18 +     */
    4.19 +    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
    4.20 +        ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
    4.21  #if SDL_VIDEO_OPENGL_EGL
    4.22 -            X11_GL_UnloadLibrary(_this);
    4.23 -            /* Better avoid conflicts! */
    4.24 -            if (_this->gl_config.dll_handle != NULL ) {
    4.25 -                GL_UnloadObject(_this->gl_config.dll_handle);
    4.26 -                _this->gl_config.dll_handle = NULL;
    4.27 -            }
    4.28 -            _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
    4.29 -            _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
    4.30 -            _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    4.31 -            _this->GL_CreateContext = X11_GLES_CreateContext;
    4.32 -            _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
    4.33 -            _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
    4.34 -            _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
    4.35 -            _this->GL_SwapWindow = X11_GLES_SwapWindow;
    4.36 -            _this->GL_DeleteContext = X11_GLES_DeleteContext;
    4.37 -            return X11_GLES_LoadLibrary(_this, NULL);
    4.38 +        X11_GL_UnloadLibrary(_this);
    4.39 +        /* Better avoid conflicts! */
    4.40 +        if (_this->gl_config.dll_handle != NULL ) {
    4.41 +            GL_UnloadObject(_this->gl_config.dll_handle);
    4.42 +            _this->gl_config.dll_handle = NULL;
    4.43 +        }
    4.44 +        _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
    4.45 +        _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
    4.46 +        _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    4.47 +        _this->GL_CreateContext = X11_GLES_CreateContext;
    4.48 +        _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
    4.49 +        _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
    4.50 +        _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
    4.51 +        _this->GL_SwapWindow = X11_GLES_SwapWindow;
    4.52 +        _this->GL_DeleteContext = X11_GLES_DeleteContext;
    4.53 +        return X11_GLES_LoadLibrary(_this, NULL);
    4.54  #else
    4.55 -            return SDL_SetError("SDL not configured with EGL support");
    4.56 +        return SDL_SetError("SDL not configured with EGL support");
    4.57  #endif
    4.58 -        }
    4.59      }
    4.60  
    4.61      return 0;
     5.1 --- a/src/video/x11/SDL_x11opengles.c	Thu Aug 29 14:03:44 2013 -0300
     5.2 +++ b/src/video/x11/SDL_x11opengles.c	Thu Aug 29 15:02:32 2013 -0300
     5.3 @@ -33,8 +33,8 @@
     5.4          
     5.5      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     5.6  
     5.7 -    /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions  */
     5.8 -    if (_this->gl_config.use_egl == 0) {
     5.9 +    /* If the profile requested is not GL ES, switch over to X11_GL functions  */
    5.10 +    if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
    5.11          #if SDL_VIDEO_OPENGL_GLX
    5.12          _this->GL_LoadLibrary = X11_GL_LoadLibrary;
    5.13          _this->GL_GetProcAddress = X11_GL_GetProcAddress;
     6.1 --- a/src/video/x11/SDL_x11window.c	Thu Aug 29 14:03:44 2013 -0300
     6.2 +++ b/src/video/x11/SDL_x11window.c	Thu Aug 29 15:02:32 2013 -0300
     6.3 @@ -366,10 +366,11 @@
     6.4  
     6.5  #if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
     6.6      if (window->flags & SDL_WINDOW_OPENGL) {
     6.7 -        XVisualInfo *vinfo;
     6.8 +        XVisualInfo *vinfo = NULL;
     6.9  
    6.10  #if SDL_VIDEO_OPENGL_EGL
    6.11 -        if (_this->gl_config.use_egl == 1) {
    6.12 +        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
    6.13 +            ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )) {
    6.14              vinfo = X11_GLES_GetVisual(_this, display, screen);
    6.15          } else
    6.16  #endif
    6.17 @@ -378,6 +379,7 @@
    6.18              vinfo = X11_GL_GetVisual(_this, display, screen);
    6.19  #endif
    6.20          }
    6.21 +
    6.22          if (!vinfo) {
    6.23              return -1;
    6.24          }
    6.25 @@ -551,7 +553,9 @@
    6.26      windowdata = (SDL_WindowData *) window->driverdata;
    6.27  
    6.28  #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    6.29 -    if ((window->flags & SDL_WINDOW_OPENGL) && (_this->gl_config.use_egl == 1)) {
    6.30 +    if ((window->flags & SDL_WINDOW_OPENGL) && 
    6.31 +        _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
    6.32 +        (!_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile) ) {
    6.33          if (!_this->egl_data) {
    6.34              XDestroyWindow(display, w);
    6.35              return -1;