]> git.tdb.fi Git - libs/gl.git/commitdiff
Prefer glMapBufferRange over glMapBuffer
authorMikko Rasa <tdb@tdb.fi>
Mon, 20 Oct 2014 08:56:10 +0000 (11:56 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 20 Oct 2014 08:56:10 +0000 (11:56 +0300)
OpenGL ES does not have glMapBuffer.

extensions/arb_map_buffer_range.glext [new file with mode: 0644]
source/buffer.cpp

diff --git a/extensions/arb_map_buffer_range.glext b/extensions/arb_map_buffer_range.glext
new file mode 100644 (file)
index 0000000..643bb9e
--- /dev/null
@@ -0,0 +1 @@
+extension ARB_map_buffer_range
index 1226dbe3223f41e438ddcc7ca1c2f9b107b0fd17..080c3fb380dc6dbf605e3a843b5ffb1e9a2851ba 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdexcept>
+#include <msp/gl/extensions/arb_map_buffer_range.h>
 #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()