[gtk/wip.win32.fixes: 10/13] gskglcompiler.c: Force GLSL version 300 es as needed




commit 5e63798169fbec0f904c6f46f032d236252fff25
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Nov 23 18:22:55 2021 +0800

    gskglcompiler.c: Force GLSL version 300 es as needed
    
    For libANGLE to work with our (slightly-updated) 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 with the exception of not
    using "noperspective" in the shaders.  In order to check whether we are
    using the GLSL 300 es shaders, we look at our GL_RENDERER to see whether
    it starts with "ANGLE " for now.
    
    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 | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/gsk/gl/gskglcompiler.c b/gsk/gl/gskglcompiler.c
index e341e54c71..30f2ae585d 100644
--- a/gsk/gl/gskglcompiler.c
+++ b/gsk/gl/gskglcompiler.c
@@ -53,6 +53,7 @@ struct _GskGLCompiler
 
   guint gl3 : 1;
   guint gles : 1;
+  guint force_glsl_300es : 1;
   guint legacy : 1;
   guint debug_shaders : 1;
 };
@@ -127,6 +128,9 @@ gsk_gl_compiler_new (GskGLDriver *driver,
 
   if (gdk_gl_context_get_use_es (context))
     {
+      /* for libANGLE to work with our shaders, we must use 300 es as our shader version */
+      self->force_glsl_300es =
+        (strncmp ("ANGLE ", (const char *) glGetString (GL_RENDERER), 6) == 0);
       self->glsl_version = SHADER_VERSION_GLES;
       self->gles = TRUE;
     }
@@ -547,7 +551,10 @@ 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);
+  if (self->force_glsl_300es)
+    g_snprintf (version, sizeof version, "#version 300 es\n");
+  else
+    g_snprintf (version, sizeof version, "#version %d\n", self->glsl_version);
 
   if (self->debug_shaders)
     debug = "#define GSK_DEBUG 1\n";
@@ -556,7 +563,12 @@ gsk_gl_compiler_compile (GskGLCompiler  *self,
     legacy = "#define GSK_LEGACY 1\n";
 
   if (self->gles)
-    gles = "#define GSK_GLES 1\n";
+    {
+      if (self->force_glsl_300es)
+        gles = "#define GSK_GLES3 1\n";
+      else
+        gles = "#define GSK_GLES 1\n";
+    }
 
   if (self->gl3)
     gl3 = "#define GSK_GL3 1\n";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]