2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2019-04-16 14:43:29 +02:00
|
|
|
// GLFW 3.4 WGL - www.glfw.org
|
2010-09-07 17:34:51 +02:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2019-04-15 20:50:00 +02:00
|
|
|
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 17:34:51 +02:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
2019-05-20 15:24:14 +02:00
|
|
|
// Please use C89 style variable declarations in this file because VS 2010
|
|
|
|
//========================================================================
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-08-12 16:46:29 +02:00
|
|
|
#include <stdlib.h>
|
2013-01-15 20:00:27 +01:00
|
|
|
#include <assert.h>
|
2012-08-12 16:46:29 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
// Return the value corresponding to the specified attribute
|
|
|
|
//
|
|
|
|
static int findPixelFormatAttribValue(const int* attribs,
|
|
|
|
int attribCount,
|
|
|
|
const int* values,
|
|
|
|
int attrib)
|
2018-10-12 12:58:32 +02:00
|
|
|
{
|
|
|
|
int i;
|
2018-12-30 18:16:28 +01:00
|
|
|
|
|
|
|
for (i = 0; i < attribCount; i++)
|
2018-10-12 12:58:32 +02:00
|
|
|
{
|
2018-12-30 18:16:28 +01:00
|
|
|
if (attribs[i] == attrib)
|
2018-10-12 12:58:32 +02:00
|
|
|
return values[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
2018-12-30 18:16:28 +01:00
|
|
|
"WGL: Unknown pixel format attribute requested");
|
2018-10-12 12:58:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
#define addAttrib(a) \
|
|
|
|
{ \
|
|
|
|
assert((size_t) attribCount < sizeof(attribs) / sizeof(attribs[0])); \
|
|
|
|
attribs[attribCount++] = a; \
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
2018-12-30 18:16:28 +01:00
|
|
|
#define findAttribValue(a) \
|
|
|
|
findPixelFormatAttribValue(attribs, attribCount, values, a)
|
2013-05-13 15:49:59 +02:00
|
|
|
|
|
|
|
// Return a list of available and usable framebuffer configs
|
|
|
|
//
|
2017-05-10 17:24:40 +02:00
|
|
|
static int choosePixelFormat(_GLFWwindow* window,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
|
|
|
_GLFWfbconfig* usableConfigs;
|
|
|
|
const _GLFWfbconfig* closest;
|
2019-01-23 23:43:15 +01:00
|
|
|
int i, pixelFormat, nativeCount, usableCount = 0, attribCount = 0;
|
2018-12-30 18:16:28 +01:00
|
|
|
int attribs[40];
|
|
|
|
int values[sizeof(attribs) / sizeof(attribs[0])];
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_pixel_format)
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
2018-12-30 18:16:28 +01:00
|
|
|
const int attrib = WGL_NUMBER_PIXEL_FORMATS_ARB;
|
|
|
|
|
2019-05-20 16:18:23 +02:00
|
|
|
if (!wglGetPixelFormatAttribivARB(window->context.wgl.dc,
|
|
|
|
1, 0, 1, &attrib, &nativeCount))
|
2018-12-30 18:16:28 +01:00
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to retrieve pixel format attribute");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
addAttrib(WGL_SUPPORT_OPENGL_ARB);
|
|
|
|
addAttrib(WGL_DRAW_TO_WINDOW_ARB);
|
|
|
|
addAttrib(WGL_PIXEL_TYPE_ARB);
|
|
|
|
addAttrib(WGL_ACCELERATION_ARB);
|
|
|
|
addAttrib(WGL_RED_BITS_ARB);
|
|
|
|
addAttrib(WGL_RED_SHIFT_ARB);
|
|
|
|
addAttrib(WGL_GREEN_BITS_ARB);
|
|
|
|
addAttrib(WGL_GREEN_SHIFT_ARB);
|
|
|
|
addAttrib(WGL_BLUE_BITS_ARB);
|
|
|
|
addAttrib(WGL_BLUE_SHIFT_ARB);
|
|
|
|
addAttrib(WGL_ALPHA_BITS_ARB);
|
|
|
|
addAttrib(WGL_ALPHA_SHIFT_ARB);
|
|
|
|
addAttrib(WGL_DEPTH_BITS_ARB);
|
|
|
|
addAttrib(WGL_STENCIL_BITS_ARB);
|
|
|
|
addAttrib(WGL_ACCUM_BITS_ARB);
|
|
|
|
addAttrib(WGL_ACCUM_RED_BITS_ARB);
|
|
|
|
addAttrib(WGL_ACCUM_GREEN_BITS_ARB);
|
|
|
|
addAttrib(WGL_ACCUM_BLUE_BITS_ARB);
|
|
|
|
addAttrib(WGL_ACCUM_ALPHA_BITS_ARB);
|
|
|
|
addAttrib(WGL_AUX_BUFFERS_ARB);
|
|
|
|
addAttrib(WGL_STEREO_ARB);
|
|
|
|
addAttrib(WGL_DOUBLE_BUFFER_ARB);
|
|
|
|
|
|
|
|
if (_glfw.wgl.ARB_multisample)
|
|
|
|
addAttrib(WGL_SAMPLES_ARB);
|
|
|
|
|
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
|
|
|
{
|
|
|
|
if (_glfw.wgl.ARB_framebuffer_sRGB || _glfw.wgl.EXT_framebuffer_sRGB)
|
|
|
|
addAttrib(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_glfw.wgl.EXT_colorspace)
|
|
|
|
addAttrib(WGL_COLORSPACE_EXT);
|
|
|
|
}
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 16:48:55 +01:00
|
|
|
nativeCount = DescribePixelFormat(window->context.wgl.dc,
|
2013-05-13 15:49:59 +02:00
|
|
|
1,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2021-08-03 20:53:48 +02:00
|
|
|
usableConfigs = _glfw_calloc(nativeCount, sizeof(_GLFWfbconfig));
|
2013-05-13 15:49:59 +02:00
|
|
|
|
|
|
|
for (i = 0; i < nativeCount; i++)
|
|
|
|
{
|
|
|
|
_GLFWfbconfig* u = usableConfigs + usableCount;
|
2018-12-30 18:16:28 +01:00
|
|
|
pixelFormat = i + 1;
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_pixel_format)
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
2015-04-07 02:51:45 +02:00
|
|
|
// Get pixel format attributes through "modern" extension
|
|
|
|
|
2019-05-20 16:18:23 +02:00
|
|
|
if (!wglGetPixelFormatAttribivARB(window->context.wgl.dc,
|
|
|
|
pixelFormat, 0,
|
|
|
|
attribCount,
|
|
|
|
attribs, values))
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
2018-12-30 18:16:28 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to retrieve pixel format attributes");
|
2019-02-14 20:19:21 +01:00
|
|
|
|
2021-08-03 20:53:48 +02:00
|
|
|
_glfw_free(usableConfigs);
|
2018-12-30 18:16:28 +01:00
|
|
|
return 0;
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
if (!findAttribValue(WGL_SUPPORT_OPENGL_ARB) ||
|
|
|
|
!findAttribValue(WGL_DRAW_TO_WINDOW_ARB))
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
if (findAttribValue(WGL_PIXEL_TYPE_ARB) != WGL_TYPE_RGBA_ARB)
|
2013-05-13 15:49:59 +02:00
|
|
|
continue;
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
if (findAttribValue(WGL_ACCELERATION_ARB) == WGL_NO_ACCELERATION_ARB)
|
|
|
|
continue;
|
|
|
|
|
2021-05-14 17:14:13 +02:00
|
|
|
if (findAttribValue(WGL_DOUBLE_BUFFER_ARB) != fbconfig->doublebuffer)
|
|
|
|
continue;
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
u->redBits = findAttribValue(WGL_RED_BITS_ARB);
|
|
|
|
u->greenBits = findAttribValue(WGL_GREEN_BITS_ARB);
|
|
|
|
u->blueBits = findAttribValue(WGL_BLUE_BITS_ARB);
|
|
|
|
u->alphaBits = findAttribValue(WGL_ALPHA_BITS_ARB);
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
u->depthBits = findAttribValue(WGL_DEPTH_BITS_ARB);
|
|
|
|
u->stencilBits = findAttribValue(WGL_STENCIL_BITS_ARB);
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
u->accumRedBits = findAttribValue(WGL_ACCUM_RED_BITS_ARB);
|
|
|
|
u->accumGreenBits = findAttribValue(WGL_ACCUM_GREEN_BITS_ARB);
|
|
|
|
u->accumBlueBits = findAttribValue(WGL_ACCUM_BLUE_BITS_ARB);
|
|
|
|
u->accumAlphaBits = findAttribValue(WGL_ACCUM_ALPHA_BITS_ARB);
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
u->auxBuffers = findAttribValue(WGL_AUX_BUFFERS_ARB);
|
2014-04-24 19:21:10 +02:00
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
if (findAttribValue(WGL_STEREO_ARB))
|
2015-08-23 19:30:04 +02:00
|
|
|
u->stereo = GLFW_TRUE;
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_multisample)
|
2018-12-30 18:16:28 +01:00
|
|
|
u->samples = findAttribValue(WGL_SAMPLES_ARB);
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2017-05-10 17:24:40 +02:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
2014-04-24 19:21:10 +02:00
|
|
|
{
|
2017-05-10 17:24:40 +02:00
|
|
|
if (_glfw.wgl.ARB_framebuffer_sRGB ||
|
|
|
|
_glfw.wgl.EXT_framebuffer_sRGB)
|
|
|
|
{
|
2018-12-30 18:16:28 +01:00
|
|
|
if (findAttribValue(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB))
|
2017-05-10 17:24:40 +02:00
|
|
|
u->sRGB = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_glfw.wgl.EXT_colorspace)
|
|
|
|
{
|
2018-12-30 18:16:28 +01:00
|
|
|
if (findAttribValue(WGL_COLORSPACE_EXT) == WGL_COLORSPACE_SRGB_EXT)
|
2017-05-10 17:24:40 +02:00
|
|
|
u->sRGB = GLFW_TRUE;
|
|
|
|
}
|
2014-04-24 19:21:10 +02:00
|
|
|
}
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-07 02:51:45 +02:00
|
|
|
// Get pixel format attributes through legacy PFDs
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2017-09-18 18:10:57 +02:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
|
|
|
|
if (!DescribePixelFormat(window->context.wgl.dc,
|
2018-12-30 18:16:28 +01:00
|
|
|
pixelFormat,
|
2013-05-13 15:49:59 +02:00
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
&pfd))
|
|
|
|
{
|
2019-02-14 21:48:08 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to describe pixel format");
|
|
|
|
|
2021-08-03 20:53:48 +02:00
|
|
|
_glfw_free(usableConfigs);
|
2019-02-14 21:48:08 +01:00
|
|
|
return 0;
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
|
2014-04-24 19:21:10 +02:00
|
|
|
!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
|
2013-05-13 15:49:59 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
|
|
|
|
(pfd.dwFlags & PFD_GENERIC_FORMAT))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pfd.iPixelType != PFD_TYPE_RGBA)
|
|
|
|
continue;
|
|
|
|
|
2021-05-14 17:14:13 +02:00
|
|
|
if (!!(pfd.dwFlags & PFD_DOUBLEBUFFER) != fbconfig->doublebuffer)
|
|
|
|
continue;
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
u->redBits = pfd.cRedBits;
|
|
|
|
u->greenBits = pfd.cGreenBits;
|
|
|
|
u->blueBits = pfd.cBlueBits;
|
|
|
|
u->alphaBits = pfd.cAlphaBits;
|
|
|
|
|
|
|
|
u->depthBits = pfd.cDepthBits;
|
|
|
|
u->stencilBits = pfd.cStencilBits;
|
|
|
|
|
|
|
|
u->accumRedBits = pfd.cAccumRedBits;
|
|
|
|
u->accumGreenBits = pfd.cAccumGreenBits;
|
|
|
|
u->accumBlueBits = pfd.cAccumBlueBits;
|
|
|
|
u->accumAlphaBits = pfd.cAccumAlphaBits;
|
|
|
|
|
|
|
|
u->auxBuffers = pfd.cAuxBuffers;
|
2014-04-24 19:21:10 +02:00
|
|
|
|
|
|
|
if (pfd.dwFlags & PFD_STEREO)
|
2015-08-23 19:30:04 +02:00
|
|
|
u->stereo = GLFW_TRUE;
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
u->handle = pixelFormat;
|
2013-05-13 15:49:59 +02:00
|
|
|
usableCount++;
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:35:36 +01:00
|
|
|
if (!usableCount)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"WGL: The driver does not appear to support OpenGL");
|
|
|
|
|
2021-08-03 20:53:48 +02:00
|
|
|
_glfw_free(usableConfigs);
|
2016-06-23 15:34:23 +02:00
|
|
|
return 0;
|
2013-12-04 05:35:36 +01:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:24:40 +02:00
|
|
|
closest = _glfwChooseFBConfig(fbconfig, usableConfigs, usableCount);
|
2013-06-13 18:29:21 +02:00
|
|
|
if (!closest)
|
|
|
|
{
|
2015-09-16 16:24:21 +02:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
2013-12-04 05:35:36 +01:00
|
|
|
"WGL: Failed to find a suitable pixel format");
|
|
|
|
|
2021-08-03 20:53:48 +02:00
|
|
|
_glfw_free(usableConfigs);
|
2016-06-23 15:34:23 +02:00
|
|
|
return 0;
|
2013-06-13 18:29:21 +02:00
|
|
|
}
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2016-06-23 15:34:23 +02:00
|
|
|
pixelFormat = (int) closest->handle;
|
2021-08-03 20:53:48 +02:00
|
|
|
_glfw_free(usableConfigs);
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2016-06-23 15:34:23 +02:00
|
|
|
return pixelFormat;
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:16:28 +01:00
|
|
|
#undef addAttrib
|
|
|
|
#undef findAttribValue
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static void makeContextCurrentWGL(_GLFWwindow* window)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
if (wglMakeCurrent(window->context.wgl.dc, window->context.wgl.handle))
|
2017-05-25 18:23:09 +02:00
|
|
|
_glfwPlatformSetTls(&_glfw.contextSlot, window);
|
2016-03-28 13:19:31 +02:00
|
|
|
else
|
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to make context current");
|
2017-05-25 18:23:09 +02:00
|
|
|
_glfwPlatformSetTls(&_glfw.contextSlot, NULL);
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!wglMakeCurrent(NULL, NULL))
|
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to clear current context");
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-25 18:23:09 +02:00
|
|
|
_glfwPlatformSetTls(&_glfw.contextSlot, NULL);
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static void swapBuffersWGL(_GLFWwindow* window)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
2018-08-12 13:58:30 +02:00
|
|
|
if (!window->monitor)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
2018-08-12 13:58:30 +02:00
|
|
|
if (IsWindowsVistaOrGreater())
|
|
|
|
{
|
2019-03-19 17:22:59 +01:00
|
|
|
// DWM Composition is always enabled on Win8+
|
|
|
|
BOOL enabled = IsWindows8OrGreater();
|
2018-08-12 13:58:30 +02:00
|
|
|
|
|
|
|
// HACK: Use DwmFlush when desktop composition is enabled
|
2019-03-19 17:22:59 +01:00
|
|
|
if (enabled ||
|
|
|
|
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
2018-08-12 13:58:30 +02:00
|
|
|
{
|
|
|
|
int count = abs(window->context.wgl.interval);
|
|
|
|
while (count--)
|
|
|
|
DwmFlush();
|
|
|
|
}
|
|
|
|
}
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SwapBuffers(window->context.wgl.dc);
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static void swapIntervalWGL(int interval)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
2017-05-25 18:23:09 +02:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
2016-03-28 13:19:31 +02:00
|
|
|
|
|
|
|
window->context.wgl.interval = interval;
|
|
|
|
|
2018-08-12 13:58:30 +02:00
|
|
|
if (!window->monitor)
|
|
|
|
{
|
|
|
|
if (IsWindowsVistaOrGreater())
|
|
|
|
{
|
2019-03-19 17:22:59 +01:00
|
|
|
// DWM Composition is always enabled on Win8+
|
|
|
|
BOOL enabled = IsWindows8OrGreater();
|
2018-08-12 13:58:30 +02:00
|
|
|
|
|
|
|
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
|
|
|
// avoid interfering with DWM vsync
|
2019-03-19 17:22:59 +01:00
|
|
|
if (enabled ||
|
|
|
|
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
2018-08-12 13:58:30 +02:00
|
|
|
interval = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-03-28 13:19:31 +02:00
|
|
|
|
|
|
|
if (_glfw.wgl.EXT_swap_control)
|
2019-05-20 16:18:23 +02:00
|
|
|
wglSwapIntervalEXT(interval);
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static int extensionSupportedWGL(const char* extension)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
2018-10-09 20:06:03 +02:00
|
|
|
const char* extensions = NULL;
|
2016-03-28 13:19:31 +02:00
|
|
|
|
|
|
|
if (_glfw.wgl.GetExtensionsStringARB)
|
2019-05-20 16:18:23 +02:00
|
|
|
extensions = wglGetExtensionsStringARB(wglGetCurrentDC());
|
2018-10-09 20:06:03 +02:00
|
|
|
else if (_glfw.wgl.GetExtensionsStringEXT)
|
2019-05-20 16:18:23 +02:00
|
|
|
extensions = wglGetExtensionsStringEXT();
|
2018-10-09 20:06:03 +02:00
|
|
|
|
|
|
|
if (!extensions)
|
|
|
|
return GLFW_FALSE;
|
2016-03-28 13:19:31 +02:00
|
|
|
|
2018-10-09 20:06:03 +02:00
|
|
|
return _glfwStringInExtensionString(extension, extensions);
|
2016-03-28 13:19:31 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static GLFWglproc getProcAddressWGL(const char* procname)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
|
|
|
const GLFWglproc proc = (GLFWglproc) wglGetProcAddress(procname);
|
|
|
|
if (proc)
|
|
|
|
return proc;
|
|
|
|
|
|
|
|
return (GLFWglproc) GetProcAddress(_glfw.wgl.instance, procname);
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
static void destroyContextWGL(_GLFWwindow* window)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
|
|
|
if (window->context.wgl.handle)
|
|
|
|
{
|
|
|
|
wglDeleteContext(window->context.wgl.handle);
|
|
|
|
window->context.wgl.handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-24 10:07:56 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Initialize WGL
|
2016-03-28 13:19:31 +02:00
|
|
|
//
|
2017-12-24 10:07:56 +01:00
|
|
|
GLFWbool _glfwInitWGL(void)
|
2016-03-28 13:19:31 +02:00
|
|
|
{
|
2016-06-22 20:09:07 +02:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2017-12-24 10:07:56 +01:00
|
|
|
HGLRC prc, rc;
|
|
|
|
HDC pdc, dc;
|
|
|
|
|
|
|
|
if (_glfw.wgl.instance)
|
|
|
|
return GLFW_TRUE;
|
|
|
|
|
|
|
|
_glfw.wgl.instance = LoadLibraryA("opengl32.dll");
|
|
|
|
if (!_glfw.wgl.instance)
|
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to load opengl32.dll");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2016-06-22 20:09:07 +02:00
|
|
|
|
2017-12-24 10:07:56 +01:00
|
|
|
_glfw.wgl.CreateContext = (PFN_wglCreateContext)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglCreateContext");
|
|
|
|
_glfw.wgl.DeleteContext = (PFN_wglDeleteContext)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglDeleteContext");
|
|
|
|
_glfw.wgl.GetProcAddress = (PFN_wglGetProcAddress)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglGetProcAddress");
|
|
|
|
_glfw.wgl.GetCurrentDC = (PFN_wglGetCurrentDC)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglGetCurrentDC");
|
|
|
|
_glfw.wgl.GetCurrentContext = (PFN_wglGetCurrentContext)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglGetCurrentContext");
|
|
|
|
_glfw.wgl.MakeCurrent = (PFN_wglMakeCurrent)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglMakeCurrent");
|
|
|
|
_glfw.wgl.ShareLists = (PFN_wglShareLists)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglShareLists");
|
2016-06-22 20:09:07 +02:00
|
|
|
|
2016-06-23 14:13:13 +02:00
|
|
|
// NOTE: A dummy context has to be created for opengl32.dll to load the
|
|
|
|
// OpenGL ICD, from which we can then query WGL extensions
|
|
|
|
// NOTE: This code will accept the Microsoft GDI ICD; accelerated context
|
|
|
|
// creation failure occurs during manual pixel format enumeration
|
|
|
|
|
2019-01-17 00:11:17 +01:00
|
|
|
dc = GetDC(_glfw.win32.helperWindowHandle);
|
2017-12-24 10:07:56 +01:00
|
|
|
|
2016-06-22 20:09:07 +02:00
|
|
|
ZeroMemory(&pfd, sizeof(pfd));
|
|
|
|
pfd.nSize = sizeof(pfd);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 24;
|
|
|
|
|
2016-06-23 14:13:13 +02:00
|
|
|
if (!SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd))
|
2016-06-22 20:09:07 +02:00
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to set pixel format for dummy context");
|
2017-12-24 10:07:56 +01:00
|
|
|
return GLFW_FALSE;
|
2016-06-22 20:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = wglCreateContext(dc);
|
|
|
|
if (!rc)
|
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to create dummy context");
|
2017-12-24 10:07:56 +01:00
|
|
|
return GLFW_FALSE;
|
2016-06-22 20:09:07 +02:00
|
|
|
}
|
|
|
|
|
2017-12-24 10:07:56 +01:00
|
|
|
pdc = wglGetCurrentDC();
|
|
|
|
prc = wglGetCurrentContext();
|
|
|
|
|
2016-06-22 20:09:07 +02:00
|
|
|
if (!wglMakeCurrent(dc, rc))
|
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to make dummy context current");
|
2017-12-24 10:07:56 +01:00
|
|
|
wglMakeCurrent(pdc, prc);
|
2016-06-22 23:42:56 +02:00
|
|
|
wglDeleteContext(rc);
|
2017-12-24 10:07:56 +01:00
|
|
|
return GLFW_FALSE;
|
2016-06-22 20:09:07 +02:00
|
|
|
}
|
|
|
|
|
2016-06-23 14:13:13 +02:00
|
|
|
// NOTE: Functions must be loaded first as they're needed to retrieve the
|
|
|
|
// extension string that tells us whether the functions are supported
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
|
|
|
|
wglGetProcAddress("wglGetExtensionsStringEXT");
|
|
|
|
_glfw.wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
|
|
|
|
wglGetProcAddress("wglGetExtensionsStringARB");
|
|
|
|
_glfw.wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
|
|
|
_glfw.wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
|
|
|
|
wglGetProcAddress("wglSwapIntervalEXT");
|
|
|
|
_glfw.wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
|
|
|
|
wglGetProcAddress("wglGetPixelFormatAttribivARB");
|
|
|
|
|
2016-06-23 14:13:13 +02:00
|
|
|
// NOTE: WGL_ARB_extensions_string and WGL_EXT_extensions_string are not
|
|
|
|
// checked below as we are already using them
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_multisample =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_multisample");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_framebuffer_sRGB =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_framebuffer_sRGB");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.EXT_framebuffer_sRGB =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_EXT_framebuffer_sRGB");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_create_context =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_create_context");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_create_context_profile =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_create_context_profile");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.EXT_create_context_es2_profile =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_EXT_create_context_es2_profile");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_create_context_robustness =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_create_context_robustness");
|
2017-06-08 15:20:24 +02:00
|
|
|
_glfw.wgl.ARB_create_context_no_error =
|
|
|
|
extensionSupportedWGL("WGL_ARB_create_context_no_error");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.EXT_swap_control =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_EXT_swap_control");
|
2017-05-10 17:24:40 +02:00
|
|
|
_glfw.wgl.EXT_colorspace =
|
|
|
|
extensionSupportedWGL("WGL_EXT_colorspace");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_pixel_format =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_pixel_format");
|
2016-03-28 13:19:31 +02:00
|
|
|
_glfw.wgl.ARB_context_flush_control =
|
2016-06-14 12:27:19 +02:00
|
|
|
extensionSupportedWGL("WGL_ARB_context_flush_control");
|
2016-03-28 13:19:31 +02:00
|
|
|
|
2017-12-24 10:07:56 +01:00
|
|
|
wglMakeCurrent(pdc, prc);
|
2016-06-22 20:09:07 +02:00
|
|
|
wglDeleteContext(rc);
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2013-01-16 20:10:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate WGL
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-12-03 18:16:46 +01:00
|
|
|
void _glfwTerminateWGL(void)
|
2013-01-16 20:10:17 +01:00
|
|
|
{
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.instance)
|
|
|
|
FreeLibrary(_glfw.wgl.instance);
|
2013-01-16 20:10:17 +01:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:52:55 +02:00
|
|
|
#define setAttrib(a, v) \
|
2013-01-15 20:00:27 +01:00
|
|
|
{ \
|
2019-04-15 15:35:38 +02:00
|
|
|
assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
|
2017-06-08 15:52:55 +02:00
|
|
|
attribs[index++] = a; \
|
|
|
|
attribs[index++] = v; \
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2014-08-20 20:12:59 +02:00
|
|
|
// Create the OpenGL or OpenGL ES context
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2015-12-10 17:10:05 +01:00
|
|
|
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
int attribs[40];
|
2016-06-23 15:34:23 +02:00
|
|
|
int pixelFormat;
|
2012-07-31 22:48:28 +02:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2013-01-15 20:00:27 +01:00
|
|
|
HGLRC share = NULL;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->share)
|
2015-11-09 16:48:55 +01:00
|
|
|
share = ctxconfig->share->context.wgl.handle;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-11-09 16:48:55 +01:00
|
|
|
window->context.wgl.dc = GetDC(window->win32.handle);
|
|
|
|
if (!window->context.wgl.dc)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: Failed to retrieve DC for window");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:24:40 +02:00
|
|
|
pixelFormat = choosePixelFormat(window, ctxconfig, fbconfig);
|
2016-06-23 15:34:23 +02:00
|
|
|
if (!pixelFormat)
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-11-09 16:48:55 +01:00
|
|
|
if (!DescribePixelFormat(window->context.wgl.dc,
|
|
|
|
pixelFormat, sizeof(pfd), &pfd))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to retrieve PFD for selected pixel format");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2015-11-09 16:48:55 +01:00
|
|
|
if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to set selected pixel format");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2016-06-22 20:09:07 +02:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
|
|
|
{
|
|
|
|
if (ctxconfig->forward)
|
|
|
|
{
|
|
|
|
if (!_glfw.wgl.ARB_create_context)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: A forward compatible OpenGL context requested but WGL_ARB_create_context is unavailable");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctxconfig->profile)
|
|
|
|
{
|
|
|
|
if (!_glfw.wgl.ARB_create_context_profile)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!_glfw.wgl.ARB_create_context ||
|
|
|
|
!_glfw.wgl.ARB_create_context_profile ||
|
|
|
|
!_glfw.wgl.EXT_create_context_es2_profile)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"WGL: OpenGL ES requested but WGL_ARB_create_context_es2_profile is unavailable");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_create_context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2015-04-10 13:18:26 +02:00
|
|
|
int index = 0, mask = 0, flags = 0;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2016-03-28 13:19:31 +02:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
2012-09-30 15:32:50 +02:00
|
|
|
{
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->forward)
|
2012-07-31 22:48:28 +02:00
|
|
|
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
2015-04-10 13:18:26 +02:00
|
|
|
if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
|
|
|
|
mask |= WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
|
|
else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE)
|
|
|
|
mask |= WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
2012-12-13 22:43:23 +01:00
|
|
|
else
|
|
|
|
mask |= WGL_CONTEXT_ES2_PROFILE_BIT_EXT;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-02-27 02:53:21 +01:00
|
|
|
if (ctxconfig->debug)
|
|
|
|
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->robustness)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_create_context_robustness)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
|
2015-04-10 13:18:26 +02:00
|
|
|
{
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_NO_RESET_NOTIFICATION_ARB);
|
2015-04-10 13:18:26 +02:00
|
|
|
}
|
2014-03-06 20:05:32 +01:00
|
|
|
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
|
2015-04-10 13:18:26 +02:00
|
|
|
{
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_LOSE_CONTEXT_ON_RESET_ARB);
|
2015-04-10 13:18:26 +02:00
|
|
|
}
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
|
|
|
|
}
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2014-08-21 19:21:45 +02:00
|
|
|
if (ctxconfig->release)
|
|
|
|
{
|
2015-11-09 16:51:27 +01:00
|
|
|
if (_glfw.wgl.ARB_context_flush_control)
|
2014-08-21 19:21:45 +02:00
|
|
|
{
|
|
|
|
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
|
|
|
|
{
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
|
2014-08-21 19:21:45 +02:00
|
|
|
}
|
|
|
|
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
|
|
|
|
{
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
|
2014-08-21 19:21:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 15:20:24 +02:00
|
|
|
if (ctxconfig->noerror)
|
|
|
|
{
|
|
|
|
if (_glfw.wgl.ARB_create_context_no_error)
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE);
|
2017-06-08 15:20:24 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 02:51:45 +02:00
|
|
|
// NOTE: Only request an explicitly versioned context when necessary, as
|
|
|
|
// explicitly requesting version 1.0 does not always return the
|
|
|
|
// highest version supported by the driver
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
|
|
|
|
setAttrib(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
|
2012-12-13 22:43:23 +01:00
|
|
|
}
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (flags)
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_FLAGS_ARB, flags);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (mask)
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2017-06-08 15:52:55 +02:00
|
|
|
setAttrib(0, 0);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-11-09 16:48:55 +01:00
|
|
|
window->context.wgl.handle =
|
2019-05-20 16:18:23 +02:00
|
|
|
wglCreateContextAttribsARB(window->context.wgl.dc, share, attribs);
|
2015-11-09 16:48:55 +01:00
|
|
|
if (!window->context.wgl.handle)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2016-08-01 20:44:02 +02:00
|
|
|
const DWORD error = GetLastError();
|
|
|
|
|
|
|
|
if (error == (0xc0070000 | ERROR_INVALID_VERSION_ARB))
|
|
|
|
{
|
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Driver does not support OpenGL version %i.%i",
|
|
|
|
ctxconfig->major,
|
|
|
|
ctxconfig->minor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Driver does not support OpenGL ES version %i.%i",
|
|
|
|
ctxconfig->major,
|
|
|
|
ctxconfig->minor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (error == (0xc0070000 | ERROR_INVALID_PROFILE_ARB))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Driver does not support the requested OpenGL profile");
|
|
|
|
}
|
2017-06-08 15:20:24 +02:00
|
|
|
else if (error == (0xc0070000 | ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"WGL: The share context is not compatible with the requested context");
|
|
|
|
}
|
2016-08-01 20:44:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Failed to create OpenGL context");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Failed to create OpenGL ES context");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-06 16:13:42 +01:00
|
|
|
window->context.wgl.handle = wglCreateContext(window->context.wgl.dc);
|
2015-11-09 16:48:55 +01:00
|
|
|
if (!window->context.wgl.handle)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Failed to create OpenGL context");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
2015-12-06 16:13:42 +01:00
|
|
|
if (!wglShareLists(share, window->context.wgl.handle))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2017-01-19 20:29:27 +01:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to enable sharing with specified OpenGL context");
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:27:19 +02:00
|
|
|
window->context.makeCurrent = makeContextCurrentWGL;
|
|
|
|
window->context.swapBuffers = swapBuffersWGL;
|
|
|
|
window->context.swapInterval = swapIntervalWGL;
|
|
|
|
window->context.extensionSupported = extensionSupportedWGL;
|
|
|
|
window->context.getProcAddress = getProcAddressWGL;
|
|
|
|
window->context.destroy = destroyContextWGL;
|
2016-03-28 13:19:31 +02:00
|
|
|
|
2015-08-23 19:30:04 +02:00
|
|
|
return GLFW_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:52:55 +02:00
|
|
|
#undef setAttrib
|
2012-12-13 22:43:23 +01:00
|
|
|
|
|
|
|
|
2013-01-15 22:38:14 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-20 00:28:08 +01:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2015-06-18 14:03:02 +02:00
|
|
|
|
2021-10-04 20:32:32 +02:00
|
|
|
if (window->context.client != GLFW_NATIVE_CONTEXT_API)
|
2015-06-18 14:03:02 +02:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 16:48:55 +01:00
|
|
|
return window->context.wgl.handle;
|
2013-01-15 22:38:14 +01:00
|
|
|
}
|
|
|
|
|