src/video/SDL_egl.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Oct 2013 00:15:24 -0700
changeset 7865 f2a42ca4ddf0
parent 7782 e4ed6e54101e
child 7896 0bca3fe7c03f
child 8541 0041edb891f3
permissions -rw-r--r--
Better cleanup if OpenGL initialization fails
gabomdq@7659
     1
/*
gabomdq@7659
     2
 *  Simple DirectMedia Layer
gabomdq@7659
     3
 *  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
gabomdq@7659
     4
 * 
gabomdq@7659
     5
 *  This software is provided 'as-is', without any express or implied
gabomdq@7659
     6
 *  warranty.  In no event will the authors be held liable for any damages
gabomdq@7659
     7
 *  arising from the use of this software.
gabomdq@7659
     8
 * 
gabomdq@7659
     9
 *  Permission is granted to anyone to use this software for any purpose,
gabomdq@7659
    10
 *  including commercial applications, and to alter it and redistribute it
gabomdq@7659
    11
 *  freely, subject to the following restrictions:
gabomdq@7659
    12
 * 
gabomdq@7659
    13
 *  1. The origin of this software must not be misrepresented; you must not
gabomdq@7659
    14
 *     claim that you wrote the original software. If you use this software
gabomdq@7659
    15
 *     in a product, an acknowledgment in the product documentation would be
gabomdq@7659
    16
 *     appreciated but is not required.
gabomdq@7659
    17
 *  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@7659
    18
 *     misrepresented as being the original software.
gabomdq@7659
    19
 *  3. This notice may not be removed or altered from any source distribution.
gabomdq@7659
    20
 */
gabomdq@7659
    21
#include "SDL_config.h"
gabomdq@7659
    22
gabomdq@7659
    23
#if SDL_VIDEO_OPENGL_EGL
gabomdq@7659
    24
gabomdq@7659
    25
#include "SDL_sysvideo.h"
gabomdq@7659
    26
#include "SDL_egl.h"
gabomdq@7659
    27
gabomdq@7782
    28
gabomdq@7753
    29
#if SDL_VIDEO_DRIVER_RPI
gabomdq@7782
    30
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
gabomdq@7753
    31
#define DEFAULT_EGL "/opt/vc/lib/libEGL.so"
gabomdq@7753
    32
#define DEFAULT_OGL_ES2 "/opt/vc/lib/libGLESv2.so"
gabomdq@7753
    33
#define DEFAULT_OGL_ES_PVR "/opt/vc/lib/libGLES_CM.so"
gabomdq@7753
    34
#define DEFAULT_OGL_ES "/opt/vc/lib/libGLESv1_CM.so"
gabomdq@7782
    35
gabomdq@7782
    36
#elif SDL_VIDEO_DRIVER_ANDROID
gabomdq@7782
    37
/* Android */
gabomdq@7782
    38
#define DEFAULT_EGL "libEGL.so"
gabomdq@7782
    39
#define DEFAULT_OGL_ES2 "libGLESv2.so"
gabomdq@7782
    40
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
gabomdq@7782
    41
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
gabomdq@7782
    42
gabomdq@7753
    43
#else
gabomdq@7782
    44
/* Desktop Linux */
gabomdq@7753
    45
#define DEFAULT_EGL "libEGL.so.1"
gabomdq@7753
    46
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
gabomdq@7753
    47
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
gabomdq@7753
    48
#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
gabomdq@7753
    49
#endif /* SDL_VIDEO_DRIVER_RPI */
gabomdq@7659
    50
gabomdq@7659
    51
#define LOAD_FUNC(NAME) \
gabomdq@7753
    52
