From a46a010f89d5cb9009de04479ca7040f7e5bd03a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 18 Jul 2012 15:02:48 -0700 Subject: [PATCH] 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 --- src/video/x11/SDL_x11video.c | 65 ++++++++++++++++++++++------------- src/video/x11/SDL_x11video.h | 4 ++- src/video/x11/SDL_x11window.c | 23 +++++-------- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 1cba0b5e3..dec4173cf 100755 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -144,13 +144,26 @@ X11_CreateDevice(int devindex) } device->driverdata = data; + /* In case GL and GLES/GLES2 is compiled in, we default to GL, but use + * GLES if SDL_VIDEO_X11_GLES is set. + */ #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); - if (!device->gles_data) { - SDL_OutOfMemory(); - SDL_free(device->driverdata); - SDL_free(device); - return NULL; +#if SDL_VIDEO_OPENGL_GLX + data->gles = SDL_getenv("SDL_VIDEO_X11_GLES") != NULL; +#else + data->gles = SDL_TRUE; +#endif +#endif + +#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 + if (data->gles) { + device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); + if (!device->gles_data) { + SDL_OutOfMemory(); + SDL_free(device->driverdata); + SDL_free(device); + return NULL; + } } #endif @@ -224,26 +237,30 @@ X11_CreateDevice(int devindex) device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape; #if SDL_VIDEO_OPENGL_GLX - device->GL_LoadLibrary = X11_GL_LoadLibrary; - device->GL_GetProcAddress = X11_GL_GetProcAddress; - device->GL_UnloadLibrary = X11_GL_UnloadLibrary; - device->GL_CreateContext = X11_GL_CreateContext; - device->GL_MakeCurrent = X11_GL_MakeCurrent; - device->GL_SetSwapInterval = X11_GL_SetSwapInterval; - device->GL_GetSwapInterval = X11_GL_GetSwapInterval; - device->GL_SwapWindow = X11_GL_SwapWindow; - device->GL_DeleteContext = X11_GL_DeleteContext; + if (!data->gles) { + device->GL_LoadLibrary = X11_GL_LoadLibrary; + device->GL_GetProcAddress = X11_GL_GetProcAddress; + device->GL_UnloadLibrary = X11_GL_UnloadLibrary; + device->GL_CreateContext = X11_GL_CreateContext; + device->GL_MakeCurrent = X11_GL_MakeCurrent; + device->GL_SetSwapInterval = X11_GL_SetSwapInterval; + device->GL_GetSwapInterval = X11_GL_GetSwapInterval; + device->GL_SwapWindow = X11_GL_SwapWindow; + device->GL_DeleteContext = X11_GL_DeleteContext; + } #endif #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - device->GL_LoadLibrary = X11_GLES_LoadLibrary; - device->GL_GetProcAddress = X11_GLES_GetProcAddress; - device->GL_UnloadLibrary = X11_GLES_UnloadLibrary; - device->GL_CreateContext = X11_GLES_CreateContext; - device->GL_MakeCurrent = X11_GLES_MakeCurrent; - device->GL_SetSwapInterval = X11_GLES_SetSwapInterval; - device->GL_GetSwapInterval = X11_GLES_GetSwapInterval; - device->GL_SwapWindow = X11_GLES_SwapWindow; - device->GL_DeleteContext = X11_GLES_DeleteContext; + if (data->gles) { + device->GL_LoadLibrary = X11_GLES_LoadLibrary; + device->GL_GetProcAddress = X11_GLES_GetProcAddress; + device->GL_UnloadLibrary = X11_GLES_UnloadLibrary; + device->GL_CreateContext = X11_GLES_CreateContext; + device->GL_MakeCurrent = X11_GLES_MakeCurrent; + device->GL_SetSwapInterval = X11_GLES_SetSwapInterval; + device->GL_GetSwapInterval = X11_GLES_GetSwapInterval; + device->GL_SwapWindow = X11_GLES_SwapWindow; + device->GL_DeleteContext = X11_GLES_DeleteContext; + } #endif device->SetClipboardText = X11_SetClipboardText; diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 59234296f..c3935cd15 100755 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -92,7 +92,9 @@ typedef struct SDL_VideoData Atom UTF8_STRING; SDL_Scancode key_layout[256]; - SDL_bool selection_waiting; + SDL_bool selection_waiting; + + SDL_bool gles; } SDL_VideoData; extern SDL_bool X11_UseDirectColorVisuals(void); diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 887d4c362..90557d109 100755 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -269,24 +269,19 @@ X11_CreateWindow(_THIS, SDL_Window * window) Atom wmstate_atoms[3]; Uint32 fevent = 0; -#if SDL_VIDEO_OPENGL_GLX +#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 if (window->flags & SDL_WINDOW_OPENGL) { XVisualInfo *vinfo; - vinfo = X11_GL_GetVisual(_this, display, screen); - if (!vinfo) { - return -1; - } - visual = vinfo->visual; - depth = vinfo->depth; - XFree(vinfo); - } else -#endif #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - if (window->flags & SDL_WINDOW_OPENGL) { - XVisualInfo *vinfo; + if (data->gles) { + vinfo = X11_GLES_GetVisual(_this, display, screen); + } else +#endif + { + vinfo = X11_GL_GetVisual(_this, display, screen); + } - vinfo = X11_GLES_GetVisual(_this, display, screen); if (!vinfo) { return -1; } @@ -395,7 +390,7 @@ X11_CreateWindow(_THIS, SDL_Window * window) return -1; } #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - if (window->flags & SDL_WINDOW_OPENGL) { + if (data->gles && window->flags & SDL_WINDOW_OPENGL) { /* Create the GLES window surface */ _this->gles_data->egl_surface = _this->gles_data->eglCreateWindowSurface(_this->gles_data->