]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Fix filename handling in the Blender exporter on Windows
[libs/gl.git] / source / texture2d.cpp
index cee932f7231e9fb23adcfb4ce86ba28e736dd17a..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,11 +22,13 @@ private:
        Buffer pixel_buffer;
        char *mapped_address;
        Graphics::Image image;
+       Graphics::ImageLoader *img_loader;
        unsigned n_bytes;
        int phase;
 
 public:
        AsyncLoader(Texture2D &, IO::Seekable &);
+       ~AsyncLoader();
 
        virtual bool needs_sync() const;
        virtual bool process();
@@ -165,7 +168,7 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
        PixelStore pstore = PixelStore::from_image(img);
        BindRestore _bind_ps(pstore);
 
-       image(0, from_buffer ? 0 : img.get_data());
+       image(0, from_buffer ? 0 : img.get_pixels());
 }
 
 unsigned Texture2D::get_n_levels() const
@@ -246,9 +249,17 @@ 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)
 { }
 
+Texture2D::AsyncLoader::~AsyncLoader()
+{
+       if(mapped_address)
+               pixel_buffer.unmap();
+       delete img_loader;
+}
+
 bool Texture2D::AsyncLoader::needs_sync() const
 {
        return phase%2;
@@ -258,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)
@@ -269,13 +278,11 @@ 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_data());
-               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);
+               mapped_address = 0;
                if(!pixel_buffer.unmap())
                {
                        phase = 1;