#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"
private:
Texture2D &texture;
IO::Seekable &io;
- bool srgb_conversion;
Buffer pixel_buffer;
char *mapped_address;
Graphics::Image image;
+ Graphics::ImageLoader *img_loader;
unsigned n_bytes;
int phase;
public:
AsyncLoader(Texture2D &, IO::Seekable &);
+ ~AsyncLoader();
- void set_srgb_conversion(bool);
virtual bool needs_sync() const;
virtual bool process();
};
sub_image(level, x, y, wd, ht, data);
}
-void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb)
+void Texture2D::image(const Graphics::Image &img, unsigned lv)
{
- image(img, lv, srgb, false);
+ image(img, lv, false);
}
-void Texture2D::image(const Graphics::Image &img, unsigned lv, bool srgb, bool from_buffer)
+void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer)
{
unsigned w = img.get_width();
unsigned h = img.get_height();
PixelFormat fmt = pixelformat_from_image(img);
if(width==0)
- storage(make_pixelformat(get_components(fmt), get_component_type(fmt), srgb), w, h, lv);
+ storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv);
else if(w!=width || h!=height || (lv && lv!=levels))
throw incompatible_data("Texture2D::image");
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
h = 1;
}
-Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *res)
+Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *)
{
AsyncLoader *ldr = new AsyncLoader(*this, io);
- if(res)
- ldr->set_srgb_conversion(res->get_srgb_conversion());
return ldr;
}
Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
texture(t),
io(i),
- srgb_conversion(false),
pixel_buffer(PIXEL_UNPACK_BUFFER),
mapped_address(0),
+ img_loader(Graphics::ImageLoader::open_io(io)),
phase(0)
{ }
-void Texture2D::AsyncLoader::set_srgb_conversion(bool c)
+Texture2D::AsyncLoader::~AsyncLoader()
{
- srgb_conversion = c;
+ if(mapped_address)
+ pixel_buffer.unmap();
+ delete img_loader;
}
bool Texture2D::AsyncLoader::needs_sync() const
{
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)
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;
else
glGenTextures(1, &texture.id);
}
- texture.image(image, 0, srgb_conversion, true);
+ texture.image(image, 0, true);
}
++phase;