Add DXT1/5 to Image*KTX

- Closes #29
- Added GL prefixes to GLDefines.h where they were missing
- Added PVRTC4 to ImageLoaderKTX
This commit is contained in:
Pavel Krajcevski 2016-12-24 17:55:27 -05:00
parent adcea1bddc
commit e19d4ec0a8
3 changed files with 94 additions and 53 deletions

View file

@ -59,20 +59,34 @@
//
////////////////////////////////////////////////////////////////////////////////
#ifndef COMPRESSED_RGB_PVRTC_4BPPV1_IMG
#define COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#endif
#ifndef COMPRESSED_RGB_PVRTC_2BPPV1_IMG
#define COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#ifndef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#endif
#ifndef COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
#define COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
#endif
#ifndef COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
#define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
#ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
#endif
////////////////////////////////////////////////////////////////////////////////
//
// DXT definitions
//
////////////////////////////////////////////////////////////////////////////////
#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
#endif
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
#endif
////////////////////////////////////////////////////////////////////////////////
@ -81,60 +95,60 @@
//
////////////////////////////////////////////////////////////////////////////////
#ifndef COMPRESSED_RGBA_ASTC_4x4_KHR
#define COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
#endif
#ifndef COMPRESSED_RGBA_ASTC_5x4_KHR
#define COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
#ifndef GL_COMPRESSED_RGBA_ASTC_5x4_KHR
#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
#endif
#ifndef COMPRESSED_RGBA_ASTC_5x5_KHR
#define COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
#ifndef GL_COMPRESSED_RGBA_ASTC_5x5_KHR
#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
#endif
#ifndef COMPRESSED_RGBA_ASTC_6x5_KHR
#define COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
#ifndef GL_COMPRESSED_RGBA_ASTC_6x5_KHR
#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
#endif
#ifndef COMPRESSED_RGBA_ASTC_6x6_KHR
#define COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
#ifndef GL_COMPRESSED_RGBA_ASTC_6x6_KHR
#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
#endif
#ifndef COMPRESSED_RGBA_ASTC_8x5_KHR
#define COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
#ifndef GL_COMPRESSED_RGBA_ASTC_8x5_KHR
#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
#endif
#ifndef COMPRESSED_RGBA_ASTC_8x6_KHR
#define COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
#ifndef GL_COMPRESSED_RGBA_ASTC_8x6_KHR
#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
#endif
#ifndef COMPRESSED_RGBA_ASTC_8x8_KHR
#define COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
#endif
#ifndef COMPRESSED_RGBA_ASTC_10x5_KHR
#define COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
#ifndef GL_COMPRESSED_RGBA_ASTC_10x5_KHR
#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
#endif
#ifndef COMPRESSED_RGBA_ASTC_10x6_KHR
#define COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
#ifndef GL_COMPRESSED_RGBA_ASTC_10x6_KHR
#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
#endif
#ifndef COMPRESSED_RGBA_ASTC_10x8_KHR
#define COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
#ifndef GL_COMPRESSED_RGBA_ASTC_10x8_KHR
#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
#endif
#ifndef COMPRESSED_RGBA_ASTC_10x10_KHR
#define COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
#ifndef GL_COMPRESSED_RGBA_ASTC_10x10_KHR
#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
#endif
#ifndef COMPRESSED_RGBA_ASTC_12x10_KHR
#define COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
#ifndef GL_COMPRESSED_RGBA_ASTC_12x10_KHR
#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
#endif
#ifndef COMPRESSED_RGBA_ASTC_12x12_KHR
#define COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
#ifndef GL_COMPRESSED_RGBA_ASTC_12x12_KHR
#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
#endif
#endif

View file

