X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fbuffer.cpp;h=4b485ddad6cb266d1d96d2e844c40583cb9ace3a;hb=HEAD;hp=1762b20482eaa45944d94529b7c044aa25c898b5;hpb=a4f59a729cb9d8183ad8fc050d7bc163abfd55e8;p=libs%2Fgl.git diff --git a/source/buffer.cpp b/source/buffer.cpp deleted file mode 100644 index 1762b204..00000000 --- a/source/buffer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include "arb_vertex_buffer_object.h" -#include "extension.h" -#include "buffer.h" - -using namespace std; - -namespace Msp { -namespace GL { - -const Buffer *Buffer::bound[4] = { 0, 0, 0, 0 }; - -Buffer::Buffer(BufferType t): - type(t), - usage(STATIC_DRAW), - size(0) -{ - require_buffer_type(type); - - glGenBuffersARB(1, &id); -} - -Buffer::~Buffer() -{ - glDeleteBuffersARB(1, &id); -} - -void Buffer::require_buffer_type(BufferType type) -{ - static RequireExtension _req_vbo("GL_ARB_vertex_buffer_object"); - if(type==PIXEL_PACK_BUFFER || type==PIXEL_UNPACK_BUFFER) - static RequireExtension _req_pbo("GL_ARB_pixel_buffer_object"); -} - -void Buffer::set_usage(BufferUsage u) -{ - usage = u; -} - -void Buffer::data(unsigned sz, const void *d) -{ - const Buffer *old = current(type); - bind(); - glBufferDataARB(type, sz, d, usage); - size = sz; - restore(old, type); -} - -void Buffer::sub_data(unsigned off, unsigned sz, const void *d) -{ - const Buffer *old = current(type); - bind(); - glBufferSubDataARB(type, off, sz, d); - restore(old, type); -} - -void Buffer::bind_to(BufferType t) const -{ - if(t!=type) - require_buffer_type(t); - if(set_current(t, this)) - glBindBufferARB(t, id); -} - -void Buffer::unbind_from(BufferType type) -{ - if(set_current(type, 0)) - glBindBufferARB(type, 0); -} - -const Buffer *&Buffer::binding(BufferType type) -{ - switch(type) - { - case ARRAY_BUFFER: return bound[0]; - case ELEMENT_ARRAY_BUFFER: return bound[1]; - case PIXEL_PACK_BUFFER: return bound[2]; - case PIXEL_UNPACK_BUFFER: return bound[3]; - default: throw invalid_argument("Buffer::binding"); - } -} - -bool Buffer::set_current(BufferType type, const Buffer *buf) -{ - const Buffer *&ptr = binding(type); - if(ptr==buf) - return false; - - ptr = buf; - return true; -} - -void Buffer::restore(const Buffer *buf, BufferType type) -{ - if(buf!=current(type)) - { - if(buf) - buf->bind_to(type); - else - unbind_from(type); - } -} - -} // namespace GL -} // namespace Msp