From e2d5a2139dce6a3dc0454477a9129b17d5f163d5 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Tue, 17 Oct 2017 10:34:27 +0200 Subject: [PATCH] gallium/wgl: When creating a context without SetPixelFormat() don't blindly take the pixel format reported by GDI. Instead, look for our own closest pixel format. --- src/gallium/state_trackers/wgl/stw_context.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c index 58fe3b0..861de8c 100644 --- a/src/gallium/state_trackers/wgl/stw_context.c +++ b/src/gallium/state_trackers/wgl/stw_context.c @@ -133,6 +133,22 @@ DrvCreateLayerContext(HDC hdc, INT iLayerPlane) /** + * Return the stw pixel format that most closely matches the pixel format + * on HDC. + * Used to get a pixel format when SetPixelFormat() hasn't been called before. + */ +static int +get_matching_pixel_format(HDC hdc) +{ + int iPixelFormat = GetPixelFormat(hdc); + PIXELFORMATDESCRIPTOR pfd; + + if (!iPixelFormat) return 0; + if (!DescribePixelFormat(hdc, iPixelFormat, sizeof(pfd), &pfd)) return 0; + return stw_pixelformat_choose(hdc, &pfd); +} + +/** * Called via DrvCreateContext(), DrvCreateLayerContext() and * wglCreateContextAttribsARB() to actually create a rendering context. * \param handle the desired DHGLRC handle to use for the context, or zero @@ -174,7 +190,7 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, DHGLRC hShareContext, * but not all do, and the opengl32 runtime seems to use a default * pixel format in some cases, so use that. */ - iPixelFormat = GetPixelFormat(hdc); + iPixelFormat = get_matching_pixel_format(hdc); if (!iPixelFormat) return 0; } @@ -458,7 +474,7 @@ stw_make_current(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) * pixel format in some cases, so we must create a framebuffer for * those here. */ - int iPixelFormat = GetPixelFormat(hDrawDC); + int iPixelFormat = get_matching_pixel_format(hDrawDC); if (iPixelFormat) fb = stw_framebuffer_create( hDrawDC, iPixelFormat ); if (!fb) -- 2.9.5