@ -244,59 +244,72 @@ bool ImageLoaderKTX::ReadData() {
m_Format = FasTC::eCompressionFormat_BPTC;
break;
case COMPRESSED_RGBA_ASTC_4x4_KHR:
case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
m_Format = FasTC::eCompressionFormat_PVRTC4;
break;
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
m_Format = FasTC::eCompressionFormat_DXT1;
break;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
m_Format = FasTC::eCompressionFormat_DXT5;
break;
case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
m_Format = FasTC::eCompressionFormat_ASTC4x4;
break;
case COMPRESSED_RGBA_ASTC_5x4_KHR:
case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
m_Format = FasTC::eCompressionFormat_ASTC5x4;
break;
case COMPRESSED_RGBA_ASTC_5x5_KHR:
case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
m_Format = FasTC::eCompressionFormat_ASTC5x5;
break;
case COMPRESSED_RGBA_ASTC_6x5_KHR:
case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
m_Format = FasTC::eCompressionFormat_ASTC6x5;
break;
case COMPRESSED_RGBA_ASTC_6x6_KHR:
case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
m_Format = FasTC::eCompressionFormat_ASTC6x6;
break;
case COMPRESSED_RGBA_ASTC_8x5_KHR:
case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
m_Format = FasTC::eCompressionFormat_ASTC8x5;
break;
case COMPRESSED_RGBA_ASTC_8x6_KHR:
case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
m_Format = FasTC::eCompressionFormat_ASTC8x6;
break;
case COMPRESSED_RGBA_ASTC_8x8_KHR:
case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
m_Format = FasTC::eCompressionFormat_ASTC8x8;
break;
case COMPRESSED_RGBA_ASTC_10x5_KHR:
case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
m_Format = FasTC::eCompressionFormat_ASTC10x5;
break;
case COMPRESSED_RGBA_ASTC_10x6_KHR:
case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
m_Format = FasTC::eCompressionFormat_ASTC10x6;
break;
case COMPRESSED_RGBA_ASTC_10x8_KHR:
case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
m_Format = FasTC::eCompressionFormat_ASTC10x8;
break;
case COMPRESSED_RGBA_ASTC_10x10_KHR:
case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
m_Format = FasTC::eCompressionFormat_ASTC10x10;
break;
case COMPRESSED_RGBA_ASTC_12x10_KHR:
case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
m_Format = FasTC::eCompressionFormat_ASTC12x10;
break;
case COMPRESSED_RGBA_ASTC_12x12_KHR:
case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
m_Format = FasTC::eCompressionFormat_ASTC12x12;
break;

View file

@ -97,7 +97,17 @@ bool ImageWriterKTX::WriteImage() {
break;
case FasTC::eCompressionFormat_PVRTC4:
wtr.Write(COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat
wtr.Write(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG); // glInternalFormat
wtr.Write(GL_RGBA); // glBaseFormat
break;
case FasTC::eCompressionFormat_DXT1:
wtr.Write(GL_COMPRESSED_RGB_S3TC_DXT1_EXT); // glInternalFormat
wtr.Write(GL_RGB); // glBaseFormat
break;
case FasTC::eCompressionFormat_DXT5:
wtr.Write(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT); // glInternalFormat
wtr.Write(GL_RGBA); // glBaseFormat
break;
@ -127,11 +137,15 @@ bool ImageWriterKTX::WriteImage() {
wtr.Write(orientationValue, oValLen + 1); // value
wtr.Write(orientationKey, tkvSz - kvSz - 4); // padding
if(ci && ci->GetFormat() == FasTC::eCompressionFormat_BPTC) {
if(ci &&
(ci->GetFormat() == FasTC::eCompressionFormat_BPTC ||
ci->GetFormat() == FasTC::eCompressionFormat_DXT5)) {
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_PVRTC4) {
} else if(ci &&
(ci->GetFormat() == FasTC::eCompressionFormat_PVRTC4 ||
ci->GetFormat() == FasTC::eCompressionFormat_DXT1)) {
static const uint32 kImageSize = m_Width * m_Height >> 1;
wtr.Write(kImageSize); // imageSize
wtr.Write(ci->GetCompressedData(), kImageSize); // imagedata...