]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/inspector.cpp
Fix several problems reported by valgrind
[gldbg.git] / flavors / gl / source / inspector.cpp
index f7d90f846802c72f97e63b1b6198d53127b70fd9..6ff3f7033fa86180b2317f85f2e2d6a443f5800b 100644 (file)
@@ -1,21 +1,28 @@
 #include <stdexcept>
 #include <cstdio>
 #include <cstdlib>
+#include "breakpoint.h"
 #include "enums.h"
+#include "functions.h"
 #include "gldbg.h"
 #include "inspector.h"
 #include "strformat.h"
 
 using namespace std;
 
-Inspector::Inspector(GlDbg &dbg)
+Inspector::Inspector(GlDbg &d):
+       gldbg(d),
+       decoder(gldecoder_new(this, NULL)),
+       query_state(0)
 {
-       CommandInterpreter &cmd_interp = dbg.get_command_interpreter();
+       CommandInterpreter &cmd_interp = gldbg.get_command_interpreter();
 
        cmd_interp.register_command("state", this, &Inspector::cmd_state)
                .set_help("Inspects general GL state",
                        "state vertex\n"
                        "  Print current vertex attributes\n\n"
+                       "state array\n"
+                       "  Show current vertex arrays\n\n"
                        "state bind\n"
                        "  Show current bindings\n");
 
@@ -46,13 +53,45 @@ Inspector::Inspector(GlDbg &dbg)
                        "  List program objects\n\n"
                        "program ID\n"
                        "  Print information about a program object\n");
+
+       decoder->gldBreak = gldBreak;
+}
+
+Inspector::~Inspector()
+{
+       gldecoder_delete(decoder);
 }
 
 void Inspector::decode(const char *data, unsigned len)
 {
+       if(query_state)
+               gldecoder_decode(decoder, data, len);
        state.decode(data, len);
 }
 
+void Inspector::process_started()
+{
+       gldbg.set_breakpoint(FUNC_GLXMAKECURRENT, BREAK_RETURN, this);
+       query_state = 1;
+}
+
+void Inspector::process_stopped(int reason)
+{
+       if((reason>>8)==3 && query_state==2)
+       {
+               GlPacket *pkt = packet_begin(FUNC_GLDQUERYLIMITS);
+               gldbg.send(pkt);
+               query_state = 0;
+               gldbg.resume_from_break(this);
+       }
+}
+
+void Inspector::gldBreak(void *user_data, unsigned short func, unsigned char flag)
+{
+       if(func==FUNC_GLXMAKECURRENT && flag==BREAK_RETURN)
+               ++reinterpret_cast<Inspector *>(user_data)->query_state;
+}
+
 void Inspector::print_indented(const string &str, unsigned indent)
 {
        string spaces(indent, ' ');
@@ -77,7 +116,8 @@ void Inspector::cmd_state(const string &args)
                printf("Current vertex attributes:\n");
                const Vector4 &color = glstate.get_color();
                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)
+               unsigned count = glstate.get_max_texture_units();
+               for(unsigned i=0; i<count; ++i)
                {
                        const Vector4 &texcoord = glstate.get_texcoord(i);
                        printf("  TexCoord%d: [%05.3f, %05.3f, %05.3f, %05.3f]\n", i, texcoord.s, texcoord.t, texcoord.p, texcoord.q);
@@ -85,17 +125,44 @@ void Inspector::cmd_state(const string &args)
                const Vector3 &normal = glstate.get_normal();
                printf("  Normal:    [%05.3f, %05.3f, %05.3f]\n", normal.x, normal.y, normal.z);
        }
