src/video/x11/SDL_x11gl.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
#include "SDL_x11video.h"
slouken@1361
    25
#include "../../events/SDL_events_c.h"
slouken@0
    26
#include "SDL_x11dga_c.h"
slouken@0
    27
#include "SDL_x11gl_c.h"
slouken@0
    28
slouken@1402
    29
#if defined(__IRIX__)
slouken@862
    30
/* IRIX doesn't have a GL library versioning system */
slouken@862
    31
#define DEFAULT_OPENGL	"libGL.so"
slouken@1402
    32
#elif defined(__MACOSX__)
icculus@1191
    33
#define DEFAULT_OPENGL	"/usr/X11R6/lib/libGL.1.dylib"
slouken@1402
    34
#elif defined(__QNXNTO__)
slouken@1402
    35
#define DEFAULT_OPENGL	"libGL.so.3"
slouken@862
    36
#else
slouken@0
    37
#define DEFAULT_OPENGL	"libGL.so.1"
slouken@862
    38
#endif
slouken@0
    39
slouken@667
    40
#ifndef GLX_ARB_multisample
slouken@667
    41
#define GLX_ARB_multisample
slouken@667
    42
#define GLX_SAMPLE_BUFFERS_ARB             100000
slouken@667
    43
#define GLX_SAMPLES_ARB                    100001
slouken@667
    44
#endif
slouken@667
    45
slouken@1656
    46
#ifndef GLX_EXT_visual_rating
slouken@1656
    47
#define GLX_EXT_visual_rating
slouken@1656
    48
#define GLX_VISUAL_CAVEAT_EXT              0x20
slouken@1659
    49
#define GLX_NONE_EXT                       0x8000
slouken@1656
    50
#define GLX_SLOW_VISUAL_EXT                0x8001
slouken@1656
    51
#define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
slouken@1656
    52
#endif
slouken@1656
    53
slouken@1656
    54
#if SDL_VIDEO_OPENGL_GLX
slouken@1662
    55
static int
slouken@1662
    56
glXExtensionSupported (_THIS, const char *extension)
slouken@1656
    57
{
slouken@1662
    58
    const char *extensions;
slouken@1662
    59
    const char *start;
slouken@1662
    60
    const char *where, *terminator;
slouken@1656
    61
slouken@1662
    62
    /* Extension names should not have spaces. */
slouken@1662
    63
    where = SDL_strchr (extension, ' ');
slouken@1662
    64
    if (where || *extension == '\0') {
slouken@1662
    65
        return 0;
slouken@1662
    66
    }
slouken@1656
    67
slouken@1662
    68
    extensions =
slouken@1662
    69
        this->gl_data->glXQueryExtensionsString (GFX_Display, SDL_Screen);
slouken@1662
    70
    /* It takes a bit of care to be fool-proof about parsing the
slouken@1662
    71
     * OpenGL extensions string. Don't be fooled by sub-strings, etc.
slouken@1662
    72
     */
slouken@1662
    73
slouken@1662
    74
    start = extensions;
slouken@1662
    75
slouken@1662
    76
    for (;;) {
slouken@1662
    77
        where = SDL_strstr (start, extension);
slouken@1662
    78
        if (!where)
slouken@1662
    79
            break;
slouken@1662
    80
slouken@1662
    81
        terminator = where + strlen (extension);
slouken@1662
    82
        if (where == start || *(where - 1) == ' ')
slouken@1662
    83
            if (*terminator == ' ' || *terminator == '\0')
slouken@1662
    84
                return 1;
slouken@1662
    85
slouken@1662
    86
        start = terminator;
slouken@1662
    87
    }
slouken@1662
    88
    return 0;
slouken@1656
    89
}
slouken@1656
    90
#endif /* SDL_VIDEO_OPENGL_GLX */
slouken@1656
    91
slouken@1662
    92
XVisualInfo *
slouken@1662
    93
