src/video/x11/SDL_x11opengles.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 18 Jul 2012 15:17:27 -0700
changeset 6370 93187f7f7d5d
parent 6368 fcbbd0e2da5e
child 6373 494e0436525f
permissions -rwxr-xr-x
Improved simultaneous support for OpenGL and OpenGL ES

From Scott Percival

Okay, I think I have something for this. Tested it on GL and GLES
machines, it seems to work okay.

- Add a new SDL GL attribute SDL_GL_CONTEXT_EGL:
- Only useful for the X11 video driver at the moment
- Set to 1 for an EGL context, 0 to use the default for the video driver
- Default is 0, unless library is built for EGL only
- Should be set after SDL init, but before window/context
creation (i.e. same place you'd specify attributes for major/minor GL
version)
- After a lot of agony pondering the least-terrible way to go about
it, made it so that X11_GL_LoadLibrary and X11_GLES_LoadLibrary check
SDL_GL_CONTEXT_EGL. If no GL context exists yet, and the attribute
choice doesn't match with the checking function, then it changes all
the function pointers in the video driver and passes control on to the
new LoadLibrary method.
- Likewise, make X11_CreateWindow check this attribute before firing
off a call to X11_GL_GetVisual/X11_GLES_GetVisual
- Added a sanity check to the start of X11_GL_LoadLibrary
- Tidied up SDL_x11opengles.h
- Moved ownership of the gles_data structure over to
X11_GLES_LoadLibrary/UnloadLibrary
- Should incorporate the 3 fixes posted by Andre Heider

This is obviously quite a bit to take in, but is (at least) a proof of
concept for the approach I think EGL/GLX mingling should take. Any
comments/criticism is much appreciated.
slouken@3190
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@3190
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@3190
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@3190
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@3190
    20
*/
slouken@3190
    21
#include "SDL_config.h"
slouken@3190
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_ES
slouken@3190
    24
slouken@3190
    25
#include "SDL_x11video.h"
slouken@3190
    26
#include "SDL_x11opengles.h"
slouken@6370
    27
#include "SDL_x11opengl.h"
slouken@3190
    28
slouken@6190
    29
#define DEFAULT_EGL "libEGL.so"
slouken@6190
    30
#define DEFAULT_OGL_ES2 "libGLESv2.so"
slouken@6190
    31
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
slouken@6190
    32
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
slouken@3190
    33
slouken@3190
    34
