From bc788a9333cf729b5a96d84fd6c61a4539d36a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 30 Jan 2024 18:21:33 +0100 Subject: [PATCH] WGL: Fix pixel format count in a Parallels VM In a Parallels VM wglGetPixelFormatAttribivARB returns fewer pixel formats than DescribePixelFormat. This broke context creation on Windows in Parallels since the changes in 2c0f34b60f7c7a07183ed71754b0156ece3b6c1b. The previous version of the code worked accidentally. This adds a workaround by iterating through the minimum of both counts. It should have no effect when running on conforming implementations. Tested on Parallels by @ dougbinks. Closes #2191 Fixes #2406 Fixes #2467 This was adapted to 3.3-stable from 00e86d4b733103a23278fe53ce58a0d14dd47d32. --- CONTRIBUTORS.md | 2 ++ README.md | 1 + src/wgl_context.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9ba21abd..684850f7 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -45,6 +45,7 @@ video tutorials. - Bailey Cosier - Noel Cower - CuriouserThing + - Bill Currie - Jason Daly - danhambleton - Jarrod Davis @@ -162,6 +163,7 @@ video tutorials. - Martins Mozeiko - James Murphy - Julian Møller + - NateIsStalling - ndogxj - F. Nedelec - Kristian Nielsen diff --git a/README.md b/README.md index 49320508..9595a4db 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: Terminating the library before showing a window could segfault - [Wayland] Bugfix: Compilation failed on FreeBSD (#2445) - [Linux] Bugfix: `regfree´ was called on invalid data (#2464) + - [WGL] Bugfix: Context creation failed in Parallels VM (#2191,#2406,#2467) ## Contact diff --git a/src/wgl_context.c b/src/wgl_context.c index eebf6cd5..b245b292 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -80,6 +80,23 @@ static int choosePixelFormat(_GLFWwindow* window, if (_glfw.wgl.ARB_pixel_format) { + // NOTE: In a Parallels VM WGL_ARB_pixel_format returns fewer pixel formats than + // DescribePixelFormat, violating the guarantees of the extension spec + // HACK: Iterate through the minimum of both counts + + const int attrib = WGL_NUMBER_PIXEL_FORMATS_ARB; + int extensionCount; + + if (!wglGetPixelFormatAttribivARB(window->context.wgl.dc, + 1, 0, 1, &attrib, &extensionCount)) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to retrieve pixel format attribute"); + return 0; + } + + nativeCount = _glfw_min(nativeCount, extensionCount); + addAttrib(WGL_SUPPORT_OPENGL_ARB); addAttrib(WGL_DRAW_TO_WINDOW_ARB); addAttrib(WGL_PIXEL_TYPE_ARB);