X11_GL_GetVisual (_THIS)
slouken@0
    94
{
slouken@1361
    95
#if SDL_VIDEO_OPENGL_GLX
slouken@1662
    96
    /* 64 seems nice. */
slouken@1662
    97
    int attribs[64];
slouken@1662
    98
    int i;
slouken@0
    99
slouken@1662
   100
    /* load the gl driver from a default path */
slouken@1662
   101
    if (!this->gl_config.driver_loaded) {
slouken@1662
   102
        /* no driver has been loaded, use default (ourselves) */
slouken@1662
   103
        if (X11_GL_LoadLibrary (this, NULL) < 0) {
slouken@1662
   104
            return NULL;
slouken@1662
   105
        }
slouken@1662
   106
    }
slouken@0
   107
slouken@1662
   108
    /* See if we already have a window which we must use */
slouken@1662
   109
    if (SDL_windowid) {
slouken@1662
   110
        XWindowAttributes a;
slouken@1662
   111
        XVisualInfo vi_in;
slouken@1662
   112
        int out_count;
slouken@0
   113
slouken@1662
   114
        XGetWindowAttributes (SDL_Display, SDL_Window, &a);
slouken@1662
   115
        vi_in.screen = SDL_Screen;
slouken@1662
   116
        vi_in.visualid = XVisualIDFromVisual (a.visual);
slouken@1662
   117
        glx_visualinfo = XGetVisualInfo (SDL_Display,
slouken@1662
   118
                                         VisualScreenMask | VisualIDMask,
slouken@1662
   119
                                         &vi_in, &out_count);
slouken@1662
   120
        return glx_visualinfo;
slouken@1662
   121
    }
slouken@0
   122
slouken@1662
   123
    /* Setup our GLX attributes according to the gl_config. */
slouken@1662
   124
    i = 0;
slouken@1662
   125
    attribs[i++] = GLX_RGBA;
slouken@1662
   126
    attribs[i++] = GLX_RED_SIZE;
slouken@1662
   127
    attribs[i++] = this->gl_config.red_size;
slouken@1662
   128
    attribs[i++] = GLX_GREEN_SIZE;
slouken@1662
   129
    attribs[i++] = this->gl_config.green_size;
slouken@1662
   130
    attribs[i++] = GLX_BLUE_SIZE;
slouken@1662
   131
    attribs[i++] = this->gl_config.blue_size;
slouken@0
   132
slouken@1662
   133
    if (this->gl_config.alpha_size) {
slouken@1662
   134
        attribs[i++] = GLX_ALPHA_SIZE;
slouken@1662
   135
        attribs[i++] = this->gl_config.alpha_size;
slouken@1662
   136
    }
slouken@0
   137
slouken@1662
   138
    if (this->gl_config.buffer_size) {
slouken@1662
   139
        attribs[i++] = GLX_BUFFER_SIZE;
slouken@1662
   140
        attribs[i++] = this->gl_config.buffer_size;
slouken@1662
   141
    }
slouken@0
   142
slouken@1662
   143
    if (this->gl_config.double_buffer) {
slouken@1662
   144
        attribs[i++] = GLX_DOUBLEBUFFER;
slouken@1662
   145
    }
slouken@0
   146
slouken@1662
   147
    attribs[i++] = GLX_DEPTH_SIZE;
slouken@1662
   148
    attribs[i++] = this->gl_config.depth_size;
slouken@0
   149
slouken@1662
   150
    if (this->gl_config.stencil_size) {
slouken@1662
   151
        attribs[i++] = GLX_STENCIL_SIZE;
slouken@1662
   152
        attribs[i++] = this->gl_config.stencil_size;
slouken@1662
   153
    }
slouken@0
   154
slouken@1662
   155
    if (this->gl_config.accum_red_size) {
slouken@1662
   156
        attribs[i++] = GLX_ACCUM_RED_SIZE;
slouken@1662
   157
        attribs[i++] = this->gl_config.accum_red_size;
slouken@1662
   158
    }
slouken@0
   159
slouken@1662
   160
    if (this->gl_config.accum_green_size) {
slouken@1662
   161
        attribs[i++] = GLX_ACCUM_GREEN_SIZE;
slouken@1662
   162
        attribs[i++] = this->gl_config.accum_green_size;
slouken@1662
   163
    }
slouken@0
   164
slouken@1662
   165
    if (this->gl_config.accum_blue_size) {
slouken@1662
   166
        attribs[i++] = GLX_ACCUM_BLUE_SIZE;
slouken@1662
   167
        attribs[i++] = this->gl_config.accum_blue_size;
slouken@1662
   168
    }
slouken@0
   169
slouken@1662
   170
    if (this->gl_config.accum_alpha_size) {
slouken@1662
   171
        attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
slouken@1662
   172
        attribs[i++] = this->gl_config.accum_alpha_size;
slouken@1662
   173
    }
slouken@0
   174
slouken@1662
   175
    if (this->gl_config.stereo) {
slouken@1662
   176
        attribs[i++] = GLX_STEREO;
slouken@1662
   177
    }
slouken@450
   178
slouken@1662
   179
    if (this->gl_config.multisamplebuffers) {
slouken@1662
   180
        attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
slouken@1662
   181
        attribs[i++] = this->gl_config.multisamplebuffers;
slouken@1662
   182
    }
slouken@1656
   183
slouken@1662
   184
    if (this->gl_config.multisamplesamples) {
slouken@1662
   185
        attribs[i++] = GLX_SAMPLES_ARB;
slouken@1662
   186
        attribs[i++] = this->gl_config.multisamplesamples;
slouken@1662
   187
    }
slouken@1662
   188
slouken@1662
   189
    if (this->gl_config.accelerated >= 0 &&
slouken@1662
   190
        glXExtensionSupported (this, "GLX_EXT_visual_rating")) {
slouken@1662
   191
        attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
slouken@1662
   192
        attribs[i++] = GLX_NONE_EXT;
slouken@1662
   193
    }
slouken@1662
   194
#ifdef GLX_DIRECT_COLOR         /* Try for a DirectColor visual for gamma support */
slouken@1662
   195
    if (!SDL_getenv ("SDL_VIDEO_X11_NODIRECTCOLOR")) {
slouken@1662
   196
        attribs[i++] = GLX_X_VISUAL_TYPE;
slouken@1662
   197
        attribs[i++] = GLX_DIRECT_COLOR;
slouken@1662
   198
    }
slouken@0
   199
#endif
slouken@1662
   200
    attribs[i++] = None;
slouken@0
   201
slouken@1662
   202
    glx_visualinfo = this->gl_data->glXChooseVisual (GFX_Display,
slouken@1662
   203
                                                     SDL_Screen, attribs);
slouken@0
   204
#ifdef GLX_DIRECT_COLOR
slouken@1662
   205
    if (!glx_visualinfo && !SDL_getenv ("SDL_VIDEO_X11_NODIRECTCOLOR")) {       /* No DirectColor visual?  Try again.. */
slouken@1662
   206
        attribs[i - 3] = None;
slouken@1662
   207
        glx_visualinfo = this->gl_data->glXChooseVisual (GFX_Display,
slouken@1662
   208
                                                         SDL_Screen, attribs);
slouken@1662
   209
    }
slouken@0
   210
#endif
slouken@1662
   211
    if (!glx_visualinfo) {
slouken@1662
   212
        SDL_SetError ("Couldn't find matching GLX visual");
slouken@1662
   213
        return NULL;
slouken@1662
   214
    }
slouken@1315
   215
/*
slouken@1315
   216
	printf("Found GLX visual 0x%x\n", glx_visualinfo->visualid);
slouken@1315
   217
*/
slouken@1662
   218
    return glx_visualinfo;
slouken@0
   219
#else
slouken@1662
   220
    SDL_SetError ("X11 driver not configured with OpenGL");
slouken@1662
   221
    return NULL;
slouken@0
   222
#endif
slouken@0
   223
}
slouken@0
   224
