author Sam Lantinga
Sun, 08 Jan 2012 02:23:37 -0500
changeset 6188 e82023802002
parent 6138 4c64952a58fb
child 6190 519380462400
permissions -rwxr-xr-x
Fixed bug 1242 - PATCH: Improve support for OpenGL ES under X11

Scott Percival 2011-07-03 06:41:51 PDT

This submission is aimed at making life easier for OpenGL ES capable devices
running a X11 stack (e.g. Maemo, Meego, TrimSlice, other ARM SoC boards not
running Android). SDL's Pandora support already has the neccesary GLES-to-X11
glue code, however it's all ghetto'd off in Makefile.pandora and not very

The patch:
- adds an awesome --enable-video-opengles option to configure
- re-modifies the opengles and opengles2 SDL_renderers to use function pointers
- no idea why this was removed?
- for SDL_Renderers, links in libGLESv1_CM, libGLES_CM (for PowerVR fans) or
libGLESv2 at runtime
- links in at runtime - the old code made an assumption that
eglFunctions could be pulled from the active GLES library, PowerVR for one
doesn't let you do that with their libGLESv2
- allows you to pick which of GLES v1 or v2 to load via

So far I've tested this on a Nokia N900 (OMAP 3430/SGX 530 running Maemo 5) and
a Toshiba AC100 (Tegra 2 running Ubuntu 10.10). I haven't tested it on... well,
everything that isn't those two, such as a Pandora, iOS or Android device. The
Pandora specific code should be kept intact (fingers crossed), and nothing
painfully drastic has been added to the SDL_renderers. The library loading
sequence in SDL_x11opengles has been updated to accomodate both NVIDIA's
propensity to let developers get away with murder and PowerVR's alternative of
punishing every missed step.

The test apps work okay with GLES or GLES2 as the renderer. For some reason
alpha blending doesn't seem to work on the Tegra 2; last week NVIDIA pushed out
a new set of X11 GLES drivers, so I'll try and investigate once I upgrade
those. Also, this patch adds things to, include/
and test/ I didn't know what the policy was re. committing
generated spaghetti from autotools, so ./ has to be run again. Sorry.

I think that's about everything, let me know if there's anything I've
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2012 Sam Lantinga <>
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    22 #include <GLES/gl.h>
    23 #include <GLES/egl.h>
    24 #include <dlfcn.h>
    25 #if defined(__OpenBSD__) && !defined(__ELF__)
    26 #define dlsym(x,y) dlsym(x, "_" y)
    27 #endif
    29 #include "../SDL_sysvideo.h"
    31 typedef struct SDL_PrivateGLESData
    32 {
    33     int egl_active;             /* to stop switching drivers while we have a valid context */
    34     XVisualInfo *egl_visualinfo;
    35     void *egl_dll_handle;
    36     EGLDisplay egl_display;
    37     EGLContext egl_context;     /* Current GLES context */
    38     EGLSurface egl_surface;
    39     EGLConfig egl_config;
    41       EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
    42       EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint * major,
    43                                   EGLint * minor);
    44       EGLBoolean(*eglTerminate) (EGLDisplay dpy);
    46     void *(*eglGetProcAddress) (const GLubyte * procName);
    48       EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
    49                                     const EGLint * attrib_list,
    50                                     EGLConfig * configs,
    51                                     EGLint config_size, EGLint * num_config);
    53       EGLContext(*eglCreateContext) (EGLDisplay dpy,
    54                                      EGLConfig config,
    55                                      EGLContext share_list,
    56                                      const EGLint * attrib_list);
    58       EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
    60       EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
    61                                            EGLConfig config,
    62                                            NativeWindowType window,
    63                                            const EGLint * attrib_list);
    64       EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
    66       EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
    67                                    EGLSurface read, EGLContext ctx);
    69       EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
    71     const char *(*eglQueryString) (EGLDisplay dpy, EGLint name);
    73       EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
    74                                        EGLint attribute, EGLint * value);
    76 } SDL_PrivateGLESData;
    78 /* OpenGLES functions */
    79 extern SDL_GLContext X11_GLES_CreateContext(_THIS, SDL_Window * window);
    80 extern XVisualInfo *X11_GLES_GetVisual(_THIS, Display * display, int screen);
    81 extern int X11_GLES_MakeCurrent(_THIS, SDL_Window * window,
    82                                 SDL_GLContext context);
    83 extern int X11_GLES_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
    84 extern int X11_GLES_LoadLibrary(_THIS, const char *path);
    85 extern void *X11_GLES_GetProcAddress(_THIS, const char *proc);
    86 extern void X11_GLES_UnloadLibrary(_THIS);
    88 extern int X11_GLES_SetSwapInterval(_THIS, int interval);
    89 extern int X11_GLES_GetSwapInterval(_THIS);
    90 extern void X11_GLES_SwapWindow(_THIS, SDL_Window * window);
    91 extern void X11_GLES_DeleteContext(_THIS, SDL_GLContext context);