src/video/win32/SDL_win32opengl.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 25 Jul 2006 06:22:42 +0000
changeset 1936 83946ee0ff1f
parent 1926 307355678142
child 1952 420716272158
permissions -rw-r--r--
Implemented OpenGL support on Mac OS X
The OpenGL renderer works without changes, yay! :)
slouken@1913
     1
/*
slouken@1913
     2
    SDL - Simple DirectMedia Layer
slouken@1913
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1913
     4
slouken@1913
     5
    This library is free software; you can redistribute it and/or
slouken@1913
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1913
     7
    License as published by the Free Software Foundation; either
slouken@1913
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1913
     9
slouken@1913
    10
    This library is distributed in the hope that it will be useful,
slouken@1913
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1913
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1913
    13
    Lesser General Public License for more details.
slouken@1913
    14
slouken@1913
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1913
    16
    License along with this library; if not, write to the Free Software
slouken@1913
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1913
    18
slouken@1913
    19
    Sam Lantinga
slouken@1913
    20
    slouken@libsdl.org
slouken@1913
    21
*/
slouken@1913
    22
#include "SDL_config.h"
slouken@1913
    23
slouken@1913
    24
#include "SDL_win32video.h"
slouken@1913
    25
slouken@1913
    26
/* WGL implementation of SDL OpenGL support */
slouken@1913
    27
slouken@1913
    28
#if SDL_VIDEO_OPENGL
slouken@1913
    29
#include "SDL_opengl.h"
slouken@1913
    30
slouken@1936
    31
#define DEFAULT_OPENGL_PATH "OPENGL32.DLL"
slouken@1913
    32
slouken@1913
    33
slouken@1913
    34
int
slouken@1913
    35
WIN_GL_LoadLibrary(_THIS, const char *path)
slouken@1913
    36
{
slouken@1913
    37
    LPTSTR wpath;
slouken@1913
    38
    HANDLE handle;
slouken@1913
    39
slouken@1913
    40
    if (_this->gl_config.driver_loaded) {
slouken@1913
    41
        if (path) {
slouken@1913
    42
            SDL_SetError("OpenGL library already loaded");
slouken@1913
    43
            return -1;
slouken@1913
    44
        } else {
slouken@1913
    45
            ++_this->gl_config.driver_loaded;
slouken@1913
    46
            return 0;
slouken@1913
    47
        }
slouken@1913
    48
    }
slouken@1913
    49
    if (path == NULL) {
slouken@1936
    50
        path = DEFAULT_OPENGL_PATH;
slouken@1913
    51
    }
slouken@1913
    52
    wpath = WIN_UTF8ToString(path);
slouken@1913
    53
    handle = LoadLibrary(wpath);
slouken@1913
    54
    SDL_free(wpath);
slouken@1913
    55
    if (!handle) {
slouken@1913
    56
        char message[1024];
slouken@1913
    57
        SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
slouken@1913
    58
                     path);
slouken@1913
    59
        WIN_SetError(message);
slouken@1913
    60
        return -1;
slouken@1913
    61
    }
slouken@1913
    62
slouken@1913
    63
    /* Load function pointers */
slouken@1913
    64
    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
slouken@1913
    65
        GetProcAddress(handle, "wglGetProcAddress");
slouken@1913
    66
    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
slouken@1913
    67
        GetProcAddress(handle, "wglCreateContext");
slouken@1913
    68
    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
slouken@1913
    69
        GetProcAddress(handle, "wglDeleteContext");
slouken@1913
    70
    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
slouken@1913
    71
        GetProcAddress(handle, "wglMakeCurrent");
slouken@1913
    72
    _this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
slouken@1913
    73
        GetProcAddress(handle, "wglSwapIntervalEXT");
slouken@1913
    74
    _this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
slouken@1913
    75
        GetProcAddress(handle, "wglGetSwapIntervalEXT");
slouken@1913
    76
slouken@1913
    77
    if (!_this->gl_data->wglGetProcAddress ||
slouken@1913
    78
        !_this->gl_data->wglCreateContext ||
slouken@1913
    79
        !_this->gl_data->wglDeleteContext ||
slouken@1913
    80
        !_this->gl_data->wglMakeCurrent) {
slouken@1913
    81
        SDL_SetError("Could not retrieve OpenGL functions");
slouken@1913
    82
        FreeLibrary(handle);
slouken@1913
    83
        return -1;
slouken@1913
    84
    }
