# HG changeset patch # User David Gow # Date 1342366281 -28800 # Node ID b3aef50d2ffb5187cf22718f3b723479d242c232 # Parent efd48af40ec3167c89d3c73d430b3b5a29a8c785 Add SDL_VIDEO_X11_USEEGL env variable to allow toggling of egl/glx. Also make GLX the default api, as it is more often used on X11 diff -r efd48af40ec3 -r b3aef50d2ffb src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Wed Jul 11 22:20:02 2012 -0400 +++ b/src/video/x11/SDL_x11video.c Sun Jul 15 23:31:21 2012 +0800 @@ -112,7 +112,9 @@ SDL_free(data->windowlist); SDL_free(device->driverdata); #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - SDL_free(device->gles_data); + if (data->use_egl) { + SDL_free(device->gles_data); + } #endif SDL_free(device); @@ -125,6 +127,7 @@ SDL_VideoDevice *device; SDL_VideoData *data; const char *display = NULL; /* Use the DISPLAY environment variable */ + char *egl_env; if (!SDL_X11_LoadSymbols()) { return NULL; @@ -144,11 +147,25 @@ } device->driverdata = data; + /* Use GLX by default as egl does not work on many X11 systems */ +#if SDL_VIDEO_OPENGL_GLX + data->use_egl = SDL_FALSE; +#elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 + data->use_egl = SDL_TRUE; +#endif + egl_env = SDL_getenv("SDL_VIDEO_X11_USEEGL"); + if (egl_env) { + data->use_egl = atoi(egl_env)?SDL_TRUE:SDL_FALSE; + } + #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(); - return NULL; + if (data->use_egl) + { + device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData)); + if (!device->gles_data) { + SDL_OutOfMemory(); + return NULL; + } } #endif @@ -218,26 +235,30 @@ 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->use_egl) { + 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->use_egl) { + 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 -r efd48af40ec3 -r b3aef50d2ffb src/video/x11/SDL_x11video.h --- a/src/video/x11/SDL_x11video.h Wed Jul 11 22:20:02 2012 -0400 +++ b/src/video/x11/SDL_x11video.h Sun Jul 15 23:31:21 2012 +0800 @@ -92,7 +92,9 @@ Atom UTF8_STRING; SDL_Scancode key_layout[256]; - SDL_bool selection_waiting; + SDL_bool selection_waiting; + + SDL_bool use_egl; } SDL_VideoData; extern SDL_bool X11_UseDirectColorVisuals(void); diff -r efd48af40ec3 -r b3aef50d2ffb src/video/x11/SDL_x11window.c --- a/src/video/x11/SDL_x11window.c Wed Jul 11 22:20:02 2012 -0400 +++ b/src/video/x11/SDL_x11window.c Sun Jul 15 23:31:21 2012 +0800 @@ -270,7 +270,7 @@ Uint32 fevent = 0; #if SDL_VIDEO_OPENGL_GLX - if (window->flags & SDL_WINDOW_OPENGL) { + if ((!data->use_egl) && (window->flags & SDL_WINDOW_OPENGL)) { XVisualInfo *vinfo; vinfo = X11_GL_GetVisual(_this, display, screen); @@ -283,7 +283,7 @@ } else #endif #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - if (window->flags & SDL_WINDOW_OPENGL) { + if ((data->use_egl) && (window->flags & SDL_WINDOW_OPENGL)) { XVisualInfo *vinfo; vinfo = X11_GLES_GetVisual(_this, display, screen); @@ -395,7 +395,7 @@ return -1; } #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 - if (window->flags & SDL_WINDOW_OPENGL) { + if ((data->use_egl) && (window->flags & SDL_WINDOW_OPENGL)) { /* Create the GLES window surface */ _this->gles_data->egl_surface = _this->gles_data->eglCreateWindowSurface(_this->gles_data->