slouken@1662
   225
int
slouken@1662
   226
X11_GL_CreateWindow (_THIS, int w, int h)
slouken@0
   227
{
slouken@1662
   228
    int retval;
slouken@1361
   229
#if SDL_VIDEO_OPENGL_GLX
slouken@1662
   230
    XSetWindowAttributes attributes;
slouken@1662
   231
    unsigned long mask;
slouken@1662
   232
    unsigned long black;
slouken@0
   233
slouken@1662
   234
    black = (glx_visualinfo->visual == DefaultVisual (SDL_Display,
slouken@1662
   235
                                                      SDL_Screen))
slouken@1662
   236
        ? BlackPixel (SDL_Display, SDL_Screen) : 0;
slouken@1662
   237
    attributes.background_pixel = black;
slouken@1662
   238
    attributes.border_pixel = black;
slouken@1662
   239
    attributes.colormap = SDL_XColorMap;
slouken@1662
   240
    mask = CWBackPixel | CWBorderPixel | CWColormap;
slouken@0
   241
slouken@1662
   242
    SDL_Window = XCreateWindow (SDL_Display, WMwindow,
slouken@1662
   243
                                0, 0, w, h, 0, glx_visualinfo->depth,
slouken@1662
   244
                                InputOutput, glx_visualinfo->visual,
slouken@1662
   245
                                mask, &attributes);
slouken@1662
   246
    if (!SDL_Window) {
slouken@1662
   247
        SDL_SetError ("Could not create window");
slouken@1662
   248
        return -1;
slouken@1662
   249
    }
slouken@1662
   250
    retval = 0;
slouken@0
   251
#else
slouken@1662
   252
    SDL_SetError ("X11 driver not configured with OpenGL");
slouken@1662
   253
    retval = -1;
slouken@0
   254
#endif
slouken@1662
   255
    return (retval);
slouken@0
   256
}
slouken@0
   257
