src/video/x11/SDL_x11opengles.c
changeset 6188 e82023802002
parent 6138 4c64952a58fb
child 6190 519380462400
--- a/src/video/x11/SDL_x11opengles.c	Sun Jan 08 01:15:20 2012 -0500
+++ b/src/video/x11/SDL_x11opengles.c	Sun Jan 08 02:23:37 2012 -0500
@@ -25,7 +25,10 @@
 #include "SDL_x11video.h"
 #include "SDL_x11opengles.h"
 
-#define DEFAULT_OPENGL	"/usr/lib/libGLES_CM.so"
+#define DEFAULT_EGL "/usr/lib/libEGL.so"
+#define DEFAULT_OGL_ES2 "/usr/lib/libGLESv2.so"
+#define DEFAULT_OGL_ES_PVR "/usr/lib/libGLES_CM.so"
+#define DEFAULT_OGL_ES "/usr/lib/libGLESv1_CM.so"
 
 #define LOAD_FUNC(NAME) \
 	*((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
@@ -44,13 +47,15 @@
     void *handle;
     void *retval;
 
-    handle = _this->gl_config.dll_handle;
+    handle = _this->gles_data->egl_dll_handle;
     if (_this->gles_data->eglGetProcAddress) {
         retval = _this->gles_data->eglGetProcAddress(proc);
         if (retval) {
             return retval;
         }
     }
+    
+    handle = _this->gl_config.dll_handle;
 #if defined(__OpenBSD__) && !defined(__ELF__)
 #undef dlsym(x,y);
 #endif
@@ -70,6 +75,7 @@
         _this->gles_data->eglTerminate(_this->gles_data->egl_display);
 
         dlclose(_this->gl_config.dll_handle);
+        dlclose(_this->gles_data->egl_dll_handle);
 
         _this->gles_data->eglGetProcAddress = NULL;
         _this->gles_data->eglChooseConfig = NULL;
@@ -111,7 +117,7 @@
         dlclose(handle);
         path = getenv("SDL_VIDEO_GL_DRIVER");
         if (path == NULL) {
-            path = DEFAULT_OPENGL;
+            path = DEFAULT_EGL;
         }
         handle = dlopen(path, dlopen_flags);
     }
@@ -153,6 +159,29 @@
         return -1;
     }
 
+    _this->gles_data->egl_dll_handle = handle;
+
+    path = getenv("SDL_VIDEO_GL_DRIVER");
+    handle = dlopen(path, dlopen_flags);
+    if ((path == NULL) | (handle == NULL)) {
+        if (_this->gl_config.major_version > 1) {
+            path = DEFAULT_OGL_ES2;
+            handle = dlopen(path, dlopen_flags);
+        } else {
+            path = DEFAULT_OGL_ES;
+            handle = dlopen(path, dlopen_flags);
+            if (handle == NULL) {
+                path = DEFAULT_OGL_ES_PVR;
+                handle = dlopen(path, dlopen_flags);
+            }
+        }
+    }
+
+    if (handle == NULL) {
+        SDL_SetError("Could not initialize OpenGL ES library");
+        return -1;
+    }
+
     _this->gl_config.dll_handle = handle;
     _this->gl_config.driver_loaded = 1;
 
@@ -218,6 +247,13 @@
         attribs[i++] = _this->gl_config.multisamplesamples;
     }
 
+    attribs[i++] = EGL_RENDERABLE_TYPE;
+    if (_this->gl_config.major_version == 2) {
+        attribs[i++] = EGL_OPENGL_ES2_BIT;
+    } else {
+        attribs[i++] = EGL_OPENGL_ES_BIT;
+    }
+
     attribs[i++] = EGL_NONE;
 
     if (_this->gles_data->eglChooseConfig(_this->gles_data->egl_display,
@@ -260,17 +296,25 @@
 SDL_GLContext
 X11_GLES_CreateContext(_THIS, SDL_Window * window)
 {
-    int retval;
+    EGLint context_attrib_list[] = {
+        EGL_CONTEXT_CLIENT_VERSION,
+        1,
+        EGL_NONE
+    };
+
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
 
     XSync(display, False);
 
+    if (_this->gl_config.major_version) {
+        context_attrib_list[1] = _this->gl_config.major_version;
+    }
 
     _this->gles_data->egl_context =
         _this->gles_data->eglCreateContext(_this->gles_data->egl_display,
                                            _this->gles_data->egl_config,
-                                           EGL_NO_CONTEXT, NULL);
+                                           EGL_NO_CONTEXT, context_attrib_list);
     XSync(display, False);
 
     if (_this->gles_data->egl_context == EGL_NO_CONTEXT) {
@@ -280,12 +324,12 @@
 
     _this->gles_data->egl_active = 1;
 
-    if (_this->gles_data->egl_active)
-        retval = 1;
-    else
-        retval = 0;
+    if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
+        X11_GLES_DeleteContext(_this, context);
+        return NULL;
+    }
 
-    return (retval);
+    return (SDL_GLContext)(1);
 }
 
 int