]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.cpp
Set viewport and scissor before clear commands
[libs/gl.git] / source / core / buffer.cpp
1 #include <stdexcept>
2 #include <msp/strings/format.h>
3 #include "buffer.h"
4 #include "error.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 Buffer::Buffer():
12         size(0)
13 { }
14
15 void Buffer::storage(unsigned sz)
16 {
17         if(size>0)
18         {
19                 if(sz!=size)
20                         throw incompatible_data("Buffer::storage");
21                 return;
22         }
23         if(sz==0)
24                 throw invalid_argument("Buffer::storage");
25
26         size = sz;
27
28         allocate();
29 }
30
31 void Buffer::data(const void *d)
32 {
33         return sub_data(0, size, d);
34 }
35
36 void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
37 {
38         if(size==0)
39                 throw invalid_operation("Buffer::sub_data");
40
41         BufferBackend::sub_data(off, sz, d);
42 }
43
44 void Buffer::require_size(unsigned req_sz) const
45 {
46         if(size<req_sz)
47                 throw buffer_too_small(format("buffer has %d bytes; %d required", size, req_sz));
48 }
49
50 } // namespace GL
51 } // namespace Msp