slouken@1662
   258
int
slouken@1662
   259
X11_GL_CreateContext (_THIS)
slouken@0
   260
{
slouken@1662
   261
    int retval;
slouken@1361
   262
#if SDL_VIDEO_OPENGL_GLX
slouken@1656
   263
slouken@1662
   264
    /* We do this to create a clean separation between X and GLX errors. */
slouken@1662
   265
    XSync (SDL_Display, False);
slouken@1662
   266
    glx_context = this->gl_data->glXCreateContext (GFX_Display,
slouken@1662
   267
                                                   glx_visualinfo, NULL,
slouken@1662
   268
                                                   True);
slouken@1662
   269
    XSync (GFX_Display, False);
slouken@0
   270
slouken@1662
   271
    if (glx_context == NULL) {
slouken@1662
   272
        SDL_SetError ("Could not create GL context");
slouken@1662
   273
        return (-1);
slouken@1662
   274
    }
slouken@1662
   275
    if (X11_GL_MakeCurrent (this) < 0) {
slouken@1662
   276
        return (-1);
slouken@1662
   277
    }
slouken@1662
   278
    gl_active = 1;
slouken@0
   279
slouken@1662
   280
    if (!glXExtensionSupported (this, "SGI_swap_control")) {
slouken@1662
   281
        this->gl_data->glXSwapIntervalSGI = NULL;
slouken@1662
   282
    }
slouken@1662
   283
    if (!glXExtensionSupported (this, "GLX_MESA_swap_control")) {
slouken@1662
   284
        this->gl_data->glXSwapIntervalMESA = NULL;
slouken@1662
   285
        this->gl_data->glXGetSwapIntervalMESA = NULL;
slouken@1662
   286
    }
slouken@1662
   287
    if (this->gl_config.swap_control >= 0) {
slouken@1662
   288
        if (this->gl_data->glXSwapIntervalMESA) {
slouken@1662
   289
            this->gl_data->glXSwapIntervalMESA (this->gl_config.swap_control);
slouken@1662
   290
        } else if (this->gl_data->glXSwapIntervalSGI) {
slouken@1662
   291
            this->gl_data->glXSwapIntervalSGI (this->gl_config.swap_control);
slouken@1662
   292
        }
slouken@1662
   293
    }
slouken@0
   294
#else
slouken@1662
   295
    SDL_SetError ("X11 driver not configured with OpenGL");
slouken@0
   296
#endif
slouken@1662
   297
    if (gl_active) {
slouken@1662
   298
        retval = 0;
slouken@1662
   299
    } else {
slouken@1662
   300
        retval = -1;
slouken@1662
   301
    }
slouken@1662
   302
    return (retval);
slouken@0
   303
}
slouken@0
   304
