]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.h
810bfc1a56253e181f7cc55b5d228c3441e99fee
[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 /**
19 A buffer for storing data in GL memory.  Putting vertex and index data in
20 buffers can improve rendering performance.  The VertexArray, Mesh and
21 UniformBlock classes contain built-in support for buffers.
22 */
23 class Buffer: public BufferBackend
24 {
25         friend BufferBackend;
26
27 private:
28         std::size_t size = 0;
29
30 public:
31         /** Defines the storage size of the buffer.  Must be called before data can
32         be uploaded.  Storage cannot be changed once set. */
33         void storage(std::size_t);
34
35         /** Uploads data into the buffer, completely replacing any previous
36         contents.  Storage must be defined beforehand.  The data must have size
37         matching the defined storage. */
38         void data(const void *);
39
40         /** Overwrites part of the buffer data with new data.  Storage must be
41         defined beforehand. */
42         void sub_data(std::size_t, std::size_t, const void *);
43
44         std::size_t get_size() const { return size; }
45
46         void require_size(std::size_t) const;
47
48         using BufferBackend::map;
49         using BufferBackend::unmap;
50
51         using BufferBackend::set_debug_name;
52 };
53
54 } // namespace GL
55 } // namespace Msp
56
57 #endif