src/video/x11/SDL_x11opengl.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 01 Jan 1970 04:04:21 +0000
changeset 8780 2d8d64a681ad
parent 8149 681eb46b8ac4
child 8804 a941cf4234c4
permissions -rw-r--r--
Fixed crash if the OpenGL library hasn't been loaded yet
slouken@1952
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@1952
     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@1952
     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@1952
    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@1952
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_X11
slouken@6044
    24
slouken@1952
    25
#include "SDL_x11video.h"
icculus@5981
    26
#include "SDL_assert.h"
slouken@1952
    27
slouken@1952
    28
/* GLX implementation of SDL OpenGL support */
slouken@1952
    29
slouken@1952
    30
#if SDL_VIDEO_OPENGL_GLX
slouken@1952
    31
#include "SDL_loadso.h"
slouken@6370
    32
#include "SDL_x11opengles.h"
slouken@1952
    33
slouken@1952
    34
#if defined(__IRIX__)
slouken@1952
    35
/* IRIX doesn't have a GL library versioning system */
slouken@7191
    36
#define DEFAULT_OPENGL  "libGL.so"
slouken@1952
    37
#elif defined(__MACOSX__)
slouken@7191
    38
#define DEFAULT_OPENGL  "/usr/X11R6/lib/libGL.1.dylib"
slouken@1952
    39
#elif defined(__QNXNTO__)
slouken@7191
    40
#define DEFAULT_OPENGL  "libGL.so.3"
slouken@1952
    41
#else
slouken@7191
    42
#define DEFAULT_OPENGL  "libGL.so.1"
slouken@1952
    43
#endif
slouken@1952
    44
slouken@3241
    45
#ifndef GLX_NONE_EXT
slouken@3241
    46
#define GLX_NONE_EXT                       0x8000
slouken@3241
    47
#endif
slouken@3241
    48
slouken@1952
    49
#ifndef GLX_ARB_multisample
slouken@1952
    50
#define GLX_ARB_multisample
slouken@1952
    51
#define GLX_SAMPLE_BUFFERS_ARB             100000
slouken@1952
    52
#define GLX_SAMPLES_ARB                    100001
slouken@1952
    53
#endif
slouken@1952
    54
slouken@1952
    55
#ifndef GLX_EXT_visual_rating
slouken@1952
    56
#define GLX_EXT_visual_rating
slouken@1952
    57
#define GLX_VISUAL_CAVEAT_EXT              0x20
slouken@1952
    58
#define GLX_NONE_EXT                       0x8000
slouken@1952
    59
#define GLX_SLOW_VISUAL_EXT                0x8001
slouken@1952
    60
#define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
slouken@1952
    61
#endif
slouken@1952
    62
mikesart@6570
    63
#ifndef GLX_EXT_visual_info
mikesart@6570
    64
#define GLX_EXT_visual_info
mikesart@6570
    65
#define GLX_X_VISUAL_TYPE_EXT              0x22
mikesart@6570
    66
#define GLX_DIRECT_COLOR_EXT               0x8003
mikesart@6570
    67
#endif
mikesart@6570
    68
slouken@3100
    69
#ifndef GLX_ARB_create_context
slouken@3100
    70
#define GLX_ARB_create_context
slouken@3100
    71
#define GLX_CONTEXT_MAJOR_VERSION_ARB      0x2091
slouken@3100
    72
#define GLX_CONTEXT_MINOR_VERSION_ARB      0x2092
slouken@3100
    73
#define GLX_CONTEXT_FLAGS_ARB              0x2094
slouken@3100
    74
#define GLX_CONTEXT_DEBUG_BIT_ARB          0x0001
slouken@3100
    75
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
slouken@5021
    76
slouken@5021
    77
/* Typedef for the GL 3.0 context creation function */
slouken@5021
    78
typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
slouken@5021
    79
                                                        GLXFBConfig config,
slouken@5021
    80
                                                        GLXContext
slouken@5021
    81
                                                        share_context,
slouken@5021
    82
                                                        Bool direct,
slouken@5021
    83
                                                        const int
slouken@5021
    84
                                                        *attrib_list);
icculus@6360
    85
#endif
slouken@6296
    86
slouken@6296
    87
#ifndef GLX_ARB_create_context_profile
slouken@6296
    88
#define GLX_ARB_create_context_profile
slouken@6296
    89
#define GLX_CONTEXT_PROFILE_MASK_ARB       0x9126
slouken@6296
    90
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB   0x00000001
slouken@6296
    91
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
slouken@6296
    92
#endif
slouken@6296
    93
slouken@6296
    94
#ifndef GLX_ARB_create_context_robustness
slouken@6296
    95
#define GLX_ARB_create_context_robustness
slouken@6296
    96
#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB  0x00000004
slouken@6296
    97
#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB     0x8256
slouken@6296
    98
#define GLX_NO_RESET_NOTIFICATION_ARB                   0x8261
slouken@6296
    99
#define GLX_LOSE_CONTEXT_ON_RESET_ARB                   0x8252
slouken@6296
   100
#endif
slouken@6296
   101
slouken@6296
   102
#ifndef GLX_EXT_create_context_es2_profile
slouken@6296
   103
#define GLX_EXT_create_context_es2_profile
icculus@6375
   104
#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
slouken@6296
   105
#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT    0x00000002
slouken@6296
   106
#endif
icculus@6375
   107
#endif
slouken@6296
   108
icculus@7853
   109
#ifndef GLX_ARB_framebuffer_sRGB
icculus@7853
   110
#define GLX_ARB_framebuffer_sRGB
icculus@7853
   111
#ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
icculus@7853
   112
#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB                0x20B2
icculus@7853
   113
#endif
icculus@7853
   114
#endif
icculus@7853
   115
