src/video/win32/SDL_win32opengl.c
changeset 1913 83420da906a5
child 1926 307355678142
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/win32/SDL_win32opengl.c	Mon Jul 17 06:47:33 2006 +0000
     1.3 @@ -0,0 +1,643 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_win32video.h"
    1.28 +
    1.29 +/* WGL implementation of SDL OpenGL support */
    1.30 +
    1.31 +#if SDL_VIDEO_OPENGL
    1.32 +#include "SDL_opengl.h"
    1.33 +
    1.34 +#define DEFAULT_GL_DRIVER_PATH "OPENGL32.DLL"
    1.35 +
    1.36 +
    1.37 +int
    1.38 +WIN_GL_LoadLibrary(_THIS, const char *path)
    1.39 +{
    1.40 +    LPTSTR wpath;
    1.41 +    HANDLE handle;
    1.42 +
    1.43 +    if (_this->gl_config.driver_loaded) {
    1.44 +        if (path) {
    1.45 +            SDL_SetError("OpenGL library already loaded");
    1.46 +            return -1;
    1.47 +        } else {
    1.48 +            ++_this->gl_config.driver_loaded;
    1.49 +            return 0;
    1.50 +        }
    1.51 +    }
    1.52 +    if (path == NULL) {
    1.53 +        path = DEFAULT_GL_DRIVER_PATH;
    1.54 +    }
    1.55 +    wpath = WIN_UTF8ToString(path);
    1.56 +    handle = LoadLibrary(wpath);
    1.57 +    SDL_free(wpath);
    1.58 +    if (!handle) {
    1.59 +        char message[1024];
    1.60 +        SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
    1.61 +                     path);
    1.62 +        WIN_SetError(message);
    1.63 +        return -1;
    1.64 +    }
    1.65 +
    1.66 +    /* Load function pointers */
    1.67 +    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
    1.68 +        GetProcAddress(handle, "wglGetProcAddress");
    1.69 +    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
    1.70 +        GetProcAddress(handle, "wglCreateContext");
    1.71 +    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
    1.72 +        GetProcAddress(handle, "wglDeleteContext");
    1.73 +    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
    1.74 +        GetProcAddress(handle, "wglMakeCurrent");
    1.75 +    _this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
    1.76 +        GetProcAddress(handle, "wglSwapIntervalEXT");
    1.77 +    _this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
    1.78 +        GetProcAddress(handle, "wglGetSwapIntervalEXT");
    1.79 +
    1.80 +    if (!_this->gl_data->wglGetProcAddress ||
    1.81 +        !_this->gl_data->wglCreateContext ||
    1.82 +        !_this->gl_data->wglDeleteContext ||
    1.83 +        !_this->gl_data->wglMakeCurrent) {
    1.84 +        SDL_SetError("Could not retrieve OpenGL functions");
    1.85 +        FreeLibrary(handle);
    1.86 +        return -1;
    1.87 +    }
    1.88 +
    1.89 +    _this->gl_config.dll_handle = handle;
    1.90 +    SDL_strlcpy(_this->gl_config.driver_path, path,
    1.91 +                SDL_arraysize(_this->gl_config.driver_path));
    1.92 +    _this->gl_config.driver_loaded = 1;
    1.93 +    return 0;
    1.94 +}
    1.95 +
    1.96 +void *
    1.97 +WIN_GL_GetProcAddress(_THIS, const char *proc)
    1.98 +{
    1.99 +    void *func;
   1.100 +
   1.101 +    /* This is to pick up extensions */
   1.102 +    func = _this->gl_data->wglGetProcAddress(proc);
   1.103 +    if (!func) {
   1.104 +        /* This is probably a normal GL function */
   1.105 +        func = GetProcAddress(_this->gl_config.dll_handle, proc);
   1.106 +    }
   1.107 +    return func;
   1.108 +}
   1.109 +
   1.110 +static void
   1.111 +WIN_GL_UnloadLibrary(_THIS)
   1.112 +{
   1.113 +    if (_this->gl_config.driver_loaded > 0) {
   1.114 +        if (--_this->gl_config.driver_loaded > 0) {
   1.115 +            return;
   1.116 +        }
   1.117 +        FreeLibrary((HMODULE) _this->gl_config.dll_handle);
   1.118 +        _this->gl_config.dll_handle = NULL;
   1.119 +    }
   1.120 +}
   1.121 +
   1.122 +static void
   1.123 +WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
   1.124 +{
   1.125 +    SDL_zerop(pfd);
   1.126 +    pfd->nSize = sizeof(*pfd);
   1.127 +    pfd->nVersion = 1;
   1.128 +    pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
   1.129 +    if (_this->gl_config.double_buffer) {
   1.130 +        pfd->dwFlags |= PFD_DOUBLEBUFFER;
   1.131 +    }
   1.132 +    if (_this->gl_config.stereo) {
   1.133 +        pfd->dwFlags |= PFD_STEREO;
   1.134 +    }
   1.135 +    pfd->iLayerType = PFD_MAIN_PLANE;
   1.136 +    pfd->iPixelType = PFD_TYPE_RGBA;
   1.137 +    pfd->cRedBits = _this->gl_config.red_size;
   1.138 +    pfd->cGreenBits = _this->gl_config.green_size;
   1.139 +    pfd->cBlueBits = _this->gl_config.blue_size;
   1.140 +    pfd->cAlphaBits = _this->gl_config.alpha_size;
   1.141 +    if (_this->gl_config.buffer_size) {
   1.142 +        pfd->cColorBits =
   1.143 +            _this->gl_config.buffer_size - _this->gl_config.alpha_size;
   1.144 +    } else {
   1.145 +        pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
   1.146 +    }
   1.147 +    pfd->cAccumRedBits = _this->gl_config.accum_red_size;
   1.148 +    pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
   1.149 +    pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
   1.150 +    pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
   1.151 +    pfd->cAccumBits =
   1.152 +        (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
   1.153 +         pfd->cAccumAlphaBits);
   1.154 +    pfd->cDepthBits = _this->gl_config.depth_size;
   1.155 +    pfd->cStencilBits = _this->gl_config.stencil_size;
   1.156 +}
   1.157 +
   1.158 +static SDL_bool
   1.159 +HasExtension(const char *extension, const char *extensions)
   1.160 +{
   1.161 +    const char *start;
   1.162 +    const char *where, *terminator;
   1.163 +
   1.164 +    /* Extension names should not have spaces. */
   1.165 +    where = SDL_strchr(extension, ' ');
   1.166 +    if (where || *extension == '\0')
   1.167 +        return SDL_FALSE;
   1.168 +
   1.169 +    if (!extensions)
   1.170 +        return SDL_FALSE;
   1.171 +
   1.172 +    /* It takes a bit of care to be fool-proof about parsing the
   1.173 +     * OpenGL extensions string. Don't be fooled by sub-strings,
   1.174 +     * etc. */
   1.175 +
   1.176 +    start = extensions;
   1.177 +
   1.178 +    for (;;) {
   1.179 +        where = SDL_strstr(start, extension);
   1.180 +        if (!where)
   1.181 +            break;
   1.182 +
   1.183 +        terminator = where + SDL_strlen(extension);
   1.184 +        if (where == start || *(where - 1) == ' ')
   1.185 +            if (*terminator == ' ' || *terminator == '\0')
   1.186 +                return SDL_TRUE;
   1.187 +
   1.188 +        start = terminator;
   1.189 +    }
   1.190 +    return SDL_FALSE;
   1.191 +}
   1.192 +
   1.193 +static void
   1.194 +WIN_GL_InitExtensions(_THIS)
   1.195 +{
   1.196 +    HWND hwnd;
   1.197 +    HDC hdc;
   1.198 +    PIXELFORMATDESCRIPTOR pfd;
   1.199 +    int pixel_format;
   1.200 +    HGLRC hglrc;
   1.201 +    const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
   1.202 +    const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
   1.203 +    const char *extensions;
   1.204 +
   1.205 +    hwnd =
   1.206 +        CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
   1.207 +                     10, 10, NULL, NULL, SDL_Instance, NULL);
   1.208 +    WIN_PumpEvents(_this);
   1.209 +
   1.210 +    hdc = GetDC(hwnd);
   1.211 +
   1.212 +    WIN_GL_SetupPixelFormat(_this, &pfd);
   1.213 +    pixel_format = ChoosePixelFormat(hdc, &pfd);
   1.214 +    SetPixelFormat(hdc, pixel_format, &pfd);
   1.215 +
   1.216 +    hglrc = _this->gl_data->wglCreateContext(hdc);
   1.217 +    if (hglrc) {
   1.218 +        _this->gl_data->wglMakeCurrent(hdc, hglrc);
   1.219 +    }
   1.220 +
   1.221 +    wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
   1.222 +        _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
   1.223 +    if (wglGetExtensionsStringARB) {
   1.224 +        extensions = wglGetExtensionsStringARB(hdc);
   1.225 +    } else {
   1.226 +        extensions = NULL;
   1.227 +    }
   1.228 +
   1.229 +    /* Check for WGL_ARB_pixel_format */
   1.230 +    _this->gl_data->WGL_ARB_pixel_format = 0;
   1.231 +    if (HasExtension("WGL_ARB_pixel_format", extensions)) {
   1.232 +        _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
   1.233 +                                                   (HDC, const int *,
   1.234 +                                                    const FLOAT *, UINT,
   1.235 +                                                    int *, UINT *))
   1.236 +            WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
   1.237 +        _this->gl_data->wglGetPixelFormatAttribivARB =
   1.238 +            (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
   1.239 +            WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
   1.240 +
   1.241 +        if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
   1.242 +            (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
   1.243 +            _this->gl_data->WGL_ARB_pixel_format = 1;
   1.244 +        }
   1.245 +    }
   1.246 +
   1.247 +    glGetStringFunc = WIN_GL_GetProcAddress(_this, "glGetString");
   1.248 +    if (glGetStringFunc) {
   1.249 +        extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
   1.250 +    } else {
   1.251 +        /* Uh oh, something is seriously wrong here... */
   1.252 +        extensions = NULL;
   1.253 +    }
   1.254 +
   1.255 +    /* Check for WGL_EXT_swap_control */
   1.256 +    if (HasExtension("WGL_EXT_swap_control", extensions)) {
   1.257 +        _this->gl_data->wglSwapIntervalEXT =
   1.258 +            WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
   1.259 +        _this->gl_data->wglGetSwapIntervalEXT =
   1.260 +            WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
   1.261 +    }
   1.262 +
   1.263 +    if (hglrc) {
   1.264 +        _this->gl_data->wglMakeCurrent(NULL, NULL);
   1.265 +        _this->gl_data->wglDeleteContext(hglrc);
   1.266 +    }
   1.267 +    ReleaseDC(hwnd, hdc);
   1.268 +    DestroyWindow(hwnd);
   1.269 +    WIN_PumpEvents(_this);
   1.270 +}
   1.271 +
   1.272 +static void
   1.273 +WIN_GL_Shutdown(_THIS)
   1.274 +{
   1.275 +    if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
   1.276 +        return;
   1.277 +    }
   1.278 +
   1.279 +    WIN_GL_UnloadLibrary(_this);
   1.280 +
   1.281 +    SDL_free(_this->gl_data);
   1.282 +    _this->gl_data = NULL;
   1.283 +}
   1.284 +
   1.285 +static int
   1.286 +WIN_GL_Initialize(_THIS)
   1.287 +{
   1.288 +    if (_this->gl_data) {
   1.289 +        ++_this->gl_data->initialized;
   1.290 +        return 0;
   1.291 +    }
   1.292 +
   1.293 +    _this->gl_data =
   1.294 +        (struct SDL_GLDriverData *) SDL_calloc(1,
   1.295 +                                               sizeof(struct
   1.296 +                                                      SDL_GLDriverData));
   1.297 +    if (!_this->gl_data) {
   1.298 +        SDL_OutOfMemory();
   1.299 +        return -1;
   1.300 +    }
   1.301 +    _this->gl_data->initialized = 1;
   1.302 +
   1.303 +    if (WIN_GL_LoadLibrary(_this, NULL) < 0) {
   1.304 +        return -1;
   1.305 +    }
   1.306 +
   1.307 +    /* Initialize extensions */
   1.308 +    WIN_GL_InitExtensions(_this);
   1.309 +
   1.310 +    return 0;
   1.311 +}
   1.312 +
   1.313 +int
   1.314 +WIN_GL_SetupWindow(_THIS, SDL_Window * window)
   1.315 +{
   1.316 +    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   1.317 +    PIXELFORMATDESCRIPTOR pfd;
   1.318 +    int pixel_format;
   1.319 +    unsigned int matching;
   1.320 +    int iAttribs[64];
   1.321 +    int *iAttr;
   1.322 +    float fAttribs[1] = { 0 };
   1.323 +
   1.324 +    if (WIN_GL_Initialize(_this) < 0) {
   1.325 +        return -1;
   1.326 +    }
   1.327 +
   1.328 +    WIN_GL_SetupPixelFormat(_this, &pfd);
   1.329 +
   1.330 +    /* setup WGL_ARB_pixel_format attribs */
   1.331 +    iAttr = &iAttribs[0];
   1.332 +
   1.333 +    *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
   1.334 +    *iAttr++ = GL_TRUE;
   1.335 +    *iAttr++ = WGL_ACCELERATION_ARB;
   1.336 +    *iAttr++ = WGL_FULL_ACCELERATION_ARB;
   1.337 +    *iAttr++ = WGL_RED_BITS_ARB;
   1.338 +    *iAttr++ = _this->gl_config.red_size;
   1.339 +    *iAttr++ = WGL_GREEN_BITS_ARB;
   1.340 +    *iAttr++ = _this->gl_config.green_size;
   1.341 +    *iAttr++ = WGL_BLUE_BITS_ARB;
   1.342 +    *iAttr++ = _this->gl_config.blue_size;
   1.343 +
   1.344 +    if (_this->gl_config.alpha_size) {
   1.345 +        *iAttr++ = WGL_ALPHA_BITS_ARB;
   1.346 +        *iAttr++ = _this->gl_config.alpha_size;
   1.347 +    }
   1.348 +
   1.349 +    *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
   1.350 +    *iAttr++ = _this->gl_config.double_buffer;
   1.351 +
   1.352 +    *iAttr++ = WGL_DEPTH_BITS_ARB;
   1.353 +    *iAttr++ = _this->gl_config.depth_size;
   1.354 +
   1.355 +    if (_this->gl_config.stencil_size) {
   1.356 +        *iAttr++ = WGL_STENCIL_BITS_ARB;
   1.357 +        *iAttr++ = _this->gl_config.stencil_size;
   1.358 +    }
   1.359 +
   1.360 +    if (_this->gl_config.accum_red_size) {
   1.361 +        *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
   1.362 +        *iAttr++ = _this->gl_config.accum_red_size;
   1.363 +    }
   1.364 +
   1.365 +    if (_this->gl_config.accum_green_size) {
   1.366 +        *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
   1.367 +        *iAttr++ = _this->gl_config.accum_green_size;
   1.368 +    }
   1.369 +
   1.370 +    if (_this->gl_config.accum_blue_size) {
   1.371 +        *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
   1.372 +        *iAttr++ = _this->gl_config.accum_blue_size;
   1.373 +    }
   1.374 +
   1.375 +    if (_this->gl_config.accum_alpha_size) {
   1.376 +        *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
   1.377 +        *iAttr++ = _this->gl_config.accum_alpha_size;
   1.378 +    }
   1.379 +
   1.380 +    if (_this->gl_config.stereo) {
   1.381 +        *iAttr++ = WGL_STEREO_ARB;
   1.382 +        *iAttr++ = GL_TRUE;
   1.383 +    }
   1.384 +
   1.385 +    if (_this->gl_config.multisamplebuffers) {
   1.386 +        *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
   1.387 +        *iAttr++ = _this->gl_config.multisamplebuffers;
   1.388 +    }
   1.389 +
   1.390 +    if (_this->gl_config.multisamplesamples) {
   1.391 +        *iAttr++ = WGL_SAMPLES_ARB;
   1.392 +        *iAttr++ = _this->gl_config.multisamplesamples;
   1.393 +    }
   1.394 +
   1.395 +    if (_this->gl_config.accelerated >= 0) {
   1.396 +        *iAttr++ = WGL_ACCELERATION_ARB;
   1.397 +        *iAttr++ =
   1.398 +            (_this->gl_config.
   1.399 +             accelerated ? WGL_GENERIC_ACCELERATION_ARB :
   1.400 +             WGL_NO_ACCELERATION_ARB);
   1.401 +    }
   1.402 +
   1.403 +    *iAttr = 0;
   1.404 +
   1.405 +    /* Choose and set the closest available pixel format */
   1.406 +    if (!_this->gl_data->WGL_ARB_pixel_format
   1.407 +        || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
   1.408 +                                                    1, &pixel_format,
   1.409 +                                                    &matching) || !matching) {
   1.410 +        pixel_format = ChoosePixelFormat(hdc, &pfd);
   1.411 +    }
   1.412 +    if (!pixel_format) {
   1.413 +        SDL_SetError("No matching GL pixel format available");
   1.414 +        return -1;
   1.415 +    }
   1.416 +    if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
   1.417 +        WIN_SetError("SetPixelFormat()");
   1.418 +        return (-1);
   1.419 +    }
   1.420 +    return 0;
   1.421 +}
   1.422 +
   1.423 +void
   1.424 +WIN_GL_CleanupWindow(_THIS, SDL_Window * window)
   1.425 +{
   1.426 +    WIN_GL_Shutdown(_this);
   1.427 +}
   1.428 +
   1.429 +int
   1.430 +WIN_GL_GetWindowAttribute(_THIS, SDL_Window * window, SDL_GLattr attrib,
   1.431 +                          int *value)
   1.432 +{
   1.433 +    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   1.434 +    int pixel_format;
   1.435 +
   1.436 +    pixel_format = GetPixelFormat(hdc);
   1.437 +
   1.438 +    if (_this->gl_data->WGL_ARB_pixel_format) {
   1.439 +        int wgl_attrib;
   1.440 +
   1.441 +        switch (attrib) {
   1.442 +        case SDL_GL_RED_SIZE:
   1.443 +            wgl_attrib = WGL_RED_BITS_ARB;
   1.444 +            break;
   1.445 +        case SDL_GL_GREEN_SIZE:
   1.446 +            wgl_attrib = WGL_GREEN_BITS_ARB;
   1.447 +            break;
   1.448 +        case SDL_GL_BLUE_SIZE:
   1.449 +            wgl_attrib = WGL_BLUE_BITS_ARB;
   1.450 +            break;
   1.451 +        case SDL_GL_ALPHA_SIZE:
   1.452 +            wgl_attrib = WGL_ALPHA_BITS_ARB;
   1.453 +            break;
   1.454 +        case SDL_GL_DOUBLEBUFFER:
   1.455 +            wgl_attrib = WGL_DOUBLE_BUFFER_ARB;
   1.456 +            break;
   1.457 +        case SDL_GL_BUFFER_SIZE:
   1.458 +            wgl_attrib = WGL_COLOR_BITS_ARB;
   1.459 +            break;
   1.460 +        case SDL_GL_DEPTH_SIZE:
   1.461 +            wgl_attrib = WGL_DEPTH_BITS_ARB;
   1.462 +            break;
   1.463 +        case SDL_GL_STENCIL_SIZE:
   1.464 +            wgl_attrib = WGL_STENCIL_BITS_ARB;
   1.465 +            break;
   1.466 +        case SDL_GL_ACCUM_RED_SIZE:
   1.467 +            wgl_attrib = WGL_ACCUM_RED_BITS_ARB;
   1.468 +            break;
   1.469 +        case SDL_GL_ACCUM_GREEN_SIZE:
   1.470 +            wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB;
   1.471 +            break;
   1.472 +        case SDL_GL_ACCUM_BLUE_SIZE:
   1.473 +            wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB;
   1.474 +            break;
   1.475 +        case SDL_GL_ACCUM_ALPHA_SIZE:
   1.476 +            wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB;
   1.477 +            break;
   1.478 +        case SDL_GL_STEREO:
   1.479 +            wgl_attrib = WGL_STEREO_ARB;
   1.480 +            break;
   1.481 +        case SDL_GL_MULTISAMPLEBUFFERS:
   1.482 +            wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
   1.483 +            break;
   1.484 +        case SDL_GL_MULTISAMPLESAMPLES:
   1.485 +            wgl_attrib = WGL_SAMPLES_ARB;
   1.486 +            break;
   1.487 +        case SDL_GL_ACCELERATED_VISUAL:
   1.488 +            wgl_attrib = WGL_ACCELERATION_ARB;
   1.489 +            _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0,
   1.490 +                                                         1, &wgl_attrib,
   1.491 +                                                         value);
   1.492 +            if (*value == WGL_NO_ACCELERATION_ARB) {
   1.493 +                *value = SDL_FALSE;
   1.494 +            } else {
   1.495 +                *value = SDL_TRUE;
   1.496 +            }
   1.497 +            return 0;
   1.498 +            break;
   1.499 +        default:
   1.500 +            return (-1);
   1.501 +        }
   1.502 +        _this->gl_data->wglGetPixelFormatAttribivARB(hdc, pixel_format, 0, 1,
   1.503 +                                                     &wgl_attrib, value);
   1.504 +        return 0;
   1.505 +    } else {
   1.506 +        PIXELFORMATDESCRIPTOR pfd;
   1.507 +        int retval;
   1.508 +
   1.509 +        if (!DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd)) {
   1.510 +            WIN_SetError("DescribePixelFormat()");
   1.511 +            return -1;
   1.512 +        }
   1.513 +        retval = 0;
   1.514 +        switch (attrib) {
   1.515 +        case SDL_GL_RED_SIZE:
   1.516 +            *value = pfd.cRedBits;
   1.517 +            break;
   1.518 +        case SDL_GL_GREEN_SIZE:
   1.519 +            *value = pfd.cGreenBits;
   1.520 +            break;
   1.521 +        case SDL_GL_BLUE_SIZE:
   1.522 +            *value = pfd.cBlueBits;
   1.523 +            break;
   1.524 +        case SDL_GL_ALPHA_SIZE:
   1.525 +            *value = pfd.cAlphaBits;
   1.526 +            break;
   1.527 +        case SDL_GL_DOUBLEBUFFER:
   1.528 +            if (pfd.dwFlags & PFD_DOUBLEBUFFER) {
   1.529 +                *value = 1;
   1.530 +            } else {
   1.531 +                *value = 0;
   1.532 +            }
   1.533 +            break;
   1.534 +        case SDL_GL_BUFFER_SIZE:
   1.535 +            *value = pfd.cColorBits;
   1.536 +            break;
   1.537 +        case SDL_GL_DEPTH_SIZE:
   1.538 +            *value = pfd.cDepthBits;
   1.539 +            break;
   1.540 +        case SDL_GL_STENCIL_SIZE:
   1.541 +            *value = pfd.cStencilBits;
   1.542 +            break;
   1.543 +        case SDL_GL_ACCUM_RED_SIZE:
   1.544 +            *value = pfd.cAccumRedBits;
   1.545 +            break;
   1.546 +        case SDL_GL_ACCUM_GREEN_SIZE:
   1.547 +            *value = pfd.cAccumGreenBits;
   1.548 +            break;
   1.549 +        case SDL_GL_ACCUM_BLUE_SIZE:
   1.550 +            *value = pfd.cAccumBlueBits;
   1.551 +            break;
   1.552 +        case SDL_GL_ACCUM_ALPHA_SIZE:
   1.553 +            *value = pfd.cAccumAlphaBits;
   1.554 +            break;
   1.555 +        case SDL_GL_STEREO:
   1.556 +            if (pfd.dwFlags & PFD_STEREO) {
   1.557 +                *value = 1;
   1.558 +            } else {
   1.559 +                *value = 0;
   1.560 +            }
   1.561 +            break;
   1.562 +        case SDL_GL_MULTISAMPLEBUFFERS:
   1.563 +            *value = 0;
   1.564 +            break;
   1.565 +        case SDL_GL_MULTISAMPLESAMPLES:
   1.566 +            *value = 1;
   1.567 +            break;
   1.568 +        default:
   1.569 +            retval = -1;
   1.570 +            break;
   1.571 +        }
   1.572 +        return retval;
   1.573 +    }
   1.574 +}
   1.575 +
   1.576 +SDL_GLContext
   1.577 +WIN_GL_CreateContext(_THIS, SDL_Window * window)
   1.578 +{
   1.579 +    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   1.580 +
   1.581 +    return _this->gl_data->wglCreateContext(hdc);
   1.582 +}
   1.583 +
   1.584 +int
   1.585 +WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   1.586 +{
   1.587 +    HDC hdc;
   1.588 +    int status;
   1.589 +
   1.590 +    if (window) {
   1.591 +        hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   1.592 +    } else {
   1.593 +        hdc = NULL;
   1.594 +    }
   1.595 +    if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
   1.596 +        WIN_SetError("wglMakeCurrent()");
   1.597 +        status = -1;
   1.598 +    } else {
   1.599 +        status = 0;
   1.600 +    }
   1.601 +    return status;
   1.602 +}
   1.603 +
   1.604 +int
   1.605 +WIN_GL_SetSwapInterval(_THIS, int interval)
   1.606 +{
   1.607 +    if (_this->gl_data->wglSwapIntervalEXT) {
   1.608 +        _this->gl_data->wglSwapIntervalEXT(interval);
   1.609 +        return 0;
   1.610 +    } else {
   1.611 +        SDL_Unsupported();
   1.612 +        return -1;
   1.613 +    }
   1.614 +}
   1.615 +
   1.616 +int
   1.617 +WIN_GL_GetSwapInterval(_THIS)
   1.618 +{
   1.619 +    if (_this->gl_data->wglGetSwapIntervalEXT) {
   1.620 +        return _this->gl_data->wglGetSwapIntervalEXT();
   1.621 +    } else {
   1.622 +        SDL_Unsupported();
   1.623 +        return -1;
   1.624 +    }
   1.625 +}
   1.626 +
   1.627 +void
   1.628 +WIN_GL_SwapWindow(_THIS, SDL_Window * window)
   1.629 +{
   1.630 +    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   1.631 +
   1.632 +    SwapBuffers(hdc);
   1.633 +}
   1.634 +
   1.635 +void
   1.636 +WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
   1.637 +{
   1.638 +    if (context) {
   1.639 +        _this->gl_data->wglDeleteContext((HGLRC) context);
   1.640 +    }
   1.641 +}
   1.642 +
   1.643 +#endif /* SDL_VIDEO_OPENGL */
   1.644 +
   1.645 +
   1.646 +/* vi: set ts=4 sw=4 expandtab: */