2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2014-01-22 01:32:00 +01:00
|
|
|
// GLFW 3.1 WGL - www.glfw.org
|
2010-09-07 17:34:51 +02:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// 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 16:46:29 +02:00
|
|
|
#include <stdlib.h>
|
2012-08-14 13:51:39 +02:00
|
|
|
#include <malloc.h>
|
2013-01-15 20:00:27 +01:00
|
|
|
#include <assert.h>
|
2012-08-12 16:46:29 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
// Initialize WGL-specific extensions
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-07-31 22:48:28 +02:00
|
|
|
static void initWGLExtensions(_GLFWwindow* window)
|
|
|
|
{
|
2015-05-04 19:26:01 +02:00
|
|
|
// Functions for WGL_EXT_extension_string
|
|
|
|
// NOTE: These are needed by _glfwPlatformExtensionSupported
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglGetProcAddress("wglGetExtensionsStringEXT");
|
2015-05-04 19:26:01 +02:00
|
|
|
window->wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglGetProcAddress("wglGetExtensionsStringARB");
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-05-04 19:26:01 +02:00
|
|
|
// Functions for WGL_ARB_create_context
|
|
|
|
window->wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglGetProcAddress("wglCreateContextAttribsARB");
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-05-04 19:26:01 +02:00
|
|
|
// Functions for WGL_EXT_swap_control
|
|
|
|
window->wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglGetProcAddress("wglSwapIntervalEXT");
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-05-04 19:26:01 +02:00
|
|
|
// Functions for WGL_ARB_pixel_format
|
|
|
|
window->wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglGetProcAddress("wglGetPixelFormatAttribivARB");
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2015-05-04 19:26:01 +02:00
|
|
|
// This needs to include every extension used below except for
|
|
|
|
// WGL_ARB_extensions_string and WGL_EXT_extensions_string
|
|
|
|
window->wgl.ARB_multisample =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_multisample");
|
|
|
|
window->wgl.ARB_framebuffer_sRGB =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB");
|
2015-07-14 15:44:13 +02:00
|
|
|
window->wgl.EXT_framebuffer_sRGB =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_EXT_framebuffer_sRGB");
|
2015-05-04 19:26:01 +02:00
|
|
|
window->wgl.ARB_create_context =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_create_context");
|
|
|
|
window->wgl.ARB_create_context_profile =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_create_context_profile");
|
|
|
|
window->wgl.EXT_create_context_es2_profile =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_EXT_create_context_es2_profile");
|
|
|
|
window->wgl.ARB_create_context_robustness =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness");
|
|
|
|
window->wgl.EXT_swap_control =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_EXT_swap_control");
|
|
|
|
window->wgl.ARB_pixel_format =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_pixel_format");
|
|
|
|
window->wgl.ARB_context_flush_control =
|
|
|
|
_glfwPlatformExtensionSupported("WGL_ARB_context_flush_control");
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
// Returns the specified attribute of the specified pixel format
|
|
|
|
//
|
|
|
|
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
|
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
|
2015-04-07 02:34:08 +02:00
|
|
|
assert(window->wgl.ARB_pixel_format);
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
if (!window->wgl.GetPixelFormatAttribivARB(window->wgl.dc,
|
|
|
|
pixelFormat,
|
|
|
|
0, 1, &attrib, &value))
|
|
|
|
{
|
2015-04-07 02:34:40 +02:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to retrieve pixel format attribute %i",
|
|
|
|
attrib);
|
2013-05-13 15:49:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of available and usable framebuffer configs
|
|
|
|
//
|
|
|
|
static GLboolean choosePixelFormat(_GLFWwindow* window,
|
|
|
|
const _GLFWfbconfig* desired,
|
|
|
|
int* result)
|
|
|
|
{
|
|
|
|
_GLFWfbconfig* usableConfigs;
|
|
|
|
const _GLFWfbconfig* closest;
|
|
|
|
int i, nativeCount, usableCount;
|
|
|
|
|
|
|
|
if (window->wgl.ARB_pixel_format)
|
|
|
|
{
|
|
|
|
nativeCount = getPixelFormatAttrib(window,
|
|
|
|
1,
|
|
|
|
WGL_NUMBER_PIXEL_FORMATS_ARB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeCount = DescribePixelFormat(window->wgl.dc,
|
|
|
|
1,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:54:07 +02:00
|
|
|
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
|
2013-05-13 15:49:59 +02:00
|
|
|
usableCount = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nativeCount; i++)
|
|
|
|
{
|
|
|
|
const int n = i + 1;
|
|
|
|
_GLFWfbconfig* u = usableConfigs + usableCount;
|
|
|
|
|
|
|
|
if (window->wgl.ARB_pixel_format)
|
|
|
|
{
|
2015-04-07 02:51:45 +02:00
|
|
|
// Get pixel format attributes through "modern" extension
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
if (!getPixelFormatAttrib(window, n, WGL_SUPPORT_OPENGL_ARB) ||
|
2014-04-24 19:21:10 +02:00
|
|
|
!getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB))
|
2013-05-13 15:49:59 +02: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 19:21:10 +02:00
|
|
|
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_STEREO_ARB))
|
|
|
|
u->stereo = GL_TRUE;
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB))
|
|
|
|
u->doublebuffer = GL_TRUE;
|
2013-05-13 15:49:59 +02:00
|
|
|
|
|
|
|
if (window->wgl.ARB_multisample)
|
|
|
|
u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB);
|
|
|
|
|
2015-07-14 15:44:13 +02:00
|
|
|
if (window->wgl.ARB_framebuffer_sRGB ||
|
|
|
|
window->wgl.EXT_framebuffer_sRGB)
|
2014-04-24 19:21:10 +02:00
|
|
|
{
|
|
|
|
if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB))
|
|
|
|
u->sRGB = GL_TRUE;
|
|
|
|
}
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
|
2015-04-07 02:51:45 +02:00
|
|
|
// Get pixel format attributes through legacy PFDs
|
2013-05-13 15:49:59 +02:00
|
|
|
|
|
|
|
if (!DescribePixelFormat(window->wgl.dc,
|
|
|
|
n,
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
&pfd))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
u->stereo = GL_TRUE;
|
|
|
|
if (pfd.dwFlags & PFD_DOUBLEBUFFER)
|
|
|
|
u->doublebuffer = GL_TRUE;
|
2013-05-13 15:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u->wgl = n;
|
|
|
|
usableCount++;
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:35:36 +01:00
|
|
|
if (!usableCount)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"WGL: The driver does not appear to support OpenGL");
|
|
|
|
|
|
|
|
free(usableConfigs);
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
closest = _glfwChooseFBConfig(desired, 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");
|
|
|
|
|
2013-06-13 18:29:21 +02:00
|
|
|
free(usableConfigs);
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2013-05-13 15:49:59 +02:00
|
|
|
|
2013-06-13 18:29:21 +02:00
|
|
|
*result = closest->wgl;
|
2013-05-13 15:49:59 +02:00
|
|
|
free(usableConfigs);
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-01-16 20:10:17 +01:00
|
|
|
// Initialize WGL
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2013-02-04 08:26:17 +01:00
|
|
|
int _glfwInitContextAPI(void)
|
2013-01-16 20:10:17 +01:00
|
|
|
{
|
2015-05-05 03:31:20 +02:00
|
|
|
if (!_glfwCreateContextTLS())
|
2014-03-30 14:37:20 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2014-03-06 18:30:14 +01:00
|
|
|
_glfw.wgl.opengl32.instance = LoadLibraryW(L"opengl32.dll");
|
2013-06-26 13:57:09 +02:00
|
|
|
if (!_glfw.wgl.opengl32.instance)
|
|
|
|
{
|
2015-03-10 19:51:14 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "WGL: Failed to load opengl32.dll");
|
2013-06-26 13:57:09 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw.wgl.opengl32.CreateContext = (WGLCREATECONTEXT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.opengl32.instance, "wglCreateContext");
|
|
|
|
_glfw.wgl.opengl32.DeleteContext = (WGLDELETECONTEXT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.opengl32.instance, "wglDeleteContext");
|
|
|
|
_glfw.wgl.opengl32.GetProcAddress = (WGLGETPROCADDRESS_T)
|
|
|
|
GetProcAddress(_glfw.wgl.opengl32.instance, "wglGetProcAddress");
|
|
|
|
_glfw.wgl.opengl32.MakeCurrent = (WGLMAKECURRENT_T)
|
|
|
|
GetProcAddress(_glfw.wgl.opengl32.instance, "wglMakeCurrent");
|
|
|
|
_glfw.wgl.opengl32.ShareLists = (WGLSHARELISTS_T)
|
|
|
|
GetProcAddress(_glfw.wgl.opengl32.instance, "wglShareLists");
|
|
|
|
|
|
|
|
if (!_glfw.wgl.opengl32.CreateContext ||
|
|
|
|
!_glfw.wgl.opengl32.DeleteContext ||
|
|
|
|
!_glfw.wgl.opengl32.GetProcAddress ||
|
|
|
|
!_glfw.wgl.opengl32.MakeCurrent ||
|
|
|
|
!_glfw.wgl.opengl32.ShareLists)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to load opengl32 functions");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-16 20:10:17 +01:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Terminate WGL
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2013-02-04 08:26:17 +01:00
|
|
|
void _glfwTerminateContextAPI(void)
|
2013-01-16 20:10:17 +01:00
|
|
|
{
|
2013-06-26 13:57:09 +02:00
|
|
|
if (_glfw.wgl.opengl32.instance)
|
|
|
|
FreeLibrary(_glfw.wgl.opengl32.instance);
|
2014-03-30 14:37:20 +02:00
|
|
|
|
2015-05-05 03:31:20 +02:00
|
|
|
_glfwDestroyContextTLS();
|
2013-01-16 20:10:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
#define setWGLattrib(attribName, attribValue) \
|
|
|
|
{ \
|
|
|
|
attribs[index++] = attribName; \
|
|
|
|
attribs[index++] = attribValue; \
|
2013-07-15 18:37:02 +02:00
|
|
|
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
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
|
|
|
//
|
2013-01-15 20:00:27 +01:00
|
|
|
int _glfwCreateContext(_GLFWwindow* window,
|
2014-03-06 20:05:32 +01:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2013-01-15 20:00:27 +01:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
int attribs[40];
|
2013-06-12 23:08:01 +02:00
|
|
|
int pixelFormat = 0;
|
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)
|
|
|
|
share = ctxconfig->share->wgl.context;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
window->wgl.dc = GetDC(window->win32.handle);
|
|
|
|
if (!window->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");
|
2013-01-15 20:00:27 +01:00
|
|
|
return GL_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-05-13 15:49:59 +02:00
|
|
|
if (!choosePixelFormat(window, fbconfig, &pixelFormat))
|
|
|
|
return GL_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!DescribePixelFormat(window->wgl.dc, pixelFormat, sizeof(pfd), &pfd))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: Failed to retrieve PFD for selected pixel format");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!SetPixelFormat(window->wgl.dc, pixelFormat, &pfd))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: Failed to set selected pixel format");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->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
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->api == 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
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->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
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_NO_RESET_NOTIFICATION_ARB);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
WGL_LOSE_CONTEXT_ON_RESET_ARB);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (window->wgl.ARB_context_flush_control)
|
|
|
|
{
|
|
|
|
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-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
|
|
|
{
|
2014-03-06 20:05:32 +01:00
|
|
|
setWGLattrib(WGL_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
|
|
|
|
setWGLattrib(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)
|
|
|
|
setWGLattrib(WGL_CONTEXT_FLAGS_ARB, flags);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (mask)
|
|
|
|
setWGLattrib(WGL_CONTEXT_PROFILE_MASK_ARB, mask);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
setWGLattrib(0, 0);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.context = window->wgl.CreateContextAttribsARB(window->wgl.dc,
|
2012-07-31 22:48:28 +02:00
|
|
|
share,
|
|
|
|
attribs);
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"WGL: Failed to create OpenGL context");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-11 15:49:19 +02:00
|
|
|
window->wgl.context = _glfw_wglCreateContext(window->wgl.dc);
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2015-03-10 19:51:14 +01:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2012-12-31 21:05:28 +01:00
|
|
|
"WGL: Failed to create OpenGL context");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
2015-08-11 15:49:19 +02:00
|
|
|
if (!_glfw_wglShareLists(share, window->wgl.context))
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: Failed to enable sharing with specified OpenGL context");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-12 14:13:18 +02:00
|
|
|
_glfwPlatformMakeContextCurrent(window);
|
2012-07-31 22:48:28 +02:00
|
|
|
initWGLExtensions(window);
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
#undef setWGLattrib
|
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
// Destroy the OpenGL context
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-07-31 22:48:28 +02:00
|
|
|
void _glfwDestroyContext(_GLFWwindow* window)
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglDeleteContext(window->wgl.context);
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.context = NULL;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.dc)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
ReleaseDC(window->win32.handle, window->wgl.dc);
|
|
|
|
window->wgl.dc = NULL;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
// Analyzes the specified context for possible recreation
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-12-13 22:43:23 +01:00
|
|
|
int _glfwAnalyzeContext(const _GLFWwindow* window,
|
2014-03-06 20:05:32 +01:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2012-12-13 22:43:23 +01:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
|
|
|
{
|
|
|
|
GLboolean required = GL_FALSE;
|
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->api == GLFW_OPENGL_API)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->forward)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.ARB_create_context)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: A forward compatible OpenGL context requested but WGL_ARB_create_context is unavailable");
|
2012-12-13 22:43:23 +01:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->profile)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.ARB_create_context_profile)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
|
2012-12-13 22:43:23 +01:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
2014-08-21 19:21:45 +02:00
|
|
|
|
|
|
|
if (ctxconfig->release)
|
|
|
|
{
|
|
|
|
if (window->wgl.ARB_context_flush_control)
|
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
2012-12-13 22:43:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.ARB_create_context ||
|
|
|
|
!window->wgl.ARB_create_context_profile ||
|
|
|
|
!window->wgl.EXT_create_context_es2_profile)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2013-08-21 11:56:48 +02:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
2015-03-10 19:51:14 +01:00
|
|
|
"WGL: OpenGL ES requested but WGL_ARB_create_context_es2_profile is unavailable");
|
2012-12-13 22:43:23 +01:00
|
|
|
return _GLFW_RECREATION_IMPOSSIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_create_context)
|
2012-12-13 22:43:23 +01:00
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:05:32 +01:00
|
|
|
if (ctxconfig->debug)
|
2012-12-13 22:43:23 +01:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_create_context)
|
2012-12-13 22:43:23 +01:00
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fbconfig->samples > 0)
|
|
|
|
{
|
2015-04-07 02:51:45 +02:00
|
|
|
// MSAA is not a hard constraint, so do nothing if it's not supported
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_multisample && window->wgl.ARB_pixel_format)
|
2012-12-13 22:43:23 +01:00
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-23 20:29:25 +02:00
|
|
|
if (fbconfig->sRGB)
|
|
|
|
{
|
2015-04-07 02:51:45 +02:00
|
|
|
// sRGB is not a hard constraint, so do nothing if it's not supported
|
2015-07-14 15:44:13 +02:00
|
|
|
if ((window->wgl.ARB_framebuffer_sRGB ||
|
|
|
|
window->wgl.EXT_framebuffer_sRGB) &&
|
|
|
|
window->wgl.ARB_pixel_format)
|
|
|
|
{
|
2014-06-23 20:29:25 +02:00
|
|
|
required = GL_TRUE;
|
2015-07-14 15:44:13 +02:00
|
|
|
}
|
2014-06-23 20:29:25 +02:00
|
|
|
}
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (required)
|
|
|
|
return _GLFW_RECREATION_REQUIRED;
|
|
|
|
|
|
|
|
return _GLFW_RECREATION_NOT_NEEDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-07-27 16:01:27 +02:00
|
|
|
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window)
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglMakeCurrent(window->wgl.dc, window->wgl.context);
|
2011-07-27 16:01:27 +02:00
|
|
|
else
|
2015-08-11 15:49:19 +02:00
|
|
|
_glfw_wglMakeCurrent(NULL, NULL);
|
2012-08-12 14:13:18 +02:00
|
|
|
|
2015-05-05 03:31:20 +02:00
|
|
|
_glfwSetContextTLS(window);
|
2011-07-27 16:01:27 +02:00
|
|
|
}
|
|
|
|
|
2012-08-06 18:13:37 +02:00
|
|
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
2011-03-04 14:25:12 +01:00
|
|
|
{
|
2015-05-21 14:48:11 +02:00
|
|
|
// HACK: Use DwmFlush when desktop composition is enabled
|
2015-06-15 20:19:44 +02:00
|
|
|
if (_glfwIsCompositionEnabled() && !window->monitor)
|
2015-05-21 14:48:11 +02:00
|
|
|
{
|
2015-08-27 20:25:28 +02:00
|
|
|
int count = abs(window->wgl.interval);
|
2015-05-21 14:48:11 +02:00
|
|
|
while (count--)
|
|
|
|
_glfw_DwmFlush();
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
SwapBuffers(window->wgl.dc);
|
2011-03-04 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval(int interval)
|
|
|
|
{
|
2013-04-08 03:48:39 +02:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
2011-03-04 14:25:12 +01:00
|
|
|
|
2015-05-21 14:48:11 +02:00
|
|
|
window->wgl.interval = interval;
|
|
|
|
|
|
|
|
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
|
|
|
// avoid interfering with DWM vsync
|
2015-06-15 20:19:44 +02:00
|
|
|
if (_glfwIsCompositionEnabled() && !window->monitor)
|
2015-05-21 14:48:11 +02:00
|
|
|
interval = 0;
|
2013-03-11 20:54:32 +01:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.EXT_swap_control)
|
|
|
|
window->wgl.SwapIntervalEXT(interval);
|
2011-03-04 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
int _glfwPlatformExtensionSupported(const char* extension)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-07-28 14:12:16 +02:00
|
|
|
const char* extensions;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-04-08 03:48:39 +02:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
2010-09-12 16:26:00 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.GetExtensionsStringEXT != NULL)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-07-28 14:12:16 +02:00
|
|
|
extensions = window->wgl.GetExtensionsStringEXT();
|
|
|
|
if (extensions)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.GetExtensionsStringARB != NULL)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-07-28 14:12:16 +02:00
|
|
|
extensions = window->wgl.GetExtensionsStringARB(window->wgl.dc);
|
|
|
|
if (extensions)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-05 00:16:40 +02:00
|
|
|
GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2015-08-11 15:49:19 +02:00
|
|
|
const GLFWglproc proc = (GLFWglproc) _glfw_wglGetProcAddress(procname);
|
2013-06-26 13:57:09 +02:00
|
|
|
if (proc)
|
|
|
|
return proc;
|
|
|
|
|
|
|
|
return (GLFWglproc) GetProcAddress(_glfw.wgl.opengl32.instance, procname);
|
2010-09-07 17:34:51 +02: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);
|
2013-01-15 22:38:14 +01:00
|
|
|
return window->wgl.context;
|
|
|
|
}
|
|
|
|
|