]> git.tdb.fi Git - gldbg.git/commitdiff
Decode and display element buffer contents
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2010 08:55:09 +0000 (08:55 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2010 08:55:09 +0000 (08:55 +0000)
flavors/gl/source/bufferstate.cpp
flavors/gl/source/bufferstate.h
flavors/gl/source/glstate.cpp
flavors/gl/source/glstate.h
flavors/gl/source/inspector.cpp

index 356e82b5ac3de9469b748338d852956f010bb808..c8b9f1348e1858196be5115bb3b9e48704614680 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the GPL
 */
 
 #include <msp/strings/formatter.h>
+#include "arraysize.h"
 #include "arraystate.h"
 #include "bufferstate.h"
 #include "enums.h"
@@ -51,6 +52,27 @@ void BufferContent::update(const ArrayState &array)
        arrays.insert(place, array);
 }
 
+void BufferContent::update_elements(GLenum type)
+{
+       if(arrays.empty())
+       {
+               Array array;
+               array.kind = GL_ELEMENT_ARRAY_BUFFER;
+               array.type = type;
+               arrays.push_back(array);
+               stride = typesize(type);
+       }
+       else if(arrays.size()>1 || arrays.front().kind!=GL_ELEMENT_ARRAY_BUFFER)
+               consistent = false;
+       else
+       {
+               if(arrays.front().type!=type)
+                       consistent = false;
+               arrays.front().type = type;
+               stride = typesize(type);
+       }
+}
+
 string BufferContent::describe() const
 {
        if(arrays.empty())
@@ -68,6 +90,8 @@ string BufferContent::describe() const
                        kind = 'C';
                else if(i->kind==GL_TEXTURE_COORD_ARRAY && i->index==0)
                        kind = 'T';
+               else if(i->kind==GL_ELEMENT_ARRAY_BUFFER)
+                       kind = 'E';
 
                char type[3] = { '?', 0, 0 };
                if(i->type==GL_FLOAT)
@@ -96,6 +120,14 @@ string BufferContent::describe() const
 }
 
 
+BufferContent::Array::Array():
+       kind(GL_NONE),
+       index(0),
+       size(1),
+       type(GL_NONE),
+       offset(0)
+{ }
+
 BufferContent::Array::Array(const ArrayState &a):
        kind(a.kind),
        index(a.index),
@@ -106,6 +138,8 @@ BufferContent::Array::Array(const ArrayState &a):
 
 
 BufferState::BufferState():
+       id(0),
+       target(0),
        usage(GL_STATIC_DRAW),
        size(0),
        data(0)
@@ -134,8 +168,11 @@ void BufferState::set_sub_data(unsigned off, unsigned sz, const void *ptr)
 string BufferState::describe() const
 {
        if(content.stride)
-               return format("%s, %d vertices (%d bytes), %s",
-                       content.describe(), size/content.stride, size, describe_enum(usage, ""));
+       {
+               const char *what = (content.arrays.front().kind==GL_ELEMENT_ARRAY_BUFFER ? "indices" : "vertices");
+               return format("%s, %d %s (%d bytes), %s",
+                       content.describe(), size/content.stride, what, size, describe_enum(usage, ""));
+       }
        else
                return format("%d bytes, %s", size, describe_enum(usage, ""));
 }
index c3f504bf593ab5416bf95170a903424b69fbc5a7..5557a5669754d11eccd1e29037e27b1f3ed60b69 100644 (file)
@@ -24,6 +24,7 @@ struct BufferContent
                GLenum type;
                int offset;
 
+               Array();
                Array(const ArrayState &);
        };
 
@@ -33,6 +34,7 @@ struct BufferContent
 
        BufferContent();
        void update(const ArrayState &);
+       void update_elements(GLenum);
        std::string describe() const;
 };
 
index 1459324232f36d3b6af583bfe1def2a3e0ffb22a..e33e49019bc6f660272a20b6cedd06fccef41354 100644 (file)
@@ -127,6 +127,10 @@ GlState::GlState():
        decoder->glBufferSubDataARB = glBufferSubData;
        decoder->glDeleteBuffers = glDeleteBuffers;
        decoder->glDeleteBuffersARB = glDeleteBuffers;
+
+       decoder->glDrawElements = glDrawElements;
+       decoder->glDrawRangeElements = glDrawRangeElements;
+       decoder->glDrawRangeElementsEXT = glDrawRangeElements;
 }
 
 GlState::~GlState()
@@ -412,3 +416,15 @@ void GlState::glDeleteBuffers(void *user_data, int count, const unsigned *ids)
        for(int i=0; i<count; ++i)
                reinterpret_cast<GlState *>(user_data)->buffers.erase(ids[i]);
 }
+
+void GlState::glDrawElements(void *user_data, GLenum, int, GLenum type, const void *)
+{
+       if(BufferState *buf = reinterpret_cast<GlState *>(user_data)->element_buffer)
+               buf->content.update_elements(type);
+}
+
+void GlState::glDrawRangeElements(void *user_data, GLenum, unsigned, unsigned, int, GLenum type, const void *)
+{
+       if(BufferState *buf = reinterpret_cast<GlState *>(user_data)->element_buffer)
+               buf->content.update_elements(type);
+}
index 86cc5386ae02acbd973fab7b4743c16e3c928672..43e8f39f094f90c17745f2832d82a3c088b94982 100644 (file)
@@ -119,6 +119,9 @@ private:
        static void glBufferData(void *, GLenum, int, const void *, GLenum);
        static void glBufferSubData(void *, GLenum, int, int, const void *);
        static void glDeleteBuffers(void *, int, const unsigned *);
+
+       static void glDrawElements(void *, GLenum, int, GLenum, const void *);
+       static void glDrawRangeElements(void *, GLenum, unsigned, unsigned, int, GLenum, const void *);
 };
 
 #endif
index 912214db825e95a27dbad401e6d16de8361835a6..87adf17f5f593918f1ce005b9ef39028576ca99f 100644 (file)
@@ -130,7 +130,41 @@ void Inspector::cmd_buffer(const string &args)
                IO::print("Buffer %d:\n", id);
                IO::print("  Size:  %d bytes\n", buf.size);
                IO::print("  Usage: %s\n", describe_enum(buf.usage, ""));
-               if(buf.content.stride)
+               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"));
+
+                       IO::print("  Data:\n");
+                       unsigned width = 1+buf.content.stride*2;
+                       string fmt = format(" %%%du", width);
+                       unsigned n_elems = buf.size/buf.content.stride;
+                       string line;
+                       const char *ptr = buf.data;
+                       for(unsigned i=0; i<n_elems; ++i)
+                       {
+                               if(line.empty())
+                                       line = "   ";
+
+                               if(array.type==GL_UNSIGNED_BYTE)
+                                       line += format(fmt, *(reinterpret_cast<unsigned char *>(ptr)+i));
+                               else if(array.type==GL_UNSIGNED_SHORT)
+                                       line += format(fmt, *(reinterpret_cast<unsigned short *>(ptr)+i));
+                               else if(array.type==GL_UNSIGNED_INT)
+                                       line += format(fmt, *(reinterpret_cast<unsigned *>(ptr)+i));
+
+                               if(line.size()+1+width>79)
+                               {
+                                       IO::print("%s\n", line);
+                                       line.clear();
+                               }
+                       }
+
+                       if(!line.empty())
+                               IO::print("%s\n", line);
+               }
+               else if(buf.content.stride)
                {
                        IO::print("  Stride: %d bytes\n", buf.content.stride);