11 Inspector::Inspector(GlDbg &dbg)
13 CommandInterpreter &cmd_interp = dbg.get_command_interpreter();
15 cmd_interp.register_command("state", this, &Inspector::cmd_state)
16 .set_help("Inspects general GL state",
18 " Print current vertex attributes\n\n"
20 " Show current bindings\n");
22 cmd_interp.register_command("texture", this, &Inspector::cmd_texture)
23 .set_help("Inspect texture state",
25 " Lists texture objects\n\n"
27 " Print information about a texture object\n");
29 cmd_interp.register_command("buffer", this, &Inspector::cmd_buffer)
30 .set_help("Inspect buffer object state",
32 " Lists buffer objects\n\n"
34 " Print information about a buffer object\n");
37 void Inspector::decode(const char *data, unsigned len)
39 state.decode(data, len);
42 void Inspector::cmd_state(const string &args)
44 const GlState &glstate = state;
47 printf("Current vertex attributes:\n");
48 const Vector4 &color = glstate.get_color();
49 printf(" Color: [%05.3f, %05.3f, %05.3f, %05.3f]\n", color.r, color.g, color.b, color.a);
50 for(unsigned i=0; i<8; ++i)
52 const Vector4 &texcoord = glstate.get_texcoord(i);
53 printf(" TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q);
55 const Vector3 &normal = glstate.get_normal();
56 printf(" Normal: [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z);
60 printf("Current bindings:\n");
61 for(unsigned i=0; i<8; ++i)
63 printf(" Texture unit %d:\n", i);
64 const TexUnitState &unit = glstate.get_texture_unit(i);
65 string descr = unit.describe_binding(GL_TEXTURE_2D);
66 printf(" GL_TEXTURE_2D: %s\n", descr.c_str());
67 descr = unit.describe_binding(GL_TEXTURE_3D);
68 printf(" GL_TEXTURE_3D: %s\n", descr.c_str());
70 printf(" Buffers:\n");
71 const BufferState *buf = glstate.get_current_buffer(GL_ARRAY_BUFFER);
72 printf(" GL_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0));
73 buf = glstate.get_current_buffer(GL_ELEMENT_ARRAY_BUFFER);
74 printf(" GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0));
77 throw runtime_error("Invalid or missing argument");
80 void Inspector::cmd_texture(const string &args)
84 const map<unsigned, TextureState> &textures = state.get_textures();
85 printf("%d texture objects:\n", textures.size());
86 for(map<unsigned, TextureState>::const_iterator i = textures.begin(); i!=textures.end(); ++i)
88 const TextureState &tex = i->second;
89 string descr = tex.describe();
90 printf(" %d: %s, %d images\n", i->first, descr.c_str(), tex.images.size());
96 unsigned id = strtoul(args.c_str(), &end, 0);
98 throw runtime_error("Invalid texture id");
100 const TextureState &tex = state.get_texture(id);
101 printf("Texture object %d\n", id);
102 printf(" Target: %s\n", describe_enum(tex.target, "TextureTarget"));
103 printf(" Images:\n");
104 for(unsigned i=0; i<tex.images.size(); ++i)
106 string descr = tex.images[i].describe();
107 printf(" Level %2d: %s\n", i, descr.c_str());
109 printf(" Min. filter: %s\n", describe_enum(tex.min_filter, "TextureMinFilter"));
110 printf(" Mag. filter: %s\n", describe_enum(tex.mag_filter, "TextureMagFilter"));
111 printf(" Wrap modes: S=%s / T=%s / R=%s\n", describe_enum(tex.wrap_s, "TextureWrapMode"),
112 describe_enum(tex.wrap_t, "TextureWrapMode"), describe_enum(tex.wrap_r, "TextureWrapMode"));
113 printf(" Compare mode: %s\n", describe_enum(tex.compare_mode, ""));
114 printf(" Compare func: %s\n", describe_enum(tex.compare_func, "DepthFunction"));
115 printf(" Generate mipmap: %s\n", (tex.generate_mipmap ? "true" : "false"));
119 void Inspector::cmd_buffer(const string &args)
123 const GlState::BufferMap &buffers = state.get_buffers();
124 printf("%d buffers:\n", buffers.size());
125 for(GlState::BufferMap::const_iterator i=buffers.begin(); i!=buffers.end(); ++i)
127 string descr = i->second.describe();
128 printf(" %d: %s\n", i->first, descr.c_str());
134 unsigned id = strtoul(args.c_str(), &end, 0);
136 throw runtime_error("Invalid buffer id");
138 const BufferState &buf = state.get_buffer(id);
139 printf("Buffer %d:\n", id);
140 printf(" Size: %d bytes\n", buf.size);
141 printf(" Usage: %s\n", describe_enum(buf.usage, ""));
142 if(buf.content.arrays.size()==1 && buf.content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER)
144 const BufferContent::Array &array = buf.content.arrays.front();
145 printf(" Arrays:\n");
146 printf(" 0: Element indices, 1 %s\n", describe_enum(array.type, "DataType"));
149 unsigned width = 1+buf.content.stride*2;
151 snprintf(fmt, sizeof(fmt), " %%%du", width);
152 unsigned n_elems = buf.size/buf.content.stride;
154 const char *ptr = buf.data;
155 for(unsigned i=0; i<n_elems; ++i)
160 if(array.type==GL_UNSIGNED_BYTE)
161 line += strformat(fmt, *(reinterpret_cast<const unsigned char *>(ptr)+i));
162 else if(array.type==GL_UNSIGNED_SHORT)
163 line += strformat(fmt, *(reinterpret_cast<const unsigned short *>(ptr)+i));
164 else if(array.type==GL_UNSIGNED_INT)
165 line += strformat(fmt, *(reinterpret_cast<const unsigned *>(ptr)+i));
167 if(line.size()+1+width>79)
169 printf("%s\n", line.c_str());
175 printf("%s\n", line.c_str());
177 else if(buf.content.stride)
179 printf(" Stride: %d bytes\n", buf.content.stride);
181 printf(" Arrays:\n");
182 const vector<BufferContent::Array> &arrays = buf.content.arrays;
183 for(vector<BufferContent::Array>::const_iterator i=arrays.begin(); i!=arrays.end(); ++i)
186 printf(" %2d: %s, %d %s\n", i->offset,
187 describe_enum(i->kind, ""), i->size, describe_enum(i->type, "DataType"));
189 printf(" %2d: Attrib %d, %d %s\n", i->offset,
190 i->index, i->size, describe_enum(i->type, "DataType"));
195 for(vector<BufferContent::Array>::const_iterator i=arrays.begin(); i!=arrays.end(); ++i)
201 if(i->kind==GL_VERTEX_ARRAY)
203 else if(i->kind==GL_NORMAL_ARRAY)
205 else if(i->kind==GL_COLOR_ARRAY)
207 else if(i->kind==GL_TEXTURE_COORD_ARRAY)
217 label = strformat("A %d", i->index);
219 label = strformat("Attrib %d", i->index);
222 unsigned width = i->size;
223 if(i->type==GL_FLOAT)
225 else if(i->type==GL_UNSIGNED_BYTE)
229 header.append((width-label.size())/2, ' ');
231 header.append((width-label.size()+1)/2, ' ');
233 printf(" %s\n", header.c_str());
235 unsigned n_verts = buf.size/buf.content.stride;
236 for(unsigned i=0; i<n_verts; ++i)
238 const char *vertex = buf.data+i*buf.content.stride;
241 for(vector<BufferContent::Array>::const_iterator j=arrays.begin(); j!=arrays.end(); ++j)
246 const char *base = vertex+j->offset;
247 for(unsigned k=0; k<j->size; ++k)
249 if(j->type==GL_FLOAT)
250 line += strformat(" %5.2f", *(reinterpret_cast<const float *>(base)+k));
251 else if(j->type==GL_UNSIGNED_BYTE)
252 line += strformat(" %3u", *(reinterpret_cast<const unsigned char *>(base)+k));
256 printf("%3d:%s\n", i, line.c_str());