slouken@1662
   305
void
slouken@1662
   306
X11_GL_Shutdown (_THIS)
slouken@0
   307
{
slouken@1361
   308
#if SDL_VIDEO_OPENGL_GLX
slouken@1662
   309
    /* Clean up OpenGL */
slouken@1662
   310
    if (glx_context) {
slouken@1662
   311
        this->gl_data->glXMakeCurrent (GFX_Display, None, NULL);
slouken@0
   312
slouken@1662
   313
        if (glx_context != NULL)
slouken@1662
   314
            this->gl_data->glXDestroyContext (GFX_Display, glx_context);
slouken@0
   315
slouken@1662
   316
        glx_context = NULL;
slouken@1662
   317
    }
slouken@1662
   318
    gl_active = 0;
slouken@1361
   319
#endif /* SDL_VIDEO_OPENGL_GLX */
slouken@0
   320
}
slouken@0
   321
slouken@1361
   322
#if SDL_VIDEO_OPENGL_GLX
slouken@0
   323
slouken@0
   324
/* Make the current context active */
slouken@1662
   325
int
slouken@1662
   326
X11_GL_MakeCurrent (_THIS)
slouken@0
   327
{
slouken@1662
   328
    int retval;
slouken@0
   329
slouken@1662
   330
    retval = 0;
slouken@1662
   331
    if (!this->gl_data->glXMakeCurrent (GFX_Display, SDL_Window, glx_context)) {
slouken@1662
   332
        SDL_SetError ("Unable to make GL context current");
slouken@1662
   333
        retval = -1;
slouken@1662
   334
    }
slouken@1662
   335
    XSync (GFX_Display, False);
slouken@0
   336
slouken@1662
   337
    /* More Voodoo X server workarounds... Grr... */
slouken@1662
   338
    SDL_Lock_EventThread ();
slouken@1662
   339
    X11_CheckDGAMouse (this);
slouken@1662
   340
    SDL_Unlock_EventThread ();
slouken@1662
   341
slouken@1662
   342
    return (retval);
slouken@0
   343
}
slouken@0
   344
slouken@0
   345
/* Get attribute data from glX. */
slouken@1662
   346
int
slouken@1662
   347
