From 696c5e20a1da222d225e9212017ef1af644b8103 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 7 Feb 2021 18:20:52 +0200 Subject: [PATCH] Async load texture data directly into the pixel buffer --- source/texture2d.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 1e8e3db8..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,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(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); -- 2.43.0