[gtk/wip.win32.fixes] GDK/Win32: Try to fix intializing GLES contexts
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip.win32.fixes] GDK/Win32: Try to fix intializing GLES contexts
- Date: Mon, 17 Jan 2022 08:14:14 +0000 (UTC)
commit c4cf2e5db952f0559c53a58aae5e09676acd5bed
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Jan 17 16:11:27 2022 +0800
GDK/Win32: Try to fix intializing GLES contexts
We are now able to create EGL contexts properly on Windows, but not GLES. This
tries to fix things by doing the following:
* Record the GL context type in a more proper fashion, using an Enum. This
makes things a bit cleaner.
* Force GLES-3.0+ contexts, since libANGLE requires this to properly work with
the shaders-its 2.0 contexts don't work well with our shaders.
gdk/win32/gdkdisplay-win32.c | 38 +++++++++++++++++++++++++++++---------
gdk/win32/gdkdisplay-win32.h | 9 ++++++++-
gdk/win32/gdkglcontext-win32-wgl.c | 9 ++++-----
3 files changed, 41 insertions(+), 15 deletions(-)
---
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index 675e1af5e2..14de69ff7b 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -1181,6 +1181,7 @@ gdk_win32_display_init_gl_backend (GdkDisplay *display,
{
gboolean result = FALSE;
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
+ GdkWin32GLType gl_type = GDK_WIN32_GL_TYPE_NONE;
if (display_win32->dummy_context_wgl.hdc == NULL)
display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
@@ -1196,20 +1197,29 @@ gdk_win32_display_init_gl_backend (GdkDisplay *display,
* usage against libANGLE EGL. EGL is used more as a compatibility layer
* on Windows rather than being a native citizen on Windows
*/
- if (_gdk_debug_flags & GDK_DEBUG_GL_EGL)
- result = gdk_display_init_egl (display,
- EGL_PLATFORM_ANGLE_ANGLE,
- display_win32->dummy_context_wgl.hdc,
- FALSE,
- error);
+ if (GDK_DEBUG_CHECK (GL_EGL) || GDK_DEBUG_CHECK (GL_GLES))
+ {
+ result = gdk_display_init_egl (display,
+ EGL_PLATFORM_ANGLE_ANGLE,
+ display_win32->dummy_context_wgl.hdc,
+ FALSE,
+ error);
+
+ if (result)
+ gl_type = GDK_WIN32_GL_TYPE_EGL;
+ }
#endif
if (!result)
{
g_clear_error (error);
result = gdk_win32_display_init_wgl (display, error);
+
+ if (result)
+ gl_type = GDK_WIN32_GL_TYPE_WGL;
}
+
#ifdef HAVE_EGL
if (!result)
{
@@ -1219,9 +1229,13 @@ gdk_win32_display_init_gl_backend (GdkDisplay *display,
display_win32->dummy_context_wgl.hdc,
TRUE,
error);
+
+ if (result)
+ gl_type = GDK_WIN32_GL_TYPE_EGL;
}
#endif
+ display_win32->gl_type = gl_type;
return result;
}
@@ -1235,11 +1249,17 @@ gdk_win32_display_init_gl (GdkDisplay *display,
if (!gdk_win32_display_init_gl_backend (display, error))
return NULL;
- if (display_win32->wgl_pixel_format != 0)
+ if (display_win32->gl_type == GDK_WIN32_GL_TYPE_WGL)
gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL, "display", display, NULL);
#ifdef HAVE_EGL
- else if (gdk_display_get_egl_display (display))
- gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL, "display", display, NULL);
+ else if (display_win32->gl_type == GDK_WIN32_GL_TYPE_EGL)
+ {
+ gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL, "display", display, NULL);
+
+ /* We want to use a GLES 3.0+ context */
+ gdk_gl_context_set_allowed_apis (gl_context, GDK_GL_API_GLES);
+ gdk_gl_context_set_required_version (gl_context, 3, 0);
+ }
#endif
g_return_val_if_fail (gl_context != NULL, NULL);
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index 3b746bbe1b..88757e03e0 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -105,6 +105,13 @@ typedef enum {
GDK_WIN32_TABLET_INPUT_API_WINPOINTER
} GdkWin32TabletInputAPI;
+typedef enum
+{
+ GDK_WIN32_GL_TYPE_NONE,
+ GDK_WIN32_GL_TYPE_WGL,
+ GDK_WIN32_GL_TYPE_EGL,
+} GdkWin32GLType;
+
typedef struct
{
HDC hdc;
@@ -125,7 +132,7 @@ struct _GdkWin32Display
/* WGL/OpenGL Items */
GdkWin32GLDummyContextWGL dummy_context_wgl;
- int wgl_pixel_format;
+ GdkWin32GLType gl_type;
guint gl_version;
GListModel *monitors;
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index d443a2c7ff..41aed57d1f 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -258,7 +258,7 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
if (!gdk_gl_backend_can_be_used (GDK_GL_WGL, error))
return FALSE;
- if (display_win32->wgl_pixel_format != 0)
+ if (display_win32->gl_type == GDK_WIN32_GL_TYPE_WGL)
return TRUE;
/* acquire and cache dummy Window (HWND & HDC) and
@@ -299,8 +299,6 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
}
}
- display_win32->wgl_pixel_format = best_idx;
-
display_win32->hasWglARBCreateContext =
epoxy_has_wgl_extension (hdc, "WGL_ARB_create_context");
display_win32->hasWglEXTSwapControl =
@@ -728,10 +726,11 @@ gdk_win32_display_get_wgl_version (GdkDisplay *display,
if (!GDK_IS_WIN32_DISPLAY (display))
return FALSE;
- display_win32 = GDK_WIN32_DISPLAY (display);
- if (display_win32->wgl_pixel_format == 0)
+ if (!gdk_win32_display_init_wgl (display, NULL))
return FALSE;
+ display_win32 = GDK_WIN32_DISPLAY (display);
+
if (major != NULL)
*major = display_win32->gl_version / 10;
if (minor != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]