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.
This commit is contained in:
Chun-wei Fan 2024-02-17 09:17:34 +08:00
parent 7477e8626d
commit 54a86a2a7e
2 changed files with 21 additions and 6 deletions

View File

@ -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;

View File

@ -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,