Add PVRTC support to KTX writer

This commit is contained in:
Pavel Krajcevski 2014-01-29 14:37:19 -05:00
parent 4601cf00c7
commit 211bc5aece
2 changed files with 37 additions and 3 deletions

View File

@ -81,4 +81,21 @@
#endif // GL_VERTSION_4_2 #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_ #endif // _IO_SRC_GL_DEFINES_H_

View File

@ -118,12 +118,25 @@ bool ImageWriterKTX::WriteImage() {
tkvSz = (tkvSz + 3) & ~0x3; // 4-byte aligned tkvSz = (tkvSz + 3) & ~0x3; // 4-byte aligned
CompressedImage *ci = dynamic_cast<CompressedImage *>(&m_Image); CompressedImage *ci = dynamic_cast<CompressedImage *>(&m_Image);
if(ci && ci->GetFormat() == FasTC::eCompressionFormat_BPTC) { if(ci) {
wtr.Write(0); // glType wtr.Write(0); // glType
wtr.Write(1); // glTypeSize wtr.Write(1); // glTypeSize
wtr.Write(GL_RGBA); // glFormat wtr.Write(GL_RGBA); // glFormat
switch(ci->GetFormat()) {
case FasTC::eCompressionFormat_BPTC:
wtr.Write(GL_COMPRESSED_RGBA_BPTC_UNORM); // glInternalFormat wtr.Write(GL_COMPRESSED_RGBA_BPTC_UNORM); // glInternalFormat
wtr.Write(GL_RGBA); // glBaseFormat 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 { } else {
wtr.Write(GL_BYTE); // glType wtr.Write(GL_BYTE); // glType
wtr.Write(1); // glTypeSize wtr.Write(1); // glTypeSize
@ -148,6 +161,10 @@ bool ImageWriterKTX::WriteImage() {
static const uint32 kImageSize = m_Width * m_Height; static const uint32 kImageSize = m_Width * m_Height;
wtr.Write(kImageSize); // imageSize wtr.Write(kImageSize); // imageSize
wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata... 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 { } else {
static const uint32 kImageSize = m_Width * m_Height * 4; static const uint32 kImageSize = m_Width * m_Height * 4;
wtr.Write(kImageSize); // imageSize wtr.Write(kImageSize); // imageSize