23 #if SDL_VIDEO_DRIVER_WINDOWS
30 #if SDL_VIDEO_OPENGL_WGL
33 #define DEFAULT_OPENGL "OPENGL32.DLL"
35 #ifndef WGL_ARB_create_context
36 #define WGL_ARB_create_context
37 #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
38 #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
39 #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
40 #define WGL_CONTEXT_FLAGS_ARB 0x2094
41 #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
42 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
44 #ifndef WGL_ARB_create_context_profile
45 #define WGL_ARB_create_context_profile
46 #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
47 #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
48 #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
51 #ifndef WGL_ARB_create_context_robustness
52 #define WGL_ARB_create_context_robustness
53 #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
54 #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
55 #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
56 #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
60 #ifndef WGL_EXT_create_context_es2_profile
61 #define WGL_EXT_create_context_es2_profile
62 #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
65 #ifndef WGL_EXT_create_context_es_profile
66 #define WGL_EXT_create_context_es_profile
67 #define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
77 WIN_GL_LoadLibrary(
_THIS,
const char *
path)
86 path = DEFAULT_OPENGL;
111 _this->
gl_data->wglGetProcAddress = (
void *(WINAPI *) (
const char *))
112 GetProcAddress(handle,
"wglGetProcAddress");
114 GetProcAddress(handle,
"wglCreateContext");
116 GetProcAddress(handle,
"wglDeleteContext");
118 GetProcAddress(handle,
"wglMakeCurrent");
120 GetProcAddress(handle,
"wglShareLists");
127 return SDL_SetError(
"Could not retrieve OpenGL functions");
134 WIN_GL_GetProcAddress(
_THIS,
const char *proc)
148 WIN_GL_UnloadLibrary(
_THIS)
159 WIN_GL_SetupPixelFormat(
_THIS, PIXELFORMATDESCRIPTOR * pfd)
162 pfd->nSize =
sizeof(*pfd);
164 pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
166 pfd->dwFlags |= PFD_DOUBLEBUFFER;
169 pfd->dwFlags |= PFD_STEREO;
171 pfd->iLayerType = PFD_MAIN_PLANE;
172 pfd->iPixelType = PFD_TYPE_RGBA;
181 pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
188 (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
189 pfd->cAccumAlphaBits);
198 WIN_GL_ChoosePixelFormat(
HDC hdc, PIXELFORMATDESCRIPTOR *
target)
200 PIXELFORMATDESCRIPTOR pfd;
202 unsigned int dist, best_dist = ~0U;
204 count = DescribePixelFormat(hdc, 1,
sizeof(pfd),
NULL);
206 for (index = 1; index <=
count; index++) {
208 if (!DescribePixelFormat(hdc, index,
sizeof(pfd), &pfd)) {
212 if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
216 if (pfd.iLayerType != target->iLayerType) {
219 if (pfd.iPixelType != target->iPixelType) {
225 if (pfd.cColorBits < target->cColorBits) {
228 dist += (pfd.cColorBits - target->cColorBits);
230 if (pfd.cRedBits < target->cRedBits) {
233 dist += (pfd.cRedBits - target->cRedBits);
235 if (pfd.cGreenBits < target->cGreenBits) {
238 dist += (pfd.cGreenBits - target->cGreenBits);
240 if (pfd.cBlueBits < target->cBlueBits) {
243 dist += (pfd.cBlueBits - target->cBlueBits);
245 if (pfd.cAlphaBits < target->cAlphaBits) {
248 dist += (pfd.cAlphaBits - target->cAlphaBits);
250 if (pfd.cAccumBits < target->cAccumBits) {
253 dist += (pfd.cAccumBits - target->cAccumBits);
255 if (pfd.cAccumRedBits < target->cAccumRedBits) {
258 dist += (pfd.cAccumRedBits - target->cAccumRedBits);
260 if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
263 dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
265 if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
268 dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
270 if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
273 dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
275 if (pfd.cDepthBits < target->cDepthBits) {
278 dist += (pfd.cDepthBits - target->cDepthBits);
280 if (pfd.cStencilBits < target->cStencilBits) {
283 dist += (pfd.cStencilBits - target->cStencilBits);
286 if (dist < best_dist) {
296 HasExtension(
const char *extension,
const char *extensions)
299 const char *where, *terminator;
303 if (where || *extension ==
'\0')
321 if (where == start || *(where - 1) ==
' ')
322 if (*terminator ==
' ' || *terminator ==
'\0')
331 WIN_GL_InitExtensions(
_THIS,
HDC hdc)
334 const char *extensions;
337 _this->
gl_data->wglGetProcAddress(
"wglGetExtensionsStringARB");
346 if (HasExtension(
"WGL_ARB_pixel_format", extensions)) {
351 WIN_GL_GetProcAddress(
_this,
"wglChoosePixelFormatARB");
354 WIN_GL_GetProcAddress(
_this,
"wglGetPixelFormatAttribivARB");
364 if (HasExtension(
"WGL_EXT_swap_control", extensions)) {
366 WIN_GL_GetProcAddress(
_this,
"wglSwapIntervalEXT");
368 WIN_GL_GetProcAddress(
_this,
"wglGetSwapIntervalEXT");
369 if (HasExtension(
"WGL_EXT_swap_control_tear", extensions)) {
379 WIN_GL_ChoosePixelFormatARB(
_THIS,
int *iAttribs,
float *fAttribs)
383 PIXELFORMATDESCRIPTOR pfd;
385 int pixel_format = 0;
386 unsigned int matching;
395 WIN_GL_SetupPixelFormat(
_this, &pfd);
397 SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
403 WIN_GL_InitExtensions(
_this, hdc);
406 _this->
gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
414 ReleaseDC(hwnd, hdc);
426 PIXELFORMATDESCRIPTOR pfd;
427 int pixel_format = 0;
431 float fAttribs[1] = { 0 };
433 WIN_GL_SetupPixelFormat(
_this, &pfd);
436 iAttr = &iAttribs[0];
513 pixel_format = WIN_GL_ChoosePixelFormatARB(
_this, iAttribs, fAttribs);
518 pixel_format = WIN_GL_ChoosePixelFormatARB(
_this, iAttribs, fAttribs);
522 pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
525 return SDL_SetError(
"No matching GL pixel format available");
527 if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
539 const int retval = WIN_GL_SetupWindowInternal(
_this, window);
540 WIN_GL_MakeCurrent(
_this, current_win, current_ctx);
561 if( share_context != 0 ) {
573 if (WIN_GL_MakeCurrent(
_this, window, temp_context) < 0) {
574 WIN_GL_DeleteContext(
_this, temp_context);
578 wglCreateContextAttribsARB =
580 wglGetProcAddress(
"wglCreateContextAttribsARB");
581 if (!wglCreateContextAttribsARB) {
583 context = temp_context;
605 attribs[iattr++] = 0;
619 if (WIN_GL_MakeCurrent(
_this, window, context) < 0) {
620 WIN_GL_DeleteContext(
_this, context);
624 WIN_GL_InitExtensions(
_this, hdc);
661 WIN_GL_SetSwapInterval(
_THIS,
int interval)
663 if ((interval < 0) && (!
_this->
gl_data->HAS_WGL_EXT_swap_control_tear)) {
664 return SDL_SetError(
"Negative swap interval unsupported in this GL");
676 WIN_GL_GetSwapInterval(
_THIS)
#define WGL_DOUBLE_BUFFER_ARB
#define WGL_ACCUM_BLUE_BITS_ARB
#define WIN_UTF8ToString(S)
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
#define WGL_CONTEXT_MAJOR_VERSION_ARB
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
#define WGL_FULL_ACCELERATION_ARB
DECLSPEC SDL_Window *SDLCALL SDL_GL_GetCurrentWindow(void)
Get the currently active OpenGL window.
DECLSPEC void SDLCALL SDL_free(void *mem)
#define WGL_SAMPLE_BUFFERS_ARB
void * SDL_GLContext
An opaque handle to an OpenGL context.
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c)
GLsizei const GLchar *const * path
#define WGL_CONTEXT_FLAGS_ARB
#define WGL_GREEN_BITS_ARB
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(VOID)
struct SDL_GLDriverData * gl_data
#define WGL_BLUE_BITS_ARB
static SDL_VideoDevice * _this
EGLContext EGLenum target
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
typedef HGLRC(WINAPI *PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC)(UINT id)
#define WGL_ACCUM_GREEN_BITS_ARB
int share_with_current_context
#define WGL_ACCELERATION_ARB
#define SDL_assert(condition)
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
#define WGL_ACCUM_ALPHA_BITS_ARB
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
int WIN_SetError(const char *prefix)
void WIN_PumpEvents(_THIS)
#define WGL_CONTEXT_MINOR_VERSION_ARB
#define WGL_CONTEXT_PROFILE_MASK_ARB
#define WGL_NO_ACCELERATION_ARB
#define WGL_DEPTH_BITS_ARB
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
#define WGL_STENCIL_BITS_ARB
EGLImageKHR EGLint EGLint * handle
#define WGL_ALPHA_BITS_ARB
#define WGL_DRAW_TO_WINDOW_ARB
HGLRC const int * attribList
struct SDL_VideoDevice::@87 gl_config
#define WGL_ACCUM_RED_BITS_ARB
#define SDL_Unsupported()
DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
Get the currently active OpenGL context.
#define wglGetExtensionsStringARB
#define wglCreateContextAttribsARB
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC