1
0
Fork 0

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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3907>
This commit is contained in:
Sebastian Wick 2024-07-31 13:57:05 +02:00 committed by Marge Bot
parent e122943bcd
commit 94806c98bf
4 changed files with 19 additions and 16 deletions

View file

@ -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)];

View file

@ -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)

View file

@ -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;

View file

@ -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;