diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2021-04-29 12:04:42 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2021-04-29 12:12:01 +0800 |
commit | 66e7f3b404405cafa2e026be7273b6d280ccf88e (patch) | |
tree | 20df5cc2c10b7c79b520abd4b0265f4c33013a39 | |
parent | 604d171d5661f6eb51d385b8eb8485c96da7608b (diff) | |
download | gtk+-66e7f3b404405cafa2e026be7273b6d280ccf88e.tar.gz |
gdkglcontext-win32.c: Fix running with Mesa driversmesa.win32.fixes
Some GL drivers such as Mesa-D3D12 do not allow one to call SetPixelFormat() on
a given HDC if one pixel format has been already set for it, so first check the
HDC with GetPixelFormat() to see whether a pixel format has already been set
with the HDC, and only attempt to acquire the pixel format if one has not been
set.
This will fix running with GL/NGL on Windows using the Mesa drivers.
-rw-r--r-- | gdk/win32/gdkglcontext-win32.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/gdk/win32/gdkglcontext-win32.c b/gdk/win32/gdkglcontext-win32.c index c7e7fa3345..610711d3b8 100644 --- a/gdk/win32/gdkglcontext-win32.c +++ b/gdk/win32/gdkglcontext-win32.c @@ -712,20 +712,30 @@ _set_pixformat_for_hdc (HDC hdc, int *best_idx, GdkWin32Display *display) { - PIXELFORMATDESCRIPTOR pfd; - gboolean set_pixel_format_result = FALSE; + gboolean already_checked = TRUE; + *best_idx = GetPixelFormat (hdc); /* one is only allowed to call SetPixelFormat(), and so ChoosePixelFormat() * one single time per window HDC */ - *best_idx = _get_wgl_pfd (hdc, &pfd, display); + if (*best_idx == 0) + { + PIXELFORMATDESCRIPTOR pfd; + gboolean set_pixel_format_result = FALSE; - if (*best_idx != 0) - set_pixel_format_result = SetPixelFormat (hdc, *best_idx, &pfd); + GDK_NOTE (OPENGL, g_print ("requesting pixel format...\n")); + already_checked = FALSE; + *best_idx = _get_wgl_pfd (hdc, &pfd, display); - /* ChoosePixelFormat() or SetPixelFormat() failed, bail out */ - if (*best_idx == 0 || !set_pixel_format_result) - return FALSE; + if (*best_idx != 0) + set_pixel_format_result = SetPixelFormat (hdc, *best_idx, &pfd); + + /* ChoosePixelFormat() or SetPixelFormat() failed, bail out */ + if (*best_idx == 0 || !set_pixel_format_result) + return FALSE; + } + + GDK_NOTE (OPENGL, g_print ("%s""requested and set pixel format: %d\n", already_checked ? "already " : "", *best_idx)); return TRUE; } |