slouken@6296
   116
#ifndef GLX_EXT_swap_control
slouken@6296
   117
#define GLX_SWAP_INTERVAL_EXT              0x20F1
slouken@6296
   118
#define GLX_MAX_SWAP_INTERVAL_EXT          0x20F2
slouken@3100
   119
#endif
slouken@3100
   120
icculus@6382
   121
#ifndef GLX_EXT_swap_control_tear
icculus@6382
   122
#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
icculus@6382
   123
#endif
icculus@6382
   124
slouken@6183
   125
#define OPENGL_REQUIRES_DLOPEN
slouken@6183
   126
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
slouken@1952
   127
#include <dlfcn.h>
slouken@7191
   128
#define GL_LoadObject(X)    dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
slouken@7191
   129
#define GL_LoadFunction     dlsym
slouken@7191
   130
#define GL_UnloadObject     dlclose
slouken@1952
   131
#else
slouken@7191
   132
#define GL_LoadObject   SDL_LoadObject
slouken@7191
   133
#define GL_LoadFunction SDL_LoadFunction
slouken@7191
   134
#define GL_UnloadObject SDL_UnloadObject
slouken@1952
   135
#endif
slouken@1952
   136
slouken@3057
   137
static void X11_GL_InitExtensions(_THIS);
bob@2322
   138
slouken@3100
   139
slouken@1952
   140
int
slouken@1952
   141
X11_GL_LoadLibrary(_THIS, const char *path)
slouken@1952
   142
{
slouken@7512
   143
    Display *display;
slouken@1952
   144
    void *handle;
slouken@1952
   145
slouken@6370
   146
    if (_this->gl_data) {
icculus@7037
   147
        return SDL_SetError("OpenGL context already created");
slouken@6370
   148
    }
slouken@6370
   149
slouken@3057
   150
    /* Load the OpenGL library */
slouken@3057
   151
    if (path == NULL) {
slouken@3057
   152
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
slouken@1952
   153
    }
slouken@3057
   154
    if (path == NULL) {
slouken@3057
   155
        path = DEFAULT_OPENGL;
slouken@3057
   156
    }
slouken@6183
   157
    _this->gl_config.dll_handle = GL_LoadObject(path);
slouken@3057
   158
    if (!_this->gl_config.dll_handle) {
slouken@6183
   159
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
slouken@6183
   160
        SDL_SetError("Failed loading %s: %s", path, dlerror());
slouken@6183
   161
#endif
slouken@3057
   162
        return -1;
slouken@3057
   163
    }
slouken@3057
   164
    SDL_strlcpy(_this->gl_config.driver_path, path,
slouken@3057
   165
                SDL_arraysize(_this->gl_config.driver_path));
slouken@2244
   166
slouken@3057
   167
    /* Allocate OpenGL memory */
slouken@3057
   168
    _this->gl_data =
slouken@3057
   169
        (struct SDL_GLDriverData *) SDL_calloc(1,
slouken@3057
   170
                                               sizeof(struct
slouken@3057
   171
                                                      SDL_GLDriverData));
slouken@3057
   172
    if (!_this->gl_data) {
icculus@7037
   173
        return SDL_OutOfMemory();
slouken@3057
   174
    }
slouken@3057
   175
slouken@3057
   176
    /* Load function pointers */
slouken@3057
   177
    handle = _this->gl_config.dll_handle;
slouken@7512
   178
    _this->gl_data->glXQueryExtension =
slouken@7512
   179
        (Bool (*)(Display *, int *, int *))
slouken@7512
   180
            GL_LoadFunction(handle, "glXQueryExtension");
slouken@1952
   181
    _this->gl_data->glXGetProcAddress =
slouken@4550
   182
        (void *(*)(const GLubyte *))
slouken@4550
   183
            GL_LoadFunction(handle, "glXGetProcAddressARB");
slouken@1952
   184
    _this->gl_data->glXChooseVisual =
slouken@4550
   185
        (XVisualInfo * (*)(Display *, int, int *))
slouken@4550
   186
            X11_GL_GetProcAddress(_this, "glXChooseVisual");
slouken@1952
   187
    _this->gl_data->glXCreateContext =
slouken@1952
   188
        (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
slouken@4550
   189
            X11_GL_GetProcAddress(_this, "glXCreateContext");
slouken@1952
   190
    _this->gl_data->glXDestroyContext =
slouken@4550
   191
        (void (*)(Display *, GLXContext))
slouken@4550
   192
            X11_GL_GetProcAddress(_this, "glXDestroyContext");
slouken@1952
   193
    _this->gl_data->glXMakeCurrent =
slouken@4550
   194
        (int (*)(Display *, GLXDrawable, GLXContext))
slouken@4550
   195
            X11_GL_GetProcAddress(_this, "glXMakeCurrent");
slouken@1952
   196
    _this->gl_data->glXSwapBuffers =
slouken@4550
   197
        (void (*)(Display *, GLXDrawable))
slouken@4550
   198
            X11_GL_GetProcAddress(_this, "glXSwapBuffers");
icculus@5572
   199
    _this->gl_data->glXQueryDrawable =
icculus@5572
   200
        (void (*)(Display*,GLXDrawable,int,unsigned int*))
icculus@5572
   201
            X11_GL_GetProcAddress(_this, "glXQueryDrawable");
slouken@1952
   202
slouken@7512
   203
    if (!_this->gl_data->glXQueryExtension ||
slouken@7512
   204
        !_this->gl_data->glXChooseVisual ||
slouken@1952
   205
        !_this->gl_data->glXCreateContext ||
slouken@1952
   206
        !_this->gl_data->glXDestroyContext ||
slouken@4550
   207
        !_this->gl_data->glXMakeCurrent ||
slouken@4550
   208
        !_this->gl_data->glXSwapBuffers) {
icculus@7037
   209
        return SDL_SetError("Could not retrieve OpenGL functions");
slouken@1952
   210
    }
slouken@1952
   211
slouken@7512
   212
    display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@7512
   213
    if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) {
slouken@7512
   214
        return SDL_SetError("GLX is not supported");
slouken@7512
   215
    }
slouken@7512
   216
slouken@3057
   217
    /* Initialize extensions */
slouken@3057
   218
    X11_GL_InitExtensions(_this);
gabomdq@7659
   219
    
gabomdq@7723
   220
    /* If we need a GL ES context and there's no  
gabomdq@7723
   221
     * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions  
gabomdq@7723
   222
     */
gabomdq@7723
   223
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && 
gabomdq@7723
   224
        ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
gabomdq@7659
   225
#if SDL_VIDEO_OPENGL_EGL
gabomdq@7723
   226
        X11_GL_UnloadLibrary(_this);
gabomdq@7723
   227
        /* Better avoid conflicts! */
gabomdq@7723
   228
        if (_this->gl_config.dll_handle != NULL ) {
gabomdq@7723
   229
            GL_UnloadObject(_this->gl_config.dll_handle);
gabomdq@7723
   230
            _this->gl_config.dll_handle = NULL;
gabomdq@7723
   231
        }
gabomdq@7723
   232
        _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
gabomdq@7723
   233
        _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
gabomdq@7723
   234
        _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
gabomdq@7723
   235
        _this->GL_CreateContext = X11_GLES_CreateContext;
gabomdq@7723
   236
        _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
gabomdq@7723
   237
        _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
gabomdq@7723
   238
        _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
gabomdq@7723
   239
        _this->GL_SwapWindow = X11_GLES_SwapWindow;
gabomdq@7723
   240
        _this->GL_DeleteContext = X11_GLES_DeleteContext;
gabomdq@7723
   241
        return X11_GLES_LoadLibrary(_this, NULL);
gabomdq@7659
   242
#else
gabomdq@7723
   243
        return SDL_SetError("SDL not configured with EGL support");
gabomdq@7659
   244
#endif
gabomdq@7659
   245
    }
