X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture2d.cpp;h=0e76128c7bc5666da5828f11fe98f5398ecaf380;hb=46752f789ea3d23928e96ce451ea96c78c694b93;hp=cee932f7231e9fb23adcfb4ce86ba28e736dd17a;hpb=635e5dc39adf09051bdacadbc402ddf22f7807a3;p=libs%2Fgl.git diff --git a/source/texture2d.cpp b/source/texture2d.cpp index cee932f7..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(); @@ -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(pixel_buffer.map()); } else if(phase==2) - { - const char *data = reinterpret_cast(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;