+       else if(args=="array")
+       {
+               printf("Current vertex arrays:\n");
+               string descr = glstate.get_array(GL_VERTEX_ARRAY).describe();
+               printf("  Vertex:    %s\n", descr.c_str());
+               descr = glstate.get_array(GL_NORMAL_ARRAY).describe();
+               printf("  Normal:    %s\n", descr.c_str());
+               descr = glstate.get_array(GL_COLOR_ARRAY).describe();
+               printf("  Color:     %s\n", descr.c_str());
+               unsigned count = glstate.get_max_texture_units();
+               for(unsigned i=0; i<count; ++i)
+               {
+                       descr = glstate.get_texture_coord_array(i).describe();
+                       printf("  TexCoord%d: %s\n", i, descr.c_str());
+               }
+               count = glstate.get_max_vertex_attribs();
+               for(unsigned i=0; i<count; ++i)
+               {
+                       descr = glstate.get_attrib_array(i).describe();
+                       printf("  Attrib%d:%s %s\n", i, (i>=10 ? " " : "  "), descr.c_str());
+               }
+       }
        else if(args=="bind")
        {
                printf("Current bindings:\n");
-               for(unsigned i=0; i<8; ++i)
+               unsigned count = glstate.get_max_texture_units();
+               for(unsigned i=0; i<count; ++i)
                {
                        printf("  Texture unit %d:\n", i);
                        const TexUnitState &unit = glstate.get_texture_unit(i);
-                       string descr = unit.describe_binding(GL_TEXTURE_2D);
-                       printf("    GL_TEXTURE_2D: %s\n", descr.c_str());
+                       string descr = unit.describe_binding(GL_TEXTURE_1D);
+                       printf("    GL_TEXTURE_1D:       %s\n", descr.c_str());
+                       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());
+                       printf("    GL_TEXTURE_3D:       %s\n", descr.c_str());
+                       descr = unit.describe_binding(GL_TEXTURE_CUBE_MAP);
+                       printf("    GL_TEXTURE_CUBE_MAP: %s\n", descr.c_str());
                }
                printf("  Buffers:\n");
                const BufferState *buf = glstate.get_current_buffer(GL_ARRAY_BUFFER);
@@ -104,7 +171,8 @@ void Inspector::cmd_state(const string &args)
                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)
+               count = glstate.get_max_uniform_buffer_bindings();
+               for(unsigned i=0; i<count; ++i)
                {
                        const BufferBindingState &binding = glstate.get_buffer_binding(GL_UNIFORM_BUFFER, i);
                        if(binding.buffer)
@@ -139,15 +207,33 @@ void Inspector::cmd_texture(const string &args)
                printf("Texture object %d\n", id);
                printf("  Target:          %s\n", describe_enum(tex.target, "TextureTarget"));
                printf("  Images:\n");
-               for(unsigned i=0; i<tex.images.size(); ++i)
+               if(tex.target==GL_TEXTURE_CUBE_MAP)
                {
-                       string descr = tex.images[i].describe();
-                       printf("    Level %2d:      %s\n", i, descr.c_str());
+                       static const char *face_labels[6] = { "+X", "-X", "+Y", "-Y", "+Z", "-Z" };
+                       for(unsigned i=0; i<6; ++i)
+                       {
+                               printf("    Face %s:\n", face_labels[i]);
+                               for(unsigned j=i; j<tex.images.size(); j+=6)
+                               {
+                                       string descr = tex.images[j].describe();
+                                       printf("      Level %2d:    %s\n", j/6, descr.c_str());
+                               }
+                       }
+               }
+               else
+               {
+                       for(unsigned i=0; i<tex.images.size(); ++i)
+                       {
+                               string descr = tex.images[i].describe();
+                               printf("    Level %2d:      %s\n", i, descr.c_str());
+                       }
                }
                printf("  Min. filter:     %s\n", describe_enum(tex.min_filter, "TextureMinFilter"));
                printf("  Mag. filter:     %s\n", describe_enum(tex.mag_filter, "TextureMagFilter"));
-               printf("  Wrap modes:      S=%s / T=%s / R=%s\n", describe_enum(tex.wrap_s, "TextureWrapMode"),
-                       describe_enum(tex.wrap_t, "TextureWrapMode"), describe_enum(tex.wrap_r, "TextureWrapMode"));
+               printf("  Wrap modes:\n");
+               printf("    S:             %s\n", describe_enum(tex.wrap_s, "TextureWrapMode"));
+               printf("    T:             %s\n", describe_enum(tex.wrap_t, "TextureWrapMode"));
+               printf("    R:             %s\n", describe_enum(tex.wrap_r, "TextureWrapMode"));
                printf("  Compare mode:    %s\n", describe_enum(tex.compare_mode, ""));
                printf("  Compare func:    %s\n", describe_enum(tex.compare_func, "DepthFunction"));
                printf("  Generate mipmap: %s\n", (tex.generate_mipmap ? "true" : "false"));