X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fbuffer.cpp;h=523b737d32bf696ff3628e48ddd4b6b64e55f428;hp=dcb83a7a5960f1cb48436cb9cff5063327c4d5f2;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=ada4b7614137221b64a00f31fde1498064e9fb19 diff --git a/source/core/buffer.cpp b/source/core/buffer.cpp index dcb83a7a..523b737d 100644 --- a/source/core/buffer.cpp +++ b/source/core/buffer.cpp @@ -1,10 +1,4 @@ #include -#include -#include -#include -#include -#include -#include #include #include "buffer.h" #include "error.h" @@ -14,26 +8,6 @@ using namespace std; namespace Msp { namespace GL { -Buffer *Buffer::scratch_binding = 0; - -Buffer::Buffer(): - size(0) -{ - static Require _req(ARB_vertex_buffer_object); - - if(ARB_direct_state_access) - glCreateBuffers(1, &id); - else - glGenBuffers(1, &id); -} - -Buffer::~Buffer() -{ - if(this==scratch_binding) - unbind_scratch(); - glDeleteBuffers(1, &id); -} - void Buffer::storage(unsigned sz) { if(size>0) @@ -47,24 +21,7 @@ void Buffer::storage(unsigned sz) size = sz; - if(ARB_buffer_storage) - { - static const int flags = GL_MAP_READ_BIT|GL_MAP_WRITE_BIT|GL_DYNAMIC_STORAGE_BIT; - if(ARB_direct_state_access) - glNamedBufferStorage(id, size, 0, flags); - else - { - bind_scratch(); - glBufferStorage(GL_ARRAY_BUFFER, size, 0, flags); - } - } - else if(ARB_direct_state_access) - glNamedBufferData(id, size, 0, GL_STATIC_DRAW); - else - { - bind_scratch(); - glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW); - } + allocate(); } void Buffer::data(const void *d) @@ -77,13 +34,7 @@ void Buffer::sub_data(unsigned off, unsigned sz, const void *d) if(size==0) throw invalid_operation("Buffer::sub_data"); - if(ARB_direct_state_access) - glNamedBufferSubData(id, off, sz, d); - else - { - bind_scratch(); - glBufferSubData(GL_ARRAY_BUFFER, off, sz, d); - } + BufferBackend::sub_data(off, sz, d); } void Buffer::require_size(unsigned req_sz) const @@ -92,62 +43,5 @@ void Buffer::require_size(unsigned req_sz) const throw buffer_too_small(format("buffer has %d bytes; %d required", size, req_sz)); } -void *Buffer::map() -{ - static Require _req(ARB_map_buffer_range); - - if(ARB_direct_state_access) - return glMapNamedBufferRange(id, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT); - else - { - bind_scratch(); - void *result = glMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_READ_BIT|GL_MAP_WRITE_BIT); - return result; - } -} - -bool Buffer::unmap() -{ - // TODO check if it's mapped - if(ARB_direct_state_access) - return glUnmapNamedBuffer(id); - else if(OES_mapbuffer) - { - bind_scratch(); - bool result = glUnmapBuffer(GL_ARRAY_BUFFER); - return result; - } - else - return true; -} - -void Buffer::set_debug_name(const string &name) -{ -#ifdef DEBUG - if(KHR_debug) - glObjectLabel(GL_BUFFER, id, name.size(), name.c_str()); -#else - (void)name; -#endif -} - -void Buffer::bind_scratch() -{ - if(scratch_binding!=this) - { - glBindBuffer(GL_ARRAY_BUFFER, id); - scratch_binding = this; - } -} - -void Buffer::unbind_scratch() -{ - if(scratch_binding) - { - glBindBuffer(GL_ARRAY_BUFFER, 0); - scratch_binding = 0; - } -} - } // namespace GL } // namespace Msp