*((void**)&_this->egl_data->NAME) = dlsym(dll_handle, #NAME); \
gabomdq@7659
    53
if (!_this->egl_data->NAME) \
gabomdq@7659
    54
{ \
gabomdq@7659
    55
    return SDL_SetError("Could not retrieve EGL function " #NAME); \
gabomdq@7659
    56
}
gabomdq@7659
    57
    
gabomdq@7659
    58
/* EGL implementation of SDL OpenGL ES support */
gabomdq@7659
    59
gabomdq@7659
    60
void *
gabomdq@7659
    61
SDL_EGL_GetProcAddress(_THIS, const char *proc)
gabomdq@7659
    62
{
gabomdq@7659
    63
    static char procname[1024];
gabomdq@7659
    64
    void *handle;
gabomdq@7659
    65
    void *retval;
gabomdq@7659
    66
    
gabomdq@7659
    67
    /* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
gabomdq@7659
    68
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
gabomdq@7659
    69
    handle = _this->egl_data->egl_dll_handle;
gabomdq@7659
    70
    if (_this->egl_data->eglGetProcAddress) {
gabomdq@7659
    71
        retval = _this->egl_data->eglGetProcAddress(proc);
gabomdq@7659
    72
        if (retval) {
gabomdq@7659
    73
            return retval;
gabomdq@7659
    74
        }
gabomdq@7659
    75
    }
gabomdq@7659
    76
#endif
gabomdq@7659
    77
    
gabomdq@7659
    78
    handle = _this->gl_config.dll_handle;
gabomdq@7659
    79
    #if defined(__OpenBSD__) && !defined(__ELF__)
gabomdq@7659
    80
    #undef dlsym(x,y);
gabomdq@7659
    81
    #endif
gabomdq@7659
    82
    retval = dlsym(handle, proc);
gabomdq@7659
    83
    if (!retval && strlen(proc) <= 1022) {
gabomdq@7659
    84
        procname[0] = '_';
gabomdq@7659
    85
        strcpy(procname + 1, proc);
gabomdq@7659
    86
        retval = dlsym(handle, procname);
gabomdq@7659
    87
    }
gabomdq@7659
    88
    return retval;
gabomdq@7659
    89
}
gabomdq@7659
    90
gabomdq@7659
    91
void
gabomdq@7659
    92
SDL_EGL_UnloadLibrary(_THIS)
gabomdq@7659
    93
{
slouken@7865
    94
    if (_this->egl_data) {
slouken@7865
    95
        if (_this->egl_data->egl_display) {
slouken@7865
    96
            _this->egl_data->eglTerminate(_this->egl_data->egl_display);
slouken@7865
    97
            _this->egl_data->egl_display = NULL;
slouken@7865
    98
        }
slouken@7865
    99
slouken@7865
   100
        if (_this->gl_config.dll_handle) {
slouken@7865
   101
            dlclose(_this->gl_config.dll_handle);
slouken@7865
   102
            _this->gl_config.dll_handle = NULL;
slouken@7865
   103
        }
slouken@7865
   104
        if (_this->egl_data->egl_dll_handle) {
slouken@7865
   105
            dlclose(_this->egl_data->egl_dll_handle);
slouken@7865
   106
            _this->egl_data->egl_dll_handle = NULL;
slouken@7865
   107
        }
gabomdq@7659
   108
        
gabomdq@7659
   109
        SDL_free(_this->egl_data);
gabomdq@7659
   110
        _this->egl_data = NULL;
gabomdq@7659
   111
    }
gabomdq@7659
   112
}
gabomdq@7659
   113
gabomdq@7659
   114
int
gabomdq@7753
   115
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
gabomdq@7659
   116
{
gabomdq@7753
   117
    void *dll_handle, *egl_dll_handle; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
gabomdq@7753
   118
    char *path;
gabomdq@7659
   119
    int dlopen_flags;
gabomdq@7659
   120
    
gabomdq@7659
   121
    if (_this->egl_data) {
gabomdq@7659
   122
        return SDL_SetError("OpenGL ES context already created");
gabomdq@7659
   123
    }
slouken@7865
   124
slouken@7865
   125
    _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
slouken@7865
   126
    if (!_this->egl_data) {
slouken@7865
   127
        return SDL_OutOfMemory();
slouken@7865
   128
    }
slouken@7865
   129
slouken@7865
   130
#ifdef RTLD_GLOBAL
gabomdq@7659
   131
    dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
slouken@7865
   132
#else
gabomdq@7659
   133
    dlopen_flags = RTLD_LAZY;
slouken@7865
   134
#endif
slouken@7865
   135
gabomdq@7753
   136
    /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
gabomdq@7753
   137
    path = getenv("SDL_VIDEO_GL_DRIVER");
gabomdq@7753
   138
    egl_dll_handle = dlopen(path, dlopen_flags);
gabomdq@7753
   139
    if ((path == NULL) | (egl_dll_handle == NULL)) {
gabomdq@7753
   140
        if (_this->gl_config.major_version > 1) {
gabomdq@7753
   141
            path = DEFAULT_OGL_ES2;
gabomdq@7753
   142
            egl_dll_handle = dlopen(path, dlopen_flags);
gabomdq@7753
   143
        } else {
gabomdq@7753
   144
            path = DEFAULT_OGL_ES;
gabomdq@7753
   145
            egl_dll_handle = dlopen(path, dlopen_flags);
gabomdq@7753
   146
            if (egl_dll_handle == NULL) {
gabomdq@7753
   147
                path = DEFAULT_OGL_ES_PVR;
gabomdq@7753
   148
                egl_dll_handle = dlopen(path, dlopen_flags);
gabomdq@7753
   149
            }
gabomdq@7753
   150
        }
gabomdq@7753
   151
    }
slouken@7865
   152
    _this->egl_data->egl_dll_handle = egl_dll_handle;
gabomdq@7753
   153
gabomdq@7753
   154
    if (egl_dll_handle == NULL) {
gabomdq@7753
   155
        return SDL_SetError("Could not initialize OpenGL ES library: %s", dlerror());
gabomdq@7753
   156
    }
gabomdq@7753
   157
    
gabomdq@7753
   158
    /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
gabomdq@7753
   159
    dll_handle = dlopen(egl_path, dlopen_flags);
gabomdq@7659
   160
    /* Catch the case where the application isn't linked with EGL */
gabomdq@7753
   161
    if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
gabomdq@7753
   162
        dlclose(dll_handle);
gabomdq@7659
   163
        path = getenv("SDL_VIDEO_EGL_DRIVER");
gabomdq@7659
   164
        if (path == NULL) {
gabomdq@7659
   165
            path = DEFAULT_EGL;
gabomdq@7659
   166
        }
gabomdq@7753
   167
        dll_handle = dlopen(path, dlopen_flags);
gabomdq@7753
   168
    }
slouken@7865
   169
    _this->gl_config.dll_handle = dll_handle;
slouken@7865
   170
gabomdq@7753
   171
    if (dll_handle == NULL) {
gabomdq@7753
   172
        return SDL_SetError("Could not load EGL library: %s", dlerror());
gabomdq@7659
   173
    }
gabomdq@7659
   174
gabomdq@7659
   175
    /* Load new function pointers */
gabomdq@7659
   176
    LOAD_FUNC(eglGetDisplay);
gabomdq@7659
   177
    LOAD_FUNC(eglInitialize);
gabomdq@7659
   178
    LOAD_FUNC(eglTerminate);
gabomdq@7659
   179
    LOAD_FUNC(eglGetProcAddress);
gabomdq@7659
   180
    LOAD_FUNC(eglChooseConfig);
gabomdq@7659
   181
    LOAD_FUNC(eglGetConfigAttrib);
gabomdq@7659
   182
    LOAD_FUNC(eglCreateContext);
gabomdq@7659
   183
    LOAD_FUNC(eglDestroyContext);
gabomdq@7659
   184
    LOAD_FUNC(eglCreateWindowSurface);
gabomdq@7659
   185
    LOAD_FUNC(eglDestroySurface);
gabomdq@7659
   186
    LOAD_FUNC(eglMakeCurrent);
gabomdq@7659
   187
    LOAD_FUNC(eglSwapBuffers);
gabomdq@7659
   188
    LOAD_FUNC(eglSwapInterval);
gabomdq@7659
   189
    LOAD_FUNC(eglWaitNative);
gabomdq@7659
   190
    LOAD_FUNC(eglWaitGL);
gabomdq@7659
   191
    
gabomdq@7659
   192
    _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
gabomdq@7659
   193
    if (!_this->egl_data->egl_display) {
gabomdq@7659
   194
        return SDL_SetError("Could not get EGL display");
gabomdq@7659
   195
    }
gabomdq@7659
   196
    
gabomdq@7659
   197
    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
gabomdq@7659
   198
        return SDL_SetError("Could not initialize EGL");
gabomdq@7659
   199
    }
gabomdq@7659
   200
gabomdq@7753
   201
    _this->gl_config.dll_handle = dll_handle;
gabomdq@7753
   202
    _this->egl_data->egl_dll_handle = egl_dll_handle;
gabomdq@7659
   203
    _this->gl_config.driver_loaded = 1;
gabomdq@7659
   204
gabomdq@7659
   205
    if (path) {
gabomdq@7753
   206
        strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
gabomdq@7659
   207
    } else {
gabomdq@7753
   208
        strcpy(_this->gl_config.driver_path, "");
gabomdq@7659
   209
    }
gabomdq@7659
   210
    
gabomdq@7659
   211
    /* We need to select a config here to satisfy some video backends such as X11 */
gabomdq@7659
   212
    SDL_EGL_ChooseConfig(_this);
gabomdq@7659
   213
    
gabomdq@7659
   214
    return 0;
gabomdq@7659
   215
}
gabomdq@7659
   216
