From 17f8a32687c040c652e6d018100bab08bb0487bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 9 Oct 2013 18:40:14 -0700 Subject: [PATCH] glstate: Dump a few object labels. --- retrace/glstate.cpp | 50 +++++++++++++++++++++++++++++++----- retrace/glstate_internal.hpp | 3 +++ retrace/glstate_params.py | 3 +++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/retrace/glstate.cpp b/retrace/glstate.cpp index a07b7f6..3a65d20 100644 --- a/retrace/glstate.cpp +++ b/retrace/glstate.cpp @@ -77,17 +77,22 @@ Context::Context(void) { glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); for (GLint i = 0; i < num_extensions; ++i) { const char *extension = (const char *)glGetStringi(GL_EXTENSIONS, i); - if (extension && - strcmp(extension, "ARB_sampler_objects")) { - ARB_sampler_objects = true; + if (extension) { + if (strcmp(extension, "GL_ARB_sampler_objects") == 0) { + ARB_sampler_objects = true; + } else if (strcmp(extension, "GL_KHR_debug") == 0) { + KHR_debug = true; + } } } } else { const char *extensions = (const char *)glGetString(GL_EXTENSIONS); - if (glws::checkExtension("ARB_sampler_objects", extensions)) { - ARB_sampler_objects = true; - } + ARB_sampler_objects = glws::checkExtension("GL_ARB_sampler_objects", extensions); + KHR_debug = glws::checkExtension("GL_KHR_debug", extensions); } + } else { + const char *extensions = (const char *)glGetString(GL_EXTENSIONS); + KHR_debug = glws::checkExtension("GL_KHR_debug", extensions); } } @@ -147,6 +152,39 @@ Context::restorePixelPackState(void) { } +/** + * Dump a GL_KHR_debug object label. + */ +void +dumpObjectLabel(JSONWriter &json, Context &context, GLenum identifier, GLuint name) +{ + if (!name) { + return; + } + + if (!context.KHR_debug) { + return; + } + + GLsizei length = 0; + glGetObjectLabel(identifier, name, 0, &length, NULL); + if (!length) { + return; + } + + char *label = (char *)malloc(length); + if (!label) { + return; + } + + glGetObjectLabel(identifier, name, length, NULL, label); + + json.writeStringMember("GL_OBJECT_LABEL", label); + + free(label); +} + + static const GLenum bindings[] = { GL_DRAW_BUFFER, GL_READ_BUFFER, diff --git a/retrace/glstate_internal.hpp b/retrace/glstate_internal.hpp index 942c3a6..0fd378b 100644 --- a/retrace/glstate_internal.hpp +++ b/retrace/glstate_internal.hpp @@ -42,6 +42,7 @@ struct Context bool ARB_draw_buffers; bool ARB_sampler_objects; + bool KHR_debug; Context(void); @@ -69,6 +70,8 @@ void dumpBoolean(JSONWriter &json, GLboolean value); void dumpEnum(JSONWriter &json, GLenum pname); +void dumpObjectLabel(JSONWriter &json, Context &context, GLenum identifier, GLuint name); + void dumpParameters(JSONWriter &json, Context &context); void dumpShadersUniforms(JSONWriter &json, Context &context); diff --git a/retrace/glstate_params.py b/retrace/glstate_params.py index 64ac02d..094eb6c 100644 --- a/retrace/glstate_params.py +++ b/retrace/glstate_params.py @@ -345,6 +345,7 @@ class StateDumper: print ' if (enabled || binding) {' print ' json.beginMember(enumToString(target));' print ' json.beginObject();' + print ' dumpObjectLabel(json, context, GL_TEXTURE, binding);' self.dump_atoms(glGetTexParameter, 'target') print ' if (!context.ES) {' print ' GLenum levelTarget;' @@ -432,6 +433,7 @@ class StateDumper: print ' if (sampler_binding) {' print ' json.beginMember("GL_SAMPLER");' print ' json.beginObject();' + print ' dumpObjectLabel(json, context, GL_SAMPLER, sampler_binding);' for _, _, name in glGetSamplerParameter.iter(): self.dump_atom(glGetSamplerParameter, 'sampler_binding', name) print ' json.endObject();' @@ -527,6 +529,7 @@ class StateDumper: print ' if (framebuffer) {' print ' json.beginMember("%s");' % target print ' json.beginObject();' + print ' dumpObjectLabel(json, context, GL_FRAMEBUFFER, framebuffer);' print ' for (GLint i = 0; i < max_color_attachments; ++i) {' print ' GLint color_attachment = GL_COLOR_ATTACHMENT0 + i;' print ' dumpFramebufferAttachementParameters(json, %s, color_attachment);' % target -- 2.43.0