slouken@3057
   246
slouken@1952
   247
    return 0;
slouken@1952
   248
}
slouken@1952
   249
slouken@1952
   250
void *
slouken@1952
   251
X11_GL_GetProcAddress(_THIS, const char *proc)
slouken@1952
   252
{
slouken@1952
   253
    if (_this->gl_data->glXGetProcAddress) {
slouken@1952
   254
        return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
slouken@1952
   255
    }
slouken@4550
   256
    return GL_LoadFunction(_this->gl_config.dll_handle, proc);
slouken@1952
   257
}
slouken@1952
   258
slouken@3057
   259
void
slouken@1952
   260
X11_GL_UnloadLibrary(_THIS)
slouken@1952
   261
{
slouken@3057
   262
    /* Don't actually unload the library, since it may have registered
slouken@3057
   263
     * X11 shutdown hooks, per the notes at:
slouken@3057
   264
     * http://dri.sourceforge.net/doc/DRIuserguide.html
slouken@3057
   265
     */
slouken@3057
   266
#if 0
slouken@3057
   267
    GL_UnloadObject(_this->gl_config.dll_handle);
slouken@3057
   268
    _this->gl_config.dll_handle = NULL;
slouken@3057
   269
#endif
slouken@3057
   270
slouken@3057
   271
    /* Free OpenGL memory */
slouken@7719
   272
    SDL_free(_this->gl_data);
slouken@7719
   273
    _this->gl_data = NULL;
slouken@1952
   274
}
slouken@1952
   275
slouken@1952
   276
static SDL_bool
slouken@1952
   277
HasExtension(const char *extension, const char *extensions)
slouken@1952
   278
{
slouken@1952
   279
    const char *start;
slouken@1952
   280
    const char *where, *terminator;
slouken@1952
   281
slouken@1952
   282
    /* Extension names should not have spaces. */
slouken@1952
   283
    where = SDL_strchr(extension, ' ');
slouken@1952
   284
    if (where || *extension == '\0')
slouken@1952
   285
        return SDL_FALSE;
slouken@1952
   286
slouken@1952
   287
    if (!extensions)
slouken@1952
   288
        return SDL_FALSE;
slouken@1952
   289
slouken@1952
   290
    /* It takes a bit of care to be fool-proof about parsing the
slouken@1952
   291
     * OpenGL extensions string. Don't be fooled by sub-strings,
slouken@1952
   292
     * etc. */
slouken@1952
   293
slouken@1952
   294
    start = extensions;
slouken@1952
   295
slouken@1952
   296
    for (;;) {
slouken@1952
   297
        where = SDL_strstr(start, extension);
slouken@1952
   298
        if (!where)
slouken@1952
   299
            break;
slouken@1952
   300
slouken@1952
   301
        terminator = where + SDL_strlen(extension);
slouken@1952
   302
        if (where == start || *(where - 1) == ' ')
slouken@1952
   303
            if (*terminator == ' ' || *terminator == '\0')
slouken@1952
   304
                return SDL_TRUE;
slouken@1952
   305
slouken@1952
   306
        start = terminator;
slouken@1952
   307
    }
slouken@1952
   308
    return SDL_FALSE;
slouken@1952
   309
}
slouken@1952
   310
slouken@1952
   311
static void
slouken@1952
   312
