src/video/windows/SDL_windowsopengl.h
author Sam Lantinga <slouken@libsdl.org>
Tue, 10 Jan 2017 08:54:33 -0800
changeset 10806 36f40b8cc979
parent 10737 3406a0f8b041
child 11332 e3797888c6f1
permissions -rw-r--r--
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
slouken@1913
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@1913
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1913
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1913
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1913
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1913
    22
slouken@5062
    23
#ifndef _SDL_windowsopengl_h
slouken@5062
    24
#define _SDL_windowsopengl_h
slouken@1913
    25
slouken@1952
    26
#if SDL_VIDEO_OPENGL_WGL
slouken@1913
    27
slouken@1913
    28
struct SDL_GLDriverData
slouken@1913
    29
{
icculus@6382
    30
    SDL_bool HAS_WGL_ARB_pixel_format;
icculus@6382
    31
    SDL_bool HAS_WGL_EXT_swap_control_tear;
icculus@9413
    32
    SDL_bool HAS_WGL_ARB_context_flush_control;
slouken@1913
    33
slouken@10806
    34
	/* Max version of OpenGL ES context that can be created if the
slouken@10806
    35
	   implementation supports WGL_EXT_create_context_es2_profile.
slouken@10806
    36
	   major = minor = 0 when unsupported.
slouken@10806
    37
	 */
slouken@10806
    38
	struct {
slouken@10806
    39
		int major;
slouken@10806
    40
		int minor;
slouken@10806
    41
	} es_profile_max_supported_version;
slouken@10806
    42
slouken@10806
    43
	void *(WINAPI * wglGetProcAddress) (const char *proc);
slouken@1913
    44
      HGLRC(WINAPI * wglCreateContext) (HDC hdc);
slouken@1913
    45
      BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
slouken@1913
    46
      BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
slouken@6393
    47
      BOOL(WINAPI * wglShareLists) (HGLRC hglrc1, HGLRC hglrc2);
slouken@1913
    48
      BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc,
slouken@1913
    49
                                              const int *piAttribIList,
slouken@1913
    50
                                              const FLOAT * pfAttribFList,
slouken@1913
    51
                                              UINT nMaxFormats,
slouken@1913
    52
                                              int *piFormats,
slouken@1913
    53
                                              UINT * nNumFormats);
slouken@1913
    54
      BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat,
slouken@1913
    55
                                                   int iLayerPlane,
slouken@1913
    56
                                                   UINT nAttributes,
slouken@1913
    57
                                                   const int *piAttributes,
slouken@1913
    58
                                                   int *piValues);
icculus@6384
    59
    BOOL (WINAPI * wglSwapIntervalEXT) (int interval);
slouken@1913
    60
    int (WINAPI * wglGetSwapIntervalEXT) (void);
slouken@1913
    61
};
slouken@1913
    62
slouken@1913
    63
/* OpenGL functions */
slouken@1913
    64
extern int WIN_GL_LoadLibrary(_THIS, const char *path);
slouken@1913
    65
extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
slouken@3057
    66
extern void WIN_GL_UnloadLibrary(_THIS);
slouken@10806
    67
extern SDL_bool WIN_GL_UseEGL(_THIS);
slouken@1913
    68
extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
slouken@1913
    69
extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
slouken@1913
    70
extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
slouken@1913
    71
                              SDL_GLContext context);
slouken@1913
    72
extern int WIN_GL_SetSwapInterval(_THIS, int interval);
slouken@1913
    73
extern int WIN_GL_GetSwapInterval(_THIS);
slouken@10690
    74
extern int WIN_GL_SwapWindow(_THIS, SDL_Window * window);
slouken@1913
    75
extern void WIN_GL_DeleteContext(_THIS, SDL_GLContext context);
gabomdq@8021
    76
extern void WIN_GL_InitExtensions(_THIS);
slouken@8144
    77
extern SDL_bool WIN_GL_SetPixelFormatFrom(_THIS, SDL_Window * fromWindow, SDL_Window * toWindow);
slouken@1913
    78
slouken@1913
    79
#ifndef WGL_ARB_pixel_format
slouken@1913
    80
#define WGL_NUMBER_PIXEL_FORMATS_ARB   0x2000
slouken@1913
    81
#define WGL_DRAW_TO_WINDOW_ARB         0x2001
slouken@1913
    82
#define WGL_DRAW_TO_BITMAP_ARB         0x2002
slouken@1913
    83
#define WGL_ACCELERATION_ARB           0x2003
slouken@1913
    84
