#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>
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;
}
}
}
- Conditional<BindRestore> _bind(!ARB_separate_shader_objects, this);
+ if(!ARB_separate_shader_objects)
+ glUseProgram(id);
for(map<string, unsigned>::const_iterator i=transient->textures.begin(); i!=transient->textures.end(); ++i)
{
int location = get_uniform_location(i->first);
return i!=attributes.end() && i->name==name ? i->location : -1;
}
-void Program::bind() const
+void Program::set_debug_name(const string &name)
{
- if(!linked)
- throw invalid_operation("Program::bind");
-
- if(!set_current(this))
- return;
-
- glUseProgram(id);
+#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::unbind()
+void Program::set_stage_debug_name(unsigned stage_id, Stage type)
{
- if(!set_current(0))
- return;
-
- glUseProgram(0);
+#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
}