]> git.tdb.fi Git - gldbg.git/blobdiff - source/bufferstate.cpp
Add classes to track OpenGL state and commands to inspect it
[gldbg.git] / source / bufferstate.cpp
diff --git a/source/bufferstate.cpp b/source/bufferstate.cpp
new file mode 100644 (file)
index 0000000..9b1c38f
--- /dev/null
@@ -0,0 +1,43 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <msp/strings/formatter.h>
+#include "bufferstate.h"
+#include "enums.h"
+
+using namespace std;
+using namespace Msp;
+
+BufferState::BufferState():
+       usage(GL_STATIC_DRAW),
+       size(0),
+       data(0)
+{ }
+
+void BufferState::set_data(unsigned sz, const void *ptr, GLenum use)
+{
+       usage = use;
+       size = sz;
+       delete[] data;
+       data = new char[size];
+       if(ptr)
+               set_sub_data(0, size, ptr);
+}
+
+void BufferState::set_sub_data(unsigned off, unsigned sz, const void *ptr)
+{
+       if(data && off+sz<size)
+       {
+               const char *cptr = reinterpret_cast<const char *>(ptr);
+               copy(cptr, cptr+sz, data+off);
+       }
+}
+
+string BufferState::describe() const
+{
+       return format("%d bytes, %s", size, describe_enum(usage, ""));
+}