]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.h
Completely hide OpenGL from the public headers
[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 <vector>
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
26 {
27         friend class PipelineState;
28         friend class Texture2D;
29         friend class VertexSetup;
30
31 private:
32         unsigned id;
33         unsigned size;
34
35         static Buffer *scratch_binding;
36
37 public:
38         Buffer();
39         ~Buffer();
40
41         /** Defines the storage size of the buffer.  Must be called before data can
42         be uploaded.  Storage cannot be changed once set. */
43         void storage(unsigned);
44
45         /** Uploads data into the buffer, completely replacing any previous
46         contents.  Storage must be defined beforehand.  The data must have size
47         matching the defined storage. */
48         void data(const void *);
49
50         /** Overwrites part of the buffer data with new data.  Storage must be
51         defined beforehand. */
52         void sub_data(unsigned, unsigned, const void *);
53
54         unsigned get_size() const { return size; }
55
56         void require_size(unsigned) const;
57
58         void *map();
59         bool unmap();
60
61         void set_debug_name(const std::string &);
62
63 private:
64         void bind_scratch();
65 public:
66         static void unbind_scratch();
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif