cogl/pipeline/glsl: Add line numbers to displayed source

When running with COGL_DEBUG=show-source include line numbers so that it
becomes easier to understand compilation errors.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3443>
This commit is contained in:
Jonas Ådahl 2023-11-09 12:44:17 +08:00 committed by Marge Bot
parent ae3a20a0a0
commit 05efc92084

View File

@ -280,21 +280,28 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE)))
{
GString *buf = g_string_new (NULL);
GString *buf;
g_auto (GStrv) lines = NULL;
int i;
g_string_append_printf (buf,
"%s shader:\n",
shader_gl_type == GL_VERTEX_SHADER ?
"vertex" : "fragment");
buf = g_string_new (NULL);
for (i = 0; i < count; i++)
if (lengths[i] != -1)
g_string_append_len (buf, strings[i], lengths[i]);
else
g_string_append (buf, strings[i]);
g_message ("%s", buf->str);
lines = g_strsplit (buf->str, "\n", 0);
g_string_free (buf, TRUE);
buf = g_string_new (NULL);
for (i = 0; lines[i]; i++)
g_string_append_printf (buf, "%4d: %s\n", i + 1, lines[i]);
g_message ("%s shader:\n%s",
shader_gl_type == GL_VERTEX_SHADER ?
"vertex" : "fragment",
buf->str);
g_string_free (buf, TRUE);
}