38static int findPixelFormatAttribValue(
const int* attribs,
45 for (i = 0; i < attribCount; i++)
47 if (attribs[i] == attrib)
52 "WGL: Unknown pixel format attribute requested");
58 assert((size_t) attribCount < sizeof(attribs) / sizeof(attribs[0])); \
59 attribs[attribCount++] = a; \
61#define findAttribValue(a) \
62 findPixelFormatAttribValue(attribs, attribCount, values, a)
72 int i, pixelFormat, nativeCount, usableCount = 0, attribCount = 0;
74 int values[
sizeof(attribs) /
sizeof(attribs[0])];
76 if (
_glfw.wgl.ARB_pixel_format)
81 1, 0, 1, &attrib, &nativeCount))
84 "WGL: Failed to retrieve pixel format attribute");
111 if (
_glfw.wgl.ARB_multisample)
116 if (
_glfw.wgl.ARB_framebuffer_sRGB ||
_glfw.wgl.EXT_framebuffer_sRGB)
121 if (
_glfw.wgl.EXT_colorspace)
127 nativeCount = DescribePixelFormat(window->
context.wgl.dc,
129 sizeof(PIXELFORMATDESCRIPTOR),
135 for (i = 0; i < nativeCount; i++)
140 if (
_glfw.wgl.ARB_pixel_format)
150 "WGL: Failed to retrieve pixel format attributes");
189 if (
_glfw.wgl.ARB_multisample)
194 if (
_glfw.wgl.ARB_framebuffer_sRGB ||
195 _glfw.wgl.EXT_framebuffer_sRGB)
203 if (
_glfw.wgl.EXT_colorspace)
214 PIXELFORMATDESCRIPTOR pfd;
216 if (!DescribePixelFormat(window->
context.wgl.dc,
218 sizeof(PIXELFORMATDESCRIPTOR),
222 "WGL: Failed to describe pixel format");
228 if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
229 !(pfd.dwFlags & PFD_SUPPORT_OPENGL))
234 if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
235 (pfd.dwFlags & PFD_GENERIC_FORMAT))
240 if (pfd.iPixelType != PFD_TYPE_RGBA)
243 if (!!(pfd.dwFlags & PFD_DOUBLEBUFFER) != fbconfig->
doublebuffer)
261 if (pfd.dwFlags & PFD_STEREO)
272 "WGL: The driver does not appear to support OpenGL");
282 "WGL: Failed to find a suitable pixel format");
288 pixelFormat = (int) closest->
handle;
295#undef findAttribValue
297static void makeContextCurrentWGL(
_GLFWwindow* window)
306 "WGL: Failed to make context current");
315 "WGL: Failed to clear current context");
335 int count = abs(window->
context.wgl.interval);
342 SwapBuffers(window->
context.wgl.dc);
345static void swapIntervalWGL(
int interval)
349 window->
context.wgl.interval = interval;
366 if (
_glfw.wgl.EXT_swap_control)
370static int extensionSupportedWGL(
const char* extension)
372 const char* extensions =
NULL;
374 if (
_glfw.wgl.GetExtensionsStringARB)
376 else if (
_glfw.wgl.GetExtensionsStringEXT)
385static GLFWglproc getProcAddressWGL(
const char* procname)
396 if (window->
context.wgl.handle)
412 PIXELFORMATDESCRIPTOR pfd;
416 if (
_glfw.wgl.instance)
419 _glfw.wgl.instance = LoadLibraryA(
"opengl32.dll");
420 if (!
_glfw.wgl.instance)
423 "WGL: Failed to load opengl32.dll");
428 GetProcAddress(
_glfw.wgl.instance,
"wglCreateContext");
430 GetProcAddress(
_glfw.wgl.instance,
"wglDeleteContext");
432 GetProcAddress(
_glfw.wgl.instance,
"wglGetProcAddress");
434 GetProcAddress(
_glfw.wgl.instance,
"wglGetCurrentDC");
436 GetProcAddress(
_glfw.wgl.instance,
"wglGetCurrentContext");
438 GetProcAddress(
_glfw.wgl.instance,
"wglMakeCurrent");
440 GetProcAddress(
_glfw.wgl.instance,
"wglShareLists");
447 dc = GetDC(
_glfw.win32.helperWindowHandle);
449 ZeroMemory(&pfd,
sizeof(pfd));
450 pfd.nSize =
sizeof(pfd);
452 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
453 pfd.iPixelType = PFD_TYPE_RGBA;
456 if (!SetPixelFormat(dc, ChoosePixelFormat(dc, &pfd), &pfd))
459 "WGL: Failed to set pixel format for dummy context");
467 "WGL: Failed to create dummy context");
477 "WGL: Failed to make dummy context current");
498 _glfw.wgl.ARB_multisample =
499 extensionSupportedWGL(
"WGL_ARB_multisample");
500 _glfw.wgl.ARB_framebuffer_sRGB =
501 extensionSupportedWGL(
"WGL_ARB_framebuffer_sRGB");
502 _glfw.wgl.EXT_framebuffer_sRGB =
503 extensionSupportedWGL(
"WGL_EXT_framebuffer_sRGB");
504 _glfw.wgl.ARB_create_context =
505 extensionSupportedWGL(
"WGL_ARB_create_context");
506 _glfw.wgl.ARB_create_context_profile =
507 extensionSupportedWGL(
"WGL_ARB_create_context_profile");
508 _glfw.wgl.EXT_create_context_es2_profile =
509 extensionSupportedWGL(
"WGL_EXT_create_context_es2_profile");
510 _glfw.wgl.ARB_create_context_robustness =
511 extensionSupportedWGL(
"WGL_ARB_create_context_robustness");
512 _glfw.wgl.ARB_create_context_no_error =
513 extensionSupportedWGL(
"WGL_ARB_create_context_no_error");
514 _glfw.wgl.EXT_swap_control =
515 extensionSupportedWGL(
"WGL_EXT_swap_control");
516 _glfw.wgl.EXT_colorspace =
517 extensionSupportedWGL(
"WGL_EXT_colorspace");
518 _glfw.wgl.ARB_pixel_format =
519 extensionSupportedWGL(
"WGL_ARB_pixel_format");
520 _glfw.wgl.ARB_context_flush_control =
521 extensionSupportedWGL(
"WGL_ARB_context_flush_control");
532 if (
_glfw.wgl.instance)
533 FreeLibrary(
_glfw.wgl.instance);
536#define setAttrib(a, v) \
538 assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
539 attribs[index++] = a; \
540 attribs[index++] = v; \
551 PIXELFORMATDESCRIPTOR pfd;
554 if (ctxconfig->
share)
557 window->
context.wgl.dc = GetDC(window->win32.handle);
561 "WGL: Failed to retrieve DC for window");
565 pixelFormat = choosePixelFormat(window, ctxconfig, fbconfig);
569 if (!DescribePixelFormat(window->
context.wgl.dc,
570 pixelFormat,
sizeof(pfd), &pfd))
573 "WGL: Failed to retrieve PFD for selected pixel format");
577 if (!SetPixelFormat(window->
context.wgl.dc, pixelFormat, &pfd))
580 "WGL: Failed to set selected pixel format");
588 if (!
_glfw.wgl.ARB_create_context)
591 "WGL: A forward compatible OpenGL context requested but WGL_ARB_create_context is unavailable");
598 if (!
_glfw.wgl.ARB_create_context_profile)
601 "WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
608 if (!
_glfw.wgl.ARB_create_context ||
609 !
_glfw.wgl.ARB_create_context_profile ||
610 !
_glfw.wgl.EXT_create_context_es2_profile)
613 "WGL: OpenGL ES requested but WGL_ARB_create_context_es2_profile is unavailable");
618 if (
_glfw.wgl.ARB_create_context)
620 int index = 0, mask = 0, flags = 0;
635 if (ctxconfig->
debug)
640 if (
_glfw.wgl.ARB_create_context_robustness)
659 if (
_glfw.wgl.ARB_context_flush_control)
676 if (
_glfw.wgl.ARB_create_context_no_error)
683 if (ctxconfig->
major != 1 || ctxconfig->
minor != 0)
699 if (!window->
context.wgl.handle)
701 const DWORD error = GetLastError();
708 "WGL: Driver does not support OpenGL version %i.%i",
715 "WGL: Driver does not support OpenGL ES version %i.%i",
723 "WGL: Driver does not support the requested OpenGL profile");
728 "WGL: The share context is not compatible with the requested context");
735 "WGL: Failed to create OpenGL context");
740 "WGL: Failed to create OpenGL ES context");
750 if (!window->
context.wgl.handle)
753 "WGL: Failed to create OpenGL context");
762 "WGL: Failed to enable sharing with specified OpenGL context");
796 return window->
context.wgl.handle;
GLFWbool _glfwStringInExtensionString(const char *string, const char *extensions)
const _GLFWfbconfig * _glfwChooseFBConfig(const _GLFWfbconfig *desired, const _GLFWfbconfig *alternatives, unsigned int count)
#define GLFW_RELEASE_BEHAVIOR_FLUSH
#define GLFW_OPENGL_COMPAT_PROFILE
#define GLFW_LOSE_CONTEXT_ON_RESET
#define GLFW_NO_RESET_NOTIFICATION
#define GLFW_OPENGL_CORE_PROFILE
#define GLFW_RELEASE_BEHAVIOR_NONE
void(* GLFWglproc)(void)
GLFW API types.
#define GLFW_FORMAT_UNAVAILABLE
The requested format is not supported or available.
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
#define GLFW_NO_WINDOW_CONTEXT
The specified window does not have an OpenGL or OpenGL ES context.
#define GLFW_VERSION_UNAVAILABLE
The requested OpenGL or OpenGL ES version is not available.
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
struct GLFWwindow GLFWwindow
Opaque window object.
void _glfwInputError(int code, const char *format,...)
void _glfwPlatformSetTls(_GLFWtls *tls, void *value)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
void * _glfwPlatformGetTls(_GLFWtls *tls)
_GLFWswapintervalfun swapInterval
_GLFWswapbuffersfun swapBuffers
_GLFWdestroycontextfun destroy
_GLFWmakecontextcurrentfun makeCurrent
_GLFWextensionsupportedfun extensionSupported
_GLFWgetprocaddressfun getProcAddress
GLFWbool _glfwCreateContextWGL(_GLFWwindow *window, const _GLFWctxconfig *ctxconfig, const _GLFWfbconfig *fbconfig)
void _glfwTerminateWGL(void)
#define findAttribValue(a)
GLFWbool _glfwInitWGL(void)
GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow *handle)
#define WGL_ACCUM_BLUE_BITS_ARB
BOOL(WINAPI * PFN_wglMakeCurrent)(HDC, HGLRC)
#define WGL_CONTEXT_MINOR_VERSION_ARB
#define WGL_STENCIL_BITS_ARB
#define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB
#define WGL_ACCELERATION_ARB
#define wglGetExtensionsStringEXT
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB
#define wglGetProcAddress
#define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB
#define WGL_BLUE_BITS_ARB
#define WGL_RED_SHIFT_ARB
#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
#define WGL_BLUE_SHIFT_ARB
#define WGL_CONTEXT_OPENGL_NO_ERROR_ARB
BOOL(WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC, int, int, UINT, const int *, int *)
BOOL(WINAPI * PFN_wglShareLists)(HGLRC, HGLRC)
#define WGL_ACCUM_GREEN_BITS_ARB
#define WGL_GREEN_BITS_ARB
#define WGL_COLORSPACE_EXT
#define WGL_ALPHA_BITS_ARB
#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT
#define WGL_CONTEXT_MAJOR_VERSION_ARB
const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC)
BOOL(WINAPI * PFN_wglDeleteContext)(HGLRC)
#define WGL_CONTEXT_PROFILE_MASK_ARB
#define ERROR_INVALID_PROFILE_ARB
#define WGL_GREEN_SHIFT_ARB
#define WGL_NO_ACCELERATION_ARB
#define WGL_PIXEL_TYPE_ARB
#define WGL_DEPTH_BITS_ARB
#define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB
#define wglSwapIntervalEXT
#define WGL_CONTEXT_DEBUG_BIT_ARB
#define WGL_DOUBLE_BUFFER_ARB
#define wglGetPixelFormatAttribivARB
BOOL(WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int)
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB
#define WGL_DRAW_TO_WINDOW_ARB
#define WGL_TYPE_RGBA_ARB
#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB
#define WGL_ALPHA_SHIFT_ARB
#define ERROR_INVALID_VERSION_ARB
#define WGL_CONTEXT_FLAGS_ARB
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
const char *(WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void)
HGLRC(WINAPI * PFN_wglGetCurrentContext)(void)
HDC(WINAPI * PFN_wglGetCurrentDC)(void)
#define WGL_LOSE_CONTEXT_ON_RESET_ARB
#define WGL_NUMBER_PIXEL_FORMATS_ARB
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
#define WGL_NO_RESET_NOTIFICATION_ARB
#define WGL_ACCUM_RED_BITS_ARB
HGLRC(WINAPI * PFN_wglCreateContext)(HDC)
#define wglCreateContextAttribsARB
HGLRC(WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int *)
#define WGL_AUX_BUFFERS_ARB
#define wglGetExtensionsStringARB
#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB
#define WGL_ACCUM_BITS_ARB
#define WGL_ACCUM_ALPHA_BITS_ARB
#define wglGetCurrentContext
#define WGL_COLORSPACE_SRGB_EXT
#define WGL_SUPPORT_OPENGL_ARB
PROC(WINAPI * PFN_wglGetProcAddress)(LPCSTR)
void _glfwInputErrorWin32(int error, const char *description)