X11_GL_InitExtensions(_THIS)
slouken@1952
   313
{
slouken@1952
   314
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@5244
   315
    int screen = DefaultScreen(display);
slouken@1952
   316
    XVisualInfo *vinfo;
slouken@1952
   317
    XSetWindowAttributes xattr;
slouken@1952
   318
    Window w;
slouken@1952
   319
    GLXContext context;
slouken@1952
   320
    const char *(*glXQueryExtensionsStringFunc) (Display *, int);
slouken@1952
   321
    const char *extensions;
slouken@1952
   322
slouken@1952
   323
    vinfo = X11_GL_GetVisual(_this, display, screen);
slouken@1952
   324
    if (!vinfo) {
slouken@1952
   325
        return;
slouken@1952
   326
    }
slouken@1952
   327
    xattr.background_pixel = 0;
slouken@1952
   328
    xattr.border_pixel = 0;
slouken@1952
   329
    xattr.colormap =
icculus@7827
   330
        X11_XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
slouken@1952
   331
                        AllocNone);
icculus@7827
   332
    w = X11_XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
slouken@1952
   333
                      vinfo->depth, InputOutput, vinfo->visual,
slouken@1952
   334
                      (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
slouken@1952
   335
    context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
slouken@1952
   336
    if (context) {
slouken@1952
   337
        _this->gl_data->glXMakeCurrent(display, w, context);
slouken@1952
   338
    }
icculus@7827
   339
    X11_XFree(vinfo);
slouken@1952
   340
slouken@1952
   341
    glXQueryExtensionsStringFunc =
slouken@1952
   342
        (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
slouken@1952
   343
                                                                "glXQueryExtensionsString");
slouken@1952
   344
    if (glXQueryExtensionsStringFunc) {
slouken@1952
   345
        extensions = glXQueryExtensionsStringFunc(display, screen);
slouken@1952
   346
    } else {
slouken@1952
   347
        extensions = NULL;
slouken@1952
   348
    }
slouken@1952
   349
icculus@6382
   350
    /* Check for GLX_EXT_swap_control(_tear) */
icculus@6382
   351
    _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_FALSE;
icculus@5572
   352
    if (HasExtension("GLX_EXT_swap_control", extensions)) {
icculus@5572
   353
        _this->gl_data->glXSwapIntervalEXT =
slouken@6846
   354
            (void (*)(Display*,GLXDrawable,int))
icculus@5572
   355
                X11_GL_GetProcAddress(_this, "glXSwapIntervalEXT");
icculus@6382
   356
        if (HasExtension("GLX_EXT_swap_control_tear", extensions)) {
icculus@6382
   357
            _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_TRUE;
icculus@6382
   358
        }
slouken@1952
   359
    }
slouken@1952
   360
slouken@1952
   361
    /* Check for GLX_MESA_swap_control */
slouken@1952
   362
    if (HasExtension("GLX_MESA_swap_control", extensions)) {
slouken@1952
   363
        _this->gl_data->glXSwapIntervalMESA =
icculus@5572
   364
            (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
slouken@1952
   365
        _this->gl_data->glXGetSwapIntervalMESA =
icculus@5572
   366
            (int(*)(void)) X11_GL_GetProcAddress(_this,
slouken@1952
   367
                                                   "glXGetSwapIntervalMESA");
slouken@1952
   368
    }
slouken@1952
   369
icculus@5572
   370
    /* Check for GLX_SGI_swap_control */
icculus@5572
   371
    if (HasExtension("GLX_SGI_swap_control", extensions)) {
icculus@5572
   372
        _this->gl_data->glXSwapIntervalSGI =
icculus@5572
   373
            (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
icculus@5572
   374
    }
icculus@5572
   375
slouken@1952
   376
    /* Check for GLX_EXT_visual_rating */
slouken@1952
   377
    if (HasExtension("GLX_EXT_visual_rating", extensions)) {
slouken@1952
   378
        _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
slouken@1952
   379
    }
slouken@1952
   380
mikesart@6570
   381
    /* Check for GLX_EXT_visual_info */
mikesart@6570
   382
    if (HasExtension("GLX_EXT_visual_info", extensions)) {
mikesart@6570
   383
        _this->gl_data->HAS_GLX_EXT_visual_info = SDL_TRUE;
mikesart@6570
   384
    }
gabomdq@7659
   385
    
gabomdq@7659
   386
    /* Check for GLX_EXT_create_context_es2_profile */
gabomdq@7659
   387
    if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
gabomdq@7659
   388
        _this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
gabomdq@7659
   389
    }
mikesart@6570
   390
slouken@1952
   391
    if (context) {
slouken@1952
   392
        _this->gl_data->glXMakeCurrent(display, None, NULL);
slouken@1952
   393
        _this->gl_data->glXDestroyContext(display, context);
slouken@1952
   394
    }
icculus@7827
   395
    X11_XDestroyWindow(display, w);
bob@2323
   396
    X11_PumpEvents(_this);
slouken@1952
   397
}
slouken@1952
   398
slouken@6296
   399
/* glXChooseVisual and glXChooseFBConfig have some small differences in
slouken@7191
   400
 * the attribute encoding, it can be chosen with the for_FBConfig parameter.
slouken@6296
   401
 */
slouken@7191
   402
int
slouken@6296
   403
X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size, Bool for_FBConfig)
slouken@1952
   404
{
slouken@5395
   405
    int i = 0;
slouken@7191
   406
    const int MAX_ATTRIBUTES = 64;
slouken@1952
   407
slouken@7191
   408
    /* assert buffer is large enough to hold all SDL attributes. */
mikesart@6570
   409
    SDL_assert(size >= MAX_ATTRIBUTES);
slouken@3139
   410
slouken@1952
   411
    /* Setup our GLX attributes according to the gl_config. */
slouken@6296
   412
    if( for_FBConfig ) {
slouken@6296
   413
        attribs[i++] = GLX_RENDER_TYPE;
icculus@7462
   414
        attribs[i++] = GLX_RGBA_BIT;
slouken@6296
   415
    } else {
slouken@6296
   416
        attribs[i++] = GLX_RGBA;
slouken@6296
   417
    }
slouken@1952
   418
    attribs[i++] = GLX_RED_SIZE;
slouken@1952
   419
    attribs[i++] = _this->gl_config.red_size;
slouken@1952
   420
    attribs[i++] = GLX_GREEN_SIZE;
slouken@1952
   421
    attribs[i++] = _this->gl_config.green_size;
slouken@1952
   422
    attribs[i++] = GLX_BLUE_SIZE;
slouken@1952
   423
    attribs[i++] = _this->gl_config.blue_size;
slouken@1952
   424
slouken@1952
   425
    if (_this->gl_config.alpha_size) {
slouken@1952
   426
        attribs[i++] = GLX_ALPHA_SIZE;
slouken@1952
   427
        attribs[i++] = _this->gl_config.alpha_size;
slouken@1952
   428
    }
slouken@1952
   429
slouken@1952
   430
    if (_this->gl_config.double_buffer) {
slouken@1952
   431
        attribs[i++] = GLX_DOUBLEBUFFER;
icculus@7462
   432
        if( for_FBConfig ) {
icculus@7462
   433
            attribs[i++] = True;
icculus@7462
   434
        }
slouken@1952
   435
    }
slouken@1952
   436
slouken@1952
   437
    attribs[i++] = GLX_DEPTH_SIZE;
slouken@1952
   438
    attribs[i++] = _this->gl_config.depth_size;
slouken@1952
   439
slouken@1952
   440
    if (_this->gl_config.stencil_size) {
slouken@1952
   441
        attribs[i++] = GLX_STENCIL_SIZE;
slouken@1952
   442
        attribs[i++] = _this->gl_config.stencil_size;
slouken@1952
   443
    }
slouken@1952
   444
slouken@1952
   445
    if (_this->gl_config.accum_red_size) {
slouken@1952
   446
        attribs[i++] = GLX_ACCUM_RED_SIZE;
slouken@1952
   447
        attribs[i++] = _this->gl_config.accum_red_size;
slouken@1952
   448
    }
slouken@1952
   449
slouken@1952
   450
    if (_this->gl_config.accum_green_size) {
slouken@1952
   451
        attribs[i++] = GLX_ACCUM_GREEN_SIZE;
slouken@1952
   452
        attribs[i++] = _this->gl_config.accum_green_size;
slouken@1952
   453
    }
slouken@1952
   454
slouken@1952
   455
    if (_this->gl_config.accum_blue_size) {
slouken@1952
   456
        attribs[i++] = GLX_ACCUM_BLUE_SIZE;
slouken@1952
   457
        attribs[i++] = _this->gl_config.accum_blue_size;
slouken@1952
   458
    }
slouken@1952
   459
slouken@1952
   460
    if (_this->gl_config.accum_alpha_size) {
slouken@1952
   461
        attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
slouken@1952
   462
        attribs[i++] = _this->gl_config.accum_alpha_size;
slouken@1952
   463
    }
slouken@1952
   464
slouken@1952
   465
    if (_this->gl_config.stereo) {
slouken@1952
   466
        attribs[i++] = GLX_STEREO;
icculus@7462
   467
        if( for_FBConfig ) {
icculus@7462
   468
            attribs[i++] = True;
icculus@7462
   469
        }
slouken@1952
   470
    }
slouken@1952
   471
slouken@1952
   472
    if (_this->gl_config.multisamplebuffers) {
slouken@1952
   473
        attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
slouken@1952
   474
        attribs[i++] = _this->gl_config.multisamplebuffers;
slouken@1952
   475
    }
slouken@1952
   476
slouken@1952
   477
    if (_this->gl_config.multisamplesamples) {
slouken@1952
   478
        attribs[i++] = GLX_SAMPLES_ARB;
slouken@1952
   479
        attribs[i++] = _this->gl_config.multisamplesamples;
slouken@1952
   480
    }
slouken@1952
   481
icculus@7853
   482
    if (_this->gl_config.framebuffer_srgb_capable) {
icculus@7853
   483
        attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
icculus@7853
   484
        if( for_FBConfig ) {
icculus@7853
   485
            attribs[i++] = True;
icculus@7853
   486
        }
icculus@7853
   487
    }
icculus@7853
   488
slouken@3571
   489
    if (_this->gl_config.accelerated >= 0 &&
slouken@3571
   490
        _this->gl_data->HAS_GLX_EXT_visual_rating) {
slouken@1952
   491
        attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
slouken@3570
   492
        attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
slouken@3570
   493
                                                      GLX_SLOW_VISUAL_EXT;
slouken@1952
   494
    }
slouken@3570
   495
icculus@6817
   496
    /* If we're supposed to use DirectColor visuals, and we've got the
icculus@6817
   497
       EXT_visual_info extension, then add GLX_X_VISUAL_TYPE_EXT. */
mikesart@6570
   498
    if (X11_UseDirectColorVisuals() &&
mikesart@6570
   499
        _this->gl_data->HAS_GLX_EXT_visual_info) {
mikesart@6570
   500
        attribs[i++] = GLX_X_VISUAL_TYPE_EXT;
mikesart@6570
   501
        attribs[i++] = GLX_DIRECT_COLOR_EXT;
mikesart@6570
   502
    }
mikesart@6570
   503
slouken@1952
   504
    attribs[i++] = None;
mikesart@6570
   505
mikesart@6570
   506
    SDL_assert(i <= MAX_ATTRIBUTES);
slouken@7191
   507
slouken@5395
   508
    return i;
slouken@5395
   509
}
slouken@5395
   510
