]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/buffer.cpp
Multiplex streaming buffer contents on Vulkan
[libs/gl.git] / source / core / buffer.cpp
index 15a37397bcb18bdf094b5e5a5cef1a7d31b38c31..ed0c552360ac8fad2345236e2024d17455200334 100644 (file)
@@ -34,7 +34,7 @@ void Buffer::sub_data(size_t off, size_t sz, const void *d)
 {
        if(size==0)
                throw invalid_operation("Buffer::sub_data");
-       if(off>size || off+sz>size)
+       if(off>get_total_size() || off%size+sz>size)
                throw out_of_range("Buffer::sub_data");
 
        BufferBackend::sub_data(off, sz, d);
@@ -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