Improved simultaneous support for OpenGL and OpenGL ES
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Jul 2012 15:17:27 -0700
changeset 637093187f7f7d5d
parent 6369 a92fbd27127b
child 6371 a6b1a0c31880
Improved simultaneous support for OpenGL and OpenGL ES

From Scott Percival

Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.

- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider

This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11opengles.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11window.c
     1.1 --- a/include/SDL_video.h	Wed Jul 18 15:02:48 2012 -0700
     1.2 +++ b/include/SDL_video.h	Wed Jul 18 15:17:27 2012 -0700
     1.3 @@ -183,6 +183,7 @@
     1.4      SDL_GL_RETAINED_BACKING,
     1.5      SDL_GL_CONTEXT_MAJOR_VERSION,
     1.6      SDL_GL_CONTEXT_MINOR_VERSION,
     1.7 +    SDL_GL_CONTEXT_EGL,
     1.8      SDL_GL_CONTEXT_FLAGS,
     1.9      SDL_GL_CONTEXT_PROFILE_MASK
    1.10  } SDL_GLattr;
     2.1 --- a/src/video/SDL_sysvideo.h	Wed Jul 18 15:02:48 2012 -0700
     2.2 +++ b/src/video/SDL_sysvideo.h	Wed Jul 18 15:17:27 2012 -0700
     2.3 @@ -272,6 +272,7 @@
     2.4          int minor_version;
     2.5          int flags;
     2.6          int profile_mask;
     2.7 +        int use_egl;
     2.8          int retained_backing;
     2.9          int driver_loaded;
    2.10          char driver_path[256];
    2.11 @@ -288,7 +289,7 @@
    2.12      void *driverdata;
    2.13      struct SDL_GLDriverData *gl_data;
    2.14  
    2.15 -#if SDL_VIDEO_OPENGL_ES
    2.16 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    2.17      struct SDL_PrivateGLESData *gles_data;
    2.18  #endif
    2.19  
     3.1 --- a/src/video/SDL_video.c	Wed Jul 18 15:02:48 2012 -0700
     3.2 +++ b/src/video/SDL_video.c	Wed Jul 18 15:17:27 2012 -0700
     3.3 @@ -493,12 +493,15 @@
     3.4  #if SDL_VIDEO_OPENGL
     3.5      _this->gl_config.major_version = 2;
     3.6      _this->gl_config.minor_version = 1;
     3.7 +    _this->gl_config.use_egl = 0;
     3.8  #elif SDL_VIDEO_OPENGL_ES
     3.9      _this->gl_config.major_version = 1;
    3.10      _this->gl_config.minor_version = 1;
    3.11 +    _this->gl_config.use_egl = 1;
    3.12  #elif SDL_VIDEO_OPENGL_ES2
    3.13      _this->gl_config.major_version = 2;
    3.14      _this->gl_config.minor_version = 0;
    3.15 +    _this->gl_config.use_egl = 1;
    3.16  #endif
    3.17      _this->gl_config.flags = 0;
    3.18      _this->gl_config.profile_mask = 0;
    3.19 @@ -2302,6 +2305,9 @@
    3.20      case SDL_GL_CONTEXT_MINOR_VERSION:
    3.21          _this->gl_config.minor_version = value;
    3.22          break;
    3.23 +    case SDL_GL_CONTEXT_EGL:
    3.24 +        _this->gl_config.use_egl = value;
    3.25 +        break;
    3.26      case SDL_GL_CONTEXT_FLAGS:
    3.27          _this->gl_config.flags = value;
    3.28          break;
    3.29 @@ -2454,6 +2460,11 @@
    3.30              *value = _this->gl_config.minor_version;
    3.31              return 0;
    3.32          }
    3.33 +    case SDL_GL_CONTEXT_EGL:
    3.34 +        {
    3.35 +            *value = _this->gl_config.use_egl;
    3.36 +            return 0;
    3.37 +        }
    3.38      case SDL_GL_CONTEXT_FLAGS:
    3.39          {
    3.40              *value = _this->gl_config.flags;
     4.1 --- a/src/video/x11/SDL_x11opengl.c	Wed Jul 18 15:02:48 2012 -0700
     4.2 +++ b/src/video/x11/SDL_x11opengl.c	Wed Jul 18 15:17:27 2012 -0700
     4.3 @@ -29,6 +29,7 @@
     4.4  
     4.5  #if SDL_VIDEO_OPENGL_GLX
     4.6  #include "SDL_loadso.h"
     4.7 +#include "SDL_x11opengles.h"
     4.8  
     4.9  #if defined(__IRIX__)
    4.10  /* IRIX doesn't have a GL library versioning system */
    4.11 @@ -122,6 +123,28 @@
    4.12  {
    4.13      void *handle;
    4.14  
    4.15 +    if (_this->gl_data) {
    4.16 +        SDL_SetError("OpenGL context already created");
    4.17 +        return -1;
    4.18 +    }
    4.19 +
    4.20 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    4.21 +    /* If SDL_GL_CONTEXT_EGL has been changed to 1, switch over to X11_GLES functions  */
    4.22 +    if (_this->gl_config.use_egl == 1) {
    4.23 +        _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
    4.24 +        _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
    4.25 +        _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    4.26 +        _this->GL_CreateContext = X11_GLES_CreateContext;
    4.27 +        _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
    4.28 +        _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
    4.29 +        _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
    4.30 +        _this->GL_SwapWindow = X11_GLES_SwapWindow;
    4.31 +        _this->GL_DeleteContext = X11_GLES_DeleteContext;
    4.32 +        return X11_GLES_LoadLibrary(_this, path);
    4.33 +    }
    4.34 +#endif
    4.35 +
    4.36 +
    4.37      /* Load the OpenGL library */
    4.38      if (path == NULL) {
    4.39          path = SDL_getenv("SDL_OPENGL_LIBRARY");
     5.1 --- a/src/video/x11/SDL_x11opengles.c	Wed Jul 18 15:02:48 2012 -0700
     5.2 +++ b/src/video/x11/SDL_x11opengles.c	Wed Jul 18 15:17:27 2012 -0700
     5.3 @@ -24,6 +24,7 @@
     5.4  
     5.5  #include "SDL_x11video.h"
     5.6  #include "SDL_x11opengles.h"
     5.7 +#include "SDL_x11opengl.h"
     5.8  
     5.9  #define DEFAULT_EGL "libEGL.so"
    5.10  #define DEFAULT_OGL_ES2 "libGLESv2.so"
    5.11 @@ -71,22 +72,14 @@
    5.12  void
    5.13  X11_GLES_UnloadLibrary(_THIS)
    5.14  {
    5.15 -    if (_this->gl_config.driver_loaded) {
    5.16 +    if ((_this->gles_data) && (_this->gl_config.driver_loaded)) {
    5.17          _this->gles_data->eglTerminate(_this->gles_data->egl_display);
    5.18  
    5.19          dlclose(_this->gl_config.dll_handle);
    5.20          dlclose(_this->gles_data->egl_dll_handle);
    5.21  
    5.22 -        _this->gles_data->eglGetProcAddress = NULL;
    5.23 -        _this->gles_data->eglChooseConfig = NULL;
    5.24 -        _this->gles_data->eglCreateContext = NULL;
    5.25 -        _this->gles_data->eglCreateWindowSurface = NULL;
    5.26 -        _this->gles_data->eglDestroyContext = NULL;
    5.27 -        _this->gles_data->eglDestroySurface = NULL;
    5.28 -        _this->gles_data->eglMakeCurrent = NULL;
    5.29 -        _this->gles_data->eglSwapBuffers = NULL;
    5.30 -        _this->gles_data->eglGetDisplay = NULL;
    5.31 -        _this->gles_data->eglTerminate = NULL;
    5.32 +        SDL_free(_this->gles_data);
    5.33 +        _this->gles_data = NULL;
    5.34  
    5.35          _this->gl_config.dll_handle = NULL;
    5.36          _this->gl_config.driver_loaded = 0;
    5.37 @@ -101,10 +94,27 @@
    5.38  
    5.39      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    5.40  
    5.41 -    if (_this->gles_data->egl_active) {
    5.42 +    if (_this->gles_data) {
    5.43          SDL_SetError("OpenGL ES context already created");
    5.44          return -1;
    5.45      }
    5.46 +
    5.47 +#if SDL_VIDEO_OPENGL_GLX
    5.48 +    /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions  */
    5.49 +    if (_this->gl_config.use_egl == 0) {
    5.50 +        _this->GL_LoadLibrary = X11_GL_LoadLibrary;
    5.51 +        _this->GL_GetProcAddress = X11_GL_GetProcAddress;
    5.52 +        _this->GL_UnloadLibrary = X11_GL_UnloadLibrary;
    5.53 +        _this->GL_CreateContext = X11_GL_CreateContext;
    5.54 +        _this->GL_MakeCurrent = X11_GL_MakeCurrent;
    5.55 +        _this->GL_SetSwapInterval = X11_GL_SetSwapInterval;
    5.56 +        _this->GL_GetSwapInterval = X11_GL_GetSwapInterval;
    5.57 +        _this->GL_SwapWindow = X11_GL_SwapWindow;
    5.58 +        _this->GL_DeleteContext = X11_GL_DeleteContext;
    5.59 +        return X11_GL_LoadLibrary(_this, path);
    5.60 +    }
    5.61 +#endif
    5.62 +
    5.63  #ifdef RTLD_GLOBAL
    5.64      dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
    5.65  #else
    5.66 @@ -130,6 +140,12 @@
    5.67      /* Unload the old driver and reset the pointers */
    5.68      X11_GLES_UnloadLibrary(_this);
    5.69  
    5.70 +    _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
    5.71 +    if (!_this->gles_data) {
    5.72 +        SDL_OutOfMemory();
    5.73 +        return -1;
    5.74 +    }
    5.75 +
    5.76      /* Load new function pointers */
    5.77      LOAD_FUNC(eglGetDisplay);
    5.78      LOAD_FUNC(eglInitialize);
    5.79 @@ -204,12 +220,9 @@
    5.80      VisualID visual_id;
    5.81      int i;
    5.82  
    5.83 -    /* load the gl driver from a default path */
    5.84 -    if (!_this->gl_config.driver_loaded) {
    5.85 -        /* no driver has been loaded, use default (ourselves) */
    5.86 -        if (X11_GLES_LoadLibrary(_this, NULL) < 0) {
    5.87 -            return NULL;
    5.88 -        }
    5.89 +    if (!_this->gles_data) {
    5.90 +        /* The EGL library wasn't loaded, SDL_GetError() should have info */
    5.91 +        return NULL;
    5.92      }
    5.93  
    5.94      i = 0;
    5.95 @@ -324,7 +337,6 @@
    5.96          return NULL;
    5.97      }
    5.98  
    5.99 -    _this->gles_data->egl_active = 1;
   5.100      _this->gles_data->egl_swapinterval = 0;
   5.101  
   5.102      if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
   5.103 @@ -359,7 +371,7 @@
   5.104  int
   5.105  X11_GLES_SetSwapInterval(_THIS, int interval)
   5.106  {
   5.107 -    if (_this->gles_data->egl_active != 1) {
   5.108 +    if (_this->gles_data) {
   5.109          SDL_SetError("OpenGL ES context not active");
   5.110          return -1;
   5.111      }
   5.112 @@ -378,7 +390,7 @@
   5.113  int
   5.114  X11_GLES_GetSwapInterval(_THIS)
   5.115  {
   5.116 -    if (_this->gles_data->egl_active != 1) {
   5.117 +    if (_this->gles_data) {
   5.118          SDL_SetError("OpenGL ES context not active");
   5.119          return -1;
   5.120      }
   5.121 @@ -397,30 +409,31 @@
   5.122  X11_GLES_DeleteContext(_THIS, SDL_GLContext context)
   5.123  {
   5.124      /* Clean up GLES and EGL */
   5.125 -    if (_this->gles_data->egl_context != EGL_NO_CONTEXT ||
   5.126 -        _this->gles_data->egl_surface != EGL_NO_SURFACE) {
   5.127 -        _this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
   5.128 -                                         EGL_NO_SURFACE, EGL_NO_SURFACE,
   5.129 -                                         EGL_NO_CONTEXT);
   5.130 +    if (_this->gles_data) {  
   5.131 +        if (_this->gles_data->egl_context != EGL_NO_CONTEXT ||
   5.132 +            _this->gles_data->egl_surface != EGL_NO_SURFACE) {
   5.133 +            _this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
   5.134 +                                             EGL_NO_SURFACE, EGL_NO_SURFACE,
   5.135 +                                             EGL_NO_CONTEXT);
   5.136  
   5.137 -        if (_this->gles_data->egl_context != EGL_NO_CONTEXT) {
   5.138 -            _this->gles_data->eglDestroyContext(_this->gles_data->egl_display,
   5.139 -                                                _this->gles_data->
   5.140 -                                                egl_context);
   5.141 -            _this->gles_data->egl_context = EGL_NO_CONTEXT;
   5.142 +            if (_this->gles_data->egl_context != EGL_NO_CONTEXT) {
   5.143 +                _this->gles_data->eglDestroyContext(_this->gles_data->egl_display,
   5.144 +                                                    _this->gles_data->
   5.145 +                                                    egl_context);
   5.146 +                _this->gles_data->egl_context = EGL_NO_CONTEXT;
   5.147 +            }
   5.148 +
   5.149 +            if (_this->gles_data->egl_surface != EGL_NO_SURFACE) {
   5.150 +                _this->gles_data->eglDestroySurface(_this->gles_data->egl_display,
   5.151 +                                                    _this->gles_data->
   5.152 +                                                    egl_surface);
   5.153 +                _this->gles_data->egl_surface = EGL_NO_SURFACE;
   5.154 +            }
   5.155          }
   5.156  
   5.157 -        if (_this->gles_data->egl_surface != EGL_NO_SURFACE) {
   5.158 -            _this->gles_data->eglDestroySurface(_this->gles_data->egl_display,
   5.159 -                                                _this->gles_data->
   5.160 -                                                egl_surface);
   5.161 -            _this->gles_data->egl_surface = EGL_NO_SURFACE;
   5.162 -        }
   5.163 +        /* crappy fix */
   5.164 +        X11_GLES_UnloadLibrary(_this);
   5.165      }
   5.166 -    _this->gles_data->egl_active = 0;
   5.167 -
   5.168 -/* crappy fix */
   5.169 -    X11_GLES_UnloadLibrary(_this);
   5.170  
   5.171  }
   5.172  
     6.1 --- a/src/video/x11/SDL_x11opengles.h	Wed Jul 18 15:02:48 2012 -0700
     6.2 +++ b/src/video/x11/SDL_x11opengles.h	Wed Jul 18 15:17:27 2012 -0700
     6.3 @@ -18,7 +18,12 @@
     6.4       misrepresented as being the original software.
     6.5    3. This notice may not be removed or altered from any source distribution.
     6.6  */
     6.7 +#include "SDL_config.h"
     6.8  
     6.9 +#ifndef _SDL_x11opengles_h
    6.10 +#define _SDL_x11opengles_h
    6.11 +
    6.12 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    6.13  #include <GLES/gl.h>
    6.14  #include <GLES/egl.h>
    6.15  #include <dlfcn.h>
    6.16 @@ -30,7 +35,6 @@
    6.17  
    6.18  typedef struct SDL_PrivateGLESData
    6.19  {
    6.20 -    int egl_active;             /* to stop switching drivers while we have a valid context */
    6.21      XVisualInfo *egl_visualinfo;
    6.22      void *egl_dll_handle;
    6.23      EGLDisplay egl_display;
    6.24 @@ -92,3 +96,9 @@
    6.25  extern int X11_GLES_GetSwapInterval(_THIS);
    6.26  extern void X11_GLES_SwapWindow(_THIS, SDL_Window * window);
    6.27  extern void X11_GLES_DeleteContext(_THIS, SDL_GLContext context);
    6.28 +
    6.29 +#endif /* SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 */
    6.30 +
    6.31 +#endif /* _SDL_x11opengles_h */
    6.32 +
    6.33 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/x11/SDL_x11video.c	Wed Jul 18 15:02:48 2012 -0700
     7.2 +++ b/src/video/x11/SDL_x11video.c	Wed Jul 18 15:17:27 2012 -0700
     7.3 @@ -111,9 +111,6 @@
     7.4      }
     7.5      SDL_free(data->windowlist);
     7.6      SDL_free(device->driverdata);
     7.7 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
     7.8 -    SDL_free(device->gles_data);
     7.9 -#endif
    7.10      SDL_free(device);
    7.11  
    7.12      SDL_X11_UnloadSymbols();
    7.13 @@ -144,29 +141,6 @@
    7.14      }
    7.15      device->driverdata = data;
    7.16  
    7.17 -    /* In case GL and GLES/GLES2 is compiled in, we default to GL, but use
    7.18 -     * GLES if SDL_VIDEO_X11_GLES is set.
    7.19 -     */
    7.20 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    7.21 -#if SDL_VIDEO_OPENGL_GLX
    7.22 -    data->gles = SDL_getenv("SDL_VIDEO_X11_GLES") != NULL;
    7.23 -#else
    7.24 -    data->gles = SDL_TRUE;
    7.25 -#endif
    7.26 -#endif
    7.27 -
    7.28 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    7.29 -    if (data->gles) {
    7.30 -        device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
    7.31 -        if (!device->gles_data) {
    7.32 -            SDL_OutOfMemory();
    7.33 -            SDL_free(device->driverdata);
    7.34 -            SDL_free(device);
    7.35 -            return NULL;
    7.36 -        }
    7.37 -    }
    7.38 -#endif
    7.39 -
    7.40      /* FIXME: Do we need this?
    7.41         if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
    7.42         (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
    7.43 @@ -190,9 +164,6 @@
    7.44      }
    7.45  #endif
    7.46      if (data->display == NULL) {
    7.47 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    7.48 -        SDL_free(device->gles_data);
    7.49 -#endif
    7.50          SDL_free(device->driverdata);
    7.51          SDL_free(device);
    7.52          SDL_SetError("Couldn't open X11 display");
    7.53 @@ -237,30 +208,25 @@
    7.54      device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
    7.55  
    7.56  #if SDL_VIDEO_OPENGL_GLX
    7.57 -    if (!data->gles) {
    7.58 -        device->GL_LoadLibrary = X11_GL_LoadLibrary;
    7.59 -        device->GL_GetProcAddress = X11_GL_GetProcAddress;
    7.60 -        device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
    7.61 -        device->GL_CreateContext = X11_GL_CreateContext;
    7.62 -        device->GL_MakeCurrent = X11_GL_MakeCurrent;
    7.63 -        device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
    7.64 -        device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
    7.65 -        device->GL_SwapWindow = X11_GL_SwapWindow;
    7.66 -        device->GL_DeleteContext = X11_GL_DeleteContext;
    7.67 -    }
    7.68 -#endif
    7.69 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    7.70 -    if (data->gles) {
    7.71 -        device->GL_LoadLibrary = X11_GLES_LoadLibrary;
    7.72 -        device->GL_GetProcAddress = X11_GLES_GetProcAddress;
    7.73 -        device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    7.74 -        device->GL_CreateContext = X11_GLES_CreateContext;
    7.75 -        device->GL_MakeCurrent = X11_GLES_MakeCurrent;
    7.76 -        device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
    7.77 -        device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
    7.78 -        device->GL_SwapWindow = X11_GLES_SwapWindow;
    7.79 -        device->GL_DeleteContext = X11_GLES_DeleteContext;
    7.80 -    }
    7.81 +    device->GL_LoadLibrary = X11_GL_LoadLibrary;
    7.82 +    device->GL_GetProcAddress = X11_GL_GetProcAddress;
    7.83 +    device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
    7.84 +    device->GL_CreateContext = X11_GL_CreateContext;
    7.85 +    device->GL_MakeCurrent = X11_GL_MakeCurrent;
    7.86 +    device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
    7.87 +    device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
    7.88 +    device->GL_SwapWindow = X11_GL_SwapWindow;
    7.89 +    device->GL_DeleteContext = X11_GL_DeleteContext;
    7.90 +#elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    7.91 +    device->GL_LoadLibrary = X11_GLES_LoadLibrary;
    7.92 +    device->GL_GetProcAddress = X11_GLES_GetProcAddress;
    7.93 +    device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
    7.94 +    device->GL_CreateContext = X11_GLES_CreateContext;
    7.95 +    device->GL_MakeCurrent = X11_GLES_MakeCurrent;
    7.96 +    device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
    7.97 +    device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
    7.98 +    device->GL_SwapWindow = X11_GLES_SwapWindow;
    7.99 +    device->GL_DeleteContext = X11_GLES_DeleteContext;
   7.100  #endif
   7.101  
   7.102      device->SetClipboardText = X11_SetClipboardText;
     8.1 --- a/src/video/x11/SDL_x11video.h	Wed Jul 18 15:02:48 2012 -0700
     8.2 +++ b/src/video/x11/SDL_x11video.h	Wed Jul 18 15:17:27 2012 -0700
     8.3 @@ -92,9 +92,7 @@
     8.4      Atom UTF8_STRING;
     8.5  
     8.6      SDL_Scancode key_layout[256];
     8.7 -    SDL_bool selection_waiting;
     8.8 -
     8.9 -    SDL_bool gles;
    8.10 +    SDL_bool selection_waiting;    
    8.11  } SDL_VideoData;
    8.12  
    8.13  extern SDL_bool X11_UseDirectColorVisuals(void);
     9.1 --- a/src/video/x11/SDL_x11window.c	Wed Jul 18 15:02:48 2012 -0700
     9.2 +++ b/src/video/x11/SDL_x11window.c	Wed Jul 18 15:17:27 2012 -0700
     9.3 @@ -273,15 +273,16 @@
     9.4      if (window->flags & SDL_WINDOW_OPENGL) {
     9.5          XVisualInfo *vinfo;
     9.6  
     9.7 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
     9.8 -        if (data->gles) {
     9.9 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2        
    9.10 +        if (_this->gl_config.use_egl == 1) {
    9.11              vinfo = X11_GLES_GetVisual(_this, display, screen);
    9.12          } else
    9.13  #endif
    9.14          {
    9.15 +#if SDL_VIDEO_OPENGL_GLX
    9.16              vinfo = X11_GL_GetVisual(_this, display, screen);
    9.17 +#endif
    9.18          }
    9.19 -
    9.20          if (!vinfo) {
    9.21              return -1;
    9.22          }
    9.23 @@ -390,7 +391,7 @@
    9.24          return -1;
    9.25      }
    9.26  #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    9.27 -    if (data->gles && window->flags & SDL_WINDOW_OPENGL) {
    9.28 +    if (window->flags & SDL_WINDOW_OPENGL) {
    9.29          /* Create the GLES window surface */
    9.30          _this->gles_data->egl_surface =
    9.31              _this->gles_data->eglCreateWindowSurface(_this->gles_data->