slouken@1913
    85
slouken@1913
    86
    _this->gl_config.dll_handle = handle;
slouken@1913
    87
    SDL_strlcpy(_this->gl_config.driver_path, path,
slouken@1913
    88
                SDL_arraysize(_this->gl_config.driver_path));
slouken@1913
    89
    _this->gl_config.driver_loaded = 1;
slouken@1913
    90
    return 0;
slouken@1913
    91
}
slouken@1913
    92
slouken@1913
    93
void *
slouken@1913
    94
WIN_GL_GetProcAddress(_THIS, const char *proc)
slouken@1913
    95
{
slouken@1913
    96
    void *func;
slouken@1913
    97
slouken@1913
    98
    /* This is to pick up extensions */
slouken@1913
    99
    func = _this->gl_data->wglGetProcAddress(proc);
slouken@1913
   100
    if (!func) {
slouken@1913
   101
        /* This is probably a normal GL function */
slouken@1913
   102
        func = GetProcAddress(_this->gl_config.dll_handle, proc);
slouken@1913
   103
    }
slouken@1913
   104
    return func;
slouken@1913
   105
}
slouken@1913
   106
slouken@1913
   107
static void
slouken@1913
   108
WIN_GL_UnloadLibrary(_THIS)
slouken@1913
   109
{
slouken@1913
   110
    if (_this->gl_config.driver_loaded > 0) {
slouken@1913
   111
        if (--_this->gl_config.driver_loaded > 0) {
slouken@1913
   112
            return;
slouken@1913
   113
        }
slouken@1913
   114
        FreeLibrary((HMODULE) _this->gl_config.dll_handle);
slouken@1913
   115
        _this->gl_config.dll_handle = NULL;
slouken@1913
   116
    }
slouken@1913
   117
}
slouken@1913
   118
slouken@1913
   119
static void
slouken@1913
   120
WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
slouken@1913
   121
{
slouken@1913
   122
    SDL_zerop(pfd);
slouken@1913
   123
    pfd->nSize = sizeof(*pfd);
slouken@1913
   124
    pfd->nVersion = 1;
slouken@1913
   125
    pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
slouken@1913
   126
    if (_this->gl_config.double_buffer) {
slouken@1913
   127
        pfd->dwFlags |= PFD_DOUBLEBUFFER;
slouken@1913
   128
    }
slouken@1913
   129
    if (_this->gl_config.stereo) {
slouken@1913
   130
        pfd->dwFlags |= PFD_STEREO;
slouken@1913
   131
    }
slouken@1913
   132
    pfd->iLayerType = PFD_MAIN_PLANE;
slouken@1913
   133
    pfd->iPixelType = PFD_TYPE_RGBA;
slouken@1913
   134
    pfd->cRedBits = _this->gl_config.red_size;
slouken@1913
   135
    pfd->cGreenBits = _this->gl_config.green_size;
slouken@1913
   136
    pfd->cBlueBits = _this->gl_config.blue_size;
slouken@1913
   137
    pfd->cAlphaBits = _this->gl_config.alpha_size;
slouken@1913
   138
    if (_this->gl_config.buffer_size) {
slouken@1913
   139
        pfd->cColorBits =
slouken@1913
   140
            _this->gl_config.buffer_size - _this->gl_config.alpha_size;
slouken@1913
   141
    } else {
slouken@1913
   142
        pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
slouken@1913
   143
    }
slouken@1913
   144
    pfd->cAccumRedBits = _this->gl_config.accum_red_size;
slouken@1913
   145
    pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
slouken@1913
   146
    pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
slouken@1913
   147
    pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
slouken@1913
   148
    pfd->cAccumBits =
slouken@1913
   149
        (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
slouken@1913
   150
         pfd->cAccumAlphaBits);
slouken@1913
   151
    pfd->cDepthBits = _this->gl_config.depth_size;
slouken@1913
   152
    pfd->cStencilBits = _this->gl_config.stencil_size;
slouken@1913
   153
}
slouken@1913
   154
slouken@1913
   155
static SDL_bool
slouken@1913
   156