X11_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
slouken@0
   348
{
slouken@1662
   349
    int retval;
slouken@1662
   350
    int glx_attrib = None;
slouken@0
   351
slouken@1662
   352
    switch (attrib) {
slouken@1662
   353
    case SDL_GL_RED_SIZE:
slouken@1662
   354
        glx_attrib = GLX_RED_SIZE;
slouken@1662
   355
        break;
slouken@1662
   356
    case SDL_GL_GREEN_SIZE:
slouken@1662
   357
        glx_attrib = GLX_GREEN_SIZE;
slouken@1662
   358
        break;
slouken@1662
   359
    case SDL_GL_BLUE_SIZE:
slouken@1662
   360
        glx_attrib = GLX_BLUE_SIZE;
slouken@1662
   361
        break;
slouken@1662
   362
    case SDL_GL_ALPHA_SIZE:
slouken@1662
   363
        glx_attrib = GLX_ALPHA_SIZE;
slouken@1662
   364
        break;
slouken@1662
   365
    case SDL_GL_DOUBLEBUFFER:
slouken@1662
   366
        glx_attrib = GLX_DOUBLEBUFFER;
slouken@1662
   367
        break;
slouken@1662
   368
    case SDL_GL_BUFFER_SIZE:
slouken@1662
   369
        glx_attrib = GLX_BUFFER_SIZE;
slouken@1662
   370
        break;
slouken@1662
   371
    case SDL_GL_DEPTH_SIZE:
slouken@1662
   372
        glx_attrib = GLX_DEPTH_SIZE;
slouken@1662
   373
        break;
slouken@1662
   374
    case SDL_GL_STENCIL_SIZE:
slouken@1662
   375
        glx_attrib = GLX_STENCIL_SIZE;
slouken@1662
   376
        break;
slouken@1662
   377
    case SDL_GL_ACCUM_RED_SIZE:
slouken@1662
   378
        glx_attrib = GLX_ACCUM_RED_SIZE;
slouken@1662
   379
        break;
slouken@1662
   380
    case SDL_GL_ACCUM_GREEN_SIZE:
slouken@1662
   381
        glx_attrib = GLX_ACCUM_GREEN_SIZE;
slouken@1662
   382
        break;
slouken@1662
   383
    case SDL_GL_ACCUM_BLUE_SIZE:
slouken@1662
   384
        glx_attrib = GLX_ACCUM_BLUE_SIZE;
slouken@1662
   385
        break;
slouken@1662
   386
    case SDL_GL_ACCUM_ALPHA_SIZE:
slouken@1662
   387
        glx_attrib = GLX_ACCUM_ALPHA_SIZE;
slouken@1662
   388
        break;
slouken@1662
   389
    case SDL_GL_STEREO:
slouken@1662
   390
        glx_attrib = GLX_STEREO;
slouken@1662
   391
        break;
slouken@1662
   392
    case SDL_GL_MULTISAMPLEBUFFERS:
slouken@1662
   393
        glx_attrib = GLX_SAMPLE_BUFFERS_ARB;
slouken@1662
   394
        break;
slouken@1662
   395
    case SDL_GL_MULTISAMPLESAMPLES:
slouken@1662
   396
        glx_attrib = GLX_SAMPLES_ARB;
slouken@1662
   397
        break;
slouken@1662
   398
    case SDL_GL_ACCELERATED_VISUAL:
slouken@1662
   399
        if (glXExtensionSupported (this, "GLX_EXT_visual_rating")) {
slouken@1662
   400
            glx_attrib = GLX_VISUAL_CAVEAT_EXT;
slouken@1662
   401
            retval =
slouken@1662
   402
                this->gl_data->glXGetConfig (GFX_Display, glx_visualinfo,
slouken@1662
   403
                                             glx_attrib, value);
slouken@1662
   404
            if (*value == GLX_SLOW_VISUAL_EXT) {
slouken@1662
   405
                *value = SDL_FALSE;
slouken@1662
   406
            } else {
slouken@1662
   407
                *value = SDL_TRUE;
slouken@1662
   408
            }
slouken@1662
   409
            return retval;
slouken@1662
   410
        } else {
slouken@1662
   411
            return (-1);
slouken@1662
   412
        }
slouken@1662
   413
        break;
slouken@1662
   414
    case SDL_GL_SWAP_CONTROL:
slouken@1662
   415
        if (this->gl_data->glXGetSwapIntervalMESA) {
slouken@1662
   416
            return this->gl_data->glXGetSwapIntervalMESA ();
slouken@1662
   417
        } else {
slouken@1662
   418
            return (-1) /*(this->gl_config.swap_control > 0) */ ;
slouken@1662
   419
        }
slouken@1662
   420
        break;
slouken@1662
   421
    default:
slouken@1662
   422
        return (-1);
slouken@1662
   423
    }
slouken@0
   424
slouken@1662
   425
    retval =
slouken@1662
   426
        this->gl_data->glXGetConfig (GFX_Display, glx_visualinfo, glx_attrib,
slouken@1662
   427
                                     value);
slouken@0
   428
slouken@1662
   429
    return retval;
slouken@0
   430
}
slouken@0
   431
slouken@1662
   432
void
slouken@1662
   433
X11_GL_SwapBuffers (_THIS)
slouken@0
   434
{
slouken@1662
   435
    this->gl_data->glXSwapBuffers (GFX_Display, SDL_Window);
slouken@0
   436
}
slouken@0
   437