gabomdq@7659
   217
int
gabomdq@7659
   218
SDL_EGL_ChooseConfig(_THIS) 
gabomdq@7659
   219
{
gabomdq@7659
   220
    /* 64 seems nice. */
gabomdq@7659
   221
    EGLint attribs[64];
gabomdq@7659
   222
    EGLint found_configs = 0;
gabomdq@7659
   223
    int i;
gabomdq@7659
   224
    
gabomdq@7659
   225
    if (!_this->egl_data) {
gabomdq@7659
   226
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
gabomdq@7659
   227
        return -1;
gabomdq@7659
   228
    }
gabomdq@7659
   229
  
gabomdq@7659
   230
    /* Get a valid EGL configuration */
gabomdq@7659
   231
    i = 0;
gabomdq@7659
   232
    attribs[i++] = EGL_RED_SIZE;
gabomdq@7659
   233
    attribs[i++] = _this->gl_config.red_size;
gabomdq@7659
   234
    attribs[i++] = EGL_GREEN_SIZE;
gabomdq@7659
   235
    attribs[i++] = _this->gl_config.green_size;
gabomdq@7659
   236
    attribs[i++] = EGL_BLUE_SIZE;
gabomdq@7659
   237
    attribs[i++] = _this->gl_config.blue_size;
gabomdq@7659
   238
    
gabomdq@7659
   239
    if (_this->gl_config.alpha_size) {
gabomdq@7659
   240
        attribs[i++] = EGL_ALPHA_SIZE;
gabomdq@7659
   241
        attribs[i++] = _this->gl_config.alpha_size;
gabomdq@7659
   242
    }
gabomdq@7659
   243
    
gabomdq@7659
   244
    if (_this->gl_config.buffer_size) {
gabomdq@7659
   245
        attribs[i++] = EGL_BUFFER_SIZE;
gabomdq@7659
   246
        attribs[i++] = _this->gl_config.buffer_size;
gabomdq@7659
   247
    }
gabomdq@7659
   248
    
gabomdq@7659
   249
    attribs[i++] = EGL_DEPTH_SIZE;
gabomdq@7659
   250
    attribs[i++] = _this->gl_config.depth_size;
gabomdq@7659
   251
    
gabomdq@7659
   252
    if (_this->gl_config.stencil_size) {
gabomdq@7659
   253
        attribs[i++] = EGL_STENCIL_SIZE;
gabomdq@7659
   254
        attribs[i++] = _this->gl_config.stencil_size;
gabomdq@7659
   255
    }
gabomdq@7659
   256
    
gabomdq@7659
   257
    if (_this->gl_config.multisamplebuffers) {
gabomdq@7659
   258
        attribs[i++] = EGL_SAMPLE_BUFFERS;
gabomdq@7659
   259
        attribs[i++] = _this->gl_config.multisamplebuffers;
gabomdq@7659
   260
    }
gabomdq@7659
   261
    
gabomdq@7659
   262
    if (_this->gl_config.multisamplesamples) {
gabomdq@7659
   263
        attribs[i++] = EGL_SAMPLES;
gabomdq@7659
   264
        attribs[i++] = _this->gl_config.multisamplesamples;
gabomdq@7659
   265
    }
gabomdq@7659
   266
    
gabomdq@7659
   267
    attribs[i++] = EGL_RENDERABLE_TYPE;
gabomdq@7659
   268
    if (_this->gl_config.major_version == 2) {
gabomdq@7659
   269
        attribs[i++] = EGL_OPENGL_ES2_BIT;
gabomdq@7659
   270
    } else {
gabomdq@7659
   271
        attribs[i++] = EGL_OPENGL_ES_BIT;
gabomdq@7659
   272
    }
gabomdq@7659
   273
    
gabomdq@7659
   274
    attribs[i++] = EGL_NONE;
gabomdq@7659
   275
    
gabomdq@7659
   276
    if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
gabomdq@7659
   277
        attribs,
gabomdq@7659
   278
        &_this->egl_data->egl_config, 1,
gabomdq@7659
   279
        &found_configs) == EGL_FALSE ||
