X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture2d.cpp;fp=source%2Fcore%2Ftexture2d.cpp;h=74071535e73f41e768f053cd5041479fe80353c3;hb=c218e021ede4e91c0fbc22ea9d636283409f847f;hp=7ac1c5ec84f599fcef2285b94e8f5531c3631958;hpb=be962824e72a7d5e2946ad4c0e69e01c60da30e8;p=libs%2Fgl.git diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 7ac1c5ec..74071535 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -48,6 +48,11 @@ void Texture2D::sub_image(unsigned level, unsigned x, unsigned y, unsigned wd, u Texture2DBackend::sub_image(level, x, y, wd, ht, data); } +Texture2D::AsyncTransfer Texture2D::sub_image_async(unsigned level, unsigned x, unsigned y, unsigned wd, unsigned ht) +{ + return AsyncTransfer(*this, level, x, y, wd, ht); +} + void Texture2D::image(const Graphics::Image &img, unsigned lv) { storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv); @@ -96,5 +101,60 @@ void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, obj.storage(fmt, w, h, l); } + +Texture2D::AsyncTransfer::AsyncTransfer(Texture2D &t, unsigned l, unsigned x_, unsigned y_, unsigned wd, unsigned ht): + texture(&t), + level(l), + x(x_), + y(y_), + width(wd), + height(ht), + data_size(width*height*get_pixel_size(texture->storage_fmt)), + dest_addr(0) +{ + dest_addr = allocate(); +} + +Texture2D::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other): + Texture2DBackend::AsyncTransfer(move(other)), + texture(other.texture), + level(other.level), + x(other.x), + y(other.y), + width(other.width), + height(other.height), + data_size(other.data_size), + dest_addr(other.dest_addr) +{ + other.dest_addr = 0; +} + +Texture2D::AsyncTransfer &Texture2D::AsyncTransfer::operator=(AsyncTransfer &&other) +{ + if(dest_addr) + finalize(); + + Texture2DBackend::AsyncTransfer::operator=(move(other)); + + texture = other.texture; + level = other.level; + x = other.x; + y = other.y; + width = other.width; + height = other.height; + data_size = other.data_size; + dest_addr = other.dest_addr; + + other.dest_addr = 0; + + return *this; +} + +Texture2D::AsyncTransfer::~AsyncTransfer() +{ + if(dest_addr) + finalize(); +} + } // namespace GL } // namespace Msp