Commit a52d48c5ab31d3f7a0259b29e409141ce623d623

Sam Lantinga 2017-01-10T08:54:33

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
diff --git a/VisualC/tests/testgles2/testgles2.vcxproj b/VisualC/tests/testgles2/testgles2.vcxproj
index 186f6af..f1c633a 100644
--- a/VisualC/tests/testgles2/testgles2.vcxproj
+++ b/VisualC/tests/testgles2/testgles2.vcxproj
@@ -189,6 +189,12 @@
       <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
       <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
+      <Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
+      <Private>false</Private>
+      <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
+      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
+    </ProjectReference>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\..\test\testgles2.c" />
@@ -196,4 +202,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/VisualC/tests/testgles2/testgles2_VS2008.vcproj b/VisualC/tests/testgles2/testgles2_VS2008.vcproj
index b70a137..efe5355 100644
--- a/VisualC/tests/testgles2/testgles2_VS2008.vcproj
+++ b/VisualC/tests/testgles2/testgles2_VS2008.vcproj
@@ -336,6 +336,10 @@
 			CopyLocalSatelliteAssemblies="false"
 			RelativePathToProject=".\SDLmain\SDLmain_VS2008.vcproj"
 		/>
+		<ProjectReference
+			ReferencedProjectIdentifier="{DA956FD3-E143-46F2-9FE5-C77BEBC56B1A}"
+			RelativePathToProject=".\SDLtest\SDLtest_VS2008.vcproj"
+		/>
 	</References>
 	<Files>
 		<File
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 63e507b..928aaaf 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -745,6 +745,37 @@ extern "C" {
 #define SDL_HINT_RPI_VIDEO_LAYER           "SDL_RPI_VIDEO_LAYER"
 
 /**
+ *  \brief  A variable controlling what driver to use for OpenGL ES contexts.
+ *
+ *  On some platforms, currently Windows and X11, OpenGL drivers may support
+ *  creating contexts with an OpenGL ES profile. By default SDL uses these
+ *  profiles, when available, otherwise it attempts to load an OpenGL ES
+ *  library, e.g. that provided by the ANGLE project. This variable controls
+ *  whether SDL follows this default behaviour or will always load an
+ *  OpenGL ES library.
+ *
+ *  Circumstances where this is useful include
+ *  - Testing an app with a particular OpenGL ES implementation, e.g ANGLE,
+ *    or emulator, e.g. those from ARM, Imagination or Qualcomm.
+ *  - Resolving OpenGL ES function addresses at link time by linking with
+ *    the OpenGL ES library instead of querying them at run time with
+ *    SDL_GL_GetProcAddress.
+ *
+ *  Caution: for an application to work with the default behaviour across
+ *  different OpenGL drivers it \i must query the OpenGL ES function
+ *  addresses at run time using SDL_GL_GetProcAddress.
+ *
+ *  This variable is ignored on most platforms because OpenGL ES is native
+ *  or not supported.
+ *
+ *  This variable can be set to the following values:
+ *    "0"       - Use ES profile of OpenGL, if available. (Default when not set.)
+ *    "1"       - Load OpenGL ES library using the default library names.
+ *
+ */
+#define SDL_HINT_OPENGL_ES_DRIVER   "SDL_OPENGL_ES_DRIVER"
+
+/**
  *  \brief  An enumeration of hint priorities
  */
 typedef enum
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 7dc44c2..2778490 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -426,6 +426,8 @@ extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayM
 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
 extern void *SDL_GetDisplayDriverData( int displayIndex );
 
+extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
+
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
 extern void SDL_OnWindowShown(SDL_Window * window);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 4738543..59d8e18 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -2886,6 +2886,37 @@ SDL_GL_ExtensionSupported(const char *extension)
 #endif
 }
 
