]> git.tdb.fi Git - gldbg.git/blob - source/bufferstate.cpp
9b1c38f4dcd95f3b801c4f76733fde3b2b39d566
[gldbg.git] / source / bufferstate.cpp
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #include <msp/strings/formatter.h>
9 #include "bufferstate.h"
10 #include "enums.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 BufferState::BufferState():
16         usage(GL_STATIC_DRAW),
17         size(0),
18         data(0)
19 { }
20
21 void BufferState::set_data(unsigned sz, const void *ptr, GLenum use)
22 {
23         usage = use;
24         size = sz;
25         delete[] data;
26         data = new char[size];
27         if(ptr)
28                 set_sub_data(0, size, ptr);
29 }
30
31 void BufferState::set_sub_data(unsigned off, unsigned sz, const void *ptr)
32 {
33         if(data && off+sz<size)
34         {
35                 const char *cptr = reinterpret_cast<const char *>(ptr);
36                 copy(cptr, cptr+sz, data+off);
37         }
38 }
39
40 string BufferState::describe() const
41 {
42         return format("%d bytes, %s", size, describe_enum(usage, ""));
43 }