HasExtension(const char *extension, const char *extensions)
slouken@1913
   157
{
slouken@1913
   158
    const char *start;
slouken@1913
   159
    const char *where, *terminator;
slouken@1913
   160
slouken@1913
   161
    /* Extension names should not have spaces. */
slouken@1913
   162
    where = SDL_strchr(extension, ' ');
slouken@1913
   163
    if (where || *extension == '\0')
slouken@1913
   164
        return SDL_FALSE;
slouken@1913
   165
slouken@1913
   166
    if (!extensions)
slouken@1913
   167
        return SDL_FALSE;
slouken@1913
   168
slouken@1913
   169
    /* It takes a bit of care to be fool-proof about parsing the
slouken@1913
   170
     * OpenGL extensions string. Don't be fooled by sub-strings,
slouken@1913
   171
     * etc. */
slouken@1913
   172
slouken@1913
   173
    start = extensions;
slouken@1913
   174
slouken@1913
   175
    for (;;) {
slouken@1913
   176
        where = SDL_strstr(start, extension);
slouken@1913
   177
        if (!where)
slouken@1913
   178
            break;
slouken@1913
   179
slouken@1913
   180
        terminator = where + SDL_strlen(extension);
slouken@1913
   181
        if (where == start || *(where - 1) == ' ')
slouken@1913
   182
            if (*terminator == ' ' || *terminator == '\0')
slouken@1913
   183
                return SDL_TRUE;
slouken@1913
   184
slouken@1913
   185
        start = terminator;
slouken@1913
   186
    }
slouken@1913
   187
    return SDL_FALSE;
slouken@1913
   188
}
slouken@1913
   189
slouken@1913
   190
static void
slouken@1913
   191
WIN_GL_InitExtensions(_THIS)
slouken@1913
   192
{
slouken@1913
   193
    HWND hwnd;
slouken@1913
   194
    HDC hdc;
slouken@1913
   195
    PIXELFORMATDESCRIPTOR pfd;
slouken@1913
   196
    int pixel_format;
slouken@1913
   197
    HGLRC hglrc;
slouken@1913
   198
    const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
slouken@1913
   199
    const char *extensions;
slouken@1913
   200
slouken@1913
   201
    hwnd =
slouken@1913
   202
        CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
slouken@1913
   203
                     10, 10, NULL, NULL, SDL_Instance, NULL);
slouken@1913
   204
    WIN_PumpEvents(_this);
slouken@1913
   205
slouken@1913
   206
    hdc = GetDC(hwnd);
slouken@1913
   207
slouken@1913
   208
    WIN_GL_SetupPixelFormat(_this, &pfd);
slouken@1913
   209
    pixel_format = ChoosePixelFormat(hdc, &pfd);
slouken@1913
   210
    SetPixelFormat(hdc, pixel_format, &pfd);
slouken@1913
   211
slouken@1913
   212
    hglrc = _this->gl_data->wglCreateContext(hdc);
slouken@1913
   213
    if (hglrc) {
slouken@1913
   214
        _this->gl_data->wglMakeCurrent(hdc, hglrc);
slouken@1913
   215
    }
slouken@1913
   216
slouken@1913
   217
    wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
slouken@1913
   218
        _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
slouken@1913
   219
    if (wglGetExtensionsStringARB) {
slouken@1913
   220
        extensions = wglGetExtensionsStringARB(hdc);
slouken@1913
   221
    } else {
slouken@1913
   222
        extensions = NULL;
slouken@1913
   223
    }
slouken@1913
   224
slouken@1913
   225
    /* Check for WGL_ARB_pixel_format */
slouken@1913
   226
    _this->gl_data->WGL_ARB_pixel_format = 0;
slouken@1913
   227
    if (HasExtension("WGL_ARB_pixel_format", extensions)) {
slouken@1913
   228
        _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
slouken@1913
   229
                                                   (HDC, const int *,
slouken@1913
   230
                                                    const FLOAT *, UINT,
slouken@1913
   231
                                                    int *, UINT *))
slouken@1913
   232
            WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
slouken@1913
   233
        _this->gl_data->wglGetPixelFormatAttribivARB =
slouken@1913
   234
            (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
slouken@1913
   235
            WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
slouken@1913
   236
slouken@1913
   237
        if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
slouken@1913
   238
            (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
slouken@1913
   239
            _this->gl_data->WGL_ARB_pixel_format = 1;
slouken@1913
   240
        }
slouken@1913
   241
    }
