src/video/windows/SDL_windowsopengl.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 20 Mar 2015 12:23:53 -0400
changeset 9413 eb50f63a5777
parent 8735 2134fc16252b
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Windows: support for OpenGL extension WGL_ARB_context_flush_control.
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
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8144
diff changeset
     3
  Copyright (C) 1997-2014 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
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 8080
diff changeset
    21
#include "../../SDL_internal.h"
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5644
diff changeset
    23
#if SDL_VIDEO_DRIVER_WINDOWS
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5644
diff changeset
    24
7553
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
    25
#include "SDL_assert.h"
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
    26
#include "SDL_loadso.h"
5062
e8916fe9cfc8 Fixed bug #925
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
    27
#include "SDL_windowsvideo.h"
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
    28
#include "SDL_windowsopengles.h"
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
/* WGL implementation of SDL OpenGL support */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    32
#if SDL_VIDEO_OPENGL_WGL
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_opengl.h"
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    35
#define DEFAULT_OPENGL "OPENGL32.DLL"
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    37
#ifndef WGL_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    38
#define WGL_ARB_create_context
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    39
#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
    40
#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
    41
#define WGL_CONTEXT_LAYER_PLANE_ARB     0x2093
6380
3990b7d564d7 Fixed typo in one of WGL definition
Kajetan Swierk <kajetan.swierk@gmail.com>
parents: 6296
diff changeset
    42
#define WGL_CONTEXT_FLAGS_ARB           0x2094
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    43
#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
    44
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB  0x0002
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    45
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    46
#ifndef WGL_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    47
#define WGL_ARB_create_context_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    48
#define WGL_CONTEXT_PROFILE_MASK_ARB              0x9126
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    49
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB          0x00000001
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    50
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    51
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    52
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    53
#ifndef WGL_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    54
#define WGL_ARB_create_context_robustness
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    55
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB         0x00000004
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    56
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB     0x8256
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    57
#define WGL_NO_RESET_NOTIFICATION_ARB                   0x8261
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    58
#define WGL_LOSE_CONTEXT_ON_RESET_ARB                   0x8252
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    59
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    60
#endif
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    61
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    62
#ifndef WGL_EXT_create_context_es2_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    63
#define WGL_EXT_create_context_es2_profile
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    64
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT           0x00000004
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    65
#endif
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
    66
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
    67
#ifndef WGL_EXT_create_context_es_profile
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
    68
#define WGL_EXT_create_context_es_profile
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
    69
#define WGL_CONTEXT_ES_PROFILE_BIT_EXT            0x00000004
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
    70
#endif
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
    71
7853
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
    72
#ifndef WGL_ARB_framebuffer_sRGB
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
    73
#define WGL_ARB_framebuffer_sRGB
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
    74
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB                0x20A9
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
    75
#endif
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
    76
9413
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    77
#ifndef WGL_ARB_context_flush_control
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    78
#define WGL_ARB_context_flush_control
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    79
#define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB   0x2097
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    80
#define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB           0x0000
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    81
#define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB          0x2098
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    82
#endif
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
    83
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    84
typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    85
                                                            HGLRC
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    86
                                                            hShareContext,
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    87
                                                            const int
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
    88
                                                            *attribList);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
WIN_GL_LoadLibrary(_THIS, const char *path)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
{
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
    93
    void *handle;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    if (path == NULL) {
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    96
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    97
    }
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    98
    if (path == NULL) {
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
    99
        path = DEFAULT_OPENGL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    }
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   101
    _this->gl_config.dll_handle = SDL_LoadObject(path);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   102
    if (!_this->gl_config.dll_handle) {
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   103
        return -1;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    }
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   105
    SDL_strlcpy(_this->gl_config.driver_path, path,
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   106
                SDL_arraysize(_this->gl_config.driver_path));
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   107
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   108
    /* Allocate OpenGL memory */
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   109
    _this->gl_data = (struct SDL_GLDriverData *) SDL_calloc(1, sizeof(struct SDL_GLDriverData));
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   110
    if (!_this->gl_data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   111
        return SDL_OutOfMemory();
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   112
    }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
    /* Load function pointers */
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   115
    handle = _this->gl_config.dll_handle;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   117
        SDL_LoadFunction(handle, "wglGetProcAddress");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   119
        SDL_LoadFunction(handle, "wglCreateContext");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   121
        SDL_LoadFunction(handle, "wglDeleteContext");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   123
        SDL_LoadFunction(handle, "wglMakeCurrent");
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   124
    _this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   125
        SDL_LoadFunction(handle, "wglShareLists");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    if (!_this->gl_data->wglGetProcAddress ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
        !_this->gl_data->wglCreateContext ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
        !_this->gl_data->wglDeleteContext ||
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
        !_this->gl_data->wglMakeCurrent) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   131
        return SDL_SetError("Could not retrieve OpenGL functions");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    }
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
    return 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
