From 196093790e242dec24bfbbf7ad8c28dcc442824c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 23 Aug 2012 12:32:30 +0300 Subject: [PATCH] Keep track of buffer size --- source/buffer.cpp | 12 +++++++----- source/buffer.h | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/buffer.cpp b/source/buffer.cpp index e033871f..c19f3727 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -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); } diff --git a/source/buffer.h b/source/buffer.h index 5e3cd29a..d8a8419c 100644 --- a/source/buffer.h +++ b/source/buffer.h @@ -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); } -- 2.43.0