X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=flavors%2Fgl%2Fsource%2Finspector.cpp;h=150457eb8a87ff4750d1f3be6243242c3ac4ec35;hb=73d29911044cfffdc7edad50aeb2a8d1175ecd11;hp=87adf17f5f593918f1ce005b9ef39028576ca99f;hpb=76324b7394d25ba654e938eb33ee985532df7cc6;p=gldbg.git diff --git a/flavors/gl/source/inspector.cpp b/flavors/gl/source/inspector.cpp index 87adf17..150457e 100644 --- a/flavors/gl/source/inspector.cpp +++ b/flavors/gl/source/inspector.cpp @@ -1,17 +1,12 @@ -/* $Id$ - -This file is part of gldbg -Copyright © 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the GPL -*/ - -#include +#include +#include +#include #include "enums.h" #include "gldbg.h" #include "inspector.h" +#include "strformat.h" using namespace std; -using namespace Msp; Inspector::Inspector(GlDbg &dbg) { @@ -49,35 +44,45 @@ void Inspector::cmd_state(const string &args) const GlState &glstate = state; if(args=="vertex") { - IO::print("Current vertex attributes:\n"); + printf("Current vertex attributes:\n"); const Vector4 &color = glstate.get_color(); - IO::print(" Color: [%05.3f, %05.3f, %05.3f, %05.3f]\n", color.r, color.g, color.b, color.a); + printf(" Color: [%05.3f, %05.3f, %05.3f, %05.3f]\n", color.r, color.g, color.b, color.a); for(unsigned i=0; i<8; ++i) { const Vector4 &texcoord = glstate.get_texcoord(i); - IO::print(" TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q); + printf(" TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q); } const Vector3 &normal = glstate.get_normal(); - IO::print(" Normal: [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z); + printf(" Normal: [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z); } else if(args=="bind") { - IO::print("Current bindings:\n"); + printf("Current bindings:\n"); for(unsigned i=0; i<8; ++i) { - IO::print(" Texture unit %d:\n", i); + printf(" Texture unit %d:\n", i); const TexUnitState &unit = glstate.get_texture_unit(i); - IO::print(" GL_TEXTURE_2D: %s\n", unit.describe_binding(GL_TEXTURE_2D)); - IO::print(" GL_TEXTURE_3D: %s\n", unit.describe_binding(GL_TEXTURE_3D)); + string descr = unit.describe_binding(GL_TEXTURE_2D); + printf(" GL_TEXTURE_2D: %s\n", descr.c_str()); + descr = unit.describe_binding(GL_TEXTURE_3D); + printf(" GL_TEXTURE_3D: %s\n", descr.c_str()); } - IO::print(" Buffers:\n"); + printf(" Buffers:\n"); const BufferState *buf = glstate.get_current_buffer(GL_ARRAY_BUFFER); - IO::print(" GL_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0)); + printf(" GL_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0)); buf = glstate.get_current_buffer(GL_ELEMENT_ARRAY_BUFFER); - IO::print(" GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0)); + 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 InvalidParameterValue("Invalid or missing argument"); + throw runtime_error("Invalid or missing argument"); } void Inspector::cmd_texture(const string &args) @@ -85,32 +90,37 @@ void Inspector::cmd_texture(const string &args) if(args.empty()) { const map &textures = state.get_textures(); - IO::print("%d texture objects:\n", textures.size()); + printf("%d texture objects:\n", textures.size()); for(map::const_iterator i = textures.begin(); i!=textures.end(); ++i) { const TextureState &tex = i->second; - IO::print(" %d: %s, %d images\n", i->first, tex.describe(), tex.images.size()); + string descr = tex.describe(); + printf(" %d: %s, %d images\n", i->first, descr.c_str(), tex.images.size()); } } else { - unsigned id = lexical_cast(args); + char *end = 0; + unsigned id = strtoul(args.c_str(), &end, 0); + if(end && *end) + throw runtime_error("Invalid texture id"); + const TextureState &tex = state.get_texture(id); - IO::print("Texture object %d\n", id); - IO::print(" Target: %s\n", describe_enum(tex.target, "TextureTarget")); - IO::print(" Images:\n"); + printf("Texture object %d\n", id); + printf(" Target: %s\n", describe_enum(tex.target, "TextureTarget")); + printf(" Images:\n"); for(unsigned i=0; ifirst, i->second.describe()); + { + string descr = i->second.describe(); + printf(" %d: %s\n", i->first, descr.c_str()); + } } else { - unsigned id = lexical_cast(args); + char *end = 0; + unsigned id = strtoul(args.c_str(), &end, 0); + if(end && *end) + throw runtime_error("Invalid buffer id"); + const BufferState &buf = state.get_buffer(id); - IO::print("Buffer %d:\n", id); - IO::print(" Size: %d bytes\n", buf.size); - IO::print(" Usage: %s\n", describe_enum(buf.usage, "")); + printf("Buffer %d:\n", id); + printf(" Size: %d bytes\n", buf.size); + printf(" Usage: %s\n", describe_enum(buf.usage, "")); if(buf.content.arrays.size()==1 && buf.content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER) { const BufferContent::Array &array = buf.content.arrays.front(); - IO::print(" Arrays:\n"); - IO::print(" 0: Element indices, 1 %s\n", describe_enum(array.type, "DataType")); + printf(" Arrays:\n"); + printf(" 0: Element indices, 1 %s\n", describe_enum(array.type, "DataType")); - IO::print(" Data:\n"); + printf(" Data:\n"); unsigned width = 1+buf.content.stride*2; - string fmt = format(" %%%du", width); + char fmt[6]; + snprintf(fmt, sizeof(fmt), " %%%du", width); unsigned n_elems = buf.size/buf.content.stride; string line; const char *ptr = buf.data; @@ -148,39 +166,39 @@ void Inspector::cmd_buffer(const string &args) line = " "; if(array.type==GL_UNSIGNED_BYTE) - line += format(fmt, *(reinterpret_cast(ptr)+i)); + line += strformat(fmt, *(reinterpret_cast(ptr)+i)); else if(array.type==GL_UNSIGNED_SHORT) - line += format(fmt, *(reinterpret_cast(ptr)+i)); + line += strformat(fmt, *(reinterpret_cast(ptr)+i)); else if(array.type==GL_UNSIGNED_INT) - line += format(fmt, *(reinterpret_cast(ptr)+i)); + line += strformat(fmt, *(reinterpret_cast(ptr)+i)); if(line.size()+1+width>79) { - IO::print("%s\n", line); + printf("%s\n", line.c_str()); line.clear(); } } if(!line.empty()) - IO::print("%s\n", line); + printf("%s\n", line.c_str()); } else if(buf.content.stride) { - IO::print(" Stride: %d bytes\n", buf.content.stride); + printf(" Stride: %d bytes\n", buf.content.stride); - IO::print(" Arrays:\n"); + printf(" Arrays:\n"); const vector &arrays = buf.content.arrays; for(vector::const_iterator i=arrays.begin(); i!=arrays.end(); ++i) { if(i->kind) - IO::print(" %2d: %s, %d %s\n", i->offset, + printf(" %2d: %s, %d %s\n", i->offset, describe_enum(i->kind, ""), i->size, describe_enum(i->type, "DataType")); else - IO::print(" %2d: Attrib %d, %d %s\n", i->offset, + printf(" %2d: Attrib %d, %d %s\n", i->offset, i->index, i->size, describe_enum(i->type, "DataType")); } - IO::print(" Data:\n"); + printf(" Data:\n"); string header; for(vector::const_iterator i=arrays.begin(); i!=arrays.end(); ++i) { @@ -204,9 +222,9 @@ void Inspector::cmd_buffer(const string &args) else if(!i->kind) { if(i->size==1) - label = format("A %d", i->index); + label = strformat("A %d", i->index); else - label = format("Attrib %d", i->index); + label = strformat("Attrib %d", i->index); } unsigned width = i->size; @@ -220,7 +238,7 @@ void Inspector::cmd_buffer(const string &args) header += label; header.append((width-label.size()+1)/2, ' '); } - IO::print(" %s\n", header); + printf(" %s\n", header.c_str()); unsigned n_verts = buf.size/buf.content.stride; for(unsigned i=0; isize; ++k) { if(j->type==GL_FLOAT) - line += format(" %5.2f", *(reinterpret_cast(base)+k)); + line += strformat(" %5.2f", *(reinterpret_cast(base)+k)); else if(j->type==GL_UNSIGNED_BYTE) - line += format(" %3u", *(reinterpret_cast(base)+k)); + line += strformat(" %3u", *(reinterpret_cast(base)+k)); } } - IO::print("%3d:%s\n", i, line); + printf("%3d:%s\n", i, line.c_str()); } } }