[gtk/gtk4-win32-egl: 8/8] gskglcompiler.c: Force GLSL version 300 es as needed
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk4-win32-egl: 8/8] gskglcompiler.c: Force GLSL version 300 es as needed
- Date: Fri, 3 Dec 2021 02:40:15 +0000 (UTC)
commit 652ab1ac7268d75aaa0b5477e4ccb6aa8304facb
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 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";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]