]> git.tdb.fi Git - libs/gl.git/blobdiff - source/buffer.h
Improve binding of buffers
[libs/gl.git] / source / buffer.h
index 7aea9665d8dd9a2ddaf77695891aa7c840a0810c..117f4ea6a1f5d0a699192ebdaffae808e400c68e 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_GL_BUFFER_H_
 #define MSP_GL_BUFFER_H_
 
@@ -45,6 +38,7 @@ private:
        BufferType type;
        BufferUsage usage;
        unsigned id;
+       unsigned size;
 
        static const Buffer *bound[4];
 
@@ -53,7 +47,7 @@ public:
        ~Buffer();
 
 private:
-       const Buffer *maybe_bind() const;
+       static void require_buffer_type(BufferType);
 
 public:
        /** Sets the usage hint of the buffer.  It will take effect the next time
@@ -68,6 +62,8 @@ public:
        not be changed with this call. */
        void sub_data(unsigned, unsigned, const void *);
 
+       unsigned get_size() const { return size; }
+
        /** Binds the buffer in its default slot. */
        void bind() const { bind_to(type); }
 
@@ -81,9 +77,27 @@ public:
        static void unbind_from(BufferType);
 private:
        static const Buffer *&binding(BufferType);
+       static bool set_current(BufferType, const Buffer *);
        static void restore(const Buffer *, BufferType);
 };
 
+/**
+An adaptor for Buffer to make it compatible with Bind.
+*/
+template<BufferType T>
+class BufferAlias
+{
+private:
+       const Buffer &buffer;
+
+public:
+       BufferAlias(const Buffer &b): buffer(b) { }
+
+       void bind() const { buffer.bind_to(T); }
+       static const Buffer *current() { return Buffer::current(T); }
+       static void unbind() { Buffer::unbind_from(T); }
+};
+
 } // namespace GL
 } // namespace Msp