slouken@5395
   511
XVisualInfo *
slouken@5395
   512
X11_GL_GetVisual(_THIS, Display * display, int screen)
slouken@5395
   513
{
slouken@5395
   514
    /* 64 seems nice. */
slouken@6296
   515
    int attribs[64];
slouken@8780
   516
    XVisualInfo *vinfo;
slouken@1952
   517
slouken@6181
   518
    if (!_this->gl_data) {
slouken@6181
   519
        /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
slouken@6181
   520
        return NULL;
slouken@6181
   521
    }
slouken@6181
   522
slouken@8780
   523
    X11_GL_GetAttributes(_this, display, screen, attribs, 64, SDL_FALSE);
slouken@1952
   524
    vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
slouken@1952
   525
    if (!vinfo) {
slouken@1952
   526
        SDL_SetError("Couldn't find matching GLX visual");
slouken@1952
   527
    }
slouken@1952
   528
    return vinfo;
slouken@1952
   529
}
slouken@1952
   530
slouken@6988
   531
#ifndef GLXBadContext
slouken@6988
   532
#define GLXBadContext 0
slouken@6988
   533
#endif
slouken@6988
   534
#ifndef GLXBadFBConfig
slouken@6988
   535
#define GLXBadFBConfig 9
slouken@6988
   536
