From 94806c98bf0ca9626926f8bcc224e1416c1e5467 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 31 Jul 2024 13:57:05 +0200 Subject: [PATCH] cogl: Derive GLSL version from major, minor and GL vs GLES The GLSL version can be derived from the major and the minor, with the exception that GLSL ES versions require the "es" suffix. Part-of: --- cogl/cogl/cogl-context-private.h | 9 +------- .../driver/gl/cogl-pipeline-vertend-glsl.c | 22 ++++++++++++++----- cogl/cogl/driver/gl/gl/cogl-driver-gl.c | 2 +- cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h index d0017e676..45b641782 100644 --- a/cogl/cogl/cogl-context-private.h +++ b/cogl/cogl/cogl-context-private.h @@ -79,14 +79,7 @@ struct _CoglContext int glsl_major; int glsl_minor; - - /* This is the GLSL version that we will claim that snippets are - * written against using the #version pragma. This will be the - * largest version that is less than or equal to the version - * provided by the driver without massively altering the syntax. Eg, - * we wouldn't use version 1.3 even if it is available because that - * removes the ‘attribute’ and ‘varying’ keywords. */ - int glsl_version_to_use; + gboolean glsl_es; /* Features cache */ unsigned long features[COGL_FLAGS_N_LONGS_FOR_SIZE (_COGL_N_FEATURE_IDS)]; diff --git a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c index 299821263..1d23bbeb5 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c @@ -188,6 +188,17 @@ add_layer_fragment_boilerplate_cb (CoglPipelineLayer *layer, return TRUE; } +static char * +glsl_version_string (CoglContext *ctx) +{ + gboolean needs_es_annotation = ctx->glsl_es && ctx->glsl_major > 1; + + return g_strdup_printf ("%d%02d%s", + ctx->glsl_major, + ctx->glsl_minor, + needs_es_annotation ? " es" : ""); +} + void _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, GLuint shader_gl_handle, @@ -202,16 +213,17 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, const char **strings = g_alloca (sizeof (char *) * (count_in + 4)); GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4)); - char *version_string; + g_autofree char *glsl_version = NULL; + g_autofree char *version_string = NULL; int count = 0; - int n_layers; vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE; fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE; - version_string = g_strdup_printf ("#version %i\n\n", - ctx->glsl_version_to_use); + glsl_version = glsl_version_string (ctx); + version_string = g_strdup_printf ("#version %s\n\n", glsl_version); + strings[count] = version_string; lengths[count++] = -1; @@ -308,8 +320,6 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, GE( ctx, glShaderSource (shader_gl_handle, count, (const char **) strings, lengths) ); - - g_free (version_string); } GLuint _cogl_pipeline_vertend_glsl_get_shader (CoglPipeline *pipeline) diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c index 586d07285..3bc20aab6 100644 --- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c @@ -482,7 +482,7 @@ _cogl_driver_update_features (CoglContext *ctx, ctx->glsl_major = 1; ctx->glsl_minor = 40; - ctx->glsl_version_to_use = 140; + ctx->glsl_es = FALSE; if (!check_glsl_version (ctx, error)) return FALSE; diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index ad8fc65bd..74e635a7a 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -663,7 +663,7 @@ _cogl_driver_update_features (CoglContext *context, context->glsl_major = 1; context->glsl_minor = 0; - context->glsl_version_to_use = 100; + context->glsl_es = TRUE; if (!check_glsl_version (context, error)) return FALSE;