3 This file is part of gldbg
4 Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
8 #include <msp/strings/formatter.h>
9 #include "arraystate.h"
10 #include "bufferstate.h"
16 BufferContent::BufferContent():
21 void BufferContent::update(const ArrayState &array)
23 if(array.stride!=stride)
26 stride = array.stride;
28 for(vector<Array>::iterator i=arrays.begin(); i!=arrays.end(); ++i)
29 if(i->kind==array.kind && i->index==array.index)
31 if(array.size!=i->size || array.type!=i->type || array.pointer!=i->offset)
43 vector<Array>::iterator place = arrays.end();
44 for(vector<Array>::iterator i=arrays.begin(); i!=arrays.end(); ++i)
45 if(i->offset>array.pointer)
51 arrays.insert(place, array);
54 string BufferContent::describe() const
60 for(vector<Array>::const_iterator i=arrays.begin(); i!=arrays.end(); ++i)
63 if(i->kind==GL_VERTEX_ARRAY)
65 else if(i->kind==GL_NORMAL_ARRAY)
67 else if(i->kind==GL_COLOR_ARRAY)
69 else if(i->kind==GL_TEXTURE_COORD_ARRAY && i->index==0)
72 char type[3] = { '?', 0, 0 };
75 else if(i->type==GL_DOUBLE)
77 else if(i->type==GL_INT || i->type==GL_UNSIGNED_INT)
79 else if(i->type==GL_SHORT || i->type==GL_UNSIGNED_SHORT)
81 else if(i->type==GL_BYTE || i->type==GL_UNSIGNED_BYTE)
84 if(i->type==GL_UNSIGNED_INT || i->type==GL_UNSIGNED_SHORT || i->type==GL_UNSIGNED_BYTE)
92 result += format("%c%d%s", kind, i->size, type);
99 BufferContent::Array::Array(const ArrayState &a):
108 BufferState::BufferState():
109 usage(GL_STATIC_DRAW),
114 void BufferState::set_data(unsigned sz, const void *ptr, GLenum use)
119 data = new char[size];
121 set_sub_data(0, size, ptr);
122 content = BufferContent();
125 void BufferState::set_sub_data(unsigned off, unsigned sz, const void *ptr)
127 if(data && off+sz<=size)
129 const char *cptr = reinterpret_cast<const char *>(ptr);
130 copy(cptr, cptr+sz, data+off);
134 string BufferState::describe() const
137 return format("%s, %d vertices (%d bytes), %s",
138 content.describe(), size/content.stride, size, describe_enum(usage, ""));
140 return format("%d bytes, %s", size, describe_enum(usage, ""));