src/video/x11/SDL_x11opengles.c
author Gabriel Jacobo <gabomdq@gmail.com>
Mon, 19 Aug 2013 16:29:46 -0300
changeset 7659 ac4ce59c40e7
parent 7471 75726efbf679
child 7723 aea98cc3e696
permissions -rw-r--r--
Fixes bug #2037, common EGL code for Android and X11
slouken@3190
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 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
gabomdq@7659
    23
#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL
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
gabomdq@7659
    29
/* EGL implementation of SDL OpenGL support */
slouken@3190
    30
slouken@3190
    31
int
gabomdq@7659
    32
X11_GLES_LoadLibrary(_THIS, const char *path) {
gabomdq@7659
    33
        
slouken@3190
    34
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@3190
    35
slouken@6370
    36
    /* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions  */
slouken@6370
    37
    if (_this->gl_config.use_egl == 0) {
gabomdq@7659
    38
        #if SDL_VIDEO_OPENGL_GLX
slouken@6370
    39
        _this->GL_LoadLibrary = X11_GL_LoadLibrary;
slouken@6370
    40
        _this->GL_GetProcAddress = X11_GL_GetProcAddress;
slouken@6370
    41
        _this->GL_UnloadLibrary = X11_GL_UnloadLibrary;
slouken@6370
    42
        _this->GL_CreateContext = X11_GL_CreateContext;
slouken@6370
    43
        _this->GL_MakeCurrent = X11_GL_MakeCurrent;
slouken@6370
    44
        _this->GL_SetSwapInterval = X11_GL_SetSwapInterval;
slouken@6370
    45
        _this->GL_GetSwapInterval = X11_GL_GetSwapInterval;
slouken@6370
    46
        _this->GL_SwapWindow = X11_GL_SwapWindow;
slouken@6370
    47
        _this->GL_DeleteContext = X11_GL_DeleteContext;
slouken@6370
    48
        return X11_GL_LoadLibrary(_this, path);
gabomdq@7659
    49
        #else
icculus@7037
    50
        return SDL_SetError("SDL not configured with OpenGL/GLX support");
gabomdq@7659
    51
        #endif
slouken@6370
    52
    }
gabomdq@7659
    53
    
gabomdq@7659
    54
    return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display);
slouken@3190
    55
}
slouken@3190
    56
slouken@3190
    57
XVisualInfo *
slouken@3190
    58
X11_GLES_GetVisual(_THIS, Display * display, int screen)
slouken@3190
    59
{
gabomdq@7659
    60
   
gabomdq@7659
    61
    XVisualInfo *egl_visualinfo = NULL;
icculus@7471
    62
    EGLint visual_id;
gabomdq@7659
    63
    XVisualInfo vi_in;
gabomdq@7659
    64
    int out_count;
slouken@3190
    65
gabomdq@7659
    66
    if (!_this->egl_data) {
slouken@6370
    67
        /* The EGL library wasn't loaded, SDL_GetError() should have info */
slouken@6370
    68
        return NULL;
slouken@3190
    69
    }
slouken@3190
    70
gabomdq@7659
    71
    if (_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
gabomdq@7659
    72
                                            _this->egl_data->egl_config,
gabomdq@7659
    73
                                            EGL_NATIVE_VISUAL_ID,
gabomdq@7659
    74
                                            &visual_id) == EGL_FALSE || !visual_id) {
gabomdq@7659
    75
        /* Use the default visual when all else fails */
gabomdq@7659
    76
        vi_in.screen = screen;
gabomdq@7659
    77
        egl_visualinfo = XGetVisualInfo(display,
gabomdq@7659
    78
                                        VisualScreenMask,
gabomdq@7659
    79
                                        &vi_in, &out_count);
gabomdq@7659
    80
    } else {
gabomdq@7659
    81
        vi_in.screen = screen;
gabomdq@7659
    82
        vi_in.visualid = visual_id;
gabomdq@7659
    83
        egl_visualinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
slouken@3190
    84
    }
slouken@3190
    85
gabomdq@7659
    86
    return egl_visualinfo;
slouken@3190
    87
}
slouken@3190
    88
slouken@3190
    89
SDL_GLContext
slouken@3190
    90
X11_GLES_CreateContext(_THIS, SDL_Window * window)
slouken@3190
    91
{
gabomdq@7659
    92
    SDL_GLContext context;
slouken@3190
    93
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@3190
    94
    Display *display = data->videodata->display;
slouken@3190
    95
slouken@3190
    96
    XSync(display, False);
gabomdq@7659
    97
    context = SDL_EGL_CreateContext(_this, data->egl_surface);
slouken@3190
    98
    XSync(display, False);
slouken@3190
    99
slouken@6190
   100
    return context;
slouken@3190
   101
}
slouken@3190
   102
gabomdq@7659
   103
SDL_EGL_SwapWindow_impl(X11)
gabomdq@7659
   104
SDL_EGL_MakeCurrent_impl(X11)
slouken@3190
   105
gabomdq@7659
   106
#endif /* SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL */
slouken@3190
   107
slouken@3190
   108
/* vi: set ts=4 sw=4 expandtab: */