slouken@1913
   242
slouken@1913
   243
    /* Check for WGL_EXT_swap_control */
slouken@1913
   244
    if (HasExtension("WGL_EXT_swap_control", extensions)) {
slouken@1913
   245
        _this->gl_data->wglSwapIntervalEXT =
slouken@1913
   246
            WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
slouken@1913
   247
        _this->gl_data->wglGetSwapIntervalEXT =
slouken@1913
   248
            WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
slouken@1913
   249
    }
slouken@1913
   250
slouken@1913
   251
    if (hglrc) {
slouken@1913
   252
        _this->gl_data->wglMakeCurrent(NULL, NULL);
slouken@1913
   253
        _this->gl_data->wglDeleteContext(hglrc);
slouken@1913
   254
    }
slouken@1913
   255
    ReleaseDC(hwnd, hdc);
slouken@1913
   256
    DestroyWindow(hwnd);
slouken@1913
   257
    WIN_PumpEvents(_this);
slouken@1913
   258
}
slouken@1913
   259
slouken@1913
   260
static void
slouken@1913
   261
WIN_GL_Shutdown(_THIS)
slouken@1913
   262
{
slouken@1913
   263
    if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
slouken@1913
   264
        return;
slouken@1913
   265
    }
slouken@1913
   266
slouken@1913
   267
    WIN_GL_UnloadLibrary(_this);
slouken@1913
   268
slouken@1913
   269
    SDL_free(_this->gl_data);
slouken@1913
   270
    _this->gl_data = NULL;
slouken@1913
   271
}
slouken@1913
   272
slouken@1913
   273
static int
slouken@1913
   274
WIN_GL_Initialize(_THIS)
slouken@1913
   275
{
slouken@1913
   276
    if (_this->gl_data) {
slouken@1913
   277
        ++_this->gl_data->initialized;
slouken@1913
   278
        return 0;
slouken@1913
   279
    }
slouken@1913
   280
slouken@1913
   281
    _this->gl_data =
slouken@1913
   282
        (struct SDL_GLDriverData *) SDL_calloc(1,
slouken@1913
   283
                                               sizeof(struct
slouken@1913
   284
                                                      SDL_GLDriverData));
slouken@1913
   285
    if (!_this->gl_data) {
slouken@1913
   286
        SDL_OutOfMemory();
slouken@1913
   287
        return -1;
slouken@1913
   288
    }
slouken@1913
   289
    _this->gl_data->initialized = 1;
slouken@1913
   290
slouken@1913
   291
    if (WIN_GL_LoadLibrary(_this, NULL) < 0) {
slouken@1913
   292
        return -1;
slouken@1913
   293
    }
slouken@1913
   294
slouken@1913
   295
    /* Initialize extensions */
slouken@1913
   296
    WIN_GL_InitExtensions(_this);
slouken@1913
   297
slouken@1913
   298
    return 0;
slouken@1913
   299
}
slouken@1913
   300
slouken@1913
   301
int
slouken@1913
   302
