]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor Texture2D::AsyncLoader to use sub_image_async
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Dec 2021 14:07:48 +0000 (16:07 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Dec 2021 14:07:48 +0000 (16:07 +0200)
source/backends/opengl/texture2d_backend.cpp
source/backends/opengl/texture2d_backend.h

index ab0c6d8cfb48ccf484da7d596fe8adf84ec07cf1..187d16934990668fb40132463ebded6cd0f387e0 100644 (file)
@@ -18,8 +18,7 @@ class OpenGLTexture2D::AsyncLoader: public Resource::AsyncLoader
 private:
        Texture2D &texture;
        IO::Seekable &io;
-       Buffer pixel_buffer;
-       char *mapped_address = 0;
+       Texture2D::AsyncTransfer transfer;
        Graphics::Image image;
        Graphics::ImageLoader *img_loader = 0;
        DataFile::RawData *raw_data = 0;
@@ -86,13 +85,6 @@ void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig
        }
 }
 
-void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const Buffer &buffer, unsigned offset)
-{
-       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer.id);
-       sub_image(level, x, y, wd, ht, reinterpret_cast<void *>(offset));
-       glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
-}
-
 Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources *)
 {
        return new AsyncLoader(static_cast<Texture2D &>(*this), io);
@@ -179,8 +171,6 @@ OpenGLTexture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
 
 OpenGLTexture2D::AsyncLoader::~AsyncLoader()
 {
-       if(mapped_address)
-               pixel_buffer.unmap();
        delete img_loader;
        delete raw_data;
 }
@@ -204,35 +194,25 @@ bool OpenGLTexture2D::AsyncLoader::process()
        }
        else if(phase==1)
        {
-               pixel_buffer.storage(n_bytes, STREAMING);
-               mapped_address = reinterpret_cast<char *>(pixel_buffer.map());
+               if(img_loader)
+               {
+                       unsigned w = image.get_width();
+                       unsigned h = image.get_height();
+                       texture.storage(pixelformat_from_image(image, texture.use_srgb_format), w, h);
+               }
+
+               transfer = texture.sub_image_async(0, 0, 0, texture.width, texture.height);
        }
        else if(phase==2)
        {
                if(raw_data)
-                       raw_data->load_into(mapped_address);
+                       raw_data->load_into(transfer.get_address());
                else
-                       image.load_into(*img_loader, mapped_address);
+                       image.load_into(*img_loader, transfer.get_address());
        }
        else if(phase==3)
        {
-               mapped_address = 0;
-               if(!pixel_buffer.unmap())
-               {
-                       phase = 1;
-                       return false;
-               }
-
-               if(!texture.id)
-                       texture.create();
-
-               if(img_loader)
-               {
-                       unsigned w = image.get_width();
-                       unsigned h = image.get_height();
-                       texture.storage(pixelformat_from_image(image, texture.use_srgb_format), w, h);
-               }
-               texture.OpenGLTexture2D::sub_image(0, 0, 0, texture.width, texture.height, pixel_buffer, 0);
+               transfer = Texture2D::AsyncTransfer();
 
                if(texture.auto_gen_mipmap)
                        texture.generate_mipmap();
index 5de1079537daf16dd08248ca1d3712844223913d..f9b5abfede4560ab55ca4e77a54e68b03e59296f 100644 (file)
@@ -31,7 +31,6 @@ protected:
 
        void allocate();
        void sub_image(unsigned, int, int, unsigned, unsigned, const void *);
-       void sub_image(unsigned, int, int, unsigned, unsigned, const Buffer &, unsigned);
 
 public:
        virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0);