namespace Msp {
namespace GL {
-void Buffer::storage(unsigned sz)
+void Buffer::storage(size_t sz, BufferUsage u)
{
if(size>0)
{
throw invalid_argument("Buffer::storage");
size = sz;
+ usage = u;
allocate();
}
return sub_data(0, size, d);
}
-void Buffer::sub_data(unsigned off, unsigned sz, const void *d)
+void Buffer::sub_data(size_t off, size_t sz, const void *d)
{
if(size==0)
throw invalid_operation("Buffer::sub_data");
+ if(off>get_total_size() || off%size+sz>size)
+ throw out_of_range("Buffer::sub_data");
BufferBackend::sub_data(off, sz, d);
}
-void Buffer::require_size(unsigned req_sz) const
+void Buffer::require_size(size_t req_sz) const
{
if(size<req_sz)
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