1 #ifndef MSP_GL_BUFFER_H_
2 #define MSP_GL_BUFFER_H_
6 #include <msp/gl/extensions/arb_pixel_buffer_object.h>
7 #include <msp/gl/extensions/arb_vertex_buffer_object.h>
8 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
15 ARRAY_BUFFER = GL_ARRAY_BUFFER,
16 ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER,
17 PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER,
18 PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER,
19 UNIFORM_BUFFER = GL_UNIFORM_BUFFER
24 STREAM_DRAW = GL_STREAM_DRAW,
25 STREAM_READ = GL_STREAM_READ,
26 STREAM_COPY = GL_STREAM_COPY,
27 STATIC_DRAW = GL_STATIC_DRAW,
28 STATIC_READ = GL_STATIC_READ,
29 STATIC_COPY = GL_STATIC_COPY,
30 DYNAMIC_DRAW = GL_DYNAMIC_DRAW,
31 DYNAMIC_READ = GL_DYNAMIC_READ,
32 DYNAMIC_COPY = GL_DYNAMIC_COPY
37 READ_ONLY = GL_READ_ONLY,
38 WRITE_ONLY = GL_WRITE_ONLY,
39 READ_WRITE = GL_READ_WRITE
45 A buffer for storing data in GL memory. Putting vertex and index data in
46 buffers can improve rendering performance. The VertexArray, Mesh and
47 UniformBlock classes contain built-in support for buffers.
51 friend class BufferRange;
59 static const Buffer *bound[5];
66 static void require_buffer_type(BufferType);
69 /** Returns the OpenGL ID of the buffer. For internal use only. */
70 unsigned get_id() const { return id; }
72 /** Returns the default binding type for the buffer. */
73 BufferType get_type() const { return type; }
75 /** Sets the usage hint of the buffer. It will take effect the next time
76 the buffer's contents are defined. */
77 void set_usage(BufferUsage);
79 /** Uploads data into the buffer, completely replacing any previous
81 void data(unsigned, const void *);
83 /** Overwrites part of the buffer data with new data. The buffer size can
84 not be changed with this call. */
85 void sub_data(unsigned, unsigned, const void *);
87 unsigned get_size() const { return size; }
89 BufferRange *create_range(unsigned, unsigned);
91 void *map(BufferAccess);
94 /** Binds the buffer in its default slot. */
95 void bind() const { bind_to(type); }
97 /** Binds the buffer in an alternate slot. */
98 void bind_to(BufferType) const;
100 /** Unbinds the buffer from its default slot. */
101 void unbind() const { unbind_from(type); }
103 static const Buffer *current(BufferType);
104 static void unbind_from(BufferType);
106 static const Buffer *&binding(BufferType);
107 static bool set_current(BufferType, const Buffer *);
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);
127 void data(const void *);
129 void bind_to(BufferType, unsigned);
131 static const BufferRange *current(BufferType t, unsigned i) { return binding(t, i); }
132 static void unbind_from(BufferType, unsigned);
134 static const BufferRange *&binding(BufferType, unsigned);
135 static bool set_current(BufferType, unsigned, const BufferRange *);
138 static unsigned get_n_uniform_buffer_bindings();
139 static unsigned get_uniform_buffer_alignment();