Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11
authorSam Lantinga <slouken@libsdl.org>
Tue, 10 Jan 2017 08:54:33 -0800
changeset 1080636f40b8cc979
parent 10805 30a00d960dc9
child 10807 3d7cae208a0c
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
VisualC/tests/testgles2/testgles2.vcxproj
VisualC/tests/testgles2/testgles2_VS2008.vcproj
include/SDL_hints.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/windows/SDL_windowsopengl.c
src/video/windows/SDL_windowsopengl.h
src/video/windows/SDL_windowswindow.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengl.h
src/video/x11/SDL_x11window.c
test/testgles2.c
     1.1 --- a/VisualC/tests/testgles2/testgles2.vcxproj	Mon Jan 09 20:37:52 2017 -0800
     1.2 +++ b/VisualC/tests/testgles2/testgles2.vcxproj	Tue Jan 10 08:54:33 2017 -0800
     1.3 @@ -189,6 +189,12 @@
     1.4        <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
     1.5        <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
     1.6      </ProjectReference>
     1.7 +    <ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
     1.8 +      <Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
     1.9 +      <Private>false</Private>
    1.10 +      <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
    1.11 +      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
    1.12 +    </ProjectReference>
    1.13    </ItemGroup>
    1.14    <ItemGroup>
    1.15      <ClCompile Include="..\..\..\test\testgles2.c" />
    1.16 @@ -196,4 +202,4 @@
    1.17    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    1.18    <ImportGroup Label="ExtensionTargets">
    1.19    </ImportGroup>
    1.20 -</Project>
    1.21 \ No newline at end of file
    1.22 +</Project>
     2.1 --- a/VisualC/tests/testgles2/testgles2_VS2008.vcproj	Mon Jan 09 20:37:52 2017 -0800
     2.2 +++ b/VisualC/tests/testgles2/testgles2_VS2008.vcproj	Tue Jan 10 08:54:33 2017 -0800
     2.3 @@ -336,6 +336,10 @@
     2.4  			CopyLocalSatelliteAssemblies="false"
     2.5  			RelativePathToProject=".\SDLmain\SDLmain_VS2008.vcproj"
     2.6  		/>
     2.7 +		<ProjectReference
     2.8 +			ReferencedProjectIdentifier="{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}"
     2.9 +			RelativePathToProject=".\SDLtest\SDLtest_VS2008.vcproj"
    2.10 +		/>
    2.11  	</References>
    2.12  	<Files>
    2.13  		<File
     3.1 --- a/include/SDL_hints.h	Mon Jan 09 20:37:52 2017 -0800
     3.2 +++ b/include/SDL_hints.h	Tue Jan 10 08:54:33 2017 -0800
     3.3 @@ -745,6 +745,37 @@
     3.4  #define SDL_HINT_RPI_VIDEO_LAYER           "SDL_RPI_VIDEO_LAYER"
     3.5  
     3.6  /**
     3.7 + *  \brief  A variable controlling what driver to use for OpenGL ES contexts.
     3.8 + *
     3.9 + *  On some platforms, currently Windows and X11, OpenGL drivers may support
    3.10 + *  creating contexts with an OpenGL ES profile. By default SDL uses these
    3.11 + *  profiles, when available, otherwise it attempts to load an OpenGL ES
    3.12 + *  library, e.g. that provided by the ANGLE project. This variable controls
    3.13 + *  whether SDL follows this default behaviour or will always load an
    3.14 + *  OpenGL ES library.
    3.15 + *
    3.16 + *  Circumstances where this is useful include
    3.17 + *  - Testing an app with a particular OpenGL ES implementation, e.g ANGLE,
    3.18 + *    or emulator, e.g. those from ARM, Imagination or Qualcomm.
    3.19 + *  - Resolving OpenGL ES function addresses at link time by linking with
    3.20 + *    the OpenGL ES library instead of querying them at run time with
    3.21 + *    SDL_GL_GetProcAddress.
    3.22 + *
    3.23 + *  Caution: for an application to work with the default behaviour across
    3.24 + *  different OpenGL drivers it \i must query the OpenGL ES function
    3.25 + *  addresses at run time using SDL_GL_GetProcAddress.
    3.26 + *
    3.27 + *  This variable is ignored on most platforms because OpenGL ES is native
    3.28 + *  or not supported.
    3.29 + *
    3.30 + *  This variable can be set to the following values:
    3.31 + *    "0"       - Use ES profile of OpenGL, if available. (Default when not set.)
    3.32 + *    "1"       - Load OpenGL ES library using the default library names.
    3.33 + *
    3.34 + */
    3.35 +#define SDL_HINT_OPENGL_ES_DRIVER   "SDL_OPENGL_ES_DRIVER"
    3.36 +
    3.37 +/**
    3.38   *  \brief  An enumeration of hint priorities
    3.39   */
    3.40  typedef enum
     4.1 --- a/src/video/SDL_sysvideo.h	Mon Jan 09 20:37:52 2017 -0800
     4.2 +++ b/src/video/SDL_sysvideo.h	Tue Jan 10 08:54:33 2017 -0800
     4.3 @@ -426,6 +426,8 @@
     4.4  extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
     4.5  extern void *SDL_GetDisplayDriverData( int displayIndex );
     4.6  
     4.7 +extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
     4.8 +
     4.9  extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
    4.10  
    4.11  extern void SDL_OnWindowShown(SDL_Window * window);
     5.1 --- a/src/video/SDL_video.c	Mon Jan 09 20:37:52 2017 -0800
     5.2 +++ b/src/video/SDL_video.c	Tue Jan 10 08:54:33 2017 -0800
     5.3 @@ -2886,6 +2886,37 @@
     5.4  #endif
     5.5  }
     5.6  
     5.7 +/* Deduce supported ES profile versions from the supported
     5.8 +   ARB_ES*_compatibility extensions. There is no direct query.
     5.9 +   
    5.10 +   This is normally only called when the OpenGL driver supports
    5.11 +   {GLX,WGL}_EXT_create_context_es2_profile.
    5.12 + */
    5.13 +void
    5.14 +SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor)
    5.15 +{
    5.16 +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
    5.17 +	/* XXX This is fragile; it will break in the event of release of
    5.18 +	 * new versions of OpenGL ES.
    5.19 +     */
    5.20 +    if (SDL_GL_ExtensionSupported("GL_ARB_ES3_2_compatibility")) {
    5.21 +        *major = 3;
    5.22 +        *minor = 2;
    5.23 +    } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_1_compatibility")) {
    5.24 +        *major = 3;
    5.25 +        *minor = 1;
    5.26 +    } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_compatibility")) {
    5.27 +        *major = 3;
    5.28 +        *minor = 0;
    5.29 +    } else {
    5.30 +        *major = 2;
    5.31 +        *minor = 0;
    5.32 +    }
    5.33 +#else
    5.34 +    return SDL_FALSE;
    5.35 +#endif
    5.36 +}
    5.37 +
    5.38  void
    5.39  SDL_GL_ResetAttributes()
    5.40  {
     6.1 --- a/src/video/windows/SDL_windowsopengl.c	Mon Jan 09 20:37:52 2017 -0800
     6.2 +++ b/src/video/windows/SDL_windowsopengl.c	Tue Jan 10 08:54:33 2017 -0800
     6.3 @@ -26,6 +26,7 @@
     6.4  #include "SDL_loadso.h"
     6.5  #include "SDL_windowsvideo.h"
     6.6  #include "SDL_windowsopengles.h"
     6.7 +#include "SDL_hints.h"
     6.8  
     6.9  /* WGL implementation of SDL OpenGL support */
    6.10  
    6.11 @@ -131,6 +132,44 @@
    6.12          return SDL_SetError("Could not retrieve OpenGL functions");
    6.13      }
    6.14  
    6.15 +    /* XXX Too sleazy? WIN_GL_InitExtensions looks for certain OpenGL
    6.16 +       extensions via SDL_GL_DeduceMaxSupportedESProfile. This uses
    6.17 +       SDL_GL_ExtensionSupported which in turn calls SDL_GL_GetProcAddress.
    6.18 +       However SDL_GL_GetProcAddress will fail if the library is not
    6.19 +       loaded; it checks for gl_config.driver_loaded > 0. To avoid this
    6.20 +       test failing, increment driver_loaded around the call to
    6.21 +       WIN_GLInitExtensions.
    6.22 +
    6.23 +       Successful loading of the library is normally indicated by
    6.24 +       SDL_GL_LoadLibrary incrementing driver_loaded immediately after
    6.25 +       this function returns 0 to it.
    6.26 +
    6.27 +       Alternatives to this are:
    6.28 +       - moving SDL_GL_DeduceMaxSupportedESProfile to both the WIN and
    6.29 +         X11 platforms while adding a function equivalent to
    6.30 +         SDL_GL_ExtensionSupported but which directly calls
    6.31 +         glGetProcAddress(). Having 3 copies of the
    6.32 +         SDL_GL_ExtensionSupported makes this alternative unattractive.
    6.33 +       - moving SDL_GL_DeduceMaxSupportedESProfile to a new file shared
    6.34 +         by the WIN and X11 platforms while adding a function equivalent
    6.35 +         to SDL_GL_ExtensionSupported. This is unattractive due to the
    6.36 +         number of project files that will need updating, plus there
    6.37 +         will be 2 copies of the SDL_GL_ExtensionSupported code.
    6.38 +       - Add a private equivalent of SDL_GL_ExtensionSupported to
    6.39 +         SDL_video.c.
    6.40 +       - Move the call to WIN_GL_InitExtensions back to WIN_CreateWindow
    6.41 +         and add a flag to gl_data to avoid multiple calls to this
    6.42 +         expensive function. This is probably the least objectionable
    6.43 +         alternative if this increment/decrement trick is unacceptable.
    6.44 +
    6.45 +       Note that the driver_loaded > 0 check needs to remain in
    6.46 +       SDL_GL_ExtensionSupported and SDL_GL_GetProcAddress as they are
    6.47 +       public API functions.
    6.48 +    */
    6.49 +    ++_this->gl_config.driver_loaded;
    6.50 +    WIN_GL_InitExtensions(_this);
    6.51 +    --_this->gl_config.driver_loaded;
    6.52 +
    6.53      return 0;
    6.54  }
    6.55  
    6.56 @@ -407,9 +446,11 @@
    6.57      }
    6.58  
    6.59      /* Check for WGL_EXT_create_context_es2_profile */
    6.60 -    _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
    6.61      if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
    6.62 -        _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
    6.63 +        SDL_GL_DeduceMaxSupportedESProfile(
    6.64 +            &_this->gl_data->es_profile_max_supported_version.major,
    6.65 +            &_this->gl_data->es_profile_max_supported_version.minor
    6.66 +        );
    6.67      }
    6.68  
    6.69      /* Check for GLX_ARB_context_flush_control */
    6.70 @@ -593,14 +634,26 @@
    6.71      return retval;
    6.72  }
    6.73  
    6.74 +SDL_bool
    6.75 +WIN_GL_UseEGL(_THIS)
    6.76 +{
    6.77 +    SDL_assert(_this->gl_data != NULL);
    6.78 +    SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
    6.79 +
    6.80 +    return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
    6.81 +            || _this->gl_config.major_version == 1 /* No WGL extension for OpenGL ES 1.x profiles. */
    6.82 +            || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
    6.83 +            || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
    6.84 +                && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
    6.85 +}
    6.86 +
    6.87  SDL_GLContext
    6.88  WIN_GL_CreateContext(_THIS, SDL_Window * window)
    6.89  {
    6.90      HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
    6.91      HGLRC context, share_context;
    6.92  
    6.93 -    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
    6.94 -        !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
    6.95 +    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && WIN_GL_UseEGL(_this)) {
    6.96  #if SDL_VIDEO_OPENGL_EGL        
    6.97          /* Switch to EGL based functions */
    6.98          WIN_GL_UnloadLibrary(_this);
     7.1 --- a/src/video/windows/SDL_windowsopengl.h	Mon Jan 09 20:37:52 2017 -0800
     7.2 +++ b/src/video/windows/SDL_windowsopengl.h	Tue Jan 10 08:54:33 2017 -0800
     7.3 @@ -29,10 +29,18 @@
     7.4  {
     7.5      SDL_bool HAS_WGL_ARB_pixel_format;
     7.6      SDL_bool HAS_WGL_EXT_swap_control_tear;
     7.7 -    SDL_bool HAS_WGL_EXT_create_context_es2_profile;
     7.8      SDL_bool HAS_WGL_ARB_context_flush_control;
     7.9  
    7.10 -    void *(WINAPI * wglGetProcAddress) (const char *proc);
    7.11 +	/* Max version of OpenGL ES context that can be created if the
    7.12 +	   implementation supports WGL_EXT_create_context_es2_profile.
    7.13 +	   major = minor = 0 when unsupported.
    7.14 +	 */
    7.15 +	struct {
    7.16 +		int major;
    7.17 +		int minor;
    7.18 +	} es_profile_max_supported_version;
    7.19 +
    7.20 +	void *(WINAPI * wglGetProcAddress) (const char *proc);
    7.21        HGLRC(WINAPI * wglCreateContext) (HDC hdc);
    7.22        BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
    7.23        BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
    7.24 @@ -56,6 +64,7 @@
    7.25  extern int WIN_GL_LoadLibrary(_THIS, const char *path);
    7.26  extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
    7.27  extern void WIN_GL_UnloadLibrary(_THIS);
    7.28 +extern SDL_bool WIN_GL_UseEGL(_THIS);
    7.29  extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
    7.30  extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
    7.31  extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
     8.1 --- a/src/video/windows/SDL_windowswindow.c	Mon Jan 09 20:37:52 2017 -0800
     8.2 +++ b/src/video/windows/SDL_windowswindow.c	Tue Jan 10 08:54:33 2017 -0800
     8.3 @@ -263,6 +263,8 @@
     8.4      return 0;
     8.5  }
     8.6  
     8.7 +
     8.8 +
     8.9  int
    8.10  WIN_CreateWindow(_THIS, SDL_Window * window)
    8.11  {
    8.12 @@ -299,38 +301,36 @@
    8.13          return -1;
    8.14      }
    8.15  
    8.16 +    if (!(window->flags & SDL_WINDOW_OPENGL)) {
    8.17 +        return 0;
    8.18 +    }
    8.19 +
    8.20 +    /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
    8.21 +#if SDL_VIDEO_OPENGL_ES2
    8.22 +    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
    8.23  #if SDL_VIDEO_OPENGL_WGL
    8.24 -    /* We need to initialize the extensions before deciding how to create ES profiles */
    8.25 -    if (window->flags & SDL_WINDOW_OPENGL) {
    8.26 -        WIN_GL_InitExtensions(_this);
    8.27 -    }
    8.28 -#endif
    8.29 -
    8.30 -#if SDL_VIDEO_OPENGL_ES2
    8.31 -    if ((window->flags & SDL_WINDOW_OPENGL) &&
    8.32 -        _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
    8.33 -#if SDL_VIDEO_OPENGL_WGL           
    8.34 -        && (!_this->gl_data || !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile)
    8.35 -#endif  
    8.36 -        ) {
    8.37 -#if SDL_VIDEO_OPENGL_EGL  
    8.38 +        && (!_this->gl_data || WIN_GL_UseEGL(_this))
    8.39 +#endif /* SDL_VIDEO_OPENGL_WGL */
    8.40 +    ) {
    8.41 +#if SDL_VIDEO_OPENGL_EGL
    8.42          if (WIN_GLES_SetupWindow(_this, window) < 0) {
    8.43              WIN_DestroyWindow(_this, window);
    8.44              return -1;
    8.45          }
    8.46 +        return 0;
    8.47  #else
    8.48 -        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
    8.49 -#endif /* SDL_VIDEO_OPENGL_EGL */
    8.50 -    } else 
    8.51 +        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
    8.52 +#endif /* SDL_VIDEO_OPENGL_EGL */ 
    8.53 +    }
    8.54  #endif /* SDL_VIDEO_OPENGL_ES2 */
    8.55  
    8.56  #if SDL_VIDEO_OPENGL_WGL
    8.57 -    if (window->flags & SDL_WINDOW_OPENGL) {
    8.58 -        if (WIN_GL_SetupWindow(_this, window) < 0) {
    8.59 -            WIN_DestroyWindow(_this, window);
    8.60 -            return -1;
    8.61 -        }
    8.62 +    if (WIN_GL_SetupWindow(_this, window) < 0) {
    8.63 +        WIN_DestroyWindow(_this, window);
    8.64 +        return -1;
    8.65      }
    8.66 +#else
    8.67 +    return SDL_SetError("Could not create GL window (WGL support not configured)");
    8.68  #endif
    8.69  
    8.70      return 0;
     9.1 --- a/src/video/x11/SDL_x11opengl.c	Mon Jan 09 20:37:52 2017 -0800
     9.2 +++ b/src/video/x11/SDL_x11opengl.c	Tue Jan 10 08:54:33 2017 -0800
     9.3 @@ -24,6 +24,7 @@
     9.4  
     9.5  #include "SDL_x11video.h"
     9.6  #include "SDL_assert.h"
     9.7 +#include "SDL_hints.h"
     9.8  
     9.9  /* GLX implementation of SDL OpenGL support */
    9.10  
    9.11 @@ -143,7 +144,6 @@
    9.12  
    9.13  static void X11_GL_InitExtensions(_THIS);
    9.14  
    9.15 -
    9.16  int
    9.17  X11_GL_LoadLibrary(_THIS, const char *path)
    9.18  {
    9.19 @@ -222,13 +222,17 @@
    9.20      }
    9.21  
    9.22      /* Initialize extensions */
    9.23 +    /* See lengthy comment about the inc/dec in 
    9.24 +       ../windows/SDL_windowsopengl.c. */
    9.25 +    ++_this->gl_config.driver_loaded;
    9.26      X11_GL_InitExtensions(_this);
    9.27 +    --_this->gl_config.driver_loaded;
    9.28      
    9.29      /* If we need a GL ES context and there's no  
    9.30       * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions  
    9.31       */
    9.32      if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
    9.33 -        ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
    9.34 +        X11_GL_UseEGL(_this) ) {
    9.35  #if SDL_VIDEO_OPENGL_EGL
    9.36          X11_GL_UnloadLibrary(_this);
    9.37          /* Better avoid conflicts! */
    9.38 @@ -380,7 +384,10 @@
    9.39      
    9.40      /* Check for GLX_EXT_create_context_es2_profile */
    9.41      if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
    9.42 -        _this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
    9.43 +        SDL_GL_DeduceMaxSupportedESProfile(
    9.44 +            &_this->gl_data->es_profile_max_supported_version.major,
    9.45 +            &_this->gl_data->es_profile_max_supported_version.minor
    9.46 +        );
    9.47      }
    9.48  
    9.49      /* Check for GLX_ARB_context_flush_control */
    9.50 @@ -565,6 +572,19 @@
    9.51      return (0);
    9.52  }
    9.53  
    9.54 +SDL_bool
    9.55 +X11_GL_UseEGL(_THIS)
    9.56 +{
    9.57 +    SDL_assert(_this->gl_data != NULL);
    9.58 +    SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
    9.59 +
    9.60 +    return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
    9.61 +            || _this->gl_config.major_version == 1 /* No GLX extension for OpenGL ES 1.x profiles. */
    9.62 +            || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
    9.63 +            || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
    9.64 +                && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
    9.65 +}
    9.66 +
    9.67  SDL_GLContext
    9.68  X11_GL_CreateContext(_THIS, SDL_Window * window)
    9.69  {
    10.1 --- a/src/video/x11/SDL_x11opengl.h	Mon Jan 09 20:37:52 2017 -0800
    10.2 +++ b/src/video/x11/SDL_x11opengl.h	Tue Jan 10 08:54:33 2017 -0800
    10.3 @@ -34,9 +34,17 @@
    10.4      SDL_bool HAS_GLX_EXT_visual_rating;
    10.5      SDL_bool HAS_GLX_EXT_visual_info;
    10.6      SDL_bool HAS_GLX_EXT_swap_control_tear;
    10.7 -    SDL_bool HAS_GLX_EXT_create_context_es2_profile;
    10.8      SDL_bool HAS_GLX_ARB_context_flush_control;
    10.9  
   10.10 +	/* Max version of OpenGL ES context that can be created if the
   10.11 +	   implementation supports WGL_EXT_create_context_es2_profile.
   10.12 +	   major = minor = 0 when unsupported.
   10.13 +	 */
   10.14 +	struct {
   10.15 +		int major;
   10.16 +		int minor;
   10.17 +	} es_profile_max_supported_version;
   10.18 +
   10.19      Bool (*glXQueryExtension) (Display*,int*,int*);
   10.20      void *(*glXGetProcAddress) (const GLubyte*);
   10.21      XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
   10.22 @@ -57,6 +65,7 @@
   10.23  extern int X11_GL_LoadLibrary(_THIS, const char *path);
   10.24  extern void *X11_GL_GetProcAddress(_THIS, const char *proc);
   10.25  extern void X11_GL_UnloadLibrary(_THIS);
   10.26 +extern SDL_bool X11_GL_UseEGL(_THIS);
   10.27  extern XVisualInfo *X11_GL_GetVisual(_THIS, Display * display, int screen);
   10.28  extern SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window);
   10.29  extern int X11_GL_MakeCurrent(_THIS, SDL_Window * window,
    11.1 --- a/src/video/x11/SDL_x11window.c	Mon Jan 09 20:37:52 2017 -0800
    11.2 +++ b/src/video/x11/SDL_x11window.c	Tue Jan 10 08:54:33 2017 -0800
    11.3 @@ -389,7 +389,7 @@
    11.4  #if SDL_VIDEO_OPENGL_EGL
    11.5          if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES 
    11.6  #if SDL_VIDEO_OPENGL_GLX            
    11.7 -            && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
    11.8 +            && ( !_this->gl_data || X11_GL_UseEGL(_this) )
    11.9  #endif
   11.10          ) {
   11.11              vinfo = X11_GLES_GetVisual(_this, display, screen);
   11.12 @@ -600,7 +600,7 @@
   11.13      if ((window->flags & SDL_WINDOW_OPENGL) && 
   11.14          _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
   11.15  #if SDL_VIDEO_OPENGL_GLX            
   11.16 -        && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
   11.17 +        && ( !_this->gl_data || X11_GL_UseEGL(_this) )
   11.18  #endif  
   11.19      ) {
   11.20  #if SDL_VIDEO_OPENGL_EGL  
   11.21 @@ -617,7 +617,7 @@
   11.22              return SDL_SetError("Could not create GLES window surface");
   11.23          }
   11.24  #else
   11.25 -        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
   11.26 +        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
   11.27  #endif /* SDL_VIDEO_OPENGL_EGL */
   11.28      }
   11.29  #endif
    12.1 --- a/test/testgles2.c	Mon Jan 09 20:37:52 2017 -0800
    12.2 +++ b/test/testgles2.c	Tue Jan 10 08:54:33 2017 -0800
    12.3 @@ -20,7 +20,8 @@
    12.4  
    12.5  #include "SDL_test_common.h"
    12.6  
    12.7 -#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__)
    12.8 +#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
    12.9 +    || defined(__WINDOWS__) || defined(__LINUX__)
   12.10  #define HAVE_OPENGLES2
   12.11  #endif
   12.12