X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbuffer.h;fp=source%2Fbuffer.h;h=bd3a999eeab0d19da7aea2f94b90abae390f4a74;hp=117f4ea6a1f5d0a699192ebdaffae808e400c68e;hb=97cd6e0695f69f3d404e22a6c831aee22d3f0987;hpb=a4f59a729cb9d8183ad8fc050d7bc163abfd55e8 diff --git a/source/buffer.h b/source/buffer.h index 117f4ea6..bd3a999e 100644 --- a/source/buffer.h +++ b/source/buffer.h @@ -1,6 +1,7 @@ #ifndef MSP_GL_BUFFER_H_ #define MSP_GL_BUFFER_H_ +#include #include "gl.h" namespace Msp { @@ -11,7 +12,8 @@ enum BufferType ARRAY_BUFFER = GL_ARRAY_BUFFER_ARB, ELEMENT_ARRAY_BUFFER = GL_ELEMENT_ARRAY_BUFFER_ARB, PIXEL_PACK_BUFFER = GL_PIXEL_PACK_BUFFER_ARB, - PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER_ARB + PIXEL_UNPACK_BUFFER = GL_PIXEL_UNPACK_BUFFER_ARB, + UNIFORM_BUFFER = GL_UNIFORM_BUFFER }; enum BufferUsage @@ -27,6 +29,8 @@ enum BufferUsage DYNAMIC_COPY = GL_DYNAMIC_COPY_ARB }; +class BufferRange; + /** A buffer for storing data in GL memory. Putting vertex and index data in buffers can improve rendering performance. The VertexArray and Mesh classes @@ -34,13 +38,15 @@ contain built-in support for buffers. */ class Buffer { + friend class BufferRange; + private: BufferType type; BufferUsage usage; unsigned id; unsigned size; - static const Buffer *bound[4]; + static const Buffer *bound[5]; public: Buffer(BufferType); @@ -64,6 +70,8 @@ public: unsigned get_size() const { return size; } + BufferRange *create_range(unsigned, unsigned); + /** Binds the buffer in its default slot. */ void bind() const { bind_to(type); } @@ -81,6 +89,7 @@ private: static void restore(const Buffer *, BufferType); }; + /** An adaptor for Buffer to make it compatible with Bind. */ @@ -98,6 +107,36 @@ public: static void unbind() { Buffer::unbind_from(T); } }; + +/** +A proxy for a subset of a buffer. Can be bound for use with uniform blocks. +*/ +class BufferRange +{ +private: + Buffer &buffer; + unsigned offset; + unsigned size; + + static std::vector bound_uniform; + +public: + BufferRange(Buffer &, unsigned, unsigned); + + void data(const void *); + + void bind_to(BufferType, unsigned); + + static const BufferRange *current(BufferType t, unsigned i) { return binding(t, i); } + static void unbind_from(BufferType, unsigned); +private: + static const BufferRange *&binding(BufferType, unsigned); + static bool set_current(BufferType, unsigned, const BufferRange *); + +public: + static unsigned get_n_uniform_buffer_bindings(); +}; + } // namespace GL } // namespace Msp