gabomdq@7659
   280
        found_configs == 0) {
gabomdq@7659
   281
        return SDL_SetError("Couldn't find matching EGL config");
gabomdq@7659
   282
    }
gabomdq@7659
   283
    
gabomdq@7659
   284
    return 0;
gabomdq@7659
   285
}
gabomdq@7659
   286
gabomdq@7659
   287
SDL_GLContext
gabomdq@7659
   288
SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
gabomdq@7659
   289
{
gabomdq@7659
   290
    EGLint context_attrib_list[] = {
gabomdq@7659
   291
        EGL_CONTEXT_CLIENT_VERSION,
gabomdq@7659
   292
        1,
gabomdq@7659
   293
        EGL_NONE
gabomdq@7659
   294
    };
gabomdq@7659
   295
    
gabomdq@7659
   296
    EGLContext egl_context;
gabomdq@7659
   297
    
gabomdq@7659
   298
    if (!_this->egl_data) {
gabomdq@7659
   299
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
gabomdq@7659
   300
        return NULL;
gabomdq@7659
   301
    }
gabomdq@7659
   302
    
gabomdq@7659
   303
    if (_this->gl_config.major_version) {
gabomdq@7659
   304
        context_attrib_list[1] = _this->gl_config.major_version;
gabomdq@7659
   305
    }
gabomdq@7659
   306
gabomdq@7659
   307
    egl_context =
gabomdq@7659
   308
    _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
gabomdq@7659
   309
                                      _this->egl_data->egl_config,
gabomdq@7659
   310
                                      EGL_NO_CONTEXT, context_attrib_list);
