2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2011-03-06 01:46:39 +01:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 17:34:51 +02:00
|
|
|
// Platform: Win32/WGL
|
2010-09-07 17:41:26 +02:00
|
|
|
// API version: 3.0
|
2010-09-07 17:34:51 +02:00
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// 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-08-13 16:03:44 +02:00
|
|
|
// Thread local storage attribute macro
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-08-13 16:03:44 +02:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define _GLFW_TLS __declspec(thread)
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define _GLFW_TLS __thread
|
|
|
|
#else
|
|
|
|
#define _GLFW_TLS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-08-12 14:13:18 +02:00
|
|
|
// The per-thread current context/window pointer
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-08-13 16:03:44 +02:00
|
|
|
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
|
2012-08-12 14:13:18 +02:00
|
|
|
|
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
// Initialize WGL-specific extensions
|
|
|
|
// This function is called once before initial context creation, i.e. before
|
|
|
|
// any WGL extensions could be present. This is done in order to have both
|
|
|
|
// extension variable clearing and loading in the same place, hopefully
|
|
|
|
// decreasing the possibility of forgetting to add one without the other.
|
2013-02-04 13:22:10 +01:00
|
|
|
//
|
2012-07-31 22:48:28 +02:00
|
|
|
static void initWGLExtensions(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
// This needs to include every function pointer loaded below
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.SwapIntervalEXT = NULL;
|
2013-01-15 20:00:27 +01:00
|
|
|
window->wgl.ChoosePixelFormatARB = NULL;
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.GetExtensionsStringARB = NULL;
|
|
|
|
window->wgl.GetExtensionsStringEXT = NULL;
|
|
|
|
window->wgl.CreateContextAttribsARB = NULL;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
|
|
|
// This needs to include every extension used below except for
|
|
|
|
// WGL_ARB_extensions_string and WGL_EXT_extensions_string
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_multisample = GL_FALSE;
|
|
|
|
window->wgl.ARB_framebuffer_sRGB = GL_FALSE;
|
|
|
|
window->wgl.ARB_create_context = GL_FALSE;
|
|
|
|
window->wgl.ARB_create_context_profile = GL_FALSE;
|
|
|
|
window->wgl.EXT_create_context_es2_profile = GL_FALSE;
|
|
|
|
window->wgl.ARB_create_context_robustness = GL_FALSE;
|
|
|
|
window->wgl.EXT_swap_control = GL_FALSE;
|
|
|
|
window->wgl.ARB_pixel_format = GL_FALSE;
|
|
|
|
|
|
|
|
window->wgl.GetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)
|
2012-07-31 22:48:28 +02:00
|
|
|
wglGetProcAddress("wglGetExtensionsStringEXT");
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.GetExtensionsStringEXT)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.GetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)
|
2012-07-31 22:48:28 +02:00
|
|
|
wglGetProcAddress("wglGetExtensionsStringARB");
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->wgl.GetExtensionsStringARB)
|
2012-07-31 22:48:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_multisample = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-02 16:10:00 +01:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB"))
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_framebuffer_sRGB = GL_TRUE;
|
2012-12-02 16:10:00 +01:00
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
2012-07-31 22:48:28 +02:00
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.CreateContextAttribsARB)
|
|
|
|
window->wgl.ARB_create_context = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_create_context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_profile"))
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_create_context_profile = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_create_context &&
|
|
|
|
window->wgl.ARB_create_context_profile)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_EXT_create_context_es2_profile"))
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.EXT_create_context_es2_profile = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.ARB_create_context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context_robustness"))
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_create_context_robustness = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_EXT_swap_control"))
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.SwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)
|
2012-07-31 22:48:28 +02:00
|
|
|
wglGetProcAddress("wglSwapIntervalEXT");
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->wgl.SwapIntervalEXT)
|
|
|
|
window->wgl.EXT_swap_control = GL_TRUE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format"))
|
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
window->wgl.ChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)
|
|
|
|
wglGetProcAddress("wglChoosePixelFormatARB");
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (window->wgl.ChoosePixelFormatARB)
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.ARB_pixel_format = 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
|
|
|
{
|
|
|
|
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-01-15 20:00:27 +01:00
|
|
|
#define setWGLattrib(attribName, attribValue) \
|
|
|
|
{ \
|
|
|
|
attribs[index++] = attribName; \
|
|
|
|
attribs[index++] = attribValue; \
|
|
|
|
assert(index < sizeof(attribs) / sizeof(attribs[0])); \
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-02-04 13:22:10 +01:00
|
|
|
// Prepare for creation of the OpenGL context
|
|
|
|
//
|
2013-01-15 20:00:27 +01:00
|
|
|
int _glfwCreateContext(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
int attribs[40];
|
|
|
|
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
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (wndconfig->share)
|
|
|
|
share = wndconfig->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,
|
|
|
|
"Win32: Failed to retrieve DC for window");
|
|
|
|
return GL_FALSE;
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (window->wgl.ARB_pixel_format)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
int index = 0;
|
|
|
|
UINT count;
|
|
|
|
|
|
|
|
setWGLattrib(WGL_SUPPORT_OPENGL_ARB, TRUE);
|
|
|
|
setWGLattrib(WGL_DRAW_TO_WINDOW_ARB, TRUE);
|
|
|
|
setWGLattrib(WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB);
|
|
|
|
setWGLattrib(WGL_DOUBLE_BUFFER_ARB, TRUE);
|
|
|
|
|
|
|
|
if (fbconfig->redBits)
|
|
|
|
setWGLattrib(WGL_RED_BITS_ARB, fbconfig->redBits);
|
|
|
|
if (fbconfig->greenBits)
|
|
|
|
setWGLattrib(WGL_GREEN_BITS_ARB, fbconfig->greenBits);
|
|
|
|
if (fbconfig->blueBits)
|
|
|
|
setWGLattrib(WGL_BLUE_BITS_ARB, fbconfig->blueBits);
|
|
|
|
if (fbconfig->alphaBits)
|
2013-01-16 19:49:15 +01:00
|
|
|
setWGLattrib(WGL_ALPHA_BITS_ARB, fbconfig->alphaBits);
|
2013-01-15 20:00:27 +01:00
|
|
|
|
|
|
|
if (fbconfig->depthBits)
|
|
|
|
setWGLattrib(WGL_DEPTH_BITS_ARB, fbconfig->depthBits);
|
|
|
|
if (fbconfig->stencilBits)
|
|
|
|
setWGLattrib(WGL_STENCIL_BITS_ARB, fbconfig->stencilBits);
|
|
|
|
|
|
|
|
if (fbconfig->auxBuffers)
|
|
|
|
setWGLattrib(WGL_AUX_BUFFERS_ARB, fbconfig->auxBuffers);
|
|
|
|
|
|
|
|
if (fbconfig->accumRedBits)
|
|
|
|
setWGLattrib(WGL_ACCUM_RED_BITS_ARB, fbconfig->accumRedBits);
|
|
|
|
if (fbconfig->accumGreenBits)
|
|
|
|
setWGLattrib(WGL_ACCUM_GREEN_BITS_ARB, fbconfig->accumGreenBits);
|
|
|
|
if (fbconfig->accumBlueBits)
|
|
|
|
setWGLattrib(WGL_ACCUM_BLUE_BITS_ARB, fbconfig->accumBlueBits);
|
|
|
|
if (fbconfig->accumAlphaBits)
|
|
|
|
setWGLattrib(WGL_ACCUM_BLUE_BITS_ARB, fbconfig->accumAlphaBits);
|
|
|
|
|
|
|
|
if (fbconfig->stereo)
|
|
|
|
setWGLattrib(WGL_STEREO_ARB, TRUE);
|
|
|
|
|
|
|
|
if (window->wgl.ARB_multisample)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
if (fbconfig->samples)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
setWGLattrib(WGL_SAMPLE_BUFFERS_ARB, 1);
|
|
|
|
setWGLattrib(WGL_SAMPLES_ARB, fbconfig->samples);
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (window->wgl.ARB_framebuffer_sRGB)
|
|
|
|
{
|
|
|
|
if (fbconfig->sRGB)
|
|
|
|
setWGLattrib(WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE);
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
setWGLattrib(0, 0);
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (!window->wgl.ChoosePixelFormatARB(window->wgl.dc,
|
|
|
|
attribs,
|
|
|
|
NULL,
|
|
|
|
1,
|
|
|
|
&pixelFormat,
|
|
|
|
&count))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to find a suitable pixel format");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2012-07-31 22:48:28 +02:00
|
|
|
}
|
2013-01-15 20:00:27 +01:00
|
|
|
else
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2013-01-15 20:00:27 +01:00
|
|
|
ZeroMemory(&pfd, sizeof(pfd));
|
|
|
|
pfd.nSize = sizeof(pfd);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
|
|
|
|
pfd.dwFlags |= PFD_DRAW_TO_WINDOW |
|
|
|
|
PFD_SUPPORT_OPENGL |
|
|
|
|
PFD_DOUBLEBUFFER;
|
|
|
|
|
|
|
|
if (fbconfig->stereo)
|
|
|
|
pfd.dwFlags |= PFD_STEREO;
|
|
|
|
|
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = fbconfig->redBits +
|
|
|
|
fbconfig->greenBits +
|
|
|
|
fbconfig->blueBits;
|
|
|
|
pfd.cAlphaBits = fbconfig->alphaBits;
|
|
|
|
pfd.cAccumBits = fbconfig->accumRedBits +
|
|
|
|
fbconfig->accumGreenBits +
|
|
|
|
fbconfig->accumBlueBits;
|
|
|
|
pfd.cDepthBits = fbconfig->depthBits;
|
|
|
|
pfd.cStencilBits = fbconfig->stencilBits;
|
|
|
|
pfd.cAuxBuffers = fbconfig->auxBuffers;
|
|
|
|
|
|
|
|
pixelFormat = ChoosePixelFormat(window->wgl.dc, &pfd);
|
2013-01-16 06:10:09 +01:00
|
|
|
if (!pixelFormat)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to find a suitable pixel format");
|
|
|
|
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,
|
|
|
|
"Win32: Failed to retrieve PFD for selected pixel "
|
|
|
|
"format");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-15 20:00:27 +01:00
|
|
|
if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
|
|
|
|
(pfd.dwFlags & PFD_GENERIC_FORMAT))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to find an accelerated pixel format");
|
|
|
|
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,
|
|
|
|
"Win32: 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
|
|
|
{
|
2012-12-13 22:43:23 +01:00
|
|
|
int index = 0, mask = 0, flags = 0, strategy = 0;
|
2012-07-31 22:48:28 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (wndconfig->clientAPI == GLFW_OPENGL_API)
|
2012-09-30 15:32:50 +02:00
|
|
|
{
|
2012-07-31 22:48:28 +02:00
|
|
|
if (wndconfig->glForward)
|
|
|
|
flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
|
|
|
if (wndconfig->glDebug)
|
|
|
|
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (wndconfig->glProfile)
|
|
|
|
{
|
|
|
|
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
|
|
|
|
mask |= WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
|
|
else if (wndconfig->glProfile == 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
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (wndconfig->glRobustness)
|
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
|
|
|
{
|
2012-12-13 22:43:23 +01:00
|
|
|
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
|
|
|
|
strategy = WGL_NO_RESET_NOTIFICATION_ARB;
|
|
|
|
else if (wndconfig->glRobustness == GLFW_LOSE_CONTEXT_ON_RESET)
|
|
|
|
strategy = 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
|
|
|
}
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-13 22:43:23 +01:00
|
|
|
setWGLattrib(WGL_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor);
|
|
|
|
setWGLattrib(WGL_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor);
|
|
|
|
}
|
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
|
|
|
if (strategy)
|
|
|
|
setWGLattrib(WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, strategy);
|
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
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->wgl.context = wglCreateContext(window->wgl.dc);
|
|
|
|
if (!window->wgl.context)
|
2012-07-31 22:48:28 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"WGL: Failed to create OpenGL context");
|
2012-07-31 22:48:28 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (share)
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!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,
|
|
|
|
"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
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
wglDeleteContext(window->wgl.context);
|
|
|
|
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,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
|
|
|
{
|
|
|
|
GLboolean required = GL_FALSE;
|
|
|
|
|
|
|
|
if (wndconfig->clientAPI == GLFW_OPENGL_API)
|
|
|
|
{
|
|
|
|
if (wndconfig->glForward)
|
|
|
|
{
|
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,
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glProfile)
|
|
|
|
{
|
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,
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
|
|
|
{
|
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 (wndconfig->glDebug)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
// We want FSAA, but can we get it?
|
|
|
|
// FSAA is not a hard constraint, so otherwise we just don't care
|
|
|
|
|
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
|
|
|
{
|
|
|
|
// We appear to have both the extension and the means to ask for it
|
|
|
|
required = GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2013-01-02 01:40:42 +01:00
|
|
|
wglMakeCurrent(window->wgl.dc, window->wgl.context);
|
2011-07-27 16:01:27 +02:00
|
|
|
else
|
|
|
|
wglMakeCurrent(NULL, NULL);
|
2012-08-12 14:13:18 +02:00
|
|
|
|
|
|
|
_glfwCurrentWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
|
|
|
{
|
|
|
|
return _glfwCurrentWindow;
|
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
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
SwapBuffers(window->wgl.dc);
|
2011-03-04 14:25:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval(int interval)
|
|
|
|
{
|
2012-08-12 14:13:18 +02:00
|
|
|
_GLFWwindow* window = _glfwCurrentWindow;
|
2011-03-04 14:25:12 +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
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
const GLubyte* extensions;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-08-12 14:13:18 +02:00
|
|
|
_GLFWwindow* window = _glfwCurrentWindow;
|
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
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
extensions = (GLubyte*) window->wgl.GetExtensionsStringEXT();
|
2010-09-10 22:03:36 +02:00
|
|
|
if (extensions != NULL)
|
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
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
extensions = (GLubyte*) window->wgl.GetExtensionsStringARB(window->wgl.dc);
|
2010-09-10 22:03:36 +02:00
|
|
|
if (extensions != NULL)
|
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
|
|
|
{
|
2012-06-11 13:47:06 +02:00
|
|
|
return (GLFWglproc) wglGetProcAddress(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;
|
|
|
|
}
|
|
|
|
|