src/video/windows/SDL_windowsopengl.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 21 Aug 2011 12:24:27 -0400
changeset 5624 84d302e859d1
parent 5535 96594ac5fd1a
child 5644 f74f1a736dd9
permissions -rw-r--r--
Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch. Fixes Bugzilla #1254. Thanks to Thilo Schulz for the patch!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     2
  Simple DirectMedia Layer
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     7
  arising from the use of this software.
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    11
  freely, subject to the following restrictions:
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5446
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    23
#include "SDL_windowsvideo.h"
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* WGL implementation of SDL OpenGL support */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    27
#if SDL_VIDEO_OPENGL_WGL
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "SDL_opengl.h"
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    30
#define DEFAULT_OPENGL "OPENGL32.DLL"
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    32
#ifndef WGL_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    33
#define WGL_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    34
#define WGL_CONTEXT_MAJOR_VERSION_ARB   0x2091
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    35
#define WGL_CONTEXT_MINOR_VERSION_ARB   0x2092
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    36
#define WGL_CONTEXT_LAYER_PLANE_ARB     0x2093
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    37
#define WGL_CONTEXT_FLAGS_ARB           0x2093
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    38
#define WGL_CONTEXT_DEBUG_BIT_ARB       0x0001
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    39
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB  0x0002
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    40
#endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    41
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    42
typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    43
                                                            HGLRC
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    44
                                                            hShareContext,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    45
                                                            const int
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    46
                                                            *attribList);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
WIN_GL_LoadLibrary(_THIS, const char *path)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    LPTSTR wpath;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    HANDLE handle;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    if (path == NULL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    55
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    56
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    57
    if (path == NULL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    58
        path = DEFAULT_OPENGL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    wpath = WIN_UTF8ToString(path);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    61
    _this->gl_config.dll_handle = LoadLibrary(wpath);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    SDL_free(wpath);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    63
    if (!_this->gl_config.dll_handle) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
        char message[1024];
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
        SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
                     path);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        WIN_SetError(message);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
    }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    70
    SDL_strlcpy(_this->gl_config.driver_path, path,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    71
                SDL_arraysize(_this->gl_config.driver_path));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    72
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    73
    /* Allocate OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    74
    _this->gl_data =
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    75
        (struct SDL_GLDriverData *) SDL_calloc(1,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    76
                                               sizeof(struct
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    77
                                                      SDL_GLDriverData));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    78
    if (!_this->gl_data) {
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    79
        SDL_OutOfMemory();
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    80
        return -1;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    81
    }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    /* Load function pointers */
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    84
    handle = _this->gl_config.dll_handle;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
        GetProcAddress(handle, "wglGetProcAddress");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
        GetProcAddress(handle, "wglCreateContext");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
        GetProcAddress(handle, "wglDeleteContext");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
        GetProcAddress(handle, "wglMakeCurrent");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    _this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
        GetProcAddress(handle, "wglSwapIntervalEXT");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    _this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
        GetProcAddress(handle, "wglGetSwapIntervalEXT");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    if (!_this->gl_data->wglGetProcAddress ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
        !_this->gl_data->wglCreateContext ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
        !_this->gl_data->wglDeleteContext ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
        !_this->gl_data->wglMakeCurrent) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
        SDL_SetError("Could not retrieve OpenGL functions");
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   103
        SDL_UnloadObject(handle);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
        return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    return 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
