src/video/x11/SDL_x11opengl.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 06 Apr 2015 00:11:58 -0400
changeset 9459 f5b468964b0b
parent 9458 543298b36b28
child 9619 b94b6d0bff0f
permissions -rw-r--r--
X11: Always specify "True" if setting GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB.

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