void *
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
WIN_GL_GetProcAddress(_THIS, const char *proc)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    void *func;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    /* This is to pick up extensions */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
    func = _this->gl_data->wglGetProcAddress(proc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    if (!func) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
        /* This is probably a normal GL function */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
        func = GetProcAddress(_this->gl_config.dll_handle, proc);
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
    return func;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   151
void
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
WIN_GL_UnloadLibrary(_THIS)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
{
7865
f2a42ca4ddf0 Better cleanup if OpenGL initialization fails
Sam Lantinga <slouken@libsdl.org>
parents: 7853
diff changeset
   154
    SDL_UnloadObject(_this->gl_config.dll_handle);
3057
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   155
    _this->gl_config.dll_handle = NULL;
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   156
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   157
    /* Free OpenGL memory */
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   158
    SDL_free(_this->gl_data);
089a77aebb7d Added test program for SDL_CreateWindowFrom()
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   159
    _this->gl_data = NULL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
static void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    SDL_zerop(pfd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    pfd->nSize = sizeof(*pfd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    pfd->nVersion = 1;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    if (_this->gl_config.double_buffer) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
        pfd->dwFlags |= PFD_DOUBLEBUFFER;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
    if (_this->gl_config.stereo) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
        pfd->dwFlags |= PFD_STEREO;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    pfd->iLayerType = PFD_MAIN_PLANE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    pfd->iPixelType = PFD_TYPE_RGBA;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    pfd->cRedBits = _this->gl_config.red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    pfd->cGreenBits = _this->gl_config.green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    pfd->cBlueBits = _this->gl_config.blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    pfd->cAlphaBits = _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    if (_this->gl_config.buffer_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
        pfd->cColorBits =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
            _this->gl_config.buffer_size - _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
        pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
    pfd->cAccumRedBits = _this->gl_config.accum_red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
    pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
    pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
    pfd->cAccumBits =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
        (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
         pfd->cAccumAlphaBits);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
    pfd->cDepthBits = _this->gl_config.depth_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
    pfd->cStencilBits = _this->gl_config.stencil_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
2150
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   198
/* Choose the closest pixel format that meets or exceeds the target.
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   199
   FIXME: Should we weight any particular attribute over any other?
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   200
*/
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   201
static int
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   202
WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   203
{
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   204
    PIXELFORMATDESCRIPTOR pfd;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   205
    int count, index, best = 0;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   206
    unsigned int dist, best_dist = ~0U;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   207
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   208
    count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   209
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   210
    for (index = 1; index <= count; index++) {
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 (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
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
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   215
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   216
        if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   217
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   218
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   219
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   220
        if (pfd.iLayerType != target->iLayerType) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   221
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   222
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   223
        if (pfd.iPixelType != target->iPixelType) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   224
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   225
        }
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
        dist = 0;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   228
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   229
        if (pfd.cColorBits < target->cColorBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   230
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   231
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   232
            dist += (pfd.cColorBits - target->cColorBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   233
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   234
        if (pfd.cRedBits < target->cRedBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   235
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   236
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   237
            dist += (pfd.cRedBits - target->cRedBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   238
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   239
        if (pfd.cGreenBits < target->cGreenBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   240
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   241
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   242
            dist += (pfd.cGreenBits - target->cGreenBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   243
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   244
        if (pfd.cBlueBits < target->cBlueBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   245
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   246
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   247
            dist += (pfd.cBlueBits - target->cBlueBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   248
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   249
        if (pfd.cAlphaBits < target->cAlphaBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   250
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   251
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   252
            dist += (pfd.cAlphaBits - target->cAlphaBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   253
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   254
        if (pfd.cAccumBits < target->cAccumBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   255
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   256
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   257
            dist += (pfd.cAccumBits - target->cAccumBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   258
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   259
        if (pfd.cAccumRedBits < target->cAccumRedBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   260
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   261
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   262
            dist += (pfd.cAccumRedBits - target->cAccumRedBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   263
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   264
        if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   265
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   266
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   267
            dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
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
        if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   270
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   271
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   272
            dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   273
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   274
        if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   275
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   276
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   277
            dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   278
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   279
        if (pfd.cDepthBits < target->cDepthBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   280
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   281
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   282
            dist += (pfd.cDepthBits - target->cDepthBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   283
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   284
        if (pfd.cStencilBits < target->cStencilBits) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   285
            continue;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   286
        } else {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   287
            dist += (pfd.cStencilBits - target->cStencilBits);
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   288
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   289
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   290
        if (dist < best_dist) {
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   291
            best = index;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   292
            best_dist = dist;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   293
        }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   294
    }
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   295
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   296
    return best;
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   297
}
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   298
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
static SDL_bool
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
HasExtension(const char *extension, const char *extensions)
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
    const char *start;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
    const char *where, *terminator;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
    /* Extension names should not have spaces. */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
    where = SDL_strchr(extension, ' ');
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
    if (where || *extension == '\0')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
        return SDL_FALSE;
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
    if (!extensions)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
        return SDL_FALSE;
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
    /* 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
   314
     * OpenGL extensions string. Don't be fooled by sub-strings,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
     * etc. */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
    start = extensions;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    for (;;) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
        where = SDL_strstr(start, extension);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
        if (!where)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
            break;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
        terminator = where + SDL_strlen(extension);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
        if (where == start || *(where - 1) == ' ')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
            if (*terminator == ' ' || *terminator == '\0')
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
                return SDL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
        start = terminator;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    return SDL_FALSE;
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
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   334
void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   335
WIN_GL_InitExtensions(_THIS)
1913
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
    const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
    const char *extensions;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   339
    HWND hwnd;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   340
    HDC hdc;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   341
    HGLRC hglrc;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   342
    PIXELFORMATDESCRIPTOR pfd;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   343
8735
2134fc16252b Don't crash in WIN_GL_InitExtensions() if the OpenGL library couldn't be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 8604
diff changeset
   344
    if (!_this->gl_data) {
2134fc16252b Don't crash in WIN_GL_InitExtensions() if the OpenGL library couldn't be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 8604
diff changeset
   345
        return;
2134fc16252b Don't crash in WIN_GL_InitExtensions() if the OpenGL library couldn't be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 8604
diff changeset
   346
    }
2134fc16252b Don't crash in WIN_GL_InitExtensions() if the OpenGL library couldn't be loaded
Sam Lantinga <slouken@libsdl.org>
parents: 8604
diff changeset
   347
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   348
    hwnd =
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   349
        CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   350
        10, 10, NULL, NULL, SDL_Instance, NULL);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   351
    if (!hwnd) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   352
        return;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   353
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   354
    WIN_PumpEvents(_this);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   355
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   356
    hdc = GetDC(hwnd);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   357
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   358
    WIN_GL_SetupPixelFormat(_this, &pfd);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   359
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   360
    SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   361
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   362
    hglrc = _this->gl_data->wglCreateContext(hdc);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   363
    if (!hglrc) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   364
        return;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   365
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   366
    _this->gl_data->wglMakeCurrent(hdc, hglrc);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
    wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
        _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
    if (wglGetExtensionsStringARB) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
        extensions = wglGetExtensionsStringARB(hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
    } else {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
        extensions = NULL;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
    /* Check for WGL_ARB_pixel_format */
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   377
    _this->gl_data->HAS_WGL_ARB_pixel_format = SDL_FALSE;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
    if (HasExtension("WGL_ARB_pixel_format", extensions)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
        _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
                                                   (HDC, const int *,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   381
                                                    const FLOAT *, UINT,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   382
                                                    int *, UINT *))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   383
            WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   384
        _this->gl_data->wglGetPixelFormatAttribivARB =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
            (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
            WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   387
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
        if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   389
            (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   390
            _this->gl_data->HAS_WGL_ARB_pixel_format = SDL_TRUE;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
        }
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
    /* Check for WGL_EXT_swap_control */
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   395
    _this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_FALSE;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
    if (HasExtension("WGL_EXT_swap_control", extensions)) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
        _this->gl_data->wglSwapIntervalEXT =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   398
            WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
        _this->gl_data->wglGetSwapIntervalEXT =
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
            WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   401
        if (HasExtension("WGL_EXT_swap_control_tear", extensions)) {
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   402
            _this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_TRUE;
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   403
        }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   404
    } else {
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   405
        _this->gl_data->wglSwapIntervalEXT = NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   406
        _this->gl_data->wglGetSwapIntervalEXT = NULL;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
    }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   408
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   409
    /* Check for WGL_EXT_create_context_es2_profile */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   410
    _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   411
    if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   412
        _this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   413
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   414
9413
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   415
    /* Check for GLX_ARB_context_flush_control */
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   416
    if (HasExtension("WGL_ARB_context_flush_control", extensions)) {
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   417
        _this->gl_data->HAS_WGL_ARB_context_flush_control = SDL_TRUE;
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   418
    }
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   419
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   420
    _this->gl_data->wglMakeCurrent(hdc, NULL);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   421
    _this->gl_data->wglDeleteContext(hglrc);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   422
    ReleaseDC(hwnd, hdc);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   423
    DestroyWindow(hwnd);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   424
    WIN_PumpEvents(_this);
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   425
}
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   426
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   427
static int
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   428
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
   429
{
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   430
    HWND hwnd;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   431
    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
   432
    PIXELFORMATDESCRIPTOR pfd;
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   433
    HGLRC hglrc;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   434
    int pixel_format = 0;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   435
    unsigned int matching;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   436
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   437
    hwnd =
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   438
        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
   439
                     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
   440
    WIN_PumpEvents(_this);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   441
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   442
    hdc = GetDC(hwnd);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   443
2180
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   444
    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
   445
5ed37b16c1a7 Yes, you need to set the pixel format before creating a context.
Sam Lantinga <slouken@libsdl.org>
parents: 2178
diff changeset
   446
    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
   447
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   448
    hglrc = _this->gl_data->wglCreateContext(hdc);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   449
    if (hglrc) {
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   450
        _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
   451
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   452
        if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   453
            _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
   454
                                                    1, &pixel_format,
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   455
                                                    &matching);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   456
        }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   457
7553
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   458
        _this->gl_data->wglMakeCurrent(hdc, NULL);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   459
        _this->gl_data->wglDeleteContext(hglrc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   460
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   461
    ReleaseDC(hwnd, hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   462
    DestroyWindow(hwnd);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   463
    WIN_PumpEvents(_this);
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   464
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   465
    return pixel_format;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   466
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   467
7559
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   468
/* actual work of WIN_GL_SetupWindow() happens here. */
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   469
static int
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   470
WIN_GL_SetupWindowInternal(_THIS, SDL_Window * window)
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   471
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   472
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   473
    PIXELFORMATDESCRIPTOR pfd;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   474
    int pixel_format = 0;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   475
    int iAttribs[64];
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   476
    int *iAttr;
7401
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   477
    int *iAccelAttr;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   478
    float fAttribs[1] = { 0 };
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   479
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   480
    WIN_GL_SetupPixelFormat(_this, &pfd);
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
    /* setup WGL_ARB_pixel_format attribs */
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   483
    iAttr = &iAttribs[0];
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   484
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   485
    *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   486
    *iAttr++ = GL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   487
    *iAttr++ = WGL_RED_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   488
    *iAttr++ = _this->gl_config.red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   489
    *iAttr++ = WGL_GREEN_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   490
    *iAttr++ = _this->gl_config.green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   491
    *iAttr++ = WGL_BLUE_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   492
    *iAttr++ = _this->gl_config.blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   493
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   494
    if (_this->gl_config.alpha_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   495
        *iAttr++ = WGL_ALPHA_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   496
        *iAttr++ = _this->gl_config.alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   498
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
    *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
    *iAttr++ = _this->gl_config.double_buffer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   501
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   502
    *iAttr++ = WGL_DEPTH_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   503
    *iAttr++ = _this->gl_config.depth_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   504
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   505
    if (_this->gl_config.stencil_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   506
        *iAttr++ = WGL_STENCIL_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   507
        *iAttr++ = _this->gl_config.stencil_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   508
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   509
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   510
    if (_this->gl_config.accum_red_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   511
        *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   512
        *iAttr++ = _this->gl_config.accum_red_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   514
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
    if (_this->gl_config.accum_green_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
        *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
        *iAttr++ = _this->gl_config.accum_green_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   520
    if (_this->gl_config.accum_blue_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
        *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   522
        *iAttr++ = _this->gl_config.accum_blue_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
    if (_this->gl_config.accum_alpha_size) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   526
        *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   527
        *iAttr++ = _this->gl_config.accum_alpha_size;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   528
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   529
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   530
    if (_this->gl_config.stereo) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   531
        *iAttr++ = WGL_STEREO_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   532
        *iAttr++ = GL_TRUE;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   533
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   534
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   535
    if (_this->gl_config.multisamplebuffers) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   536
        *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   537
        *iAttr++ = _this->gl_config.multisamplebuffers;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   538
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   539
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   540
    if (_this->gl_config.multisamplesamples) {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   541
        *iAttr++ = WGL_SAMPLES_ARB;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   542
        *iAttr++ = _this->gl_config.multisamplesamples;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   543
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   544
7853
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
   545
    if (_this->gl_config.framebuffer_srgb_capable) {
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
   546
        *iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
   547
        *iAttr++ = _this->gl_config.framebuffer_srgb_capable;
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
   548
    }
4861edda71d1 Added SDL_GL_FRAMEBUFFER_SRGB_CAPABLE (thanks, David!).
Ryan C. Gordon <icculus@icculus.org>
parents: 7559
diff changeset
   549
7401
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   550
    /* We always choose either FULL or NO accel on Windows, because of flaky
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   551
       drivers. If the app didn't specify, we use FULL, because that's
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   552
       probably what they wanted (and if you didn't care and got FULL, that's
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   553
       a perfectly valid result in any case). */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   554
    *iAttr++ = WGL_ACCELERATION_ARB;
7401
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   555
    iAccelAttr = iAttr;
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   556
    if (_this->gl_config.accelerated) {
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   557
        *iAttr++ = WGL_FULL_ACCELERATION_ARB;
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   558
    } else {
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   559
        *iAttr++ = WGL_NO_ACCELERATION_ARB;
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   560
    }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   561
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   562
    *iAttr = 0;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   563
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   564
    /* Choose and set the closest available pixel format */
7401
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   565
    pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   566
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   567
    /* App said "don't care about accel" and FULL accel failed. Try NO. */
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   568
    if ( ( !pixel_format ) && ( _this->gl_config.accelerated < 0 ) ) {
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   569
        *iAccelAttr = WGL_NO_ACCELERATION_ARB;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   570
        pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
7401
698995795574 Cleaned up WGL_ACCELERATION_ARB usage.
Ryan C. Gordon <icculus@icculus.org>
parents: 7191
diff changeset
   571
        *iAccelAttr = WGL_FULL_ACCELERATION_ARB;  /* if we try again. */
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   572
    }
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   573
    if (!pixel_format) {
2150
abbe2c1dcf0a Fixed bug #77
Sam Lantinga <slouken@libsdl.org>
parents: 1952
diff changeset
   574
        pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   575
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   576
    if (!pixel_format) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   577
        return SDL_SetError("No matching GL pixel format available");
1913
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
    if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   580
        return WIN_SetError("SetPixelFormat()");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   581
    }
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   582
    return 0;
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
7559
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   585
int
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   586
WIN_GL_SetupWindow(_THIS, SDL_Window * window)
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   587
{
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   588
    /* The current context is lost in here; save it and reset it. */
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   589
    SDL_Window *current_win = SDL_GL_GetCurrentWindow();
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   590
    SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   591
    const int retval = WIN_GL_SetupWindowInternal(_this, window);
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   592
    WIN_GL_MakeCurrent(_this, current_win, current_ctx);
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   593
    return retval;
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   594
}
0dd3b05797f9 Move the fix for Bugzilla #1395 into WIN_GL_SetupWindow() directly.
Ryan C. Gordon <icculus@icculus.org>
parents: 7553
diff changeset
   595
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   596
SDL_GLContext
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   597
WIN_GL_CreateContext(_THIS, SDL_Window * window)
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
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   600
    HGLRC context, share_context;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   601
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   602
    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   603
        !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
8022
7396e3cc5337 Fixes compilation on Mingw.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   604
#if SDL_VIDEO_OPENGL_EGL        
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   605
        /* Switch to EGL based functions */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   606
        WIN_GL_UnloadLibrary(_this);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   607
        _this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   608
        _this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   609
        _this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   610
        _this->GL_CreateContext = WIN_GLES_CreateContext;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   611
        _this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   612
        _this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   613
        _this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   614
        _this->GL_SwapWindow = WIN_GLES_SwapWindow;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   615
        _this->GL_DeleteContext = WIN_GLES_DeleteContext;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   616
        
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   617
        if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   618
            return NULL;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   619
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   620
        
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   621
        return WIN_GLES_CreateContext(_this, window);
8022
7396e3cc5337 Fixes compilation on Mingw.
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8021
diff changeset
   622
#else
8080
bf767de0bcdc Fixed pointer from integer warning and bug if compiled without EGL.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8022
diff changeset
   623
        SDL_SetError("SDL not configured with EGL support");
bf767de0bcdc Fixed pointer from integer warning and bug if compiled without EGL.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8022
diff changeset
   624
        return NULL;
bf767de0bcdc Fixed pointer from integer warning and bug if compiled without EGL.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8022
diff changeset
   625
#endif
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   626
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7865
diff changeset
   627
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   628
    if (_this->gl_config.share_with_current_context) {
7412
50211a1fd557 Fixed bug 1946 - OpenGL contexts in threads
Sam Lantinga <slouken@libsdl.org>
parents: 7401
diff changeset
   629
        share_context = (HGLRC)SDL_GL_GetCurrentContext();
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   630
    } else {
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   631
        share_context = 0;
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   632
    }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   633
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   634
    if (_this->gl_config.major_version < 3 &&
8604
459bd7365e9d Fixed Mac OS X OpenGL context creation to match other backends, where we only care about the actual version we request if it's 3.0 or newer or a special profile context.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   635
        _this->gl_config.profile_mask == 0 &&
459bd7365e9d Fixed Mac OS X OpenGL context creation to match other backends, where we only care about the actual version we request if it's 3.0 or newer or a special profile context.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   636
        _this->gl_config.flags == 0) {
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   637
        /* Create legacy context */
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   638
        context = _this->gl_data->wglCreateContext(hdc);
8604
459bd7365e9d Fixed Mac OS X OpenGL context creation to match other backends, where we only care about the actual version we request if it's 3.0 or newer or a special profile context.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   639
        if( share_context != 0 ) {
6406
3a098f2d4dea Fixed wglShareLists() call that used the wrong variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6393
diff changeset
   640
            _this->gl_data->wglShareLists(share_context, context);
8604
459bd7365e9d Fixed Mac OS X OpenGL context creation to match other backends, where we only care about the actual version we request if it's 3.0 or newer or a special profile context.
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   641
        }
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   642
    } else {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   643
        PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   644
        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
   645
        if (!temp_context) {
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   646
            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
   647
            return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   648
        }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   649
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   650
        /* Make the context current */
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   651
        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
   652
            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
   653
            return NULL;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   654
        }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   655
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   656
        wglCreateContextAttribsARB =
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   657
            (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   658
            wglGetProcAddress("wglCreateContextAttribsARB");
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   659
        if (!wglCreateContextAttribsARB) {
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   660
            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
   661
            context = temp_context;
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   662
        } else {
9413
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   663
        /* max 10 attributes plus terminator */
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   664
            int attribs[11] = {
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   665
                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
   666
                WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   667
                0
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   668
            };
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   669
        int iattr = 4;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   670
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   671
        /* SDL profile bits match WGL profile bits */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   672
        if( _this->gl_config.profile_mask != 0 ) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   673
            attribs[iattr++] = WGL_CONTEXT_PROFILE_MASK_ARB;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   674
        attribs[iattr++] = _this->gl_config.profile_mask;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   675
        }
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   676
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   677
        /* SDL flags match WGL flags */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   678
        if( _this->gl_config.flags != 0 ) {
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   679
            attribs[iattr++] = WGL_CONTEXT_FLAGS_ARB;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   680
        attribs[iattr++] = _this->gl_config.flags;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   681
        }
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   682
9413
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   683
        /* only set if wgl extension is available */
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   684
        if( _this->gl_data->HAS_WGL_ARB_context_flush_control ) {
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   685
            attribs[iattr++] = WGL_CONTEXT_RELEASE_BEHAVIOR_ARB;
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   686
            attribs[iattr++] = _this->gl_config.release_behavior ?
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   687
                                    WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB :
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   688
                                    WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   689
        }
eb50f63a5777 Windows: support for OpenGL extension WGL_ARB_context_flush_control.
Ryan C. Gordon <icculus@icculus.org>
parents: 8735
diff changeset
   690
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   691
        attribs[iattr++] = 0;
6296
b42657486c0d Add OpenGL 3.X context creation support
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   692
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   693
            /* Create the GL 3.x context */
6393
a773384edf20 Fixed bug 1565 - some small GL context creation enhancements
Sam Lantinga <slouken@libsdl.org>
parents: 6383
diff changeset
   694
            context = wglCreateContextAttribsARB(hdc, share_context, attribs);
3100
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   695
            /* Delete the GL 2.x context */
3105
cdeee9f9b14b Fixed bug #721
Sam Lantinga <slouken@libsdl.org>
parents: 3100
diff changeset
   696
            _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
   697
        }
7dc982143c06 Date: Sun, 22 Mar 2009 12:52:29 +0000
Sam Lantinga <slouken@libsdl.org>
parents: 3057
diff changeset
   698
    }
3139
Sam Lantinga <slouken@libsdl.org>
parents: 3105
diff changeset
   699
2178
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   700
    if (!context) {
3565
f43c8f688f77 Fixed bug #906
Sam Lantinga <slouken@libsdl.org>
parents: 3139
diff changeset
   701
        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
   702
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   703
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   704
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   705
    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
   706
        WIN_GL_DeleteContext(_this, context);
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   707
        return NULL;
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   708
    }
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   709
114a541cfae2 Creating a context makes it current, per the documentation.
Sam Lantinga <slouken@libsdl.org>
parents: 2150
diff changeset
   710
    return context;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   711
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   712
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   713
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   714
WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   715
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   716
    HDC hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   717
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   718
    if (!_this->gl_data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   719
        return SDL_SetError("OpenGL not initialized");
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   720
    }
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   721
7553
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   722
    /* sanity check that higher level handled this. */
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   723
    SDL_assert(window || (!window && !context));
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   724
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   725
    /* Some Windows drivers freak out if hdc is NULL, even when context is
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   726
       NULL, against spec. Since hdc is _supposed_ to be ignored if context
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   727
       is NULL, we either use the current GL window, or do nothing if we
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   728
       already have no current context. */
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   729
    if (!window) {
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   730
        window = SDL_GL_GetCurrentWindow();
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   731
        if (!window) {
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   732
            SDL_assert(SDL_GL_GetCurrentContext() == NULL);
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   733
            return 0;  /* already done. */
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   734
        }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   735
    }
7553
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   736
f0091f8eae33 Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Ryan C. Gordon <icculus@icculus.org>
parents: 7412
diff changeset
   737
    hdc = ((SDL_WindowData *) window->driverdata)->hdc;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   738
    if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   739
        return WIN_SetError("wglMakeCurrent()");
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   740
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   741
    return 0;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   742
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   743
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   744
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   745
WIN_GL_SetSwapInterval(_THIS, int interval)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   746
{
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   747
    if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   748
        return SDL_SetError("Negative swap interval unsupported in this GL");
6382
64d54101773a Add support for (GLX|WGL)_EXT_swap_control_tear.
Ryan C. Gordon <icculus@icculus.org>
parents: 6380
diff changeset
   749
    } else if (_this->gl_data->wglSwapIntervalEXT) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   750
        if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) {
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   751
            return WIN_SetError("wglSwapIntervalEXT()");
6383
869effc44c41 Cleanups to Windows WGL_EXT_swap_control_tear code.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   752
        }
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   753
    } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   754
        return SDL_Unsupported();
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   755
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6885
diff changeset
   756
    return 0;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   757
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   758
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   759
int
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   760
WIN_GL_GetSwapInterval(_THIS)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   761
{
6383
869effc44c41 Cleanups to Windows WGL_EXT_swap_control_tear code.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   762
    int retval = 0;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   763
    if (_this->gl_data->wglGetSwapIntervalEXT) {
6383
869effc44c41 Cleanups to Windows WGL_EXT_swap_control_tear code.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   764
        retval = _this->gl_data->wglGetSwapIntervalEXT();
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   765
    }
6383
869effc44c41 Cleanups to Windows WGL_EXT_swap_control_tear code.
Ryan C. Gordon <icculus@icculus.org>
parents: 6382
diff changeset
   766
    return retval;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   767
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   768
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   769
void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   770
WIN_GL_SwapWindow(_THIS, SDL_Window * window)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   771
{
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   772
    HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   773
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   774
    SwapBuffers(hdc);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   775
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   776
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   777
void
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   778
WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   779
{
6522
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   780
    if (!_this->gl_data) {
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   781
        return;
edacce9402fb The gl_data is optional for the driver, so don't early out of the context delete call if it doesn't exist.
Sam Lantinga <slouken@libsdl.org>
parents: 6406
diff changeset
   782
    }
1936
83946ee0ff1f Implemented OpenGL support on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1926
diff changeset
   783
    _this->gl_data->wglDeleteContext((HGLRC) context);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   784
}
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   785
8144
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   786
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   787
SDL_bool
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   788
WIN_GL_SetPixelFormatFrom(_THIS, SDL_Window * fromWindow, SDL_Window * toWindow)
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   789
{
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   790
    HDC hfromdc = ((SDL_WindowData *) fromWindow->driverdata)->hdc;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   791
    HDC htodc = ((SDL_WindowData *) toWindow->driverdata)->hdc;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   792
    BOOL result;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   793
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   794
    /* get the pixel format of the fromWindow */
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   795
    int pixel_format = GetPixelFormat(hfromdc);
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   796
    PIXELFORMATDESCRIPTOR pfd;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   797
    SDL_memset(&pfd, 0, sizeof(pfd));
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   798
    DescribePixelFormat(hfromdc, pixel_format, sizeof(pfd), &pfd);
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   799
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   800
    /* set the pixel format of the toWindow */
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   801
    result = SetPixelFormat(htodc, pixel_format, &pfd);
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   802
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   803
    return result ? SDL_TRUE : SDL_FALSE;
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   804
}
855b1d6d7d8e Add a new hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT that allows SDL_CreateWindowFrom() to set the pixel format of another SDL_Window (and also will set the SDL_WINDOW_OPENGL flag on the window created with SDL_CreateWindowFrom()).
Sam Lantinga <slouken@libsdl.org>
parents: 8093
diff changeset
   805
1952
420716272158 Implemented X11 OpenGL support.
Sam Lantinga <slouken@libsdl.org>
parents: 1936
diff changeset
   806
#endif /* SDL_VIDEO_OPENGL_WGL */
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   807
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5644
diff changeset
   808
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5644
diff changeset
   809
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   810
/* vi: set ts=4 sw=4 expandtab: */