X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=0e76128c7bc5666da5828f11fe98f5398ecaf380;hb=46752f789ea3d23928e96ce451ea96c78c694b93;hp=311a3e4569704c92b99703c4a0473f508778c9e1;hpb=71ca61440610e650c6c1b761ebee1b587bbc969e;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 311a3e45..0e76128c 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #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(); @@ -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(pixel_buffer.map()); } else if(phase==2) - { - const char *data = reinterpret_cast(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); + mapped_address = 0; if(!pixel_buffer.unmap()) { phase = 1;