#endif
slouken@6988
   537
#ifndef GLXBadProfileARB
slouken@6988
   538
#define GLXBadProfileARB 13
slouken@6988
   539
#endif
slouken@6988
   540
static int (*handler) (Display *, XErrorEvent *) = NULL;
slouken@7512
   541
static int errorBase = 0;
slouken@6988
   542
static int
slouken@6988
   543
X11_GL_CreateContextErrorHandler(Display * d, XErrorEvent * e)
slouken@6988
   544
{
slouken@6988
   545
    switch (e->error_code) {
slouken@6988
   546
    case BadRequest:
slouken@6988
   547
    case BadMatch:
slouken@6988
   548
    case BadValue:
slouken@6988
   549
    case BadAlloc:
slouken@6988
   550
        return (0);
slouken@6988
   551
    default:
slouken@7512
   552
        if (errorBase && 
slouken@7512
   553
            (e->error_code == errorBase + GLXBadContext ||
slouken@7512
   554
             e->error_code == errorBase + GLXBadFBConfig ||
slouken@7512
   555
             e->error_code == errorBase + GLXBadProfileARB)) {
slouken@7512
   556
            return (0);
slouken@7512
   557
        }
slouken@6988
   558
        return (handler(d, e));
slouken@6988
   559
    }
slouken@6988
   560
}
slouken@6988
   561
slouken@1952
   562
SDL_GLContext
slouken@1952
   563
X11_GL_CreateContext(_THIS, SDL_Window * window)
slouken@1952
   564
{
slouken@1952
   565
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1952
   566
    Display *display = data->videodata->display;
slouken@1952
   567
    int screen =
slouken@5246
   568
        ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
slouken@1952
   569
    XWindowAttributes xattr;
slouken@1952
   570
    XVisualInfo v, *vinfo;
slouken@1952
   571
    int n;
slouken@6393
   572
    GLXContext context = NULL, share_context;
gabomdq@7679
   573
    PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = NULL;
slouken@6393
   574
slouken@6393
   575
    if (_this->gl_config.share_with_current_context) {
slouken@7413
   576
        share_context = (GLXContext)SDL_GL_GetCurrentContext();
slouken@6393
   577
    } else {
slouken@6393
   578
        share_context = NULL;
slouken@6393
   579
    }
slouken@1952
   580
slouken@1955
   581
    /* We do this to create a clean separation between X and GLX errors. */
icculus@7827
   582
    X11_XSync(display, False);
slouken@7512
   583
    errorBase = _this->gl_data->errorBase;
icculus@7827
   584
    handler = X11_XSetErrorHandler(X11_GL_CreateContextErrorHandler);
icculus@7827
   585
    X11_XGetWindowAttributes(display, data->xwindow, &xattr);
slouken@1952
   586
    v.screen = screen;
icculus@7827
   587
    v.visualid = X11_XVisualIDFromVisual(xattr.visual);
icculus@7827
   588
    vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
slouken@1952
   589
    if (vinfo) {
slouken@6393
   590
        if (_this->gl_config.major_version < 3 &&
slouken@6393
   591
            _this->gl_config.profile_mask == 0 &&
slouken@6393
   592
            _this->gl_config.flags == 0) {
slouken@6393
   593
            /* Create legacy context */
slouken@3100
   594
            context =
slouken@6393
   595
                _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
slouken@3100
   596
        } else {
slouken@3100
   597
            /* If we want a GL 3.0 context or later we need to get a temporary
slouken@3100
   598
               context to grab the new context creation function */
slouken@3139
   599
            GLXContext temp_context =
slouken@3139
   600
                _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
slouken@6988
   601
            if (temp_context) {
slouken@6393
   602
                /* max 8 attributes plus terminator */
slouken@6296
   603
                int attribs[9] = {
slouken@3139
   604
                    GLX_CONTEXT_MAJOR_VERSION_ARB,
slouken@3139
   605
                    _this->gl_config.major_version,
slouken@3139
   606
                    GLX_CONTEXT_MINOR_VERSION_ARB,
slouken@3139
   607
                    _this->gl_config.minor_version,
slouken@3139
   608
                    0
slouken@3100
   609
                };
slouken@6393
   610
                int iattr = 4;
slouken@6296
   611
slouken@6393
   612
                /* SDL profile bits match GLX profile bits */
slouken@6393
   613
                if( _this->gl_config.profile_mask != 0 ) {
slouken@6393
   614
                    attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
slouken@6393
   615
                    attribs[iattr++] = _this->gl_config.profile_mask;
slouken@6393
   616
                }
slouken@6296
   617
slouken@6393
   618
                /* SDL flags match GLX flags */
slouken@6393
   619
                if( _this->gl_config.flags != 0 ) {
slouken@6393
   620
                    attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
slouken@6393
   621
                    attribs[iattr++] = _this->gl_config.flags;
slouken@6393
   622
                }
slouken@6296
   623
slouken@6393
   624
                attribs[iattr++] = 0;
slouken@3139
   625
slouken@3100
   626
                /* Get a pointer to the context creation function for GL 3.0 */
gabomdq@7679
   627
                glXCreateContextAttribs =
slouken@3139
   628
                    (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
slouken@3139
   629
                    glXGetProcAddress((GLubyte *)
slouken@3139
   630
                                      "glXCreateContextAttribsARB");
slouken@3100
   631
                if (!glXCreateContextAttribs) {
slouken@3100
   632
                    SDL_SetError("GL 3.x is not supported");
slouken@3100
   633
                    context = temp_context;
slouken@3100
   634
                } else {
slouken@5395
   635
                    int glxAttribs[64];
slouken@5395
   636
slouken@3105
   637
                    /* Create a GL 3.x context */
slouken@3100
   638
                    GLXFBConfig *framebuffer_config = NULL;
slouken@3139
   639
                    int fbcount = 0;
slouken@3139
   640
                    GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
slouken@3139
   641
                                                       int screen,
slouken@3139
   642
                                                       const int *attrib_list,
slouken@3139
   643
                                                       int *nelements);
slouken@3105
   644
slouken@3139
   645
                    glXChooseFBConfig =
slouken@3139
   646
                        (GLXFBConfig *
slouken@3139
   647
                         (*)(Display *, int, const int *,
slouken@3139
   648
                             int *)) _this->gl_data->
slouken@3139
   649
                        glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
slouken@3105
   650
slouken@6296
   651
                    X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE);
slouken@5395
   652
slouken@3139
   653
                    if (!glXChooseFBConfig
slouken@3139
   654
                        || !(framebuffer_config =
slouken@3139
   655
                             glXChooseFBConfig(display,
slouken@5395
   656
                                               DefaultScreen(display), glxAttribs,
slouken@3139
   657
                                               &fbcount))) {
slouken@3139
   658
                        SDL_SetError
slouken@3139
   659
                            ("No good framebuffers found. GL 3.x disabled");
slouken@3100
   660
                        context = temp_context;
slouken@3139
   661
                    } else {
slouken@3139
   662
                        context =
slouken@3139
   663
                            glXCreateContextAttribs(display,
slouken@3139
   664
                                                    framebuffer_config[0],
slouken@6393
   665
                                                    share_context, True, attribs);
slouken@3139
   666
                        _this->gl_data->glXDestroyContext(display,
slouken@3139
   667
                                                          temp_context);
slouken@3100
   668
                    }
slouken@3100
   669
                }
slouken@3100
   670
            }
slouken@3100
   671
        }
icculus@7827
   672
        X11_XFree(vinfo);
slouken@1952
   673
    }
