]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.h
Use default member initializers for simple types
[libs/gl.git] / source / core / buffer.h
1 #ifndef MSP_GL_BUFFER_H_
2 #define MSP_GL_BUFFER_H_
3
4 #include <stdexcept>
5 #include <string>
6 #include "buffer_backend.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class buffer_too_small: public std::logic_error
12 {
13 public:
14         buffer_too_small(const std::string &w): std::logic_error(w) { }
15         virtual ~buffer_too_small() throw() { }
16 };
17
18 class BufferRange;
19
20 /**
21 A buffer for storing data in GL memory.  Putting vertex and index data in
22 buffers can improve rendering performance.  The VertexArray, Mesh and
23 UniformBlock classes contain built-in support for buffers.
24 */
25 class Buffer: public BufferBackend
26 {
27         friend BufferBackend;
28
29 private:
30         unsigned size = 0;
31
32 public:
33         /** Defines the storage size of the buffer.  Must be called before data can
34         be uploaded.  Storage cannot be changed once set. */
35         void storage(unsigned);
36
37         /** Uploads data into the buffer, completely replacing any previous
38         contents.  Storage must be defined beforehand.  The data must have size
39         matching the defined storage. */
40         void data(const void *);
41
42         /** Overwrites part of the buffer data with new data.  Storage must be
43         defined beforehand. */
44         void sub_data(unsigned, unsigned, const void *);
45
46         unsigned get_size() const { return size; }
47
48         void require_size(unsigned) const;
49
50         using BufferBackend::map;
51         using BufferBackend::unmap;
52
53         using BufferBackend::set_debug_name;
54 };
55
56 } // namespace GL
57 } // namespace Msp
58
59 #endif