]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.h
df570d7eb01d2b8bae9f6115adfb2345435c4c53
[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
7 namespace Msp {
8 namespace GL {
9
10 class buffer_too_small: public std::logic_error
11 {
12 public:
13         buffer_too_small(const std::string &w): std::logic_error(w) { }
14         virtual ~buffer_too_small() throw() { }
15 };
16
17 class BufferRange;
18
19 /**
20 A buffer for storing data in GL memory.  Putting vertex and index data in
21 buffers can improve rendering performance.  The VertexArray, Mesh and
22 UniformBlock classes contain built-in support for buffers.
23 */
24 class Buffer
25 {
26         friend class PipelineState;
27         friend class Texture2D;
28         friend class VertexSetup;
29
30 private:
31         unsigned id;
32         unsigned size;
33
34         static Buffer *scratch_binding;
35
36 public:
37         Buffer();
38         ~Buffer();
39
40         /** Defines the storage size of the buffer.  Must be called before data can
41         be uploaded.  Storage cannot be changed once set. */
42         void storage(unsigned);
43
44         /** Uploads data into the buffer, completely replacing any previous
45         contents.  Storage must be defined beforehand.  The data must have size
46         matching the defined storage. */
47         void data(const void *);
48
49         /** Overwrites part of the buffer data with new data.  Storage must be
50         defined beforehand. */
51         void sub_data(unsigned, unsigned, const void *);
52
53         unsigned get_size() const { return size; }
54
55         void require_size(unsigned) const;
56
57         void *map();
58         bool unmap();
59
60         void set_debug_name(const std::string &);
61
62 private:
63         void bind_scratch();
64 public:
65         static void unbind_scratch();
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif