From 05efc9208419fca6a147f6d798e005aba1bea17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 9 Nov 2023 12:44:17 +0800 Subject: [PATCH] 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: --- .../driver/gl/cogl-pipeline-vertend-glsl.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c index b250e46f2..6b5671b51 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c @@ -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); }