mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-22 15:53:51 +00:00
Override LoadImage for ktx files
This commit is contained in:
parent
41a7abcdbb
commit
ebfd8f8f81
2 changed files with 52 additions and 11 deletions
|
@ -62,6 +62,8 @@
|
||||||
#include "ScopedAllocator.h"
|
#include "ScopedAllocator.h"
|
||||||
|
|
||||||
#include "GLDefines.h"
|
#include "GLDefines.h"
|
||||||
|
#include "Image.h"
|
||||||
|
#include "CompressedImage.h"
|
||||||
|
|
||||||
class ByteReader {
|
class ByteReader {
|
||||||
private:
|
private:
|
||||||
|
@ -138,8 +140,31 @@ ImageLoaderKTX::ImageLoaderKTX(const uint8 *rawData, const int32 rawDataSz)
|
||||||
|
|
||||||
ImageLoaderKTX::~ImageLoaderKTX() { }
|
ImageLoaderKTX::~ImageLoaderKTX() { }
|
||||||
|
|
||||||
|
FasTC::Image<> *ImageLoaderKTX::LoadImage() {
|
||||||
|
|
||||||
|
// Get rid of the pixel data if it exists...
|
||||||
|
if(m_PixelData) {
|
||||||
|
delete m_PixelData;
|
||||||
|
m_PixelData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ReadData()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!m_bIsCompressed) {
|
||||||
|
uint32 *pixels = reinterpret_cast<uint32 *>(m_PixelData);
|
||||||
|
return new FasTC::Image<>(m_Width, m_Height, pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CompressedImage(m_Width, m_Height, m_Format, m_PixelData);
|
||||||
|
}
|
||||||
|
|
||||||
bool ImageLoaderKTX::ReadData() {
|
bool ImageLoaderKTX::ReadData() {
|
||||||
|
|
||||||
|
// Default is uncompressed
|
||||||
|
m_bIsCompressed = false;
|
||||||
|
|
||||||
ByteReader rdr (m_RawData, m_NumRawDataBytes);
|
ByteReader rdr (m_RawData, m_NumRawDataBytes);
|
||||||
|
|
||||||
// First, check to make sure that the identifier is present...
|
// First, check to make sure that the identifier is present...
|
||||||
|
@ -246,13 +271,24 @@ bool ImageLoaderKTX::ReadData() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glType == 0 &&
|
m_Width = pixelWidth;
|
||||||
glFormat == 0 &&
|
m_Height = pixelHeight;
|
||||||
glInternalFormat == GL_COMPRESSED_RGBA_BPTC_UNORM) {
|
|
||||||
fprintf(stderr, "KTX loader - BPTC compressed textures unsupported!\n");
|
if(glType == 0 && glFormat == 0) {
|
||||||
return false;
|
switch(glInternalFormat) {
|
||||||
// Load compressed texture...
|
case GL_COMPRESSED_RGBA_BPTC_UNORM:
|
||||||
// rdr.Advance(pixelWidth * pixelHeight);
|
m_Format = FasTC::eCompressionFormat_BPTC;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "KTX loader - texture format (0x%x) unsupported!\n", glInternalFormat);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 dataSize = CompressedImage::GetCompressedSize(pixelWidth * pixelHeight * 4, m_Format);
|
||||||
|
m_PixelData = new uint8[dataSize];
|
||||||
|
memcpy(m_PixelData, rdr.GetData(), dataSize);
|
||||||
|
rdr.Advance(dataSize);
|
||||||
|
|
||||||
|
m_bIsCompressed = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(glType != GL_BYTE) {
|
if(glType != GL_BYTE) {
|
||||||
|
@ -267,10 +303,10 @@ bool ImageLoaderKTX::ReadData() {
|
||||||
|
|
||||||
// We should have RGBA8 data here so we can simply load it
|
// We should have RGBA8 data here so we can simply load it
|
||||||
// as we normally would.
|
// as we normally would.
|
||||||
m_Width = pixelWidth;
|
uint32 pixelDataSz = m_Width * m_Height * 4;
|
||||||
m_Height = pixelHeight;
|
m_PixelData = new uint8[pixelDataSz];
|
||||||
LoadFromPixelBuffer(reinterpret_cast<const uint32 *>(rdr.GetData()));
|
memcpy(m_PixelData, rdr.GetData(), pixelDataSz);
|
||||||
rdr.Advance(pixelWidth * pixelHeight * 4);
|
rdr.Advance(pixelDataSz);
|
||||||
}
|
}
|
||||||
return rdr.GetBytesLeft() == 0;
|
return rdr.GetBytesLeft() == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#define _IO_SRC_IMAGE_LOADER_KTX_H_
|
#define _IO_SRC_IMAGE_LOADER_KTX_H_
|
||||||
|
|
||||||
#include "ImageLoader.h"
|
#include "ImageLoader.h"
|
||||||
|
#include "CompressionFormat.h"
|
||||||
|
|
||||||
class ImageLoaderKTX : public ImageLoader {
|
class ImageLoaderKTX : public ImageLoader {
|
||||||
public:
|
public:
|
||||||
|
@ -68,8 +69,12 @@ class ImageLoaderKTX : public ImageLoader {
|
||||||
m_Processor = proc;
|
m_Processor = proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual FasTC::Image<> *LoadImage();
|
||||||
private:
|
private:
|
||||||
KTXKeyValueProcessor m_Processor;
|
KTXKeyValueProcessor m_Processor;
|
||||||
|
|
||||||
|
bool m_bIsCompressed;
|
||||||
|
FasTC::ECompressionFormat m_Format;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _IO_SRC_IMAGE_LOADER_KTX_H_
|
#endif // _IO_SRC_IMAGE_LOADER_KTX_H_
|
||||||
|
|
Loading…
Reference in a new issue