]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture2d.cpp
Add an asynchronous version of Texture2D::sub_image
[libs/gl.git] / source / core / texture2d.cpp
index 7ac1c5ec84f599fcef2285b94e8f5531c3631958..74071535e73f41e768f053cd5041479fe80353c3 100644 (file)
@@ -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