X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=flavors%2Fgl%2Fsource%2Finspector.cpp;h=f7d90f846802c72f97e63b1b6198d53127b70fd9;hb=90368e53a94c6fa68cb678a1a03a9da7bf0c7dd8;hp=bbdcfedbf1f6054b778bcaf6c37bb79efa54510e;hpb=81f1ddee977603293d0c5710f2db69130dac6a96;p=gldbg.git diff --git a/flavors/gl/source/inspector.cpp b/flavors/gl/source/inspector.cpp index bbdcfed..f7d90f8 100644 --- a/flavors/gl/source/inspector.cpp +++ b/flavors/gl/source/inspector.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2011 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - #include #include #include @@ -39,6 +32,20 @@ Inspector::Inspector(GlDbg &dbg) " Lists buffer objects\n\n" "buffer ID\n" " Print information about a buffer object\n"); + + cmd_interp.register_command("shader", this, &Inspector::cmd_shader) + .set_help("Inspect shader object state", + "shader\n" + " List shader objects\n\n" + "shader ID\n" + " Print information about a shader object\n"); + + cmd_interp.register_command("program", this, &Inspector::cmd_program) + .set_help("Inspect program object state", + "program\n" + " List program objects\n\n" + "program ID\n" + " Print information about a program object\n"); } void Inspector::decode(const char *data, unsigned len) @@ -46,6 +53,22 @@ void Inspector::decode(const char *data, unsigned len) state.decode(data, len); } +void Inspector::print_indented(const string &str, unsigned indent) +{ + string spaces(indent, ' '); + string::size_type start = 0; + while(1) + { + string::size_type newline = str.find('\n', start); + string line = str.substr(start, newline-start); + if(newline!=string::npos || !line.empty()) + printf("%s%s\n", spaces.c_str(), line.c_str()); + if(newline==string::npos) + break; + start = newline+1; + } +} + void Inspector::cmd_state(const string &args) { const GlState &glstate = state; @@ -79,6 +102,14 @@ void Inspector::cmd_state(const string &args) printf(" GL_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0)); buf = glstate.get_current_buffer(GL_ELEMENT_ARRAY_BUFFER); printf(" GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0)); + buf = glstate.get_current_buffer(GL_UNIFORM_BUFFER); + printf(" GL_UNIFORM_BUFFER: %d\n", (buf ? buf->id : 0)); + for(unsigned i=0; i<64; ++i) + { + const BufferBindingState &binding = glstate.get_buffer_binding(GL_UNIFORM_BUFFER, i); + if(binding.buffer) + printf(" %d: %d (%d bytes at %d)\n", i, binding.buffer->id, binding.size, binding.offset); + } } else throw runtime_error("Invalid or missing argument"); @@ -265,3 +296,86 @@ void Inspector::cmd_buffer(const string &args) } } } + +void Inspector::cmd_shader(const string &args) +{ + if(args.empty()) + { + const GlState::ShaderMap &shaders = state.get_shaders(); + printf("%d shader objects:\n", shaders.size()); + for(GlState::ShaderMap::const_iterator i=shaders.begin(); i!=shaders.end(); ++i) + { + string descr = i->second.describe(); + printf(" %d: %s\n", i->first, descr.c_str()); + } + } + else + { + char *end = 0; + unsigned id = strtoul(args.c_str(), &end, 0); + if(end && *end) + throw runtime_error("Invalid shader id"); + + const ShaderState &shader = state.get_shader(id); + printf("Shader %d:\n", shader.id); + printf(" Type: %s\n", describe_enum(shader.type, "")); + unsigned n = 0; + for(vector::const_iterator i=shader.source.begin(); i!=shader.source.end(); ++i, ++n) + { + printf(" Source string %d:\n", n); + print_indented(*i, 4); + } + if(shader.source_changed) + printf(" Source changed since last compile\n"); + printf(" Compile status: %d\n", shader.compile_status); + if(shader.info_log.empty()) + printf(" Info log is empty\n"); + else + { + printf(" Info log:\n"); + print_indented(shader.info_log, 4); + } + if(shader.pending_delete) + printf(" Pending deletion\n"); + } +} + +void Inspector::cmd_program(const std::string &args) +{ + if(args.empty()) + { + const GlState::ProgramMap &programs = state.get_programs(); + printf("%d program objects:\n", programs.size()); + for(GlState::ProgramMap::const_iterator i=programs.begin(); i!=programs.end(); ++i) + { + string descr = i->second.describe(); + printf(" %d: %s\n", i->first, descr.c_str()); + } + } + else + { + char *end = 0; + unsigned id = strtoul(args.c_str(), &end, 0); + if(end && *end) + throw runtime_error("Invalid program id"); + + const ProgramState &program = state.get_program(id); + printf("Program %d:\n", program.id); + printf(" Attached shaders:\n"); + for(vector::const_iterator i=program.shaders.begin(); i!=program.shaders.end(); ++i) + { + string descr = (*i)->describe(); + printf(" %d: %s\n", (*i)->id, descr.c_str()); + } + if(program.shaders_changed) + printf(" Shaders changed since last compile\n"); + printf(" Link status: %d\n", program.link_status); + if(program.info_log.empty()) + printf(" Info log is empty\n"); + else + { + printf(" Info log:\n"); + print_indented(program.info_log, 4); + } + } +}