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