gabomdq@7659
   311
    
gabomdq@7659
   312
    if (egl_context == EGL_NO_CONTEXT) {
gabomdq@7659
   313
        SDL_SetError("Could not create EGL context");
gabomdq@7659
   314
        return NULL;
gabomdq@7659
   315
    }
gabomdq@7659
   316
    
gabomdq@7659
   317
    _this->egl_data->egl_swapinterval = 0;
gabomdq@7659
   318
    
gabomdq@7659
   319
    if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
gabomdq@7659
   320
        SDL_EGL_DeleteContext(_this, egl_context);
gabomdq@7659
   321
        SDL_SetError("Could not make EGL context current");
gabomdq@7659
   322
        return NULL;
gabomdq@7659
   323
    }
gabomdq@7659
   324
  
gabomdq@7659
   325
    return (SDL_GLContext) egl_context;
gabomdq@7659
   326
}
gabomdq@7659
   327
gabomdq@7659
   328
int
gabomdq@7659
   329
SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
gabomdq@7659
   330
{
gabomdq@7679
   331
    EGLContext egl_context = (EGLContext) context;
gabomdq@7679
   332
gabomdq@7659
   333
    if (!_this->egl_data) {
gabomdq@7659
   334
        return SDL_SetError("OpenGL not initialized");
gabomdq@7659
   335
    }
gabomdq@7659
   336
    
gabomdq@7659
   337
    /* The android emulator crashes badly if you try to eglMakeCurrent 
gabomdq@7659
   338
     * with a valid context and invalid surface, so we have to check for both here.
gabomdq@7659
   339
     */
gabomdq@7659
   340
    if (!egl_context || !egl_surface) {
gabomdq@7659
   341
         _this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
gabomdq@7659
   342
    }
gabomdq@7659
   343
    else {
gabomdq@7659
   344
        if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
gabomdq@7659
   345
            egl_surface, egl_surface, egl_context)) {
gabomdq@7659
   346
            return SDL_SetError("Unable to make EGL context current");
gabomdq@7659
   347
        }
gabomdq@7659
   348
    }
gabomdq@7659
   349
      
