Fix OpenGL initialization when OpenGL and OpenGLES are both available.
Both options default to "yes" via configure, and having libs/headers
for both installed is not unusual.
We default to OpenGL on this compile time combination, but can enforce
OpenGLES via setting the envvar SDL_VIDEO_X11_GLES.
This will be further refined based on community feedback.
Contributed by Andre Heider
1.1 --- a/src/video/x11/SDL_x11video.c Wed Jul 18 15:01:41 2012 -0700
1.2 +++ b/src/video/x11/SDL_x11video.c Wed Jul 18 15:02:48 2012 -0700
1.3 @@ -144,13 +144,26 @@
1.4 }
1.5 device->driverdata = data;
1.6
1.7 + /* In case GL and GLES/GLES2 is compiled in, we default to GL, but use
1.8 + * GLES if SDL_VIDEO_X11_GLES is set.
1.9 + */
1.10 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
1.11 - device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
1.12 - if (!device->gles_data) {
1.13 - SDL_OutOfMemory();
1.14 - SDL_free(device->driverdata);
1.15 - SDL_free(device);
1.16 - return NULL;
1.17 +#if SDL_VIDEO_OPENGL_GLX
1.18 + data->gles = SDL_getenv("SDL_VIDEO_X11_GLES") != NULL;
1.19 +#else
1.20 + data->gles = SDL_TRUE;
1.21 +#endif
1.22 +#endif
1.23 +
1.24 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
1.25 + if (data->gles) {
1.26 + device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
1.27 + if (!device->gles_data) {
1.28 + SDL_OutOfMemory();
1.29 + SDL_free(device->driverdata);
1.30 + SDL_free(device);
1.31 + return NULL;
1.32 + }
1.33 }
1.34 #endif
1.35
1.36 @@ -224,26 +237,30 @@
1.37 device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
1.38
1.39 #if SDL_VIDEO_OPENGL_GLX
1.40 - device->GL_LoadLibrary = X11_GL_LoadLibrary;
1.41 - device->GL_GetProcAddress = X11_GL_GetProcAddress;
1.42 - device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
1.43 - device->GL_CreateContext = X11_GL_CreateContext;
1.44 - device->GL_MakeCurrent = X11_GL_MakeCurrent;
1.45 - device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
1.46 - device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
1.47 - device->GL_SwapWindow = X11_GL_SwapWindow;
1.48 - device->GL_DeleteContext = X11_GL_DeleteContext;
1.49 + if (!data->gles) {
1.50 + device->GL_LoadLibrary = X11_GL_LoadLibrary;
1.51 + device->GL_GetProcAddress = X11_GL_GetProcAddress;
1.52 + device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
1.53 + device->GL_CreateContext = X11_GL_CreateContext;
1.54 + device->GL_MakeCurrent = X11_GL_MakeCurrent;
1.55 + device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
1.56 + device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
1.57 + device->GL_SwapWindow = X11_GL_SwapWindow;
1.58 + device->GL_DeleteContext = X11_GL_DeleteContext;
1.59 + }
1.60 #endif
1.61 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
1.62 - device->GL_LoadLibrary = X11_GLES_LoadLibrary;
1.63 - device->GL_GetProcAddress = X11_GLES_GetProcAddress;
1.64 - device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
1.65 - device->GL_CreateContext = X11_GLES_CreateContext;
1.66 - device->GL_MakeCurrent = X11_GLES_MakeCurrent;
1.67 - device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
1.68 - device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
1.69 - device->GL_SwapWindow = X11_GLES_SwapWindow;
1.70 - device->GL_DeleteContext = X11_GLES_DeleteContext;
1.71 + if (data->gles) {
1.72 + device->GL_LoadLibrary = X11_GLES_LoadLibrary;
1.73 + device->GL_GetProcAddress = X11_GLES_GetProcAddress;
1.74 + device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
1.75 + device->GL_CreateContext = X11_GLES_CreateContext;
1.76 + device->GL_MakeCurrent = X11_GLES_MakeCurrent;
1.77 + device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
1.78 + device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
1.79 + device->GL_SwapWindow = X11_GLES_SwapWindow;
1.80 + device->GL_DeleteContext = X11_GLES_DeleteContext;
1.81 + }
1.82 #endif
1.83
1.84 device->SetClipboardText = X11_SetClipboardText;
2.1 --- a/src/video/x11/SDL_x11video.h Wed Jul 18 15:01:41 2012 -0700
2.2 +++ b/src/video/x11/SDL_x11video.h Wed Jul 18 15:02:48 2012 -0700
2.3 @@ -92,7 +92,9 @@
2.4 Atom UTF8_STRING;
2.5
2.6 SDL_Scancode key_layout[256];
2.7 - SDL_bool selection_waiting;
2.8 + SDL_bool selection_waiting;
2.9 +
2.10 + SDL_bool gles;
2.11 } SDL_VideoData;
2.12
2.13 extern SDL_bool X11_UseDirectColorVisuals(void);
3.1 --- a/src/video/x11/SDL_x11window.c Wed Jul 18 15:01:41 2012 -0700
3.2 +++ b/src/video/x11/SDL_x11window.c Wed Jul 18 15:02:48 2012 -0700
3.3 @@ -269,24 +269,19 @@
3.4 Atom wmstate_atoms[3];
3.5 Uint32 fevent = 0;
3.6
3.7 -#if SDL_VIDEO_OPENGL_GLX
3.8 +#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
3.9 if (window->flags & SDL_WINDOW_OPENGL) {
3.10 XVisualInfo *vinfo;
3.11
3.12 - vinfo = X11_GL_GetVisual(_this, display, screen);
3.13 - if (!vinfo) {
3.14 - return -1;
3.15 +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
3.16 + if (data->gles) {
3.17 + vinfo = X11_GLES_GetVisual(_this, display, screen);
3.18 + } else
3.19 +#endif
3.20 + {
3.21 + vinfo = X11_GL_GetVisual(_this, display, screen);
3.22 }
3.23 - visual = vinfo->visual;
3.24 - depth = vinfo->depth;
3.25 - XFree(vinfo);
3.26 - } else
3.27 -#endif
3.28 -#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
3.29 - if (window->flags & SDL_WINDOW_OPENGL) {
3.30 - XVisualInfo *vinfo;
3.31
3.32 - vinfo = X11_GLES_GetVisual(_this, display, screen);
3.33 if (!vinfo) {
3.34 return -1;
3.35 }
3.36 @@ -395,7 +390,7 @@
3.37 return -1;
3.38 }
3.39 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
3.40 - if (window->flags & SDL_WINDOW_OPENGL) {
3.41 + if (data->gles && window->flags & SDL_WINDOW_OPENGL) {
3.42 /* Create the GLES window surface */
3.43 _this->gles_data->egl_surface =
3.44 _this->gles_data->eglCreateWindowSurface(_this->gles_data->