]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/inspector.cpp
Query implementation limits on process startup
[gldbg.git] / flavors / gl / source / inspector.cpp
index f7d90f846802c72f97e63b1b6198d53127b70fd9..122c2e45298f340ddfe935a2f5e29375dcde480c 100644 (file)
@@ -1,16 +1,21 @@
 #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",
@@ -46,13 +51,40 @@ Inspector::Inspector(GlDbg &dbg)
                        "  List program objects\n\n"
                        "program ID\n"
                        "  Print information about a program object\n");
+
+       decoder->gldBreak = gldBreak;
 }
 
 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 +109,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);
@@ -88,7 +121,8 @@ void Inspector::cmd_state(const string &args)
        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);
@@ -104,7 +138,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)