]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.cpp
Move the Resource function override of Texture classes into backend
[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 void Buffer::storage(size_t sz)
12 {
13         if(size>0)
14         {
15                 if(sz!=size)
16                         throw incompatible_data("Buffer::storage");
17                 return;
18         }
19         if(sz==0)
20                 throw invalid_argument("Buffer::storage");
21
22         size = sz;
23
24         allocate();
25 }
26
27 void Buffer::data(const void *d)
28 {
29         return sub_data(0, size, d);
30 }
31
32 void Buffer::sub_data(size_t off, size_t sz, const void *d)
33 {
34         if(size==0)
35                 throw invalid_operation("Buffer::sub_data");
36         if(off>size || off+sz>size)
37                 throw out_of_range("Buffer::sub_data");
38
39         BufferBackend::sub_data(off, sz, d);
40 }
41
42 void Buffer::require_size(size_t req_sz) const
43 {
44         if(size<req_sz)
45                 throw buffer_too_small(format("buffer has %d bytes; %d required", size, req_sz));
46 }
47
48 } // namespace GL
49 } // namespace Msp