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