]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/program.cpp
Set OpenGL debug labels on various objects loaded from Resources
[libs/gl.git] / source / core / program.cpp
index d6bd5ee88d889c4efc02a0b9ee86a8051b8ec9a2..33c53cd7755fe4f0e4d7b1bd293c2f6af30c8748 100644 (file)
@@ -13,6 +13,7 @@
 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
 #include <msp/gl/extensions/ext_gpu_shader4.h>
+#include <msp/gl/extensions/khr_debug.h>
 #include <msp/gl/extensions/nv_non_square_matrices.h>
 #include <msp/io/print.h>
 #include <msp/strings/format.h>
@@ -123,6 +124,11 @@ unsigned Program::add_stage(Stage type)
        stage_ids[type] = stage_id;
        glAttachShader(id, stage_id);
 
+#ifdef DEBUG
+       if(!debug_name.empty() && KHR_debug)
+               set_stage_debug_name(stage_id, type);
+#endif
+
        return stage_id;
 }
 
@@ -767,6 +773,33 @@ void Program::unbind()
        glUseProgram(0);
 }
 
+void Program::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+       if(KHR_debug)
+       {
+               glObjectLabel(GL_PROGRAM, id, name.size(), name.c_str());
+               for(unsigned i=0; i<MAX_STAGES; ++i)
+                       if(stage_ids[i])
+                               set_stage_debug_name(stage_ids[i], static_cast<Stage>(i));
+       }
+#else
+       (void)name;
+#endif
+}
+
+void Program::set_stage_debug_name(unsigned stage_id, Stage type)
+{
+#ifdef DEBUG
+       static const char *const suffixes[] = { " [VS]", " [GS]", " [FS]" };
+       string name = debug_name+suffixes[type];
+       glObjectLabel(GL_SHADER, stage_id, name.size(), name.c_str());
+#else
+       (void)stage_id; (void)type;
+#endif
+}
+
 
 Program::UniformInfo::UniformInfo():
        block(0),