From 2de8371929419f878a04ee2682d137b9fcaf9e6e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 15 Sep 2022 17:08:10 +0900 Subject: [PATCH] Use wglGetPixelFormatAttribivARB to get pixel format count DescribePixelFormat can return a very different number of pixel formats than does wglGetPixelFormatAttribivARB: 220 vs 670 on my system (Nvidia GTX 965 M). Being different in that direction is not a problem, but if DescribePixelFormat returns more formats than wglGetPixelFormatAttribivARB, the loop will fail and terminate the context creation. --- src/wgl_context.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/wgl_context.c diff --git a/src/wgl_context.c b/src/wgl_context.c old mode 100644 new mode 100755 index 4a5e77a8..055298a1 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -72,10 +72,20 @@ static int choosePixelFormatWGL(_GLFWwindow* window, int attribs[40]; int values[sizeof(attribs) / sizeof(attribs[0])]; - nativeCount = DescribePixelFormat(window->context.wgl.dc, - 1, - sizeof(PIXELFORMATDESCRIPTOR), - NULL); + if (_glfw.wgl.ARB_pixel_format) + { + int attrib[] = { WGL_NUMBER_PIXEL_FORMATS_ARB }; + + wglGetPixelFormatAttribivARB(window->context.wgl.dc, 1, 0, + 1, attrib, &nativeCount); + } + else + { + nativeCount = DescribePixelFormat(window->context.wgl.dc, + 1, + sizeof(PIXELFORMATDESCRIPTOR), + NULL); + } if (_glfw.wgl.ARB_pixel_format) {