WIN_GL_SetupWindow(_THIS, SDL_Window * window)
slouken@1913
   303
{
slouken@1913
   304
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
slouken@1913
   305
    PIXELFORMATDESCRIPTOR pfd;
slouken@1913
   306
    int pixel_format;
slouken@1913
   307
    unsigned int matching;
slouken@1913
   308
    int iAttribs[64];
slouken@1913
   309
    int *iAttr;
slouken@1913
   310
    float fAttribs[1] = { 0 };
slouken@1913
   311
slouken@1913
   312
    if (WIN_GL_Initialize(_this) < 0) {
slouken@1913
   313
        return -1;
slouken@1913
   314
    }
slouken@1913
   315
slouken@1913
   316
    WIN_GL_SetupPixelFormat(_this, &pfd);
slouken@1913
   317
slouken@1913
   318
    /* setup WGL_ARB_pixel_format attribs */
slouken@1913
   319
    iAttr = &iAttribs[0];
slouken@1913
   320
slouken@1913
   321
    *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
slouken@1913
   322
    *iAttr++ = GL_TRUE;
slouken@1913
   323
    *iAttr++ = WGL_ACCELERATION_ARB;
slouken@1913
   324
    *iAttr++ = WGL_FULL_ACCELERATION_ARB;
slouken@1913
   325
    *iAttr++ = WGL_RED_BITS_ARB;
slouken@1913
   326
    *iAttr++ = _this->gl_config.red_size;
slouken@1913
   327
    *iAttr++ = WGL_GREEN_BITS_ARB;
slouken@1913
   328
    *iAttr++ = _this->gl_config.green_size;
slouken@1913
   329
    *iAttr++ = WGL_BLUE_BITS_ARB;
slouken@1913
   330
    *iAttr++ = _this->gl_config.blue_size;
slouken@1913
   331
slouken@1913
   332
    if (_this->gl_config.alpha_size) {
slouken@1913
   333
        *iAttr++ = WGL_ALPHA_BITS_ARB;
slouken@1913
   334
        *iAttr++ = _this->gl_config.alpha_size;
slouken@1913
   335
    }
slouken@1913
   336
slouken@1913
   337
    *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
slouken@1913
   338
    *iAttr++ = _this->gl_config.double_buffer;
slouken@1913
   339
slouken@1913
   340
    *iAttr++ = WGL_DEPTH_BITS_ARB;
slouken@1913
   341
    *iAttr++ = _this->gl_config.depth_size;
slouken@1913
   342
slouken@1913
   343
    if (_this->gl_config.stencil_size) {
slouken@1913
   344
        *iAttr++ = WGL_STENCIL_BITS_ARB;
slouken@1913
   345
        *iAttr++ = _this->gl_config.stencil_size;
slouken@1913
   346
    }
slouken@1913
   347
slouken@1913
   348
    if (_this->gl_config.accum_red_size) {
slouken@1913
   349
        *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
slouken@1913
   350
        *iAttr++ = _this->gl_config.accum_red_size;
slouken@1913
   351
    }
slouken@1913
   352
slouken@1913
   353
    if (_this->gl_config.accum_green_size) {
slouken@1913
   354
        *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
slouken@1913
   355
        *iAttr++ = _this->gl_config.accum_green_size;
slouken@1913
   356
    }
slouken@1913
   357
slouken@1913
   358
    if (_this->gl_config.accum_blue_size) {
slouken@1913
   359
        *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
slouken@1913
   360
        *iAttr++ = _this->gl_config.accum_blue_size;
slouken@1913
   361
    }
slouken@1913
   362
slouken@1913
   363
    if (_this->gl_config.accum_alpha_size) {
slouken@1913
   364
        *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
slouken@1913
   365
        *iAttr++ = _this->gl_config.accum_alpha_size;
slouken@1913
   366
    }
slouken@1913
   367
slouken@1913
   368
    if (_this->gl_config.stereo) {
slouken@1913
   369
        *iAttr++ = WGL_STEREO_ARB;
slouken@1913
   370
        *iAttr++ = GL_TRUE;
slouken@1913
   371
    }
slouken@1913
   372
slouken@1913
   373
    if (_this->gl_config.multisamplebuffers) {
slouken@1913
   374
        *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
slouken@1913
   375
        *iAttr++ = _this->gl_config.multisamplebuffers;
slouken@1913
   376
    }
slouken@1913
   377
slouken@1913
   378
    if (_this->gl_config.multisamplesamples) {
slouken@1913
   379
        *iAttr++ = WGL_SAMPLES_ARB;
slouken@1913
   380
        *iAttr++ = _this->gl_config.multisamplesamples;
slouken@1913
   381
    }
slouken@1913
   382
slouken@1913
   383
    if (_this->gl_config.accelerated >= 0) {
slouken@1913
   384
        *iAttr++ = WGL_ACCELERATION_ARB;
slouken@1913
   385
        *iAttr++ =
slouken@1913
   386
            (_this->gl_config.
slouken@1913
   387
             accelerated ? WGL_GENERIC_ACCELERATION_ARB :
slouken@1913
   388
             WGL_NO_ACCELERATION_ARB);
slouken@1913
   389
    }
slouken@1913
   390
slouken@1913
   391
    *iAttr = 0;
slouken@1913
   392
slouken@1913
   393
    /* Choose and set the closest available pixel format */
slouken@1913
   394
    if (!_this->gl_data->WGL_ARB_pixel_format
slouken@1913
   395
        || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
slouken@1913
   396
                                                    1, &pixel_format,
slouken@1913
   397
                                                    &matching) || !matching) {
slouken@1913
   398
        pixel_format = ChoosePixelFormat(hdc, &pfd);
slouken@1913
   399
    }