slouken@1361
   438
#endif /* SDL_VIDEO_OPENGL_GLX */
slouken@0
   439
slouken@1662
   440
void
slouken@1662
   441
X11_GL_UnloadLibrary (_THIS)
slouken@0
   442
{
slouken@1361
   443
#if SDL_VIDEO_OPENGL_GLX
slouken@1662
   444
    if (this->gl_config.driver_loaded) {
icculus@1191
   445
slouken@1662
   446
        SDL_UnloadObject (this->gl_config.dll_handle);
slouken@0
   447
slouken@1662
   448
        this->gl_data->glXGetProcAddress = NULL;
slouken@1662
   449
        this->gl_data->glXChooseVisual = NULL;
slouken@1662
   450
        this->gl_data->glXCreateContext = NULL;
slouken@1662
   451
        this->gl_data->glXDestroyContext = NULL;
slouken@1662
   452
        this->gl_data->glXMakeCurrent = NULL;
slouken@1662
   453
        this->gl_data->glXSwapBuffers = NULL;
slouken@1662
   454
        this->gl_data->glXSwapIntervalSGI = NULL;
slouken@1662
   455
        this->gl_data->glXSwapIntervalMESA = NULL;
slouken@1662
   456
        this->gl_data->glXGetSwapIntervalMESA = NULL;
slouken@0
   457
slouken@1662
   458
        this->gl_config.dll_handle = NULL;
slouken@1662
   459
        this->gl_config.driver_loaded = 0;
slouken@1662
   460
    }
slouken@0
   461
#endif
slouken@0
   462
}
slouken@0
   463
slouken@1361
   464
#if SDL_VIDEO_OPENGL_GLX
icculus@1182
   465
slouken@0
   466
/* Passing a NULL path means load pointers from the application */
slouken@1662
   467
int
slouken@1662
   468
