]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/buffer.cpp
Add validation for mapping buffers
[libs/gl.git] / source / core / buffer.cpp
index 15a37397bcb18bdf094b5e5a5cef1a7d31b38c31..4a36937e7b745d1dd32f8c1e9ce19df0766037d7 100644 (file)
@@ -46,5 +46,23 @@ void Buffer::require_size(size_t req_sz) const
                throw buffer_too_small(format("buffer has %d bytes; %d required", size, req_sz));
 }
 
+void *Buffer::map()
+{
+       if(!can_map() || mapped)
+               throw invalid_operation("Buffer::map");
+       void *result = BufferBackend::map();
+       mapped = true;
+       return result;
+}
+
+bool Buffer::unmap()
+{
+       if(!can_map() || !mapped)
+               throw invalid_operation("Buffer::map");
+       bool result = BufferBackend::unmap();
+       mapped = false;
+       return result;
+}
+
 } // namespace GL
 } // namespace Msp