+/* Deduce supported ES profile versions from the supported
+   ARB_ES*_compatibility extensions. There is no direct query.
+   
+   This is normally only called when the OpenGL driver supports
+   {GLX,WGL}_EXT_create_context_es2_profile.
+ */
+void
+SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor)
+{
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+	/* XXX This is fragile; it will break in the event of release of
+	 * new versions of OpenGL ES.
+     */
+    if (SDL_GL_ExtensionSupported("GL_ARB_ES3_2_compatibility")) {
+        *major = 3;
+        *minor = 2;
+    } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_1_compatibility")) {
+        *major = 3;
+        *minor = 1;
+    } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_compatibility")) {
+        *major = 3;
+        *minor = 0;
+    } else {
+        *major = 2;
+        *minor = 0;
+    }
+#else
+    return SDL_FALSE;
+#endif
+}
+
 void
 SDL_GL_ResetAttributes()
 {
diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c
index 3df2fe3..ffa6c2b 100644
--- a/src/video/windows/SDL_windowsopengl.c
+++ b/src/video/windows/SDL_windowsopengl.c
@@ -26,6 +26,7 @@
 #include "SDL_loadso.h"
 #include "SDL_windowsvideo.h"
 #include "SDL_windowsopengles.h"
+#include "SDL_hints.h"
 
 /* WGL implementation of SDL OpenGL support */
 
@@ -131,6 +132,44 @@ WIN_GL_LoadLibrary(_THIS, const char *path)
         return SDL_SetError("Could not retrieve OpenGL functions");
     }
 
+    /* XXX Too sleazy? WIN_GL_InitExtensions looks for certain OpenGL
+       extensions via SDL_GL_DeduceMaxSupportedESProfile. This uses
+       SDL_GL_ExtensionSupported which in turn calls SDL_GL_GetProcAddress.
+       However SDL_GL_GetProcAddress will fail if the library is not
+       loaded; it checks for gl_config.driver_loaded > 0. To avoid this
+       test failing, increment driver_loaded around the call to
+       WIN_GLInitExtensions.
+
+       Successful loading of the library is normally indicated by
+       SDL_GL_LoadLibrary incrementing driver_loaded immediately after
+       this function returns 0 to it.
+
+       Alternatives to this are:
+       - moving SDL_GL_DeduceMaxSupportedESProfile to both the WIN and
+         X11 platforms while adding a function equivalent to
+         SDL_GL_ExtensionSupported but which directly calls
+         glGetProcAddress(). Having 3 copies of the
+         SDL_GL_ExtensionSupported makes this alternative unattractive.
+       - moving SDL_GL_DeduceMaxSupportedESProfile to a new file shared
+         by the WIN and X11 platforms while adding a function equivalent
+         to SDL_GL_ExtensionSupported. This is unattractive due to the
+         number of project files that will need updating, plus there
+         will be 2 copies of the SDL_GL_ExtensionSupported code.
+       - Add a private equivalent of SDL_GL_ExtensionSupported to
+         SDL_video.c.
+       - Move the call to WIN_GL_InitExtensions back to WIN_CreateWindow
+         and add a flag to gl_data to avoid multiple calls to this
+         expensive function. This is probably the least objectionable
+         alternative if this increment/decrement trick is unacceptable.
+
+       Note that the driver_loaded > 0 check needs to remain in
+       SDL_GL_ExtensionSupported and SDL_GL_GetProcAddress as they are
+       public API functions.
+    */
+    ++_this->gl_config.driver_loaded;
+    WIN_GL_InitExtensions(_this);
+    --_this->gl_config.driver_loaded;
+
     return 0;
 }
 
@@ -407,9 +446,11 @@ WIN_GL_InitExtensions(_THIS)
     }
 
     /* Check for WGL_EXT_create_context_es2_profile */
-    _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
     if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
-        _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
+        SDL_GL_DeduceMaxSupportedESProfile(
+            &_this->gl_data->es_profile_max_supported_version.major,
+            &_this->gl_data->es_profile_max_supported_version.minor
+        );
     }
 
     /* Check for GLX_ARB_context_flush_control */
@@ -593,14 +634,26 @@ WIN_GL_SetupWindow(_THIS, SDL_Window * window)
     return retval;
 }
 
