1 #ifndef MSP_GL_BUFFER_H_
2 #define MSP_GL_BUFFER_H_
6 #include <msp/gl/extensions/arb_vertex_buffer_object.h>
7 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
14 ARRAY_BUFFER = GL_ARRAY_BUFFER,
15 ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER,
16 PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER,
17 PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER,
18 UNIFORM_BUFFER = GL_UNIFORM_BUFFER
23 STREAM_DRAW = GL_STREAM_DRAW,
24 STREAM_READ = GL_STREAM_READ,
25 STREAM_COPY = GL_STREAM_COPY,
26 STATIC_DRAW = GL_STATIC_DRAW,
27 STATIC_READ = GL_STATIC_READ,
28 STATIC_COPY = GL_STATIC_COPY,
29 DYNAMIC_DRAW = GL_DYNAMIC_DRAW,
30 DYNAMIC_READ = GL_DYNAMIC_READ,
31 DYNAMIC_COPY = GL_DYNAMIC_COPY
37 A buffer for storing data in GL memory. Putting vertex and index data in
38 buffers can improve rendering performance. The VertexArray, Mesh and
39 UniformBlock classes contain built-in support for buffers.
43 friend class BufferRange;
51 static const Buffer *bound[5];
58 static void require_buffer_type(BufferType);
61 /** Sets the usage hint of the buffer. It will take effect the next time
62 the buffer's contents are defined. */
63 void set_usage(BufferUsage);
65 /** Uploads data into the buffer, completely replacing any previous
67 void data(unsigned, const void *);
69 /** Overwrites part of the buffer data with new data. The buffer size can
70 not be changed with this call. */
71 void sub_data(unsigned, unsigned, const void *);
73 unsigned get_size() const { return size; }
75 BufferRange *create_range(unsigned, unsigned);
77 /** Binds the buffer in its default slot. */
78 void bind() const { bind_to(type); }
80 /** Binds the buffer in an alternate slot. */
81 void bind_to(BufferType) const;
83 /** Unbinds the buffer from its default slot. */
84 void unbind() const { unbind_from(type); }
86 static const Buffer *current(BufferType t) { return binding(t); }
87 static void unbind_from(BufferType);
89 static const Buffer *&binding(BufferType);
90 static bool set_current(BufferType, const Buffer *);
91 static void restore(const Buffer *, BufferType);
96 An adaptor for Buffer to make it compatible with Bind.
98 template<BufferType T>
102 const Buffer &buffer;
105 BufferAlias(const Buffer &b): buffer(b) { }
107 void bind() const { buffer.bind_to(T); }
108 static const Buffer *current() { return Buffer::current(T); }
109 static void unbind() { Buffer::unbind_from(T); }
114 A proxy for a subset of a buffer. Can be bound for use with uniform blocks.
123 static std::vector<const BufferRange *> bound_uniform;
126 BufferRange(Buffer &, unsigned, unsigned);
128 void data(const void *);
130 void bind_to(BufferType, unsigned);
132 static const BufferRange *current(BufferType t, unsigned i) { return binding(t, i); }
133 static void unbind_from(BufferType, unsigned);
135 static const BufferRange *&binding(BufferType, unsigned);
136 static bool set_current(BufferType, unsigned, const BufferRange *);
139 static unsigned get_n_uniform_buffer_bindings();
140 static unsigned get_uniform_buffer_alignment();