slouken@1913
   400
    if (!pixel_format) {
slouken@1913
   401
        SDL_SetError("No matching GL pixel format available");
slouken@1913
   402
        return -1;
slouken@1913
   403
    }
slouken@1913
   404
    if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
slouken@1913
   405
        WIN_SetError("SetPixelFormat()");
slouken@1913
   406
        return (-1);
slouken@1913
   407
    }
slouken@1913
   408
    return 0;
slouken@1913
   409
}
slouken@1913
   410
slouken@1913
   411
void
slouken@1913
   412
WIN_GL_CleanupWindow(_THIS, SDL_Window * window)
slouken@1913
   413
{
slouken@1913
   414
    WIN_GL_Shutdown(_this);
slouken@1913
   415
}
slouken@1913
   416
slouken@1913
   417
SDL_GLContext
slouken@1913
   418
WIN_GL_CreateContext(_THIS, SDL_Window * window)
slouken@1913
   419
{
slouken@1913
   420
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
slouken@1913
   421
slouken@1913
   422
    return _this->gl_data->wglCreateContext(hdc);
slouken@1913
   423
}
slouken@1913
   424
slouken@1913
   425
int
slouken@1913
   426
WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
slouken@1913
   427
{
slouken@1913
   428
    HDC hdc;
slouken@1913
   429
    int status;
slouken@1913
   430
slouken@1913
   431
    if (window) {
slouken@1913
   432
        hdc = ((SDL_WindowData *) window->driverdata)->hdc;
slouken@1913
   433
    } else {
slouken@1913
   434
        hdc = NULL;
slouken@1913
   435
    }
slouken@1913
   436
    if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
slouken@1913
   437
        WIN_SetError("wglMakeCurrent()");
slouken@1913
   438
        status = -1;
slouken@1913
   439
    } else {
slouken@1913
   440
        status = 0;
slouken@1913
   441
    }
slouken@1913
   442
    return status;
slouken@1913
   443
}
slouken@1913
   444
slouken@1913
   445
int
slouken@1913
   446
WIN_GL_SetSwapInterval(_THIS, int interval)
slouken@1913
   447
{
slouken@1913
   448
    if (_this->gl_data->wglSwapIntervalEXT) {
slouken@1913
   449
        _this->gl_data->wglSwapIntervalEXT(interval);
slouken@1913
   450
        return 0;
slouken@1913
   451
    } else {
slouken@1913
   452
        SDL_Unsupported();
slouken@1913
   453
        return -1;
slouken@1913
   454
    }
slouken@1913
   455
}
slouken@1913
   456
slouken@1913
   457
int
slouken@1913
   458
WIN_GL_GetSwapInterval(_THIS)
slouken@1913
   459
{
slouken@1913
   460
    if (_this->gl_data->wglGetSwapIntervalEXT) {
slouken@1913
   461
        return _this->gl_data->wglGetSwapIntervalEXT();
slouken@1913
   462
    } else {
slouken@1913
   463
        SDL_Unsupported();
slouken@1913
   464
        return -1;
slouken@1913
   465
    }
slouken@1913
   466
}
slouken@1913
   467
slouken@1913
   468
void
slouken@1913
   469
WIN_GL_SwapWindow(_THIS, SDL_Window * window)
slouken@1913
   470
{
slouken@1913
   471
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
slouken@1913
   472
slouken@1913
   473
    SwapBuffers(hdc);
slouken@1913
   474
}
slouken@1913
   475
slouken@1913
   476
void
slouken@1913
   477
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
slouken@1913
   478
{
slouken@1936
   479
    _this->gl_data->wglDeleteContext((HGLRC) context);
slouken@1913
   480
}
slouken@1913
   481
slouken@1913
   482
#endif /* SDL_VIDEO_OPENGL */
slouken@1913
   483
slouken@1913
   484
slouken@1913
   485
/* vi: set ts=4 sw=4 expandtab: */