diff --git a/IO/src/GLDefines.h b/IO/src/GLDefines.h index 03d01c4..5c086d2 100644 --- a/IO/src/GLDefines.h +++ b/IO/src/GLDefines.h @@ -81,4 +81,21 @@ #endif // GL_VERTSION_4_2 + +#ifndef COMPRESSED_RGB_PVRTC_4BPPV1_IMG +#define COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#endif // COMPRESSED_RGB_PVRTC_4BPPV1_IMG + +#ifndef COMPRESSED_RGB_PVRTC_2BPPV1_IMG +#define COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#endif // COMPRESSED_RGB_PVRTC_2BPPV1_IMG + +#ifndef COMPRESSED_RGBA_PVRTC_4BPPV1_IMG +#define COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#endif // COMPRESSED_RGBA_PVRTC_4BPPV1_IMG + +#ifndef COMPRESSED_RGBA_PVRTC_2BPPV1_IMG +#define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif // COMPRESSED_RGBA_PVRTC_2BPPV1_IMG + #endif // _IO_SRC_GL_DEFINES_H_ diff --git a/IO/src/ImageWriterKTX.cpp b/IO/src/ImageWriterKTX.cpp index 642896a..8c29972 100644 --- a/IO/src/ImageWriterKTX.cpp +++ b/IO/src/ImageWriterKTX.cpp @@ -118,12 +118,25 @@ bool ImageWriterKTX::WriteImage() { tkvSz = (tkvSz + 3) & ~0x3; // 4-byte aligned CompressedImage *ci = dynamic_cast(&m_Image); - if(ci && ci->GetFormat() == FasTC::eCompressionFormat_BPTC) { + if(ci) { wtr.Write(0); // glType wtr.Write(1); // glTypeSize wtr.Write(GL_RGBA); // glFormat - wtr.Write(GL_COMPRESSED_RGBA_BPTC_UNORM); // glInternalFormat - wtr.Write(GL_RGBA); // glBaseFormat + switch(ci->GetFormat()) { + case FasTC::eCompressionFormat_BPTC: + wtr.Write(GL_COMPRESSED_RGBA_BPTC_UNORM); // glInternalFormat + wtr.Write(GL_RGBA); // glBaseFormat + break; + + case FasTC::eCompressionFormat_PVRTC: + wtr.Write(COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat + wtr.Write(GL_RGBA); // glBaseFormat + break; + + default: + fprintf(stderr, "Unsupported KTX compressed format: %d\n", ci->GetFormat()); + return false; + } } else { wtr.Write(GL_BYTE); // glType wtr.Write(1); // glTypeSize @@ -148,6 +161,10 @@ bool ImageWriterKTX::WriteImage() { static const uint32 kImageSize = m_Width * m_Height; wtr.Write(kImageSize); // imageSize wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata... + } else if(ci && ci->GetFormat() == FasTC::eCompressionFormat_PVRTC) { + static const uint32 kImageSize = m_Width * m_Height >> 1; + wtr.Write(kImageSize); // imageSize + wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata... } else { static const uint32 kImageSize = m_Width * m_Height * 4; wtr.Write(kImageSize); // imageSize