+SDL_bool
+WIN_GL_UseEGL(_THIS)
+{
+    SDL_assert(_this->gl_data != NULL);
+    SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
+
+    return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
+            || _this->gl_config.major_version == 1 /* No WGL extension for OpenGL ES 1.x profiles. */
+            || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
+            || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
+                && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
+}
+
 SDL_GLContext
 WIN_GL_CreateContext(_THIS, SDL_Window * window)
 {
     HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
     HGLRC context, share_context;
 
-    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
-        !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
+    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && WIN_GL_UseEGL(_this)) {
 #if SDL_VIDEO_OPENGL_EGL        
         /* Switch to EGL based functions */
         WIN_GL_UnloadLibrary(_this);
diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h
index b01f96b..de0a1c7 100644
--- a/src/video/windows/SDL_windowsopengl.h
+++ b/src/video/windows/SDL_windowsopengl.h
@@ -29,10 +29,18 @@ struct SDL_GLDriverData
 {
     SDL_bool HAS_WGL_ARB_pixel_format;
     SDL_bool HAS_WGL_EXT_swap_control_tear;
-    SDL_bool HAS_WGL_EXT_create_context_es2_profile;
     SDL_bool HAS_WGL_ARB_context_flush_control;
 
-    void *(WINAPI * wglGetProcAddress) (const char *proc);
+	/* Max version of OpenGL ES context that can be created if the
+	   implementation supports WGL_EXT_create_context_es2_profile.
+	   major = minor = 0 when unsupported.
+	 */
+	struct {
+		int major;
+		int minor;
+	} es_profile_max_supported_version;
+
+	void *(WINAPI * wglGetProcAddress) (const char *proc);
       HGLRC(WINAPI * wglCreateContext) (HDC hdc);
       BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
       BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
@@ -56,6 +64,7 @@ struct SDL_GLDriverData
 extern int WIN_GL_LoadLibrary(_THIS, const char *path);
 extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
 extern void WIN_GL_UnloadLibrary(_THIS);
+extern SDL_bool WIN_GL_UseEGL(_THIS);
 extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
 extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
 extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index f1eeb28..531010e 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -263,6 +263,8 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
     return 0;
 }
 
+
+
 int
 WIN_CreateWindow(_THIS, SDL_Window * window)
 {
@@ -299,38 +301,36 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
         return -1;
     }
 
-#if SDL_VIDEO_OPENGL_WGL
-    /* We need to initialize the extensions before deciding how to create ES profiles */
-    if (window->flags & SDL_WINDOW_OPENGL) {
-        WIN_GL_InitExtensions(_this);
+    if (!(window->flags & SDL_WINDOW_OPENGL)) {
+        return 0;
     }
-#endif
 
+    /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
 #if SDL_VIDEO_OPENGL_ES2
-    if ((window->flags & SDL_WINDOW_OPENGL) &&
-        _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
-#if SDL_VIDEO_OPENGL_WGL           
-        && (!_this->gl_data || !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile)
-#endif  
-        ) {
-#if SDL_VIDEO_OPENGL_EGL  
+    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
+#if SDL_VIDEO_OPENGL_WGL
+        && (!_this->gl_data || WIN_GL_UseEGL(_this))
+#endif /* SDL_VIDEO_OPENGL_WGL */
+    ) {
+#if SDL_VIDEO_OPENGL_EGL
         if (WIN_GLES_SetupWindow(_this, window) < 0) {
             WIN_DestroyWindow(_this, window);
             return -1;
         }
+        return 0;
 #else
-        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
-#endif /* SDL_VIDEO_OPENGL_EGL */
-    } else 
+        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
+#endif /* SDL_VIDEO_OPENGL_EGL */ 
+    }
 #endif /* SDL_VIDEO_OPENGL_ES2 */
 
 #if SDL_VIDEO_OPENGL_WGL
-    if (window->flags & SDL_WINDOW_OPENGL) {
-        if (WIN_GL_SetupWindow(_this, window) < 0) {
-            WIN_DestroyWindow(_this, window);
-            return -1;
-        }
+    if (WIN_GL_SetupWindow(_this, window) < 0) {
+        WIN_DestroyWindow(_this, window);
+        return -1;
     }
+#else
+    return SDL_SetError("Could not create GL window (WGL support not configured)");
 #endif
 
     return 0;
diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c
index e407c29..a16bdc2 100644
--- a/src/video/x11/SDL_x11opengl.c
+++ b/src/video/x11/SDL_x11opengl.c
@@ -24,6 +24,7 @@
 
 #include "SDL_x11video.h"
 #include "SDL_assert.h"
+#include "SDL_hints.h"
 
 /* GLX implementation of SDL OpenGL support */
 
@@ -143,7 +144,6 @@ typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
 
 static void X11_GL_InitExtensions(_THIS);
 
-
 int
 X11_GL_LoadLibrary(_THIS, const char *path)
 {
@@ -222,13 +222,17 @@ X11_GL_LoadLibrary(_THIS, const char *path)
     }
 
     /* Initialize extensions */
+    /* See lengthy comment about the inc/dec in 
+       ../windows/SDL_windowsopengl.c. */
+    ++_this->gl_config.driver_loaded;
     X11_GL_InitExtensions(_this);
+    --_this->gl_config.driver_loaded;
     
     /* If we need a GL ES context and there's no  
      * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions  
      */
     if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
-        ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
+        X11_GL_UseEGL(_this) ) {
 #if SDL_VIDEO_OPENGL_EGL
         X11_GL_UnloadLibrary(_this);
         /* Better avoid conflicts! */
@@ -380,7 +384,10 @@ X11_GL_InitExtensions(_THIS)
     
     /* Check for GLX_EXT_create_context_es2_profile */
     if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
-        _this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
+        SDL_GL_DeduceMaxSupportedESProfile(
+            &_this->gl_data->es_profile_max_supported_version.major,
+            &_this->gl_data->es_profile_max_supported_version.minor
+        );
     }
 
     /* Check for GLX_ARB_context_flush_control */
@@ -565,6 +572,19 @@ X11_GL_ErrorHandler(Display * d, XErrorEvent * e)
     return (0);
 }
 