icculus@7827
   674
    X11_XSync(display, False);
icculus@7827
   675
    X11_XSetErrorHandler(handler);
slouken@7191
   676
slouken@1952
   677
    if (!context) {
slouken@1952
   678
        SDL_SetError("Could not create GL context");
slouken@2178
   679
        return NULL;
slouken@1952
   680
    }
slouken@2178
   681
slouken@2178
   682
    if (X11_GL_MakeCurrent(_this, window, context) < 0) {
slouken@2178
   683
        X11_GL_DeleteContext(_this, context);
slouken@2178
   684
        return NULL;
slouken@2178
   685
    }
slouken@2178
   686
slouken@2178
   687
    return context;
slouken@1952
   688
}
slouken@1952
   689
slouken@1952
   690
int
slouken@1952
   691
X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
slouken@1952
   692
{
slouken@1952
   693
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@1952
   694
    Window drawable =
urkle@6794
   695
        (context ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
slouken@1952
   696
    GLXContext glx_context = (GLXContext) context;
slouken@1952
   697
slouken@6522
   698
    if (!_this->gl_data) {
icculus@7037
   699
        return SDL_SetError("OpenGL not initialized");
slouken@6522
   700
    }
slouken@6522
   701
slouken@1952
   702
    if (!_this->gl_data->glXMakeCurrent(display, drawable, glx_context)) {
icculus@7037
   703
        return SDL_SetError("Unable to make GL context current");
slouken@1952
   704
    }
slouken@1952
   705
icculus@7037
   706
    return 0;
slouken@1952
   707
}
slouken@1952
   708
slouken@7191
   709
/*
icculus@5572
   710
   0 is a valid argument to glxSwapInterval(MESA|EXT) and setting it to 0
icculus@5572
   711
   will undo the effect of a previous call with a value that is greater
icculus@5572
   712
   than zero (or at least that is what the docs say). OTOH, 0 is an invalid
icculus@5572
   713
   argument to glxSwapIntervalSGI and it returns an error if you call it
icculus@5572
   714
   with 0 as an argument.
bob@2327
   715
*/
bob@2327
   716
bob@2327
   717
static int swapinterval = -1;
slouken@1952
   718
int
slouken@1952
   719
X11_GL_SetSwapInterval(_THIS, int interval)
slouken@1952
   720
{
icculus@6382
   721
    int status = -1;
slouken@1952
   722
icculus@6382
   723
    if ((interval < 0) && (!_this->gl_data->HAS_GLX_EXT_swap_control_tear)) {
icculus@6382
   724
        SDL_SetError("Negative swap interval unsupported in this GL");
icculus@6382
   725
    } else if (_this->gl_data->glXSwapIntervalEXT) {
icculus@5572
   726
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
icculus@5572
   727
        const SDL_WindowData *windowdata = (SDL_WindowData *)
slouken@7412
   728
            SDL_GL_GetCurrentWindow()->driverdata;
slouken@6846
   729
icculus@5572
   730
        Window drawable = windowdata->xwindow;
slouken@6846
   731
slouken@6846
   732
        /*
slouken@6846
   733
         * This is a workaround for a bug in NVIDIA drivers. Bug has been reported
slouken@6846
   734
         * and will be fixed in a future release (probably 319.xx).
slouken@6846
   735
         *
slouken@6846
   736
         * There's a bug where glXSetSwapIntervalEXT ignores updates because
slouken@6846
   737
         * it has the wrong value cached. To work around it, we just run a no-op
slouken@6846
   738
         * update to the current value.
slouken@6846
   739
         */
slouken@6851
   740
        int currentInterval = X11_GL_GetSwapInterval(_this);
slouken@6846
   741
        _this->gl_data->glXSwapIntervalEXT(display, drawable, currentInterval);
slouken@6846
   742
        _this->gl_data->glXSwapIntervalEXT(display, drawable, interval);
slouken@6846
   743
slouken@6846
   744
        status = 0;
slouken@6846
   745
        swapinterval = interval;
icculus@5572
   746
    } else if (_this->gl_data->glXSwapIntervalMESA) {
slouken@1952
   747
        status = _this->gl_data->glXSwapIntervalMESA(interval);
slouken@1952
   748
        if (status != 0) {
slouken@1952
   749
            SDL_SetError("glxSwapIntervalMESA failed");
bob@2327
   750
        } else {
bob@2327
   751
            swapinterval = interval;
slouken@1952
   752
        }
slouken@1952
   753
    } else if (_this->gl_data->glXSwapIntervalSGI) {
slouken@1952
   754
        status = _this->gl_data->glXSwapIntervalSGI(interval);
slouken@1952
   755
        if (status != 0) {
slouken@1952
   756
            SDL_SetError("glxSwapIntervalSGI failed");
bob@2327
   757
        } else {
bob@2327
   758
            swapinterval = interval;
slouken@1952
   759
        }
slouken@1952
   760
    } else {
slouken@1952
   761
        SDL_Unsupported();
slouken@1952
   762
    }
slouken@1952
   763
    return status;
slouken@1952
   764
}
slouken@1952
   765
slouken@1952
   766
int
slouken@1952
   767
X11_GL_GetSwapInterval(_THIS)
slouken@1952
   768
{
icculus@5572
   769
    if (_this->gl_data->glXSwapIntervalEXT) {
icculus@5572
   770
        Display *display = ((SDL_VideoData *) _this->driverdata)->display;
icculus@5572
   771
        const SDL_WindowData *windowdata = (SDL_WindowData *)
slouken@7412
   772
            SDL_GL_GetCurrentWindow()->driverdata;
icculus@5572
   773
        Window drawable = windowdata->xwindow;
icculus@6382
   774
        unsigned int allow_late_swap_tearing = 0;
icculus@6382
   775
        unsigned int interval = 0;
icculus@6382
   776
icculus@6382
   777
        if (_this->gl_data->HAS_GLX_EXT_swap_control_tear) {
icculus@6382
   778
            _this->gl_data->glXQueryDrawable(display, drawable,
icculus@6382
   779
                                            GLX_LATE_SWAPS_TEAR_EXT,
icculus@6382
   780
                                            &allow_late_swap_tearing);
icculus@6382
   781
        }
icculus@6382
   782
icculus@5572
   783
        _this->gl_data->glXQueryDrawable(display, drawable,
icculus@6382
   784
                                         GLX_SWAP_INTERVAL_EXT, &interval);
icculus@6382
   785
icculus@6382
   786
        if ((allow_late_swap_tearing) && (interval > 0)) {
icculus@6382
   787
            return -((int) interval);
icculus@6382
   788
        }
icculus@6382
   789
icculus@6382
   790
        return (int) interval;
icculus@5572
   791
    } else if (_this->gl_data->glXGetSwapIntervalMESA) {
slouken@1952
   792
        return _this->gl_data->glXGetSwapIntervalMESA();
slouken@1952
   793
    } else {
bob@2327
   794
        return swapinterval;
slouken@1952
   795
    }
slouken@1952
   796
}
slouken@1952
   797
slouken@1952
   798
void
slouken@1952
   799
X11_GL_SwapWindow(_THIS, SDL_Window * window)
slouken@1952
   800
{
slouken@1952
   801
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
slouken@1952
   802
    Display *display = data->videodata->display;
slouken@1952
   803
slouken@3685
   804
    _this->gl_data->glXSwapBuffers(display, data->xwindow);
slouken@1952
   805
}
slouken@1952
   806
slouken@1952
   807
void
slouken@1952
   808
X11_GL_DeleteContext(_THIS, SDL_GLContext context)
slouken@1952
   809
{
slouken@1952
   810
    Display *display = ((SDL_VideoData *) _this->driverdata)->display;
slouken@1952
   811
    GLXContext glx_context = (GLXContext) context;
slouken@1952
   812
slouken@6522
   813
    if (!_this->gl_data) {
slouken@6522
   814
        return;
slouken@6522
   815
    }
slouken@1952
   816
    _this->gl_data->glXDestroyContext(display, glx_context);
icculus@7827
   817
    X11_XSync(display, False);
slouken@1952
   818
}
slouken@1952
   819
slouken@1952
   820
#endif /* SDL_VIDEO_OPENGL_GLX */
slouken@1952
   821
slouken@6044
   822
#endif /* SDL_VIDEO_DRIVER_X11 */
slouken@6044
   823
slouken@1952
   824
/* vi: set ts=4 sw=4 expandtab: */