X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture2d_backend.cpp;h=a4e3cad64c737d78a840b15930542e7cf7e6838f;hb=HEAD;hp=ab0c6d8cfb48ccf484da7d596fe8adf84ec07cf1;hpb=c218e021ede4e91c0fbc22ea9d636283409f847f;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index ab0c6d8c..a4e3cad6 100644 --- a/source/backends/opengl/texture2d_backend.cpp +++ b/source/backends/opengl/texture2d_backend.cpp @@ -1,8 +1,6 @@ -#include #include #include #include -#include #include "buffer.h" #include "gl.h" #include "texture2d.h" @@ -13,28 +11,6 @@ using namespace std; namespace Msp { namespace GL { -class OpenGLTexture2D::AsyncLoader: public Resource::AsyncLoader -{ -private: - Texture2D &texture; - IO::Seekable &io; - Buffer pixel_buffer; - char *mapped_address = 0; - Graphics::Image image; - Graphics::ImageLoader *img_loader = 0; - DataFile::RawData *raw_data = 0; - unsigned n_bytes = 0; - int phase = 0; - -public: - AsyncLoader(Texture2D &, IO::Seekable &); - ~AsyncLoader(); - - virtual bool needs_sync() const; - virtual bool process(); -}; - - OpenGLTexture2D::OpenGLTexture2D(): Texture(GL_TEXTURE_2D) { } @@ -86,18 +62,6 @@ void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig } } -void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const Buffer &buffer, unsigned offset) -{ - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer.id); - sub_image(level, x, y, wd, ht, reinterpret_cast(offset)); - glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); -} - -Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources *) -{ - return new AsyncLoader(static_cast(*this), io); -} - uint64_t OpenGLTexture2D::get_data_size() const { if(!id) @@ -159,88 +123,5 @@ void OpenGLTexture2D::AsyncTransfer::finalize() glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } - -OpenGLTexture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i): - texture(t), - io(i) -{ - char magic[4] = { }; - io.read(magic, 4); - io.seek(0, IO::S_BEG); - - if(DataFile::RawData::detect_signature(string(magic, 4))) - { - raw_data = new DataFile::RawData; - raw_data->open_io(io, "async"); - } - else - img_loader = Graphics::ImageLoader::open_io(io); -} - -OpenGLTexture2D::AsyncLoader::~AsyncLoader() -{ - if(mapped_address) - pixel_buffer.unmap(); - delete img_loader; - delete raw_data; -} - -bool OpenGLTexture2D::AsyncLoader::needs_sync() const -{ - return phase%2; -} - -bool OpenGLTexture2D::AsyncLoader::process() -{ - if(phase==0) - { - if(raw_data) - n_bytes = raw_data->get_size(); - else - { - image.load_headers(*img_loader); - n_bytes = image.get_stride()*image.get_height(); - } - } - else if(phase==1) - { - pixel_buffer.storage(n_bytes, STREAMING); - mapped_address = reinterpret_cast(pixel_buffer.map()); - } - else if(phase==2) - { - if(raw_data) - raw_data->load_into(mapped_address); - else - image.load_into(*img_loader, mapped_address); - } - else if(phase==3) - { - mapped_address = 0; - if(!pixel_buffer.unmap()) - { - phase = 1; - return false; - } - - if(!texture.id) - texture.create(); - - if(img_loader) - { - unsigned w = image.get_width(); - unsigned h = image.get_height(); - texture.storage(pixelformat_from_image(image, texture.use_srgb_format), w, h); - } - texture.OpenGLTexture2D::sub_image(0, 0, 0, texture.width, texture.height, pixel_buffer, 0); - - if(texture.auto_gen_mipmap) - texture.generate_mipmap(); - } - - ++phase; - return phase>3; -} - } // namespace GL } // namespace Msp