X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fbuffer.cpp;h=b6f2e44b9e55555bebcfa08b80bf1ffeadb4a3c5;hp=ed0c552360ac8fad2345236e2024d17455200334;hb=c356a20547afae97b412da36e0b0a7d51e879401;hpb=7d221b1fd6194e59bc0783740a2a17ac71fa4da5 diff --git a/source/core/buffer.cpp b/source/core/buffer.cpp index ed0c5523..b6f2e44b 100644 --- a/source/core/buffer.cpp +++ b/source/core/buffer.cpp @@ -31,13 +31,23 @@ void Buffer::data(const void *d) } void Buffer::sub_data(size_t off, size_t sz, const void *d) +{ + check_sub_data(off, sz, "Buffer::sub_data"); + BufferBackend::sub_data(off, sz, d); +} + +Buffer::AsyncTransfer Buffer::sub_data_async(size_t off, size_t sz) +{ + check_sub_data(off, sz, "Buffer::sub_data_async"); + return AsyncTransfer(*this, off, sz); +} + +void Buffer::check_sub_data(size_t off, size_t sz, const char *func) { if(size==0) - throw invalid_operation("Buffer::sub_data"); + throw invalid_operation(func); if(off>get_total_size() || off%size+sz>size) - throw out_of_range("Buffer::sub_data"); - - BufferBackend::sub_data(off, sz, d); + throw out_of_range(func); } void Buffer::require_size(size_t req_sz) const @@ -64,5 +74,30 @@ bool Buffer::unmap() return result; } + +Buffer::AsyncTransfer::AsyncTransfer(Buffer &b, size_t o, size_t s): + buffer(b), + offset(o), + size(s), + dest_addr(0) +{ + allocate(); +} + +Buffer::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other): + buffer(other.buffer), + offset(other.offset), + size(other.size), + dest_addr(other.dest_addr) +{ + other.dest_addr = 0; +} + +Buffer::AsyncTransfer::~AsyncTransfer() +{ + if(dest_addr) + finalize(); +} + } // namespace GL } // namespace Msp