1 #ifndef MSP_GL_BUFFER_H_
2 #define MSP_GL_BUFFER_H_
12 ARRAY_BUFFER = GL_ARRAY_BUFFER,
13 ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER,
14 PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER,
15 PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER,
16 UNIFORM_BUFFER = GL_UNIFORM_BUFFER
21 STREAM_DRAW = GL_STREAM_DRAW,
22 STREAM_READ = GL_STREAM_READ,
23 STREAM_COPY = GL_STREAM_COPY,
24 STATIC_DRAW = GL_STATIC_DRAW,
25 STATIC_READ = GL_STATIC_READ,
26 STATIC_COPY = GL_STATIC_COPY,
27 DYNAMIC_DRAW = GL_DYNAMIC_DRAW,
28 DYNAMIC_READ = GL_DYNAMIC_READ,
29 DYNAMIC_COPY = GL_DYNAMIC_COPY
35 A buffer for storing data in GL memory. Putting vertex and index data in
36 buffers can improve rendering performance. The VertexArray, Mesh and
37 UniformBlock classes contain built-in support for buffers.
41 friend class BufferRange;
49 static const Buffer *bound[5];
56 static void require_buffer_type(BufferType);
59 /** Sets the usage hint of the buffer. It will take effect the next time
60 the buffer's contents are defined. */
61 void set_usage(BufferUsage);
63 /** Uploads data into the buffer, completely replacing any previous
65 void data(unsigned, const void *);
67 /** Overwrites part of the buffer data with new data. The buffer size can
68 not be changed with this call. */
69 void sub_data(unsigned, unsigned, const void *);
71 unsigned get_size() const { return size; }
73 BufferRange *create_range(unsigned, unsigned);
75 /** Binds the buffer in its default slot. */
76 void bind() const { bind_to(type); }
78 /** Binds the buffer in an alternate slot. */
79 void bind_to(BufferType) const;
81 /** Unbinds the buffer from its default slot. */
82 void unbind() const { unbind_from(type); }
84 static const Buffer *current(BufferType t) { return binding(t); }
85 static void unbind_from(BufferType);
87 static const Buffer *&binding(BufferType);
88 static bool set_current(BufferType, const Buffer *);
89 static void restore(const Buffer *, BufferType);
94 An adaptor for Buffer to make it compatible with Bind.
96 template<BufferType T>
100 const Buffer &buffer;
103 BufferAlias(const Buffer &b): buffer(b) { }
105 void bind() const { buffer.bind_to(T); }
106 static const Buffer *current() { return Buffer::current(T); }
107 static void unbind() { Buffer::unbind_from(T); }
112 A proxy for a subset of a buffer. Can be bound for use with uniform blocks.
121 static std::vector<const BufferRange *> bound_uniform;
124 BufferRange(Buffer &, unsigned, unsigned);
126 void data(const void *);
128 void bind_to(BufferType, unsigned);
130 static const BufferRange *current(BufferType t, unsigned i) { return binding(t, i); }
131 static void unbind_from(BufferType, unsigned);
133 static const BufferRange *&binding(BufferType, unsigned);
134 static bool set_current(BufferType, unsigned, const BufferRange *);
137 static unsigned get_n_uniform_buffer_bindings();
138 static unsigned get_uniform_buffer_alignment();