Adding the reading path

This commit is contained in:
sam 2017-02-16 16:03:55 -08:00
parent 2f7181fb32
commit 8ee5defc60
3 changed files with 43 additions and 7 deletions

View file

@ -481,7 +481,7 @@ public:
ExternalUpdates getUpdates() const;
static ktx::KTXUniquePointer serialize(const Texture& texture);
static TexturePointer unserialize(const ktx::KTXUniquePointer& srcData);
static Texture* unserialize(const ktx::KTXUniquePointer& srcData);
protected:
// Should only be accessed internally or by the backend sync function

View file

@ -34,9 +34,21 @@ ktx::KTXUniquePointer Texture::serialize(const Texture& texture) {
auto ktxBuffer = ktx::KTX::create(header, images);
return ktxBuffer;
}
TexturePointer Texture::unserialize(const ktx::KTXUniquePointer& srcData) {
Texture* Texture::unserialize(const ktx::KTXUniquePointer& srcData) {
if (!srcData) {
return nullptr;
}
const auto& header = *srcData->getHeader();
return nullptr;
Format pixelFormat = Format::COLOR_RGBA_32;
auto tex = Texture::create2D(pixelFormat, header.getPixelWidth(), header.getPixelHeight());
uint16_t level = 0;
for (auto& image : srcData->_images) {
tex->assignStoredMip(level, pixelFormat, image._imageSize, image._bytes);
level++;
}
return tex;
}

View file

@ -286,12 +286,36 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
filename += std::to_string((size_t) theTexture);
filename += ".ktx";
FILE* file = fopen (filename.c_str(),"wb");
if (file != nullptr) {
fwrite(theKTX->_storage->data(), 1, theKTX->_storage->size(), file);
fclose (file);
{
FILE* file = fopen (filename.c_str(),"wb");
if (file != nullptr) {
fwrite(theKTX->_storage->data(), 1, theKTX->_storage->size(), file);
fclose (file);
}
}
{
FILE* file = fopen (filename.c_str(),"rb");
if (file != nullptr) {
// obtain file size:
fseek (file , 0 , SEEK_END);
auto size = ftell(file);
rewind(file);
std::unique_ptr<ktx::Storage> storage(new ktx::Storage(size));
fread(storage->_bytes, 1, storage->_size, file);
fclose (file);
//then create a new texture out of the ktx
auto theNewTexure = Texture::unserialize(ktx::KTX::create(storage));
if (theNewTexure) {
auto srcTexture = theTexture;
theTexture = theNewTexure;
delete srcTexture;
}
}
}
}
}