From 00ffc97eda26687f98f04226c2da728e2ca1220e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 20 Oct 2014 11:56:10 +0300 Subject: [PATCH] Prefer glMapBufferRange over glMapBuffer OpenGL ES does not have glMapBuffer. --- extensions/arb_map_buffer_range.glext | 1 + source/buffer.cpp | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 extensions/arb_map_buffer_range.glext diff --git a/extensions/arb_map_buffer_range.glext b/extensions/arb_map_buffer_range.glext new file mode 100644 index 00000000..643bb9ea --- /dev/null +++ b/extensions/arb_map_buffer_range.glext @@ -0,0 +1 @@ +extension ARB_map_buffer_range diff --git a/source/buffer.cpp b/source/buffer.cpp index 1226dbe3..080c3fb3 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -1,4 +1,5 @@ #include +#include #include "buffer.h" #include "error.h" #include "mesh.h" @@ -64,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() -- 2.45.2