X11 OpenGL ES minor corrections
authorSam Lantinga <slouken@libsdl.org>
Sun, 08 Jan 2012 13:31:22 -0500
changeset 6190519380462400
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
     1.1 --- a/src/render/opengles/SDL_glesfuncs.h	Fri Aug 26 13:23:40 2011 +0100
     1.2 +++ b/src/render/opengles/SDL_glesfuncs.h	Sun Jan 08 13:31:22 2012 -0500
     1.3 @@ -10,6 +10,7 @@
     1.4  SDL_PROC(void, glDrawTexiOES, (GLint, GLint, GLint, GLint, GLint))
     1.5  SDL_PROC(void, glEnable, (GLenum))
     1.6  SDL_PROC(void, glEnableClientState, (GLenum))
     1.7 +SDL_PROC(void, glFinish, (void))
     1.8  SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
     1.9  SDL_PROC(GLenum, glGetError, (void))
    1.10  SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
     2.1 --- a/src/render/opengles/SDL_render_gles.c	Fri Aug 26 13:23:40 2011 +0100
     2.2 +++ b/src/render/opengles/SDL_render_gles.c	Sun Jan 08 13:31:22 2012 -0500
     2.3 @@ -40,7 +40,7 @@
     2.4  
     2.5  /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
     2.6  
     2.7 -/* Used to re-create the window with OpenGL capability */
     2.8 +/* Used to re-create the window with OpenGL ES capability */
     2.9  extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
    2.10  
    2.11  static const float inv255f = 1.0f / 255.0f;
    2.12 @@ -151,6 +151,14 @@
    2.13  
    2.14  static int GLES_LoadFunctions(GLES_RenderData * data)
    2.15  {
    2.16 +#if SDL_VIDEO_DRIVER_UIKIT
    2.17 +#define __SDL_NOGETPROCADDR__
    2.18 +#elif SDL_VIDEO_DRIVER_ANDROID
    2.19 +#define __SDL_NOGETPROCADDR__
    2.20 +#elif SDL_VIDEO_DRIVER_PANDORA
    2.21 +#define __SDL_NOGETPROCADDR__
    2.22 +#endif
    2.23 +
    2.24  #ifdef __SDL_NOGETPROCADDR__
    2.25  #define SDL_PROC(ret,func,params) data->func=func;
    2.26  #else
    2.27 @@ -318,6 +326,8 @@
    2.28  static void
    2.29  GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
    2.30  {
    2.31 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    2.32 +    
    2.33      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
    2.34          /* Rebind the context to the window area and update matrices */
    2.35          SDL_CurrentContext = NULL;
    2.36 @@ -325,7 +335,7 @@
    2.37  
    2.38      if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
    2.39          /* According to Apple documentation, we need to finish drawing NOW! */
    2.40 -	glFinish();
    2.41 +	data->glFinish();
    2.42      }
    2.43  }
    2.44  
     3.1 --- a/src/render/opengles2/SDL_render_gles2.c	Fri Aug 26 13:23:40 2011 +0100
     3.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Jan 08 13:31:22 2012 -0500
     3.3 @@ -27,7 +27,7 @@
     3.4  #include "../SDL_sysrender.h"
     3.5  #include "SDL_shaders_gles2.h"
     3.6  
     3.7 -/* Used to re-create the window with OpenGL capability */
     3.8 +/* Used to re-create the window with OpenGL ES capability */
     3.9  extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
    3.10  
    3.11  /*************************************************************************************************
    3.12 @@ -158,7 +158,15 @@
    3.13  
    3.14  static int GLES2_LoadFunctions(GLES2_DriverContext * data)
    3.15  {
    3.16 -#ifdef __SDL_NOGETPROCADDR__
    3.17 +#if SDL_VIDEO_DRIVER_UIKIT
    3.18 +#define __SDL_NOGETPROCADDR__
    3.19 +#elif SDL_VIDEO_DRIVER_ANDROID
    3.20 +#define __SDL_NOGETPROCADDR__
    3.21 +#elif SDL_VIDEO_DRIVER_PANDORA
    3.22 +#define __SDL_NOGETPROCADDR__
    3.23 +#endif
    3.24 +
    3.25 +#if defined __SDL_NOGETPROCADDR__
    3.26  #define SDL_PROC(ret,func,params) data->func=func;
    3.27  #else
    3.28  #define SDL_PROC(ret,func,params) \
     4.1 --- a/src/video/x11/SDL_x11opengles.c	Fri Aug 26 13:23:40 2011 +0100
     4.2 +++ b/src/video/x11/SDL_x11opengles.c	Sun Jan 08 13:31:22 2012 -0500
     4.3 @@ -25,10 +25,10 @@
     4.4  #include "SDL_x11video.h"
     4.5  #include "SDL_x11opengles.h"
     4.6  
     4.7 -#define DEFAULT_EGL "/usr/lib/libEGL.so"
     4.8 -#define DEFAULT_OGL_ES2 "/usr/lib/libGLESv2.so"
     4.9 -#define DEFAULT_OGL_ES_PVR "/usr/lib/libGLES_CM.so"
    4.10 -#define DEFAULT_OGL_ES "/usr/lib/libGLESv1_CM.so"
    4.11 +#define DEFAULT_EGL "libEGL.so"
    4.12 +#define DEFAULT_OGL_ES2 "libGLESv2.so"
    4.13 +#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
    4.14 +#define DEFAULT_OGL_ES "libGLESv1_CM.so"
    4.15  
    4.16  #define LOAD_FUNC(NAME) \
    4.17  	*((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
    4.18 @@ -143,6 +143,7 @@
    4.19      LOAD_FUNC(eglDestroySurface);
    4.20      LOAD_FUNC(eglMakeCurrent);
    4.21      LOAD_FUNC(eglSwapBuffers);
    4.22 +    LOAD_FUNC(eglSwapInterval);
    4.23  
    4.24      _this->gles_data->egl_display =
    4.25          _this->gles_data->eglGetDisplay((NativeDisplayType) data->display);
    4.26 @@ -304,6 +305,7 @@
    4.27  
    4.28      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    4.29      Display *display = data->videodata->display;
    4.30 +    SDL_GLContext context = 1;
    4.31  
    4.32      XSync(display, False);
    4.33  
    4.34 @@ -323,13 +325,14 @@
    4.35      }
    4.36  
    4.37      _this->gles_data->egl_active = 1;
    4.38 +    _this->gles_data->egl_swapinterval = 0;
    4.39  
    4.40      if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
    4.41          X11_GLES_DeleteContext(_this, context);
    4.42          return NULL;
    4.43      }
    4.44  
    4.45 -    return (SDL_GLContext)(1);
    4.46 +    return context;
    4.47  }
    4.48  
    4.49  int
    4.50 @@ -353,17 +356,34 @@
    4.51      return (retval);
    4.52  }
    4.53  
    4.54 -static int swapinterval = -1;
    4.55  int
    4.56  X11_GLES_SetSwapInterval(_THIS, int interval)
    4.57  {
    4.58 -    return 0;
    4.59 +    if (_this->gles_data->egl_active != 1) {
    4.60 +        SDL_SetError("OpenGL ES context not active");
    4.61 +        return -1;
    4.62 +    }
    4.63 +
    4.64 +    EGLBoolean status;
    4.65 +    status = _this->gles_data->eglSwapInterval(_this->gles_data->egl_display, interval);
    4.66 +    if (status == EGL_TRUE) {
    4.67 +        _this->gles_data->egl_swapinterval = interval;
    4.68 +        return 0; 
    4.69 +    }
    4.70 +
    4.71 +    SDL_SetError("Unable to set the EGL swap interval");
    4.72 +    return -1;
    4.73  }
    4.74  
    4.75  int
    4.76  X11_GLES_GetSwapInterval(_THIS)
    4.77  {
    4.78 -    return 0;
    4.79 +    if (_this->gles_data->egl_active != 1) {
    4.80 +        SDL_SetError("OpenGL ES context not active");
    4.81 +        return -1;
    4.82 +    }
    4.83 +
    4.84 +    return _this->gles_data->egl_swapinterval;
    4.85  }
    4.86  
    4.87  void
     5.1 --- a/src/video/x11/SDL_x11opengles.h	Fri Aug 26 13:23:40 2011 +0100
     5.2 +++ b/src/video/x11/SDL_x11opengles.h	Sun Jan 08 13:31:22 2012 -0500
     5.3 @@ -37,13 +37,14 @@
     5.4      EGLContext egl_context;     /* Current GLES context */
     5.5      EGLSurface egl_surface;
     5.6      EGLConfig egl_config;
     5.7 +    int egl_swapinterval;
     5.8  
     5.9        EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
    5.10        EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
    5.11                                    EGLint * minor);
    5.12        EGLBoolean(*eglTerminate) (EGLDisplay dpy);
    5.13  
    5.14 -    void *(*eglGetProcAddress) (const GLubyte * procName);
    5.15 +    void *(*eglGetProcAddress) (const char * procName);
    5.16  
    5.17        EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
    5.18                                      const EGLint * attrib_list,
    5.19 @@ -68,6 +69,8 @@
    5.20  
    5.21        EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
    5.22  
    5.23 +      EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
    5.24 +
    5.25      const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
    5.26  
    5.27        EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,