From bdf879427cdf83e55c0645bb480fa342b0b2603f Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 23 Nov 2021 16:19:34 +0800 Subject: [PATCH 1/2] gdksurface-win32.c: Call gdk_surface_set_egl_native_window() .. when creating the surface (with the HWND associated with the newly-created surface) as well as destroying the surface (with NULL, since the HWND is going to be destroyed), so that we can tie the EGL calls to the HWND that we want to do the EGL stuff. --- gdk/win32/gdksurface-win32.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index 6cfe38f679..1b4effa80f 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -638,6 +638,7 @@ _gdk_win32_display_create_surface (GdkDisplay *display, return NULL; } + gdk_surface_set_egl_native_window (surface, (void *) impl->handle); if (display_win32->tablet_input_api == GDK_WIN32_TABLET_INPUT_API_WINPOINTER) gdk_winpointer_initialize_surface (surface); @@ -693,6 +694,7 @@ gdk_win32_surface_destroy (GdkSurface *window, if (!foreign_destroy) { + gdk_surface_set_egl_native_window (window, NULL); window->destroyed = TRUE; DestroyWindow (GDK_SURFACE_HWND (window)); } From 652ab1ac7268d75aaa0b5477e4ccb6aa8304facb Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 23 Nov 2021 18:22:55 +0800 Subject: [PATCH 2/2] gskglcompiler.c: Force GLSL version 300 es as needed For libANGLE to work with our shaders, we must use "300 es" for the #version directive in our shaders, as well as using the non-legacy/ non-GLES codepath in the shaders. In order to check whether we are using the GLSL 300 es shaders, we check whether we are using a GLES 3.0+ context. As a result, make ->glsl_version a const char* and make sure the existing shader version macros are defined apprpriately, and add a new macro for the "300 es" shader version string. This will allow the gtk4 programs to run under Windows using EGL via libANGLE. Some of the GL demos won't work for now, but at least this makes things a lot better for using GL-accelerated graphics under Windows for those that want to or need to use libANGLE (such as those with graphics drivers that aren't capable of our Desktop (W)GL requirements in GTK. --- gsk/gl/gskglcompiler.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/gsk/gl/gskglcompiler.c b/gsk/gl/gskglcompiler.c index c885df8f45..ca76c60aae 100644 --- a/gsk/gl/gskglcompiler.c +++ b/gsk/gl/gskglcompiler.c @@ -28,10 +28,11 @@ #include "gskglcompilerprivate.h" #include "gskglprogramprivate.h" -#define SHADER_VERSION_GLES 100 -#define SHADER_VERSION_GL2_LEGACY 110 -#define SHADER_VERSION_GL3_LEGACY 130 -#define SHADER_VERSION_GL3 150 +#define SHADER_VERSION_GLES "100" +#define SHADER_VERSION_GLES3 "300 es" +#define SHADER_VERSION_GL2_LEGACY "110" +#define SHADER_VERSION_GL3_LEGACY "130" +#define SHADER_VERSION_GL3 "150" struct _GskGLCompiler { @@ -49,7 +50,7 @@ struct _GskGLCompiler GArray *attrib_locations; - int glsl_version; + const char *glsl_version; guint gl3 : 1; guint gles : 1; @@ -98,7 +99,7 @@ gsk_gl_compiler_class_init (GskGLCompilerClass *klass) static void gsk_gl_compiler_init (GskGLCompiler *self) { - self->glsl_version = 150; + self->glsl_version = "150"; self->attrib_locations = g_array_new (FALSE, FALSE, sizeof (GskGLProgramAttrib)); self->all_preamble = g_bytes_ref (empty_bytes); self->vertex_preamble = g_bytes_ref (empty_bytes); @@ -127,8 +128,18 @@ gsk_gl_compiler_new (GskGLDriver *driver, if (gdk_gl_context_get_use_es (context)) { - self->glsl_version = SHADER_VERSION_GLES; - self->gles = TRUE; + int maj, min; + + /* for OpenGL/ES 3.0+, use "300 es" as our shader version */ + gdk_gl_context_get_version (context, &maj, &min); + + if (maj >= 3) + self->glsl_version = SHADER_VERSION_GLES3; + else + { + self->glsl_version = SHADER_VERSION_GLES; + self->gles = TRUE; + } } else if (gdk_gl_context_is_legacy (context)) { @@ -546,7 +557,7 @@ gsk_gl_compiler_compile (GskGLCompiler *self, gsk_gl_command_queue_make_current (self->driver->command_queue); - g_snprintf (version, sizeof version, "#version %d\n", self->glsl_version); + g_snprintf (version, sizeof version, "#version %s\n", self->glsl_version); if (self->debug_shaders) debug = "#define GSK_DEBUG 1\n";