X11 OpenGL ES minor corrections
authorSam Lantinga <slouken@libsdl.org>
Sun, 08 Jan 2012 13:31:22 -0500
changeset 6190 519380462400
parent 6189 b5a665fbaedc
child 6191 2c0d35b1af4e
X11 OpenGL ES minor corrections Scott Percival 2012-01-08 04:21:22 PST I tested the new build on my two ARM machines, and fixed a few bugs: - if SDL_VIDEO_DRIVER_UIKIT, SDL_VIDEO_DRIVER_ANDROID or SDL_VIDEO_DRIVER_PANDORA are specified, function pointers are grabbed from the compile-linked library instead of through SDL_GL_GetProcAddress. (not sure if this is the best way to go about it) - removing "/usr/lib/" from all the library names (hey, with multiarch you can't be too sure anymore) - added glFinish to glesfuncs.h - changed the eglGetProcAddress arg type to "const char *" as per the EGL spec - filled in the stubs for X11_GLES_SetSwapInterval and X11_GLES_GetSwapInterval
src/render/opengles/SDL_glesfuncs.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11opengles.h
--- a/src/render/opengles/SDL_glesfuncs.h	Fri Aug 26 13:23:40 2011 +0100
+++ b/src/render/opengles/SDL_glesfuncs.h	Sun Jan 08 13:31:22 2012 -0500
@@ -10,6 +10,7 @@
 SDL_PROC(void, glDrawTexiOES, (GLint, GLint, GLint, GLint, GLint))
 SDL_PROC(void, glEnable, (GLenum))
 SDL_PROC(void, glEnableClientState, (GLenum))
+SDL_PROC(void, glFinish, (void))
 SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
 SDL_PROC(GLenum, glGetError, (void))
 SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
--- a/src/render/opengles/SDL_render_gles.c	Fri Aug 26 13:23:40 2011 +0100
+++ b/src/render/opengles/SDL_render_gles.c	Sun Jan 08 13:31:22 2012 -0500
@@ -40,7 +40,7 @@
 
 /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
 
-/* Used to re-create the window with OpenGL capability */
+/* Used to re-create the window with OpenGL ES capability */
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
 static const float inv255f = 1.0f / 255.0f;
@@ -151,6 +151,14 @@
 
 static int GLES_LoadFunctions(GLES_RenderData * data)
 {
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_PANDORA
+#define __SDL_NOGETPROCADDR__
+#endif
+
 #ifdef __SDL_NOGETPROCADDR__
 #define SDL_PROC(ret,func,params) data->func=func;
 #else
@@ -318,6 +326,8 @@
 static void
 GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
 {
+    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+    
     if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
         /* Rebind the context to the window area and update matrices */
         SDL_CurrentContext = NULL;
@@ -325,7 +335,7 @@
 
     if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
         /* According to Apple documentation, we need to finish drawing NOW! */
-	glFinish();
+	data->glFinish();
     }
 }
 
--- a/src/render/opengles2/SDL_render_gles2.c	Fri Aug 26 13:23:40 2011 +0100
+++ b/src/render/opengles2/SDL_render_gles2.c	Sun Jan 08 13:31:22 2012 -0500
@@ -27,7 +27,7 @@
 #include "../SDL_sysrender.h"
 #include "SDL_shaders_gles2.h"
 
-/* Used to re-create the window with OpenGL capability */
+/* Used to re-create the window with OpenGL ES capability */
 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
 
 /*************************************************************************************************
@@ -158,7 +158,15 @@
 
 static int GLES2_LoadFunctions(GLES2_DriverContext * data)
 {
-#ifdef __SDL_NOGETPROCADDR__
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_PANDORA
+#define __SDL_NOGETPROCADDR__
+#endif
+
+#if defined __SDL_NOGETPROCADDR__
 #define SDL_PROC(ret,func,params) data->func=func;
 #else
 #define SDL_PROC(ret,func,params) \
--- a/src/video/x11/SDL_x11opengles.c	Fri Aug 26 13:23:40 2011 +0100
+++ b/src/video/x11/SDL_x11opengles.c	Sun Jan 08 13:31:22 2012 -0500
@@ -25,10 +25,10 @@
 #include "SDL_x11video.h"
 #include "SDL_x11opengles.h"
 
-#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 DEFAULT_EGL "libEGL.so"
+#define DEFAULT_OGL_ES2 "libGLESv2.so"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
+#define DEFAULT_OGL_ES "libGLESv1_CM.so"
 
 #define LOAD_FUNC(NAME) \
 	*((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
@@ -143,6 +143,7 @@
     LOAD_FUNC(eglDestroySurface);
     LOAD_FUNC(eglMakeCurrent);
     LOAD_FUNC(eglSwapBuffers);
+    LOAD_FUNC(eglSwapInterval);
 
     _this->gles_data->egl_display =
         _this->gles_data->eglGetDisplay((NativeDisplayType) data->display);
@@ -304,6 +305,7 @@
 
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
+    SDL_GLContext context = 1;
 
     XSync(display, False);
 
@@ -323,13 +325,14 @@
     }
 
     _this->gles_data->egl_active = 1;
+    _this->gles_data->egl_swapinterval = 0;
 
     if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
         X11_GLES_DeleteContext(_this, context);
         return NULL;
     }
 
-    return (SDL_GLContext)(1);
+    return context;
 }
 
 int
@@ -353,17 +356,34 @@
     return (retval);
 }
 
-static int swapinterval = -1;
 int
 X11_GLES_SetSwapInterval(_THIS, int interval)
 {
-    return 0;
+    if (_this->gles_data->egl_active != 1) {
+        SDL_SetError("OpenGL ES context not active");
+        return -1;
+    }
+
+    EGLBoolean status;
+    status = _this->gles_data->eglSwapInterval(_this->gles_data->egl_display, interval);
+    if (status == EGL_TRUE) {
+        _this->gles_data->egl_swapinterval = interval;
+        return 0; 
+    }
+
+    SDL_SetError("Unable to set the EGL swap interval");
+    return -1;
 }
 
 int
 X11_GLES_GetSwapInterval(_THIS)
 {
-    return 0;
+    if (_this->gles_data->egl_active != 1) {
+        SDL_SetError("OpenGL ES context not active");
+        return -1;
+    }
+
+    return _this->gles_data->egl_swapinterval;
 }
 
 void
--- a/src/video/x11/SDL_x11opengles.h	Fri Aug 26 13:23:40 2011 +0100
+++ b/src/video/x11/SDL_x11opengles.h	Sun Jan 08 13:31:22 2012 -0500
@@ -37,13 +37,14 @@
     EGLContext egl_context;     /* Current GLES context */
     EGLSurface egl_surface;
     EGLConfig egl_config;
+    int egl_swapinterval;
 
       EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
       EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
                                   EGLint * minor);
       EGLBoolean(*eglTerminate) (EGLDisplay dpy);
 
-    void *(*eglGetProcAddress) (const GLubyte * procName);
+    void *(*eglGetProcAddress) (const char * procName);
 
       EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
                                     const EGLint * attrib_list,
@@ -68,6 +69,8 @@
 
       EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
 
+      EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
+
     const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
 
       EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,