]> git.tdb.fi Git - libs/gl.git/commitdiff
Async load texture data directly into the pixel buffer
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Feb 2021 16:20:52 +0000 (18:20 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Feb 2021 16:20:52 +0000 (18:20 +0200)
source/texture2d.cpp

index 1e8e3db8fefe659a8b46390719e14177c29e5315..0e76128c7bc5666da5828f11fe98f5398ecaf380 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/raii.h>
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_texture_storage.h>
+#include <msp/graphics/imageloader.h>
 #include "bindable.h"
 #include "buffer.h"
 #include "error.h"
@@ -21,6 +22,7 @@ private:
        Buffer pixel_buffer;
        char *mapped_address;
        Graphics::Image image;
+       Graphics::ImageLoader *img_loader;
        unsigned n_bytes;
        int phase;
 
@@ -247,6 +249,7 @@ Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
        io(i),
        pixel_buffer(PIXEL_UNPACK_BUFFER),
        mapped_address(0),
+       img_loader(Graphics::ImageLoader::open_io(io)),
        phase(0)
 { }
 
@@ -254,6 +257,7 @@ Texture2D::AsyncLoader::~AsyncLoader()
 {
        if(mapped_address)
                pixel_buffer.unmap();
+       delete img_loader;
 }
 
 bool Texture2D::AsyncLoader::needs_sync() const
@@ -265,9 +269,7 @@ bool Texture2D::AsyncLoader::process()
 {
        if(phase==0)
        {
-               /* TODO Enhance the ImageLoader system so that the image can be loaded
-               directly to the buffer */
-               image.load_io(io);
+               image.load_headers(*img_loader);
                n_bytes = image.get_stride()*image.get_height();
        }
        else if(phase==1)
@@ -276,10 +278,7 @@ bool Texture2D::AsyncLoader::process()
                mapped_address = reinterpret_cast<char *>(pixel_buffer.map());
        }
        else if(phase==2)
-       {
-               const char *data = reinterpret_cast<const char *>(image.get_pixels());
-               copy(data, data+n_bytes, mapped_address);
-       }
+               image.load_into(*img_loader, mapped_address);
        else if(phase==3)
        {
                Bind _bind_buf(pixel_buffer, PIXEL_UNPACK_BUFFER);