+SDL_bool
+X11_GL_UseEGL(_THIS)
+{
+    SDL_assert(_this->gl_data != NULL);
+    SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
+
+    return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
+            || _this->gl_config.major_version == 1 /* No GLX extension for OpenGL ES 1.x profiles. */
+            || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
+            || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
+                && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
+}
+
 SDL_GLContext
 X11_GL_CreateContext(_THIS, SDL_Window * window)
 {
diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h
index 0f81e21..5d781c3 100644
--- a/src/video/x11/SDL_x11opengl.h
+++ b/src/video/x11/SDL_x11opengl.h
@@ -34,9 +34,17 @@ struct SDL_GLDriverData
     SDL_bool HAS_GLX_EXT_visual_rating;
     SDL_bool HAS_GLX_EXT_visual_info;
     SDL_bool HAS_GLX_EXT_swap_control_tear;
-    SDL_bool HAS_GLX_EXT_create_context_es2_profile;
     SDL_bool HAS_GLX_ARB_context_flush_control;
 
+	/* Max version of OpenGL ES context that can be created if the
+	   implementation supports WGL_EXT_create_context_es2_profile.
+	   major = minor = 0 when unsupported.
+	 */
+	struct {
+		int major;
+		int minor;
+	} es_profile_max_supported_version;
+
     Bool (*glXQueryExtension) (Display*,int*,int*);
     void *(*glXGetProcAddress) (const GLubyte*);
     XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
@@ -57,6 +65,7 @@ struct SDL_GLDriverData
 extern int X11_GL_LoadLibrary(_THIS, const char *path);
 extern void *X11_GL_GetProcAddress(_THIS, const char *proc);
 extern void X11_GL_UnloadLibrary(_THIS);
+extern SDL_bool X11_GL_UseEGL(_THIS);
 extern XVisualInfo *X11_GL_GetVisual(_THIS, Display * display, int screen);
 extern SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window);
 extern int X11_GL_MakeCurrent(_THIS, SDL_Window * window,
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index a6042af..9082448 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -389,7 +389,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
 #if SDL_VIDEO_OPENGL_EGL
         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES 
 #if SDL_VIDEO_OPENGL_GLX            
-            && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
+            && ( !_this->gl_data || X11_GL_UseEGL(_this) )
 #endif
         ) {
             vinfo = X11_GLES_GetVisual(_this, display, screen);
@@ -600,7 +600,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
     if ((window->flags & SDL_WINDOW_OPENGL) && 
         _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
 #if SDL_VIDEO_OPENGL_GLX            
-        && ( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )
+        && ( !_this->gl_data || X11_GL_UseEGL(_this) )
 #endif  
     ) {
 #if SDL_VIDEO_OPENGL_EGL  
@@ -617,7 +617,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
             return SDL_SetError("Could not create GLES window surface");
         }
 #else
-        return SDL_SetError("Could not create GLES window surface (no EGL support available)");
+        return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
 #endif /* SDL_VIDEO_OPENGL_EGL */
     }
 #endif
diff --git a/test/testgles2.c b/test/testgles2.c
index d6261cb..58a46ac 100644
--- a/test/testgles2.c
+++ b/test/testgles2.c
@@ -20,7 +20,8 @@
 
 #include "SDL_test_common.h"
 
-#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__)
+#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
+    || defined(__WINDOWS__) || defined(__LINUX__)
 #define HAVE_OPENGLES2
 #endif