From 54a86a2a7e5bbe20637443fb526fbaeb4d4d5497 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Sat, 17 Feb 2024 09:17:34 +0800 Subject: [PATCH] Win32 GL: Also force not to use depth/stencil/accum bits on legacy contexts For completeness' sake, also specifiy in the PIXELFORMATDESCRIPTOR to use no depth, stencil and accum bits to initializing WGL when we can't (yet) use wglChoosePixelFormatARB(), as we must always fist have a base legacy WGL context using ChoosePixelFormat() before we can use that to use wglChoosePixelFormatARB(), or if wglChoosePixelFormatARB() is somehow not available for us. Some drivers, however, enforces enabling depth buffers, so if we can't acquire a pixel format that disables depth buffers, retry acquiring one with that, which sadly is not optimal but we must make do. Attempts to complete fix for issue #6401. --- gdk/win32/gdkdisplay-win32.h | 1 + gdk/win32/gdkglcontext-win32-wgl.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h index 1eca5f4317..0e6be8dd69 100644 --- a/gdk/win32/gdkdisplay-win32.h +++ b/gdk/win32/gdkdisplay-win32.h @@ -134,6 +134,7 @@ struct _GdkWin32Display guint hasWglEXTSwapControl : 1; guint hasWglOMLSyncControl : 1; guint hasWglARBPixelFormat : 1; + guint force_enable_depth_bits : 1; #ifdef HAVE_EGL guint hasEglKHRCreateContext : 1; diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c index 34fcca5677..e12604f3f5 100644 --- a/gdk/win32/gdkglcontext-win32-wgl.c +++ b/gdk/win32/gdkglcontext-win32-wgl.c @@ -142,8 +142,7 @@ get_wgl_pfd (HDC hdc, pfd->nSize = sizeof (PIXELFORMATDESCRIPTOR); - if (display_win32 != NULL && - display_win32->hasWglARBPixelFormat) + if (display_win32->hasWglARBPixelFormat) { UINT num_formats; int colorbits = GetDeviceCaps (hdc, BITSPIXEL); @@ -176,15 +175,18 @@ get_wgl_pfd (HDC hdc, pixelAttribs[i++] = WGL_ALPHA_BITS_ARB; pixelAttribs[i++] = 8; - pixelAttribs[i++] = WGL_DEPTH_BITS_ARB; - pixelAttribs[i++] = 0; - pixelAttribs[i++] = WGL_STENCIL_BITS_ARB; pixelAttribs[i++] = 0; pixelAttribs[i++] = WGL_ACCUM_BITS_ARB; pixelAttribs[i++] = 0; + if (!display_win32->force_enable_depth_bits) + { + pixelAttribs[i++] = WGL_DEPTH_BITS_ARB; + pixelAttribs[i++] = 0; + } + /* end of "Update PIXEL_ATTRIBUTES above if any groups are added here!" */ pixelAttribs[i++] = 0; /* end of pixelAttribs */ @@ -215,8 +217,20 @@ get_wgl_pfd (HDC hdc, pfd->cColorBits = GetDeviceCaps (hdc, BITSPIXEL); pfd->cAlphaBits = 8; pfd->iLayerType = PFD_MAIN_PLANE; + pfd->cAccumBits = 0; + pfd->cStencilBits = 0; + + if (!display_win32->force_enable_depth_bits) + pfd->cDepthBits = 0; best_pf = ChoosePixelFormat (hdc, pfd); + + /* try again if driver enforces depth buffers */ + if (best_pf == 0 && !display_win32->force_enable_depth_bits) + { + display_win32->force_enable_depth_bits = TRUE; + get_wgl_pfd (hdc, pfd, display_win32); + } } return best_pf; @@ -234,7 +248,7 @@ gdk_init_dummy_wgl_context (GdkWin32Display *display_win32) memset (&pfd, 0, sizeof (PIXELFORMATDESCRIPTOR)); - best_idx = get_wgl_pfd (display_win32->dummy_context_wgl.hdc, &pfd, NULL); + best_idx = get_wgl_pfd (display_win32->dummy_context_wgl.hdc, &pfd, display_win32); if (best_idx != 0) set_pixel_format_result = SetPixelFormat (display_win32->dummy_context_wgl.hdc,