X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbuffer.cpp;h=4b485ddad6cb266d1d96d2e844c40583cb9ace3a;hp=b4b71c3a0130efadcaea894f0fd921b9e833629b;hb=HEAD;hpb=76e338af116120d93d082ad247591ec9adad9233 diff --git a/source/buffer.cpp b/source/buffer.cpp deleted file mode 100644 index b4b71c3a..00000000 --- a/source/buffer.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "arb_vertex_buffer_object.h" -#include "extension.h" -#include "buffer.h" - -namespace Msp { -namespace GL { - -Buffer::Buffer(BufferType t): - type(t), - usage(STATIC_DRAW) -{ - 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"); - - glGenBuffersARB(1, &id); -} - -Buffer::~Buffer() -{ - glDeleteBuffersARB(1, &id); -} - -void Buffer::bind(BufferType t) const -{ - glBindBufferARB(t, id); - binding(t)=this; -} - -void Buffer::maybe_bind() const -{ - if(binding(type)!=this) - bind(); -} - -void Buffer::set_usage(BufferUsage u) -{ - usage=u; -} - -void Buffer::data(unsigned size, const void *d) -{ - maybe_bind(); - glBufferDataARB(type, size, d, usage); -} - -void Buffer::sub_data(unsigned offset, unsigned size, const void *d) -{ - maybe_bind(); - glBufferSubDataARB(type, offset, size, d); -} - -void Buffer::unbind(BufferType type) -{ - const Buffer *&ptr=binding(type); - if(ptr) - { - glBindBufferARB(type, 0); - ptr=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 InvalidParameterValue("Invalid buffer type"); - } -} - -const Buffer *Buffer::bound[4]={ 0, 0, 0, 0 }; - -} // namespace GL -} // namespace Msp