2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
2015-06-01 16:55:06 -04:00
|
|
|
// GLFW 3.2 WGL - www.glfw.org
|
2010-09-07 11:34:51 -04:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2016-06-01 10:17:06 -04:00
|
|
|
// Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org>
|
2010-09-07 11:34:51 -04: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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-08-12 10:46:29 -04:00
|
|
|
#include <stdlib.h>
|
2012-08-14 07:51:39 -04:00
|
|
|
#include <malloc.h>
|
2013-01-15 14:00:27 -05:00
|
|
|
#include <assert.h>
|
2012-08-12 10:46:29 -04:00
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-05-13 09:49:59 -04:00
|
|
|
// Returns the specified attribute of the specified pixel format
|
|
|
|
//
|
|
|
|
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
|
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
assert(_glfw.wgl.ARB_pixel_format);
|
2015-04-06 20:34:08 -04:00
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
if (!_glfw.wgl.GetPixelFormatAttribivARB(window->context.wgl.dc,
|
2015-11-09 10:51:27 -05:00
|
|
|
pixelFormat,
|
|
|
|
0, 1, &attrib, &value))
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
2015-04-06 20:34:40 -04:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to retrieve pixel format attribute %i",
|
|
|
|
attrib);
|
2013-05-13 09:49:59 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of available and usable framebuffer configs
|
|
|
|
//
|
2015-08-23 13:30:04 -04:00
|
|
|
static GLFWbool choosePixelFormat(_GLFWwindow* window,
|
|
|
|
const _GLFWfbconfig* desired,
|
|
|
|
int* result)
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
|
|
|
_GLFWfbconfig* usableConfigs;
|
|
|
|
const _GLFWfbconfig* closest;
|
|
|
|
int i, nativeCount, usableCount;
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_pixel_format)
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
|
|
|
nativeCount = getPixelFormatAttrib(window,
|
|
|
|
1,
|
|
|
|
WGL_NUMBER_PIXEL_FORMATS_ARB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 10:48:55 -05:00
|
|
|
nativeCount = DescribePixelFormat(window->context.wgl.dc,
|
2013-05-13 09:49:59 -04:00
|
|
|
1,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2013-07-04 08:54:07 -04:00
|
|
|
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
|
2013-05-13 09:49:59 -04:00
|
|
|
usableCount = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nativeCount; i++)
|
|
|
|
{
|
|
|
|
const int n = i + 1;
|
|
|
|
_GLFWfbconfig* u = usableConfigs + usableCount;
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_pixel_format)
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
2015-04-06 20:51:45 -04:00
|
|
|
// Get pixel format attributes through "modern" extension
|
|
|
|
|
2013-05-13 09:49:59 -04:00
|
|
|
if (!getPixelFormatAttrib(window, n, WGL_SUPPORT_OPENGL_ARB) ||
|
2014-04-24 13:21:10 -04:00
|
|
|
!getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB))
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_PIXEL_TYPE_ARB) !=
|
|
|
|
WGL_TYPE_RGBA_ARB)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_ACCELERATION_ARB) ==
|
|
|
|
WGL_NO_ACCELERATION_ARB)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
u->redBits = getPixelFormatAttrib(window, n, WGL_RED_BITS_ARB);
|
|
|
|
u->greenBits = getPixelFormatAttrib(window, n, WGL_GREEN_BITS_ARB);
|
|
|
|
u->blueBits = getPixelFormatAttrib(window, n, WGL_BLUE_BITS_ARB);
|
|
|
|
u->alphaBits = getPixelFormatAttrib(window, n, WGL_ALPHA_BITS_ARB);
|
|
|
|
|
|
|
|
u->depthBits = getPixelFormatAttrib(window, n, WGL_DEPTH_BITS_ARB);
|
|
|
|
u->stencilBits = getPixelFormatAttrib(window, n, WGL_STENCIL_BITS_ARB);
|
|
|
|
|
|
|
|
u->accumRedBits = getPixelFormatAttrib(window, n, WGL_ACCUM_RED_BITS_ARB);
|
|
|
|
u->accumGreenBits = getPixelFormatAttrib(window, n, WGL_ACCUM_GREEN_BITS_ARB);
|
|
|
|
u->accumBlueBits = getPixelFormatAttrib(window, n, WGL_ACCUM_BLUE_BITS_ARB);
|
|
|
|
u->accumAlphaBits = getPixelFormatAttrib(window, n, WGL_ACCUM_ALPHA_BITS_ARB);
|
|
|
|
|
|
|
|
u->auxBuffers = getPixelFormatAttrib(window, n, WGL_AUX_BUFFERS_ARB);
|
2014-04-24 13:21:10 -04:00
|
|
|
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_STEREO_ARB))
|
2015-08-23 13:30:04 -04:00
|
|
|
u->stereo = GLFW_TRUE;
|
2014-04-24 13:21:10 -04:00
|
|
|
if (getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB))
|
2015-08-23 13:30:04 -04:00
|
|
|
u->doublebuffer = GLFW_TRUE;
|
2013-05-13 09:49:59 -04:00
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_multisample)
|
2013-05-13 09:49:59 -04:00
|
|
|
u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB);
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_framebuffer_sRGB ||
|
|
|
|
_glfw.wgl.EXT_framebuffer_sRGB)
|
2014-04-24 13:21:10 -04:00
|
|
|
{
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB))
|
2015-08-23 13:30:04 -04:00
|
|
|
u->sRGB = GLFW_TRUE;
|
2014-04-24 13:21:10 -04:00
|
|
|
}
|
2013-05-13 09:49:59 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
|
2015-04-06 20:51:45 -04:00
|
|
|
// Get pixel format attributes through legacy PFDs
|
2013-05-13 09:49:59 -04:00
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
if (!DescribePixelFormat(window->context.wgl.dc,
|
2013-05-13 09:49:59 -04:00
|
|
|
n,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
&pfd))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
|
2014-04-24 13:21:10 -04:00
|
|
|
!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
|
2013-05-13 09:49:59 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
|
|
|
|
(pfd.dwFlags & PFD_GENERIC_FORMAT))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pfd.iPixelType != PFD_TYPE_RGBA)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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 13:21:10 -04:00
|
|
|
|
|
|
|
if (pfd.dwFlags & PFD_STEREO)
|
2015-08-23 13:30:04 -04:00
|
|
|
u->stereo = GLFW_TRUE;
|
2014-04-24 13:21:10 -04:00
|
|
|
if (pfd.dwFlags & PFD_DOUBLEBUFFER)
|
2015-08-23 13:30:04 -04:00
|
|
|
u->doublebuffer = GLFW_TRUE;
|
2013-05-13 09:49:59 -04:00
|
|
|
}
|
|
|
|
|
2016-03-28 14:11:22 -04:00
|
|
|
u->handle = n;
|
2013-05-13 09:49:59 -04:00
|
|
|
usableCount++;
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:35:36 -05:00
|
|
|
if (!usableCount)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"WGL: The driver does not appear to support OpenGL");
|
|
|
|
|
|
|
|
free(usableConfigs);
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-03 23:35:36 -05:00
|
|
|
}
|
|
|
|
|
2013-05-13 09:49:59 -04:00
|
|
|
closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
|
2013-06-13 12:29:21 -04:00
|
|
|
if (!closest)
|
|
|
|
{
|
2015-09-16 10:24:21 -04:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
2013-12-03 23:35:36 -05:00
|
|
|
"WGL: Failed to find a suitable pixel format");
|
|
|
|
|
2013-06-13 12:29:21 -04:00
|
|
|
free(usableConfigs);
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-06-13 12:29:21 -04:00
|
|
|
}
|
2013-05-13 09:49:59 -04:00
|
|
|
|
2016-03-28 14:11:22 -04:00
|
|
|
*result = (int) closest->handle;
|
2013-05-13 09:49:59 -04:00
|
|
|
free(usableConfigs);
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2013-05-13 09:49:59 -04:00
|
|
|
}
|
|
|
|
|
2015-12-06 10:19:39 -05:00
|
|
|
// Returns whether desktop compositing is enabled
|
|
|
|
//
|
|
|
|
static GLFWbool isCompositionEnabled(void)
|
|
|
|
{
|
|
|
|
BOOL enabled;
|
|
|
|
|
|
|
|
if (!_glfw_DwmIsCompositionEnabled)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (_glfw_DwmIsCompositionEnabled(&enabled) != S_OK)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
static void makeContextCurrent(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
if (wglMakeCurrent(window->context.wgl.dc, window->context.wgl.handle))
|
|
|
|
_glfwPlatformSetCurrentContext(window);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to make context current");
|
|
|
|
_glfwPlatformSetCurrentContext(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!wglMakeCurrent(NULL, NULL))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to clear current context");
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfwPlatformSetCurrentContext(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void swapBuffers(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
// HACK: Use DwmFlush when desktop composition is enabled
|
|
|
|
if (isCompositionEnabled() && !window->monitor)
|
|
|
|
{
|
|
|
|
int count = abs(window->context.wgl.interval);
|
|
|
|
while (count--)
|
|
|
|
_glfw_DwmFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapBuffers(window->context.wgl.dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void swapInterval(int interval)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
|
|
|
|
|
|
|
window->context.wgl.interval = interval;
|
|
|
|
|
|
|
|
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
|
|
|
// avoid interfering with DWM vsync
|
|
|
|
if (isCompositionEnabled() && !window->monitor)
|
|
|
|
interval = 0;
|
|
|
|
|
|
|
|
if (_glfw.wgl.EXT_swap_control)
|
|
|
|
_glfw.wgl.SwapIntervalEXT(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extensionSupported(const char* extension)
|
|
|
|
{
|
|
|
|
const char* extensions;
|
|
|
|
|
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
|
|
|
|
|
|
|
if (_glfw.wgl.GetExtensionsStringEXT)
|
|
|
|
{
|
|
|
|
extensions = _glfw.wgl.GetExtensionsStringEXT();
|
|
|
|
if (extensions)
|
|
|
|
{
|
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
|
|
|
return GLFW_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfw.wgl.GetExtensionsStringARB)
|
|
|
|
{
|
|
|
|
extensions = _glfw.wgl.GetExtensionsStringARB(window->context.wgl.dc);
|
|
|
|
if (extensions)
|
|
|
|
{
|
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
|
|
|
return GLFW_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLFWglproc getProcAddress(const char* procname)
|
|
|
|
{
|
|
|
|
const GLFWglproc proc = (GLFWglproc) wglGetProcAddress(procname);
|
|
|
|
if (proc)
|
|
|
|
return proc;
|
|
|
|
|
|
|
|
return (GLFWglproc) GetProcAddress(_glfw.wgl.instance, procname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the OpenGL context
|
|
|
|
//
|
|
|
|
static void destroyContext(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window->context.wgl.handle)
|
|
|
|
{
|
|
|
|
wglDeleteContext(window->context.wgl.handle);
|
|
|
|
window->context.wgl.handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize WGL-specific extensions
|
|
|
|
//
|
|
|
|
static void loadExtensions(void)
|
|
|
|
{
|
|
|
|
// Functions for WGL_EXT_extension_string
|
|
|
|
// NOTE: These are needed by extensionSupported
|
|
|
|
_glfw.wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
|
|
|
|
wglGetProcAddress("wglGetExtensionsStringEXT");
|
|
|
|
_glfw.wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
|
|
|
|
wglGetProcAddress("wglGetExtensionsStringARB");
|
|
|
|
|
|
|
|
// Functions for WGL_ARB_create_context
|
|
|
|
_glfw.wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
|
|
|
|
|
|
|
// Functions for WGL_EXT_swap_control
|
|
|
|
_glfw.wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
|
|
|
|
wglGetProcAddress("wglSwapIntervalEXT");
|
|
|
|
|
|
|
|
// Functions for WGL_ARB_pixel_format
|
|
|
|
_glfw.wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
|
|
|
|
wglGetProcAddress("wglGetPixelFormatAttribivARB");
|
|
|
|
|
|
|
|
// This needs to include every extension used below except for
|
|
|
|
// WGL_ARB_extensions_string and WGL_EXT_extensions_string
|
|
|
|
_glfw.wgl.ARB_multisample =
|
|
|
|
extensionSupported("WGL_ARB_multisample");
|
|
|
|
_glfw.wgl.ARB_framebuffer_sRGB =
|
|
|
|
extensionSupported("WGL_ARB_framebuffer_sRGB");
|
|
|
|
_glfw.wgl.EXT_framebuffer_sRGB =
|
|
|
|
extensionSupported("WGL_EXT_framebuffer_sRGB");
|
|
|
|
_glfw.wgl.ARB_create_context =
|
|
|
|
extensionSupported("WGL_ARB_create_context");
|
|
|
|
_glfw.wgl.ARB_create_context_profile =
|
|
|
|
extensionSupported("WGL_ARB_create_context_profile");
|
|
|
|
_glfw.wgl.EXT_create_context_es2_profile =
|
|
|
|
extensionSupported("WGL_EXT_create_context_es2_profile");
|
|
|
|
_glfw.wgl.ARB_create_context_robustness =
|
|
|
|
extensionSupported("WGL_ARB_create_context_robustness");
|
|
|
|
_glfw.wgl.EXT_swap_control =
|
|
|
|
extensionSupported("WGL_EXT_swap_control");
|
|
|
|
_glfw.wgl.ARB_pixel_format =
|
|
|
|
extensionSupported("WGL_ARB_pixel_format");
|
|
|
|
_glfw.wgl.ARB_context_flush_control =
|
|
|
|
extensionSupported("WGL_ARB_context_flush_control");
|
|
|
|
|
|
|
|
_glfw.wgl.extensionsLoaded = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2013-01-15 14:00:27 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-01-16 14:10:17 -05:00
|
|
|
// Initialize WGL
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2015-12-10 11:10:05 -05:00
|
|
|
GLFWbool _glfwInitWGL(void)
|
2013-01-16 14:10:17 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
_glfw.wgl.instance = LoadLibraryA("opengl32.dll");
|
|
|
|
if (!_glfw.wgl.instance)
|
2013-06-26 07:57:09 -04:00
|
|
|
{
|
2015-03-10 14:51:14 -04:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to load opengl32.dll");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-06-26 07:57:09 -04:00
|
|
|
}
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
_glfw.wgl.CreateContext = (WGLCREATECONTEXT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglCreateContext");
|
|
|
|
_glfw.wgl.DeleteContext = (WGLDELETECONTEXT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglDeleteContext");
|
|
|
|
_glfw.wgl.GetProcAddress = (WGLGETPROCADDRESS_T)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglGetProcAddress");
|
|
|
|
_glfw.wgl.MakeCurrent = (WGLMAKECURRENT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglMakeCurrent");
|
|
|
|
_glfw.wgl.ShareLists = (WGLSHARELISTS_T)
|
|
|
|
GetProcAddress(_glfw.wgl.instance, "wglShareLists");
|
2015-08-11 09:49:19 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2013-01-16 14:10:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate WGL
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2015-12-03 12:16:46 -05:00
|
|
|
void _glfwTerminateWGL(void)
|
2013-01-16 14:10:17 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.instance)
|
|
|
|
FreeLibrary(_glfw.wgl.instance);
|
2013-01-16 14:10:17 -05:00
|
|
|
}
|
|
|
|
|
2013-01-15 14:00:27 -05:00
|
|
|
#define setWGLattrib(attribName, attribValue) \
|
|
|
|
{ \
|
|
|
|
attribs[index++] = attribName; \
|
|
|
|
attribs[index++] = attribValue; \
|
2013-07-15 12:37:02 -04:00
|
|
|
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:12:59 -04:00
|
|
|
// Create the OpenGL or OpenGL ES context
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2015-12-10 11:10:05 -05:00
|
|
|
GLFWbool _glfwCreateContextWGL(_GLFWwindow* window,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2013-01-15 14:00:27 -05:00
|
|
|
int attribs[40];
|
2013-06-12 17:08:01 -04:00
|
|
|
int pixelFormat = 0;
|
2012-07-31 16:48:28 -04:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2013-01-15 14:00:27 -05:00
|
|
|
HGLRC share = NULL;
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
if (ctxconfig->client == GLFW_NO_API)
|
2015-12-03 12:16:46 -05:00
|
|
|
return GLFW_TRUE;
|
|
|
|
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->share)
|
2015-11-09 10:48:55 -05:00
|
|
|
share = ctxconfig->share->context.wgl.handle;
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
window->context.wgl.dc = GetDC(window->win32.handle);
|
|
|
|
if (!window->context.wgl.dc)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2013-01-15 14:00:27 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: Failed to retrieve DC for window");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2013-05-13 09:49:59 -04:00
|
|
|
if (!choosePixelFormat(window, fbconfig, &pixelFormat))
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
if (!DescribePixelFormat(window->context.wgl.dc,
|
|
|
|
pixelFormat, sizeof(pfd), &pfd))
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: Failed to retrieve PFD for selected pixel format");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
if (!SetPixelFormat(window->context.wgl.dc, pixelFormat, &pfd))
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: Failed to set selected pixel format");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_create_context)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2015-04-10 07:18:26 -04:00
|
|
|
int index = 0, mask = 0, flags = 0;
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
2012-09-30 09:32:50 -04:00
|
|
|
{
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->forward)
|
2012-07-31 16:48:28 -04:00
|
|
|
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
2015-04-10 07:18:26 -04: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 16:48:28 -04:00
|
|
|
}
|
2012-12-13 16:43:23 -05:00
|
|
|
else
|
|
|
|
mask |= WGL_CONTEXT_ES2_PROFILE_BIT_EXT;
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2015-02-26 20:53:21 -05:00
|
|
|
if (ctxconfig->debug)
|
|
|
|
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
|
2015-08-10 06:46:14 -04:00
|
|
|
if (ctxconfig->noerror)
|
|
|
|
flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
|
2015-02-26 20:53:21 -05:00
|
|
|
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->robustness)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_create_context_robustness)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
|
2015-04-10 07:18:26 -04:00
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_NO_RESET_NOTIFICATION_ARB);
|
|
|
|
}
|
2014-03-06 14:05:32 -05:00
|
|
|
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
|
2015-04-10 07:18:26 -04:00
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_LOSE_CONTEXT_ON_RESET_ARB);
|
|
|
|
}
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
|
|
|
|
}
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2014-08-21 13:21:45 -04:00
|
|
|
if (ctxconfig->release)
|
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_context_flush_control)
|
2014-08-21 13:21:45 -04:00
|
|
|
{
|
|
|
|
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
|
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
|
|
|
|
}
|
|
|
|
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
|
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 20:51:45 -04: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 14:05:32 -05:00
|
|
|
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2014-03-06 14:05:32 -05:00
|
|
|
setWGLattrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
|
|
|
|
setWGLattrib(WGL_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
if (flags)
|
|
|
|
setWGLattrib(WGL_CONTEXT_FLAGS_ARB, flags);
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
if (mask)
|
|
|
|
setWGLattrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask);
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
setWGLattrib(0, 0);
|
2012-07-31 16:48:28 -04:00
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
window->context.wgl.handle =
|
|
|
|
_glfw.wgl.CreateContextAttribsARB(window->context.wgl.dc,
|
|
|
|
share, attribs);
|
|
|
|
if (!window->context.wgl.handle)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Failed to create OpenGL context");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-06 10:13:42 -05:00
|
|
|
window->context.wgl.handle = wglCreateContext(window->context.wgl.dc);
|
2015-11-09 10:48:55 -05:00
|
|
|
if (!window->context.wgl.handle)
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2015-03-10 14:51:14 -04:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2012-12-31 15:05:28 -05:00
|
|
|
"WGL: Failed to create OpenGL context");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
2015-12-06 10:13:42 -05:00
|
|
|
if (!wglShareLists(share, window->context.wgl.handle))
|
2012-07-31 16:48:28 -04:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: Failed to enable sharing with specified OpenGL context");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 08:43:51 -04:00
|
|
|
window->context.makeCurrent = makeContextCurrent;
|
2016-03-28 07:19:31 -04:00
|
|
|
window->context.swapBuffers = swapBuffers;
|
|
|
|
window->context.swapInterval = swapInterval;
|
|
|
|
window->context.extensionSupported = extensionSupported;
|
|
|
|
window->context.getProcAddress = getProcAddress;
|
2016-05-25 08:43:51 -04:00
|
|
|
window->context.destroy = destroyContext;
|
2016-03-28 07:19:31 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2012-07-31 16:48:28 -04:00
|
|
|
}
|
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
#undef setWGLattrib
|
|
|
|
|
|
|
|
// Analyzes the specified context for possible recreation
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2015-12-03 12:16:46 -05:00
|
|
|
int _glfwAnalyzeContextWGL(_GLFWwindow* window,
|
|
|
|
const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
GLFWbool required = GLFW_FALSE;
|
2012-12-13 16:43:23 -05:00
|
|
|
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.extensionsLoaded)
|
|
|
|
return _GLFW_RECREATION_NOT_NEEDED;
|
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
makeContextCurrent(window);
|
2015-11-09 10:51:27 -05:00
|
|
|
loadExtensions();
|
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->forward)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (!_glfw.wgl.ARB_create_context)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: A forward compatible OpenGL context requested but WGL_ARB_create_context is unavailable");
|
2012-12-13 16:43:23 -05:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->profile)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (!_glfw.wgl.ARB_create_context_profile)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
|
2012-12-13 16:43:23 -05:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
2014-08-21 13:21:45 -04:00
|
|
|
|
|
|
|
if (ctxconfig->release)
|
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_context_flush_control)
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2014-08-21 13:21:45 -04:00
|
|
|
}
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (!_glfw.wgl.ARB_create_context ||
|
|
|
|
!_glfw.wgl.ARB_create_context_profile ||
|
|
|
|
!_glfw.wgl.EXT_create_context_es2_profile)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2013-08-21 05:56:48 -04:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
2015-03-10 14:51:14 -04:00
|
|
|
"WGL: OpenGL ES requested but WGL_ARB_create_context_es2_profile is unavailable");
|
2012-12-13 16:43:23 -05:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_create_context)
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
|
2014-03-06 14:05:32 -05:00
|
|
|
if (ctxconfig->debug)
|
2012-12-13 16:43:23 -05:00
|
|
|
{
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_create_context)
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fbconfig->samples > 0)
|
|
|
|
{
|
2015-04-06 20:51:45 -04:00
|
|
|
// MSAA is not a hard constraint, so do nothing if it's not supported
|
2015-11-09 10:51:27 -05:00
|
|
|
if (_glfw.wgl.ARB_multisample && _glfw.wgl.ARB_pixel_format)
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2012-12-13 16:43:23 -05:00
|
|
|
}
|
|
|
|
|
2014-06-23 14:29:25 -04:00
|
|
|
if (fbconfig->sRGB)
|
|
|
|
{
|
2015-04-06 20:51:45 -04:00
|
|
|
// sRGB is not a hard constraint, so do nothing if it's not supported
|
2015-11-09 10:51:27 -05:00
|
|
|
if ((_glfw.wgl.ARB_framebuffer_sRGB ||
|
|
|
|
_glfw.wgl.EXT_framebuffer_sRGB) &&
|
|
|
|
_glfw.wgl.ARB_pixel_format)
|
2015-07-14 09:44:13 -04:00
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
required = GLFW_TRUE;
|
2015-07-14 09:44:13 -04:00
|
|
|
}
|
2014-06-23 14:29:25 -04:00
|
|
|
}
|
|
|
|
|
2012-12-13 16:43:23 -05:00
|
|
|
if (required)
|
|
|
|
return _GLFW_RECREATION_REQUIRED;
|
|
|
|
|
|
|
|
return _GLFW_RECREATION_NOT_NEEDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-15 16:38:14 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 18:28:08 -05:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2015-06-18 08:03:02 -04:00
|
|
|
|
2016-03-28 07:19:31 -04:00
|
|
|
if (window->context.client == GLFW_NO_API)
|
2015-06-18 08:03:02 -04:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-09 10:48:55 -05:00
|
|
|
return window->context.wgl.handle;
|
2013-01-15 16:38:14 -05:00
|
|
|
}
|
|
|
|
|