]> git.tdb.fi Git - libs/gl.git/commitdiff
Keep track of buffer size
authorMikko Rasa <tdb@tdb.fi>
Thu, 23 Aug 2012 09:32:30 +0000 (12:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 23 Aug 2012 09:32:30 +0000 (12:32 +0300)
source/buffer.cpp
source/buffer.h

index e033871f45ea818f2376ebf41166210cf3715a14..c19f3727f8f5c685a2ab5abc761a0293c3aa7c85 100644 (file)
@@ -12,7 +12,8 @@ const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 };
 
 Buffer::Buffer(BufferType t):
        type(t),
-       usage(STATIC_DRAW)
+       usage(STATIC_DRAW),
+       size(0)
 {
        static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object");
        if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER)
@@ -31,19 +32,20 @@ void Buffer::set_usage(BufferUsage u)
        usage = u;
 }
 
-void Buffer::data(unsigned size, const void *d)
+void Buffer::data(unsigned sz, const void *d)
 {
        const Buffer *old = current(type);
        bind();
-       glBufferDataARB(type, size, d, usage);
+       glBufferDataARB(type, sz, d, usage);
+       size = sz;
        restore(old, type);
 }
 
-void Buffer::sub_data(unsigned offset, unsigned size, const void *d)
+void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
 {
        const Buffer *old = current(type);
        bind();
-       glBufferSubDataARB(type, offset, size, d);
+       glBufferSubDataARB(type, off, sz, d);
        restore(old, type);
 }
 
index 5e3cd29a4162c124a3b259f419cd9a558760d3db..d8a8419c0211fbc9b70429a95bcb7cc7c5065145 100644 (file)
@@ -38,6 +38,7 @@ private:
        BufferType type;
        BufferUsage usage;
        unsigned id;
+       unsigned size;
 
        static const Buffer *bound[4];
 
@@ -61,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); }