void *
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
WIN_GL_GetProcAddress(_THIS, const char *proc)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    void *func;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    /* This is to pick up extensions */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    func = _this->gl_data->wglGetProcAddress(proc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    if (!func) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
        /* This is probably a normal GL function */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
        func = GetProcAddress(_this->gl_config.dll_handle, proc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    return func;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   124
void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
WIN_GL_UnloadLibrary(_THIS)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
{
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   127
    FreeLibrary((HMODULE) _this->gl_config.dll_handle);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   128
    _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   129
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   130
    /* Free OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   131
    SDL_free(_this->gl_data);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   132
    _this->gl_data = NULL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
static void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    SDL_zerop(pfd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    pfd->nSize = sizeof(*pfd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    pfd->nVersion = 1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    if (_this->gl_config.double_buffer) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
        pfd->dwFlags |= PFD_DOUBLEBUFFER;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    if (_this->gl_config.stereo) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
        pfd->dwFlags |= PFD_STEREO;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
    pfd->iLayerType = PFD_MAIN_PLANE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
    pfd->iPixelType = PFD_TYPE_RGBA;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    pfd->cRedBits = _this->gl_config.red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    pfd->cGreenBits = _this->gl_config.green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    pfd->cBlueBits = _this->gl_config.blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
    pfd->cAlphaBits = _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
    if (_this->gl_config.buffer_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        pfd->cColorBits =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
            _this->gl_config.buffer_size - _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
        pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
    pfd->cAccumRedBits = _this->gl_config.accum_red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
    pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
    pfd->cAccumBits =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
        (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
         pfd->cAccumAlphaBits);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    pfd->cDepthBits = _this->gl_config.depth_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    pfd->cStencilBits = _this->gl_config.stencil_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
2150
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   171
/* Choose the closest pixel format that meets or exceeds the target.
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   172
   FIXME: Should we weight any particular attribute over any other?
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   173
*/
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   174
static int
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   175
WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   176
{
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   177
    PIXELFORMATDESCRIPTOR pfd;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   178
    int count, index, best = 0;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   179
    unsigned int dist, best_dist = ~0U;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   180
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   181
    count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   182
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   183
    for (index = 1; index <= count; index++) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   184
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   185
        if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   186
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   187
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   188
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   189
        if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   190
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   191
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   192
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   193
        if (pfd.iLayerType != target->iLayerType) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   194
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   195
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   196
        if (pfd.iPixelType != target->iPixelType) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   197
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   198
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   199
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   200
        dist = 0;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   201
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   202
        if (pfd.cColorBits < target->cColorBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   203
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   204
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   205
            dist += (pfd.cColorBits - target->cColorBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   206
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   207
        if (pfd.cRedBits < target->cRedBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   208
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   209
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   210
            dist += (pfd.cRedBits - target->cRedBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   211
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   212
        if (pfd.cGreenBits < target->cGreenBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   213
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   214
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   215
            dist += (pfd.cGreenBits - target->cGreenBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   216
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   217
        if (pfd.cBlueBits < target->cBlueBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   218
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   219
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   220
            dist += (pfd.cBlueBits - target->cBlueBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   221
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   222
        if (pfd.cAlphaBits < target->cAlphaBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   223
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   224
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   225
            dist += (pfd.cAlphaBits - target->cAlphaBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   226
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   227
        if (pfd.cAccumBits < target->cAccumBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   228
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   229
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   230
            dist += (pfd.cAccumBits - target->cAccumBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   231
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   232
        if (pfd.cAccumRedBits < target->cAccumRedBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   233
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   234
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   235
            dist += (pfd.cAccumRedBits - target->cAccumRedBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   236
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   237
        if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   238
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   239
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   240
            dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   241
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   242
        if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   243
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   244
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   245
            dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   246
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   247
        if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   248
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   249
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   250
            dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   251
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   252
        if (pfd.cDepthBits < target->cDepthBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   253
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   254
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   255
            dist += (pfd.cDepthBits - target->cDepthBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   256
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   257
        if (pfd.cStencilBits < target->cStencilBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   258
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   259
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   260
            dist += (pfd.cStencilBits - target->cStencilBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   261
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   262
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   263
        if (dist < best_dist) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   264
            best = index;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   265
            best_dist = dist;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   266
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   267
    }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   268
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   269
    return best;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   270
}
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   271
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
static SDL_bool
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
HasExtension(const char *extension, const char *extensions)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
    const char *start;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
    const char *where, *terminator;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
    /* Extension names should not have spaces. */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
    where = SDL_strchr(extension, ' ');
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
    if (where || *extension == '\0')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
        return SDL_FALSE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
    if (!extensions)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
        return SDL_FALSE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    /* It takes a bit of care to be fool-proof about parsing the
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
     * OpenGL extensions string. Don't be fooled by sub-strings,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
     * etc. */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
    start = extensions;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
    for (;;) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
        where = SDL_strstr(start, extension);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
        if (!where)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
            break;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
        terminator = where + SDL_strlen(extension);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
        if (where == start || *(where - 1) == ' ')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
            if (*terminator == ' ' || *terminator == '\0')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
                return SDL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
        start = terminator;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
    return SDL_FALSE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
static void
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   308
WIN_GL_InitExtensions(_THIS, HDC hdc)
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
    const char *extensions;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
        _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
    if (wglGetExtensionsStringARB) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
        extensions = wglGetExtensionsStringARB(hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
        extensions = NULL;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
    /* Check for WGL_ARB_pixel_format */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
    _this->gl_data->WGL_ARB_pixel_format = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    if (HasExtension("WGL_ARB_pixel_format", extensions)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
        _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
                                                   (HDC, const int *,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
                                                    const FLOAT *, UINT,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
                                                    int *, UINT *))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
            WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
        _this->gl_data->wglGetPixelFormatAttribivARB =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
            (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
            WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
        if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
            (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
            _this->gl_data->WGL_ARB_pixel_format = 1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
        }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    /* Check for WGL_EXT_swap_control */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    if (HasExtension("WGL_EXT_swap_control", extensions)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
        _this->gl_data->wglSwapIntervalEXT =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
            WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
        _this->gl_data->wglGetSwapIntervalEXT =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
            WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   345
    } else {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   346
        _this->gl_data->wglSwapIntervalEXT = NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   347
        _this->gl_data->wglGetSwapIntervalEXT = NULL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   349
}
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   350
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   351
static int
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   352
WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   353
{
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   354
    HWND hwnd;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   355
    HDC hdc;
2180
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   356
    PIXELFORMATDESCRIPTOR pfd;
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   357
    HGLRC hglrc;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   358
    int pixel_format = 0;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   359
    unsigned int matching;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   361
    hwnd =
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   362
        CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   363
                     10, 10, NULL, NULL, SDL_Instance, NULL);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   364
    WIN_PumpEvents(_this);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   365
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   366
    hdc = GetDC(hwnd);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   367
2180
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   368
    WIN_GL_SetupPixelFormat(_this, &pfd);
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   369
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   370
    SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   371
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   372
    hglrc = _this->gl_data->wglCreateContext(hdc);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
    if (hglrc) {
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   374
        _this->gl_data->wglMakeCurrent(hdc, hglrc);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   375
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   376
        WIN_GL_InitExtensions(_this, hdc);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   377
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   378
        if (_this->gl_data->WGL_ARB_pixel_format) {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   379
            _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   380
                                                    1, &pixel_format,
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   381
                                                    &matching);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   382
        }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   383
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
        _this->gl_data->wglMakeCurrent(NULL, NULL);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
        _this->gl_data->wglDeleteContext(hglrc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
    ReleaseDC(hwnd, hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
    DestroyWindow(hwnd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
    WIN_PumpEvents(_this);
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   390
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   391
    return pixel_format;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
WIN_GL_SetupWindow(_THIS, SDL_Window * window)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
    PIXELFORMATDESCRIPTOR pfd;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    int pixel_format;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
    int iAttribs[64];
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    int *iAttr;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
    float fAttribs[1] = { 0 };
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    WIN_GL_SetupPixelFormat(_this, &pfd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   406
    /* setup WGL_ARB_pixel_format attribs */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
    iAttr = &iAttribs[0];
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
    *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
    *iAttr++ = GL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    *iAttr++ = WGL_RED_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   412
    *iAttr++ = _this->gl_config.red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   413
    *iAttr++ = WGL_GREEN_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   414
    *iAttr++ = _this->gl_config.green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    *iAttr++ = WGL_BLUE_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    *iAttr++ = _this->gl_config.blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   417
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   418
    if (_this->gl_config.alpha_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   419
        *iAttr++ = WGL_ALPHA_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
        *iAttr++ = _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   422
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
    *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    *iAttr++ = _this->gl_config.double_buffer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
    *iAttr++ = WGL_DEPTH_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    *iAttr++ = _this->gl_config.depth_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
    if (_this->gl_config.stencil_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
        *iAttr++ = WGL_STENCIL_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   431
        *iAttr++ = _this->gl_config.stencil_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   433
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   434
    if (_this->gl_config.accum_red_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   435
        *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
        *iAttr++ = _this->gl_config.accum_red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   437
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   438
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   439
    if (_this->gl_config.accum_green_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   440
        *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   441
        *iAttr++ = _this->gl_config.accum_green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   442
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   443
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   444
    if (_this->gl_config.accum_blue_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   445
        *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   446
        *iAttr++ = _this->gl_config.accum_blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   447
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   448
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
    if (_this->gl_config.accum_alpha_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   450
        *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   451
        *iAttr++ = _this->gl_config.accum_alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   452
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   453
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   454
    if (_this->gl_config.stereo) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   455
        *iAttr++ = WGL_STEREO_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   456
        *iAttr++ = GL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   457
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   458
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
    if (_this->gl_config.multisamplebuffers) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
        *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
        *iAttr++ = _this->gl_config.multisamplebuffers;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   464
    if (_this->gl_config.multisamplesamples) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   465
        *iAttr++ = WGL_SAMPLES_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
        *iAttr++ = _this->gl_config.multisamplesamples;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   468
5624
84d302e859d1 Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   469
    if ( this->gl_config.accelerated >= 0 ) {
84d302e859d1 Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   470
        *iAttr++ = WGL_ACCELERATION_ARB;
84d302e859d1 Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   471
        *iAttr++ = (_this->gl_config.accelerated ? WGL_FULL_ACCELERATION_ARB :
84d302e859d1 Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   472
                                                   WGL_NO_ACCELERATION_ARB);
84d302e859d1 Fix SDL_GL_ACCELERATED_VISUAL on Windows in the 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   473
    }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   474
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
    *iAttr = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   477
    /* Choose and set the closest available pixel format */
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   478
    pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   479
    if (!pixel_format) {
2150
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   480
        pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   481
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   482
    if (!pixel_format) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
        SDL_SetError("No matching GL pixel format available");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
        return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
    if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
        WIN_SetError("SetPixelFormat()");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
        return (-1);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
    return 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
SDL_GLContext
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
WIN_GL_CreateContext(_THIS, SDL_Window * window)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   497
    HGLRC context;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   499
    if (_this->gl_config.major_version < 3) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   500
        context = _this->gl_data->wglCreateContext(hdc);
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   501
    } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   502
        PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   503
        HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   504
        if (!temp_context) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   505
            SDL_SetError("Could not create GL context");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   506
            return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   507
        }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   508
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   509
        /* Make the context current */
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   510
        if (WIN_GL_MakeCurrent(_this, window, temp_context) < 0) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   511
            WIN_GL_DeleteContext(_this, temp_context);
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   512
            return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   513
        }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   514
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   515
        wglCreateContextAttribsARB =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   516
            (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   517
            wglGetProcAddress("wglCreateContextAttribsARB");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   518
        if (!wglCreateContextAttribsARB) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   519
            SDL_SetError("GL 3.x is not supported");
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   520
            context = temp_context;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   521
        } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   522
            int attribs[] = {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   523
                WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   524
                WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   525
                0
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   526
            };
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   527
            /* Create the GL 3.x context */
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   528
            context = wglCreateContextAttribsARB(hdc, 0, attribs);
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   529
            /* Delete the GL 2.x context */
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   530
            _this->gl_data->wglDeleteContext(temp_context);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   531
        }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   532
    }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   533
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   534
    if (!context) {
3565
f43c8f688f77 Fixed bug #906
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   535
        WIN_SetError("Could not create GL context");
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   536
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   537
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   538
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   539
    if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   540
        WIN_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   541
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   542
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   543
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   544
    WIN_GL_InitExtensions(_this, hdc);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   545
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   546
    return context;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   547
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   548
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   549
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   550
WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   551
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   552
    HDC hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   553
    int status;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   554
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
    if (window) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
        hdc = ((SDL_WindowData *) window->driverdata)->hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   557
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   558
        hdc = NULL;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   559
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   560
    if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
        WIN_SetError("wglMakeCurrent()");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
        status = -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
        status = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   565
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   566
    return status;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   567
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   568
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   569
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   570
WIN_GL_SetSwapInterval(_THIS, int interval)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   571
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   572
    if (_this->gl_data->wglSwapIntervalEXT) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   573
        _this->gl_data->wglSwapIntervalEXT(interval);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   574
        return 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
        SDL_Unsupported();
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   577
        return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   578
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   579
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   580
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
WIN_GL_GetSwapInterval(_THIS)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   583
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   584
    if (_this->gl_data->wglGetSwapIntervalEXT) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   585
        return _this->gl_data->wglGetSwapIntervalEXT();
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   586
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   587
        SDL_Unsupported();
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   588
        return -1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   589
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   590
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   591
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   592
void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   593
WIN_GL_SwapWindow(_THIS, SDL_Window * window)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   594
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   595
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
    SwapBuffers(hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   598
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   599
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   600
void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   601
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   602
{
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
   603
    _this->gl_data->wglDeleteContext((HGLRC) context);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   604
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   605
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   606
#endif /* SDL_VIDEO_OPENGL_WGL */
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   607
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   608
/* vi: set ts=4 sw=4 expandtab: */