3 This file is part of libmspgl
4 Copyright © 2007, 2009-2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_BUFFER_H_
9 #define MSP_GL_BUFFER_H_
18 ARRAY_BUFFER = GL_ARRAY_BUFFER_ARB,
19 ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER_ARB,
20 PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER_ARB,
21 PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER_ARB
26 STREAM_DRAW = GL_STREAM_DRAW_ARB,
27 STREAM_READ = GL_STREAM_READ_ARB,
28 STREAM_COPY = GL_STREAM_COPY_ARB,
29 STATIC_DRAW = GL_STATIC_DRAW_ARB,
30 STATIC_READ = GL_STATIC_READ_ARB,
31 STATIC_COPY = GL_STATIC_COPY_ARB,
32 DYNAMIC_DRAW = GL_DYNAMIC_DRAW_ARB,
33 DYNAMIC_READ = GL_DYNAMIC_READ_ARB,
34 DYNAMIC_COPY = GL_DYNAMIC_COPY_ARB
38 A buffer for storing data in GL memory. Putting vertex and index data in
39 buffers can improve rendering performance. The VertexArray and Mesh classes
40 contain built-in support for buffers.
49 static const Buffer *bound[4];
56 const Buffer *maybe_bind() const;
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 /** Binds the buffer in its default slot. */
72 void bind() const { bind_to(type); }
74 /** Binds the buffer in an alternate slot. */
75 void bind_to(BufferType) const;
77 /** Unbinds the buffer from its default slot. */
78 void unbind() const { unbind_from(type); }
80 static const Buffer *current(BufferType t) { return binding(t); }
81 static void unbind_from(BufferType);
83 static const Buffer *&binding(BufferType);
84 static void restore(const Buffer *, BufferType);
88 An adaptor for Buffer to make it compatible with Bind.
90 template<BufferType T>
97 BufferAlias(const Buffer &b): buffer(b) { }
99 void bind() const { buffer.bind_to(T); }
100 static const Buffer *current() { return Buffer::current(T); }
101 static void unbind() { Buffer::unbind_from(T); }