X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuffer.cpp;h=080c3fb380dc6dbf605e3a843b5ffb1e9a2851ba;hb=6a7510a74193ad442bfe82d8377606c3cb66e6b2;hp=93ef98db60ad32654309945d505726d9255414d0;hpb=0ef8e620a008e92069b0dd9ae4e972bc69430fc7;p=libs%2Fgl.git diff --git a/source/buffer.cpp b/source/buffer.cpp index 93ef98db..080c3fb3 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -1,7 +1,5 @@ #include -#include -#include -#include +#include #include "buffer.h" #include "error.h" #include "mesh.h" @@ -67,8 +65,23 @@ BufferRange *Buffer::create_range(unsigned s, unsigned o) void *Buffer::map(BufferAccess access) { - BindRestore _bind(this, type); - return glMapBuffer(type, access); + if(ARB_map_buffer_range) + { + BindRestore _bind(this, type); + GLenum access_bits = 0; + if(access==READ_ONLY) + access_bits = GL_MAP_READ_BIT; + else if(access==WRITE_ONLY) + access_bits = GL_MAP_WRITE_BIT; + else if(access==READ_WRITE) + access_bits = GL_MAP_READ_BIT|GL_MAP_WRITE_BIT; + return glMapBufferRange(type, 0, size, access_bits); + } + else + { + BindRestore _bind(this, type); + return glMapBuffer(type, access); + } } bool Buffer::unmap() @@ -160,9 +173,12 @@ void BufferRange::bind_to(BufferType t, unsigned i) { if(t!=buffer.type) Buffer::require_buffer_type(t); - // Intentionally using bitwise | to avoid short-circuiting - if(Buffer::set_current(t, &buffer) | set_current(t, i, this)) + if(set_current(t, i, this)) + { + // The buffer gets bound as a side effect + Buffer::set_current(t, &buffer); glBindBufferRange(t, i, buffer.id, offset, size); + } } void BufferRange::unbind_from(BufferType t, unsigned i)