X11_GL_LoadLibrary (_THIS, const char *path)
slouken@0
   469
{
slouken@1662
   470
    void *handle = NULL;
slouken@0
   471
slouken@1662
   472
    if (gl_active) {
slouken@1662
   473
        SDL_SetError ("OpenGL context already created");
slouken@1662
   474
        return -1;
slouken@1662
   475
    }
icculus@1182
   476
slouken@1662
   477
    if (path == NULL) {
slouken@1662
   478
        path = SDL_getenv ("SDL_VIDEO_GL_DRIVER");
slouken@1662
   479
        if (path == NULL) {
slouken@1662
   480
            path = DEFAULT_OPENGL;
slouken@1662
   481
        }
slouken@1662
   482
    }
icculus@1191
   483
slouken@1662
   484
    handle = SDL_LoadObject (path);
slouken@1662
   485
    if (handle == NULL) {
slouken@1662
   486
        /* SDL_LoadObject() will call SDL_SetError() for us. */
slouken@1662
   487
        return -1;
slouken@1662
   488
    }
slouken@0
   489
slouken@1662
   490
    /* Unload the old driver and reset the pointers */
slouken@1662
   491
    X11_GL_UnloadLibrary (this);
slouken@0
   492
slouken@1662
   493
    /* Load new function pointers */
slouken@1662
   494
    this->gl_data->glXGetProcAddress =
slouken@1662
   495
        (void *(*)(const GLubyte *)) SDL_LoadFunction (handle,
slouken@1662
   496
                                                       "glXGetProcAddressARB");
slouken@1662
   497
    this->gl_data->glXChooseVisual =
slouken@1662
   498
        (XVisualInfo * (*)(Display *, int, int *)) SDL_LoadFunction (handle,
slouken@1662
   499
                                                                     "glXChooseVisual");
slouken@1662
   500
    this->gl_data->glXCreateContext =
slouken@1662
   501
        (GLXContext (*)(Display *, XVisualInfo *, GLXContext, int))
slouken@1662
   502
        SDL_LoadFunction (handle, "glXCreateContext");
slouken@1662
   503
    this->gl_data->glXDestroyContext =
slouken@1662
   504
        (void (*)(Display *, GLXContext)) SDL_LoadFunction (handle,
slouken@1662
   505
                                                            "glXDestroyContext");
slouken@1662
   506
    this->gl_data->glXMakeCurrent =
slouken@1662
   507
        (int (*)(Display *, GLXDrawable, GLXContext))
slouken@1662
   508
        SDL_LoadFunction (handle, "glXMakeCurrent");
slouken@1662
   509
    this->gl_data->glXSwapBuffers =
slouken@1662
   510
        (void (*)(Display *, GLXDrawable)) SDL_LoadFunction (handle,
slouken@1662
   511
                                                             "glXSwapBuffers");
slouken@1662
   512
    this->gl_data->glXGetConfig =
slouken@1662
   513
        (int (*)(Display *, XVisualInfo *, int, int *))
slouken@1662
   514
        SDL_LoadFunction (handle, "glXGetConfig");
slouken@1662
   515
    this->gl_data->glXQueryExtensionsString =
slouken@1662
   516
        (const char *(*)(Display *, int)) SDL_LoadFunction (handle,
slouken@1662
   517
                                                            "glXQueryExtensionsString");
slouken@1662
   518
    this->gl_data->glXSwapIntervalSGI =
slouken@1662
   519
        (int (*)(int)) SDL_LoadFunction (handle, "glXSwapIntervalSGI");
slouken@1662
   520
    this->gl_data->glXSwapIntervalMESA =
slouken@1662
   521
        (GLint (*)(unsigned)) SDL_LoadFunction (handle,
slouken@1662
   522
                                                "glXSwapIntervalMESA");
slouken@1662
   523
    this->gl_data->glXGetSwapIntervalMESA =
slouken@1662
   524
        (GLint (*)(void)) SDL_LoadFunction (handle, "glXGetSwapIntervalMESA");
slouken@1315
   525
slouken@1662
   526
    if ((this->gl_data->glXChooseVisual == NULL) ||
slouken@1662
   527
        (this->gl_data->glXCreateContext == NULL) ||
slouken@1662
   528
        (this->gl_data->glXDestroyContext == NULL) ||
slouken@1662
   529
        (this->gl_data->glXMakeCurrent == NULL) ||
slouken@1662
   530
        (this->gl_data->glXSwapBuffers == NULL) ||
slouken@1662
   531
        (this->gl_data->glXGetConfig == NULL) ||
slouken@1662
   532
        (this->gl_data->glXQueryExtensionsString == NULL)) {
slouken@1662
   533
        SDL_SetError ("Could not retrieve OpenGL functions");
slouken@1662
   534
        return -1;
slouken@1662
   535
    }
slouken@0
   536
slouken@1662
   537
    this->gl_config.dll_handle = handle;
slouken@1662
   538
    this->gl_config.driver_loaded = 1;
slouken@1662
   539
    if (path) {
slouken@1662
   540
        SDL_strlcpy (this->gl_config.driver_path, path,
slouken@1662
   541
                     SDL_arraysize (this->gl_config.driver_path));
slouken@1662
   542
    } else {
slouken@1662
   543
        *this->gl_config.driver_path = '\0';
slouken@1662
   544
    }
slouken@1662
   545
    return 0;
slouken@0
   546
}
slouken@0
   547
slouken@1662
   548
void *
slouken@1662
   549
X11_GL_GetProcAddress (_THIS, const char *proc)
slouken@0
   550
{
slouken@1662
   551
    void *handle;
slouken@1662
   552
slouken@1662
   553
    handle = this->gl_config.dll_handle;
slouken@1662
   554
    if (this->gl_data->glXGetProcAddress) {
slouken@1662
   555
        return this->gl_data->glXGetProcAddress ((const GLubyte *) proc);
slouken@1662
   556
    }
slouken@1662
   557
    return SDL_LoadFunction (handle, proc);
slouken@0
   558
}
slouken@0
   559
slouken@1361
   560
#endif /* SDL_VIDEO_OPENGL_GLX */
slouken@1662
   561
/* vi: set ts=4 sw=4 expandtab: */