gabomdq@7659
   350
    return 0;
gabomdq@7659
   351
}
gabomdq@7659
   352
gabomdq@7659
   353
int
gabomdq@7659
   354
SDL_EGL_SetSwapInterval(_THIS, int interval)
gabomdq@7659
   355
{
gabomdq@7679
   356
    EGLBoolean status;
gabomdq@7679
   357
    
gabomdq@7702
   358
    if (!_this->egl_data) {
gabomdq@7702
   359
        return SDL_SetError("EGL not initialized");
gabomdq@7659
   360
    }
gabomdq@7659
   361
    
gabomdq@7659
   362
    status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
gabomdq@7659
   363
    if (status == EGL_TRUE) {
gabomdq@7659
   364
        _this->egl_data->egl_swapinterval = interval;
gabomdq@7659
   365
        return 0;
gabomdq@7659
   366
    }
gabomdq@7659
   367
    
gabomdq@7659
   368
    return SDL_SetError("Unable to set the EGL swap interval");
gabomdq@7659
   369
}
gabomdq@7659
   370
gabomdq@7659
   371
int
gabomdq@7659
   372
SDL_EGL_GetSwapInterval(_THIS)
gabomdq@7659
   373
{
gabomdq@7702
   374
    if (!_this->egl_data) {
gabomdq@7702
   375
        return SDL_SetError("EGL not initialized");
gabomdq@7659
   376
    }
gabomdq@7659
   377
    
gabomdq@7659
   378
    return _this->egl_data->egl_swapinterval;
gabomdq@7659
   379
}
gabomdq@7659
   380
gabomdq@7659
   381
void
gabomdq@7659
   382
SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
gabomdq@7659
   383
{
gabomdq@7659
   384
    _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface);
gabomdq@7659
   385
}
gabomdq@7659
   386
gabomdq@7659
   387
void
gabomdq@7659
   388
SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
gabomdq@7659
   389
{
gabomdq@7679
   390
    EGLContext egl_context = (EGLContext) context;
gabomdq@7679
   391
gabomdq@7659
   392
    /* Clean up GLES and EGL */
gabomdq@7659
   393
    if (!_this->egl_data) {
gabomdq@7659
   394
        return;
gabomdq@7659
   395
    }
gabomdq@7659
   396
    
gabomdq@7659
   397
    if (!egl_context && egl_context != EGL_NO_CONTEXT) {
gabomdq@7659
   398
        SDL_EGL_MakeCurrent(_this, NULL, NULL);
gabomdq@7659
   399
        _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
gabomdq@7659
   400
    }
gabomdq@7659
   401
        
gabomdq@7659
   402
    /* FIXME: This "crappy fix" comes from the X11 code, 
gabomdq@7659
   403
     * it's required so you can create a GLX context, destroy it and create a EGL one */
gabomdq@7659
   404
    SDL_EGL_UnloadLibrary(_this);
gabomdq@7659
   405
}
gabomdq@7659
   406
gabomdq@7659
   407
EGLSurface *
gabomdq@7659
   408
SDL_EGL_CreateSurface(_THIS, NativeWindowType nw) 
gabomdq@7659
   409
{
gabomdq@7659
   410
    return _this->egl_data->eglCreateWindowSurface(
gabomdq@7659
   411
            _this->egl_data->egl_display,
gabomdq@7659
   412
            _this->egl_data->egl_config,
gabomdq@7659
   413
            nw, NULL);
gabomdq@7659
   414
}
gabomdq@7659
   415
gabomdq@7659
   416
void
gabomdq@7659
   417
SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface) 
gabomdq@7659
   418
{
gabomdq@7659
   419
    if (!_this->egl_data) {
gabomdq@7659
   420
        return;
gabomdq@7659
   421
    }
gabomdq@7659
   422
    
gabomdq@7659
   423
    if (egl_surface != EGL_NO_SURFACE) {
gabomdq@7659
   424
        _this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
gabomdq@7659
   425
    }
gabomdq@7659
   426
}
gabomdq@7659
   427
gabomdq@7659
   428
#endif /* SDL_VIDEO_OPENGL_EGL */
gabomdq@7659
   429
gabomdq@7659
   430
/* vi: set ts=4 sw=4 expandtab: */
slouken@7865
   431