]> git.tdb.fi Git - gldbg.git/blobdiff - flavors/gl/source/inspector.cpp
Decode and display element buffer contents
[gldbg.git] / flavors / gl / source / inspector.cpp
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);