#define LOAD_FUNC(NAME) \
slouken@3190
    35
	*((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
slouken@3190
    36
	if (!_this->gles_data->NAME) \
slouken@3190
    37
	{ \
slouken@3190
    38
		SDL_SetError("Could not retrieve EGL function " #NAME); \
slouken@3190
    39
		return -1; \
slouken@3190
    40
	}
slouken@3190
    41
slouken@3190
    42
/* GLES implementation of SDL OpenGL support */
slouken@3190
    43
slouken@3190
    44
void *
slouken@3190
    45
X11_GLES_GetProcAddress(_THIS, const char *proc)
slouken@3190
    46
{
slouken@3190
    47
    static char procname[1024];
slouken@3190
    48
    void *handle;
slouken@3190
    49
    void *retval;
slouken@3190
    50
slouken@6188
    51
    handle = _this->gles_data->egl_dll_handle;
slouken@3190
    52
    if (_this->gles_data->eglGetProcAddress) {
slouken@3190
    53
        retval = _this->gles_data->eglGetProcAddress(proc);
slouken@3190
    54
        if (retval) {
slouken@3190
    55
            return retval;
slouken@3190
    56
        }
slouken@3190
    57
    }
slouken@6188
    58
    
slouken@6188
    59
    handle = _this->gl_config.dll_handle;
slouken@3190
    60
#if defined(__OpenBSD__) && !defined(__ELF__)
slouken@3190
    61
#undef dlsym(x,y);
slouken@3190
    62
#endif
slouken@3190
    63
    retval = dlsym(handle, proc);
slouken@3190
    64
    if (!retval && strlen(proc) <= 1022) {
slouken@3190
    65
        procname[0] = '_';
slouken@3190
    66
        strcpy(procname + 1, proc);
slouken@3190
    67
        retval = dlsym(handle, procname);
slouken@3190
    68
    }
slouken@3190
    69
    return retval;
slouken@3190
    70
}
slouken@3190
    71
slouken@3190
    72
void
slouken@3190
    73
X11_GLES_UnloadLibrary(_THIS)
slouken@3190
    74
{
slouken@6370
    75
    if ((_this->gles_data) && (_this->gl_config.driver_loaded)) {
slouken@3190
    76
        _this->gles_data->eglTerminate(_this->gles_data->egl_display);
slouken@3190
    77
slouken@3190
    78
        dlclose(_this->gl_config.dll_handle);
slouken@6188
    79
        dlclose(_this->gles_data->egl_dll_handle);
slouken@3190
    80
slouken@6370
    81
        SDL_free(_this->gles_data);
slouken@6370
    82
        _this->gles_data = NULL;
slouken@3190
    83
slouken@3190
    84
        _this->gl_config.dll_handle = NULL;
slouken@3190
    85
        _this->gl_config.driver_loaded = 0;
slouken@3190
    86
    }
slouken@3190
    87
}
slouken@3190
    88
slouken@3190
    89
int
slouken@3190
    90
X11_GLES_LoadLibrary(_THIS, const char *path)
slouken@3190
    91
{
slouken@3190
    92
    void *handle;
slouken@3190
    93
    int dlopen_flags;
slouken@3190
    94
slouken@3190
    95
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3190
    96
slouken@6370
    97
    if (_this->gles_data) {
slouken@3190
    98
        SDL_SetError("OpenGL ES context already created");
slouken@3190
    99
        return -1;
slouken@3190
   100
    }
slouken@6370
   101
slouken@6370
   102
#if SDL_VIDEO_OPENGL_GLX
slouken@6370
   103
    /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions  */
slouken@6370
   104
    if (_this->gl_config.use_egl == 0) {
slouken@6370
   105
        _this->GL_LoadLibrary = X11_GL_LoadLibrary;
slouken@6370
   106
        _this->GL_GetProcAddress = X11_GL_GetProcAddress;
slouken@6370
   107
        _this->GL_UnloadLibrary = X11_GL_UnloadLibrary;
slouken@6370
   108
        _this->GL_CreateContext = X11_GL_CreateContext;
slouken@6370
   109
        _this->GL_MakeCurrent = X11_GL_MakeCurrent;
slouken@6370
   110
        _this->GL_SetSwapInterval = X11_GL_SetSwapInterval;
slouken@6370
   111
        _this->GL_GetSwapInterval = X11_GL_GetSwapInterval;
slouken@6370
   112
        _this->GL_SwapWindow = X11_GL_SwapWindow;
slouken@6370
   113
        _this->GL_DeleteContext = X11_GL_DeleteContext;
slouken@6370
   114
        return X11_GL_LoadLibrary(_this, path);
slouken@6370
   115
    }
slouken@6370
   116
#endif
slouken@6370
   117
slouken@3190
   118
#ifdef RTLD_GLOBAL
slouken@3190
   119
    dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
slouken@3190
   120
#else
slouken@3190
   121
    dlopen_flags = RTLD_LAZY;
slouken@3190
   122
#endif
slouken@3190
   123
    handle = dlopen(path, dlopen_flags);
slouken@3190
   124
    /* Catch the case where the application isn't linked with EGL */
slouken@3190
   125
    if ((dlsym(handle, "eglChooseConfig") == NULL) && (path == NULL)) {
slouken@3190
   126
slouken@3190
   127
        dlclose(handle);
slouken@6368
   128
        path = getenv("SDL_VIDEO_EGL_DRIVER");
slouken@3190
   129
        if (path == NULL) {
slouken@6188
   130
            path = DEFAULT_EGL;
slouken@3190
   131
        }
slouken@3190
   132
        handle = dlopen(path, dlopen_flags);
slouken@3190
   133
    }
slouken@3190
   134
slouken@3190
   135
    if (handle == NULL) {
slouken@3190
   136
        SDL_SetError("Could not load OpenGL ES/EGL library");
slouken@3190
   137
        return -1;
slouken@3190
   138
    }
slouken@3190
   139
slouken@3190
   140
    /* Unload the old driver and reset the pointers */
slouken@3190
   141
    X11_GLES_UnloadLibrary(_this);
slouken@3190
   142
slouken@6370
   143
    _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
slouken@6370
   144
    if (!_this->gles_data) {
slouken@6370
   145
        SDL_OutOfMemory();
slouken@6370
   146
        return -1;
slouken@6370
   147
    }
slouken@6370
   148
slouken@3190
   149
    /* Load new function pointers */
slouken@3190
   150
    LOAD_FUNC(eglGetDisplay);
slouken@3190
   151
    LOAD_FUNC(eglInitialize);
slouken@3190
   152
    LOAD_FUNC(eglTerminate);
slouken@3190
   153
    LOAD_FUNC(eglGetProcAddress);
slouken@3190
   154
    LOAD_FUNC(eglChooseConfig);
slouken@3190
   155
    LOAD_FUNC(eglGetConfigAttrib);
slouken@3190
   156
    LOAD_FUNC(eglCreateContext);
slouken@3190
   157
    LOAD_FUNC(eglDestroyContext);
slouken@3190
   158
    LOAD_FUNC(eglCreateWindowSurface);
slouken@3190
   159
    LOAD_FUNC(eglDestroySurface);
slouken@3190
   160
    LOAD_FUNC(eglMakeCurrent);
slouken@3190
   161
    LOAD_FUNC(eglSwapBuffers);
slouken@6190
   162
    LOAD_FUNC(eglSwapInterval);
slouken@3190
   163
slouken@3190
   164
    _this->gles_data->egl_display =
slouken@3190
   165
        _this->gles_data->eglGetDisplay((NativeDisplayType) data->display);
slouken@3190
   166
slouken@3190
   167
    if (!_this->gles_data->egl_display) {
slouken@3190
   168
        SDL_SetError("Could not get EGL display");
slouken@3190
   169
        return -1;
slouken@3190
   170
    }
slouken@3190
   171
slouken@3190
   172
    if (_this->gles_data->
slouken@3190
   173
        eglInitialize(_this->gles_data->egl_display, NULL,
slouken@3190
   174
                      NULL) != EGL_TRUE) {
slouken@3190
   175
        SDL_SetError("Could not initialize EGL");
slouken@3190
   176
        return -1;
slouken@3190
   177
    }
slouken@3190
   178
slouken@6188
   179
    _this->gles_data->egl_dll_handle = handle;
slouken@6188
   180
slouken@6188
   181
    path = getenv("SDL_VIDEO_GL_DRIVER");
slouken@6188
   182
    handle = dlopen(path, dlopen_flags);
slouken@6188
   183
    if ((path == NULL) | (handle == NULL)) {
slouken@6188
   184
        if (_this->gl_config.major_version > 1) {
slouken@6188
   185
            path = DEFAULT_OGL_ES2;
slouken@6188
   186
            handle = dlopen(path, dlopen_flags);
slouken@6188
   187
        } else {
slouken@6188
   188
            path = DEFAULT_OGL_ES;
slouken@6188
   189
            handle = dlopen(path, dlopen_flags);
slouken@6188
   190
            if (handle == NULL) {
slouken@6188
   191
                path = DEFAULT_OGL_ES_PVR;
slouken@6188
   192
                handle = dlopen(path, dlopen_flags);
slouken@6188
   193
            }
slouken@6188
   194
        }
slouken@6188
   195
    }
slouken@6188
   196
slouken@6188
   197
    if (handle == NULL) {
slouken@6188
   198
        SDL_SetError("Could not initialize OpenGL ES library");
slouken@6188
   199
        return -1;
slouken@6188
   200
    }
slouken@6188
   201
slouken@3190
   202
    _this->gl_config.dll_handle = handle;
slouken@3190
   203
    _this->gl_config.driver_loaded = 1;
slouken@3190
   204
slouken@3190
   205
    if (path) {
slouken@3190
   206
        strncpy(_this->gl_config.driver_path, path,
slouken@3190
   207
                sizeof(_this->gl_config.driver_path) - 1);
slouken@3190
   208
    } else {
slouken@3190
   209
        strcpy(_this->gl_config.driver_path, "");
slouken@3190
   210
    }
slouken@3190
   211
    return 0;
slouken@3190
   212
}
slouken@3190
   213
slouken@3190
   214
XVisualInfo *
slouken@3190
   215
X11_GLES_GetVisual(_THIS, Display * display, int screen)
slouken@3190
   216
{
slouken@3190
   217
    /* 64 seems nice. */
slouken@3190
   218
    EGLint attribs[64];
slouken@3190
   219
    EGLint found_configs = 0;
slouken@3190
   220
    VisualID visual_id;
slouken@3190
   221
    int i;
slouken@3190
   222
slouken@6370
   223
    if (!_this->gles_data) {
slouken@6370
   224
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
slouken@6370
   225
        return NULL;
slouken@3190
   226
    }
slouken@3190
   227
slouken@3190
   228
    i = 0;
slouken@3190
   229
    attribs[i++] = EGL_RED_SIZE;
slouken@3190
   230
    attribs[i++] = _this->gl_config.red_size;
slouken@3190
   231
    attribs[i++] = EGL_GREEN_SIZE;
slouken@3190
   232
    attribs[i++] = _this->gl_config.green_size;
slouken@3190
   233
    attribs[i++] = EGL_BLUE_SIZE;
slouken@3190
   234
    attribs[i++] = _this->gl_config.blue_size;
slouken@3190
   235
slouken@3190
   236
    if (_this->gl_config.alpha_size) {
slouken@3190
   237
        attribs[i++] = EGL_ALPHA_SIZE;
slouken@3190
   238
        attribs[i++] = _this->gl_config.alpha_size;
slouken@3190
   239
    }
slouken@3190
   240
slouken@3190
   241
    if (_this->gl_config.buffer_size) {
slouken@3190
   242
        attribs[i++] = EGL_BUFFER_SIZE;
slouken@3190
   243
        attribs[i++] = _this->gl_config.buffer_size;
slouken@3190
   244
    }
slouken@3190
   245
slouken@3190
   246
    attribs[i++] = EGL_DEPTH_SIZE;
slouken@3190
   247
    attribs[i++] = _this->gl_config.depth_size;
slouken@3190
   248
slouken@3190
   249
    if (_this->gl_config.stencil_size) {
slouken@3190
   250
        attribs[i++] = EGL_STENCIL_SIZE;
slouken@3190
   251
        attribs[i++] = _this->gl_config.stencil_size;
slouken@3190
   252
    }
slouken@3190
   253
slouken@3190
   254
    if (_this->gl_config.multisamplebuffers) {
slouken@3190
   255
        attribs[i++] = EGL_SAMPLE_BUFFERS;
slouken@3190
   256
        attribs[i++] = _this->gl_config.multisamplebuffers;
slouken@3190
   257
    }
slouken@3190
   258
slouken@3190
   259
    if (_this->gl_config.multisamplesamples) {
slouken@3190
   260
        attribs[i++] = EGL_SAMPLES;
slouken@3190
   261
        attribs[i++] = _this->gl_config.multisamplesamples;
slouken@3190
   262
    }
slouken@3190
   263
slouken@6188
   264
    attribs[i++] = EGL_RENDERABLE_TYPE;
slouken@6188
   265
    if (_this->gl_config.major_version == 2) {
slouken@6188
   266
        attribs[i++] = EGL_OPENGL_ES2_BIT;
slouken@6188
   267
    } else {
slouken@6188
   268
        attribs[i++] = EGL_OPENGL_ES_BIT;
slouken@6188
   269
    }
slouken@6188
   270
slouken@3190
   271
    attribs[i++] = EGL_NONE;
slouken@3190
   272
slouken@3190
   273
    if (_this->gles_data->eglChooseConfig(_this->gles_data->egl_display,
slouken@3190
   274
                                          attribs,
slouken@3190
   275
                                          &_this->gles_data->egl_config, 1,
slouken@3190
   276
                                          &found_configs) == EGL_FALSE ||
slouken@3190
   277
        found_configs == 0) {
slouken@3190
   278
        SDL_SetError("Couldn't find matching EGL config");
slouken@3190
   279
        return NULL;
slouken@3190
   280
    }
slouken@3190
   281
slouken@3190
   282
    if (_this->gles_data->eglGetConfigAttrib(_this->gles_data->egl_display,
slouken@3190
   283
                                             _this->gles_data->egl_config,
slouken@3190
   284
                                             EGL_NATIVE_VISUAL_ID,
slouken@3190
   285
                                             (EGLint *) & visual_id) ==
slouken@3190
   286
        EGL_FALSE || !visual_id) {
slouken@3190
   287
        /* Use the default visual when all else fails */
slouken@3190
   288
        XVisualInfo vi_in;
slouken@3190
   289
        int out_count;
slouken@3190
   290
        vi_in.screen = screen;
slouken@3190
   291
slouken@3190
   292
        _this->gles_data->egl_visualinfo = XGetVisualInfo(display,
slouken@3190
   293
                                                          VisualScreenMask,
slouken@3190
   294
                                                          &vi_in, &out_count);
slouken@3190
   295
    } else {
slouken@3190
   296
        XVisualInfo vi_in;
slouken@3190
   297
        int out_count;
slouken@3190
   298
slouken@3190
   299
        vi_in.screen = screen;
slouken@3190
   300
        vi_in.visualid = visual_id;
slouken@3190
   301
        _this->gles_data->egl_visualinfo = XGetVisualInfo(display,
slouken@3190
   302
                                                          VisualScreenMask |
slouken@3190
   303
                                                          VisualIDMask,
slouken@3190
   304
                                                          &vi_in, &out_count);
slouken@3190
   305
    }
slouken@3190
   306
slouken@3190
   307
    return _this->gles_data->egl_visualinfo;
slouken@3190
   308
}
slouken@3190
   309
slouken@3190
   310
SDL_GLContext
slouken@3190
   311
X11_GLES_CreateContext(_THIS, SDL_Window * window)
slouken@3190
   312
{
slouken@6188
   313
    EGLint context_attrib_list[] = {
slouken@6188
   314
        EGL_CONTEXT_CLIENT_VERSION,
slouken@6188
   315
        1,
slouken@6188
   316
        EGL_NONE
slouken@6188
   317
    };
slouken@6188
   318
slouken@3190
   319
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@3190
   320
    Display *display = data->videodata->display;
slouken@6190
   321
    SDL_GLContext context = 1;
slouken@3190
   322
slouken@3190
   323
    XSync(display, False);
slouken@3190
   324
slouken@6188
   325
    if (_this->gl_config.major_version) {
slouken@6188
   326
        context_attrib_list[1] = _this->gl_config.major_version;
slouken@6188
   327
    }
slouken@3190
   328
slouken@3190
   329
    _this->gles_data->egl_context =
slouken@3190
   330
        _this->gles_data->eglCreateContext(_this->gles_data->egl_display,
slouken@3190
   331
                                           _this->gles_data->egl_config,
slouken@6188
   332
                                           EGL_NO_CONTEXT, context_attrib_list);
slouken@3190
   333
    XSync(display, False);
slouken@3190
   334
slouken@3190
   335
    if (_this->gles_data->egl_context == EGL_NO_CONTEXT) {
slouken@3190
   336
        SDL_SetError("Could not create EGL context");
slouken@3190
   337
        return NULL;
slouken@3190
   338
    }
slouken@3190
   339
slouken@6190
   340
    _this->gles_data->egl_swapinterval = 0;
slouken@3190
   341
slouken@6188
   342
    if (X11_GLES_MakeCurrent(_this, window, context) < 0) {
slouken@6188
   343
        X11_GLES_DeleteContext(_this, context);
slouken@6188
   344
        return NULL;
slouken@6188
   345
    }
slouken@3190
   346
slouken@6190
   347
    return context;
slouken@3190
   348
}
slouken@3190
   349
slouken@3190
   350
int
slouken@3190
   351
X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
slouken@3190
   352
{
slouken@3190
   353
    int retval;
slouken@3190
   354
slouken@3218
   355
//    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@3218
   356
//    Display *display = data->videodata->display;
slouken@3190
   357
slouken@3190
   358
    retval = 1;
slouken@3190
   359
    if (!_this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
slouken@3190
   360
                                          _this->gles_data->egl_surface,
slouken@3190
   361
                                          _this->gles_data->egl_surface,
slouken@3190
   362
                                          _this->gles_data->egl_context)) {
slouken@3190
   363
        SDL_SetError("Unable to make EGL context current");
slouken@3190
   364
        retval = -1;
slouken@3190
   365
    }
slouken@3218
   366
//    XSync(display, False);
slouken@3190
   367
slouken@3190
   368
    return (retval);
slouken@3190
   369
}
slouken@3190
   370
slouken@3190
   371
int
slouken@3190
   372
X11_GLES_SetSwapInterval(_THIS, int interval)
slouken@3190
   373
{
slouken@6370
   374
    if (_this->gles_data) {
slouken@6190
   375
        SDL_SetError("OpenGL ES context not active");
slouken@6190
   376
        return -1;
slouken@6190
   377
    }
slouken@6190
   378
slouken@6190
   379
    EGLBoolean status;
slouken@6190
   380
    status = _this->gles_data->eglSwapInterval(_this->gles_data->egl_display, interval);
slouken@6190
   381
    if (status == EGL_TRUE) {
slouken@6190
   382
        _this->gles_data->egl_swapinterval = interval;
slouken@6190
   383
        return 0; 
slouken@6190
   384
    }
slouken@6190
   385
slouken@6190
   386
    SDL_SetError("Unable to set the EGL swap interval");
slouken@6190
   387
    return -1;
slouken@3190
   388
}
slouken@3190
   389
slouken@3190
   390
int
slouken@3190
   391
X11_GLES_GetSwapInterval(_THIS)
slouken@3190
   392
{
slouken@6370
   393
    if (_this->gles_data) {
slouken@6190
   394
        SDL_SetError("OpenGL ES context not active");
slouken@6190
   395
        return -1;
slouken@6190
   396
    }
slouken@6190
   397
slouken@6190
   398
    return _this->gles_data->egl_swapinterval;
slouken@3190
   399
}
slouken@3190
   400
slouken@3190
   401
void
slouken@3190
   402
X11_GLES_SwapWindow(_THIS, SDL_Window * window)
slouken@3190
   403
{
slouken@3190
   404
    _this->gles_data->eglSwapBuffers(_this->gles_data->egl_display,
slouken@3190
   405
                                     _this->gles_data->egl_surface);
slouken@3190
   406
}
slouken@3190
   407
slouken@3190
   408
void
slouken@3190
   409
X11_GLES_DeleteContext(_THIS, SDL_GLContext context)
slouken@3190
   410
{
slouken@3190
   411
    /* Clean up GLES and EGL */
slouken@6370
   412
    if (_this->gles_data) {  
slouken@6370
   413
        if (_this->gles_data->egl_context != EGL_NO_CONTEXT ||
slouken@6370
   414
            _this->gles_data->egl_surface != EGL_NO_SURFACE) {
slouken@6370
   415
            _this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
slouken@6370
   416
                                             EGL_NO_SURFACE, EGL_NO_SURFACE,
slouken@6370
   417
                                             EGL_NO_CONTEXT);
slouken@3190
   418
slouken@6370
   419
            if (_this->gles_data->egl_context != EGL_NO_CONTEXT) {
slouken@6370
   420
                _this->gles_data->eglDestroyContext(_this->gles_data->egl_display,
slouken@6370
   421
                                                    _this->gles_data->
slouken@6370
   422
                                                    egl_context);
slouken@6370
   423
                _this->gles_data->egl_context = EGL_NO_CONTEXT;
slouken@6370
   424
            }
slouken@6370
   425
slouken@6370
   426
            if (_this->gles_data->egl_surface != EGL_NO_SURFACE) {
slouken@6370
   427
                _this->gles_data->eglDestroySurface(_this->gles_data->egl_display,
slouken@6370
   428
                                                    _this->gles_data->
slouken@6370
   429
                                                    egl_surface);
slouken@6370
   430
                _this->gles_data->egl_surface = EGL_NO_SURFACE;
slouken@6370
   431
            }
slouken@3190
   432
        }
slouken@3190
   433
slouken@6370
   434
        /* crappy fix */
slouken@6370
   435
        X11_GLES_UnloadLibrary(_this);
slouken@3190
   436
    }
slouken@3218
   437
slouken@3190
   438
}
slouken@3190
   439
slouken@6044
   440
#endif /* SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_ES */
slouken@3190
   441
slouken@3190
   442
/* vi: set ts=4 sw=4 expandtab: */