#define WGL_NEED_PALETTE_ARB           0x2004
slouken@1913
    85
#define WGL_NEED_SYSTEM_PALETTE_ARB    0x2005
slouken@1913
    86
#define WGL_SWAP_LAYER_BUFFERS_ARB     0x2006
slouken@1913
    87
#define WGL_SWAP_METHOD_ARB            0x2007
slouken@1913
    88
#define WGL_NUMBER_OVERLAYS_ARB        0x2008
slouken@1913
    89
#define WGL_NUMBER_UNDERLAYS_ARB       0x2009
slouken@1913
    90
#define WGL_TRANSPARENT_ARB            0x200A
slouken@1913
    91
#define WGL_TRANSPARENT_RED_VALUE_ARB  0x2037
slouken@1913
    92
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
slouken@1913
    93
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
slouken@1913
    94
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
slouken@1913
    95
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
slouken@1913
    96
#define WGL_SHARE_DEPTH_ARB            0x200C
slouken@1913
    97
#define WGL_SHARE_STENCIL_ARB          0x200D
slouken@1913
    98
#define WGL_SHARE_ACCUM_ARB            0x200E
slouken@1913
    99
#define WGL_SUPPORT_GDI_ARB            0x200F
slouken@1913
   100
#define WGL_SUPPORT_OPENGL_ARB         0x2010
slouken@1913
   101
#define WGL_DOUBLE_BUFFER_ARB          0x2011
slouken@1913
   102
#define WGL_STEREO_ARB                 0x2012
slouken@1913
   103
#define WGL_PIXEL_TYPE_ARB             0x2013
slouken@1913
   104
#define WGL_COLOR_BITS_ARB             0x2014
slouken@1913
   105
#define WGL_RED_BITS_ARB               0x2015
slouken@1913
   106
#define WGL_RED_SHIFT_ARB              0x2016
slouken@1913
   107
#define WGL_GREEN_BITS_ARB             0x2017
slouken@1913
   108
#define WGL_GREEN_SHIFT_ARB            0x2018
slouken@1913
   109
#define WGL_BLUE_BITS_ARB              0x2019
slouken@1913
   110
#define WGL_BLUE_SHIFT_ARB             0x201A
slouken@1913
   111
#define WGL_ALPHA_BITS_ARB             0x201B
slouken@1913
   112
#define WGL_ALPHA_SHIFT_ARB            0x201C
slouken@1913
   113
#define WGL_ACCUM_BITS_ARB             0x201D
slouken@1913
   114
#define WGL_ACCUM_RED_BITS_ARB         0x201E
slouken@1913
   115
#define WGL_ACCUM_GREEN_BITS_ARB       0x201F
slouken@1913
   116
#define WGL_ACCUM_BLUE_BITS_ARB        0x2020
slouken@1913
   117
#define WGL_ACCUM_ALPHA_BITS_ARB       0x2021
slouken@1913
   118
#define WGL_DEPTH_BITS_ARB             0x2022
slouken@1913
   119
#define WGL_STENCIL_BITS_ARB           0x2023
slouken@1913
   120
#define WGL_AUX_BUFFERS_ARB            0x2024
slouken@1913
   121
#define WGL_NO_ACCELERATION_ARB        0x2025
slouken@1913
   122
#define WGL_GENERIC_ACCELERATION_ARB   0x2026
slouken@1913
   123
#define WGL_FULL_ACCELERATION_ARB      0x2027
slouken@1913
   124
#define WGL_SWAP_EXCHANGE_ARB          0x2028
slouken@1913
   125
#define WGL_SWAP_COPY_ARB              0x2029
slouken@1913
   126
#define WGL_SWAP_UNDEFINED_ARB         0x202A
slouken@1913
   127
#define WGL_TYPE_RGBA_ARB              0x202B
slouken@1913
   128
#define WGL_TYPE_COLORINDEX_ARB        0x202C
slouken@1913
   129
#endif
slouken@1913
   130
slouken@1913
   131
#ifndef WGL_ARB_multisample
slouken@1913
   132
#define WGL_SAMPLE_BUFFERS_ARB         0x2041
slouken@1913
   133
#define WGL_SAMPLES_ARB                0x2042
slouken@1913
   134
#endif
slouken@1913
   135
slouken@1952
   136
#endif /* SDL_VIDEO_OPENGL_WGL */
slouken@1913
   137
slouken@5062
   138
#endif /* _SDL_windowsopengl_h */
slouken@1913
   139
slouken@1913
   140
/* vi: set ts=4 sw=4 expandtab: */