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>
9 #include <msp/gl/extensions/oes_mapbuffer.h>
16 ARRAY_BUFFER = GL_ARRAY_BUFFER,
17 ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER,
18 PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER,
19 PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER,
20 UNIFORM_BUFFER = GL_UNIFORM_BUFFER
25 STREAM_DRAW = GL_STREAM_DRAW,
26 STREAM_READ = GL_STREAM_READ,
27 STREAM_COPY = GL_STREAM_COPY,
28 STATIC_DRAW = GL_STATIC_DRAW,
29 STATIC_READ = GL_STATIC_READ,
30 STATIC_COPY = GL_STATIC_COPY,
31 DYNAMIC_DRAW = GL_DYNAMIC_DRAW,
32 DYNAMIC_READ = GL_DYNAMIC_READ,
33 DYNAMIC_COPY = GL_DYNAMIC_COPY
38 READ_ONLY = GL_READ_ONLY,
39 WRITE_ONLY = GL_WRITE_ONLY,
40 READ_WRITE = GL_READ_WRITE
46 A buffer for storing data in GL memory. Putting vertex and index data in
47 buffers can improve rendering performance. The VertexArray, Mesh and
48 UniformBlock classes contain built-in support for buffers.
52 friend class BufferRange;
60 static const Buffer *bound[5];
67 static void require_buffer_type(BufferType);
70 /** Returns the OpenGL ID of the buffer. For internal use only. */
71 unsigned get_id() const { return id; }
73 /** Returns the default binding type for the buffer. */
74 BufferType get_type() const { return type; }
76 /** Sets the usage hint of the buffer. It will take effect the next time
77 the buffer's contents are defined. */
78 void set_usage(BufferUsage);
80 /** Uploads data into the buffer, completely replacing any previous
82 void data(unsigned, const void *);
84 /** Overwrites part of the buffer data with new data. The buffer size can
85 not be changed with this call. */
86 void sub_data(unsigned, unsigned, const void *);
88 unsigned get_size() const { return size; }
90 BufferRange *create_range(unsigned, unsigned);
92 void *map(BufferAccess);
95 /** Binds the buffer in its default slot. */
96 void bind() const { bind_to(type); }
98 /** Binds the buffer in an alternate slot. */
99 void bind_to(BufferType) const;
101 /** Unbinds the buffer from its default slot. */
102 void unbind() const { unbind_from(type); }
104 static const Buffer *current(BufferType);
105 static void unbind_from(BufferType);
107 static const Buffer *&binding(BufferType);
108 static bool set_current(BufferType, const Buffer *);
113 A proxy for a subset of a buffer. Can be bound for use with uniform blocks.
122 static std::vector<const BufferRange *> bound_uniform;
125 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();