Skip to content

Commit 5ba449d

Browse files
committed
Add support for BC4-7 compressed texture formats in KTX files. Updated the changelog.
1 parent 43fcacc commit 5ba449d

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

changes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Released: N/A
99
* Added love.window.isMaximized.
1010
* Added 'shaderswitches' field to the table returned by love.graphics.getStats.
1111
* Added Quad:getTextureDimensions.
12+
* Added 'ellipse' area distribution to ParticleSystems.
13+
* Added support for BC4-7 compressed texture formats in KTX files.
1214
* Added PrismaticJoint:getAxis and WheelJoint:getAxis.
1315
* Added 2-point version of love.physics.newRevoluteJoint.
1416
* Added table variants of Fixture:setCategory and Fixture:setMask.

src/modules/image/magpie/KTXHandler.cpp

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum KTXGLInternalFormat
6767
{
6868
KTX_GL_ETC1_RGB8_OES = 0x8D64,
6969

70+
// ETC2 and EAC.
7071
KTX_GL_COMPRESSED_R11_EAC = 0x9270,
7172
KTX_GL_COMPRESSED_SIGNED_R11_EAC = 0x9271,
7273
KTX_GL_COMPRESSED_RG11_EAC = 0x9272,
@@ -78,17 +79,33 @@ enum KTXGLInternalFormat
7879
KTX_GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
7980
KTX_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
8081

81-
// I don't know if any KTX file contains PVR data, but why not support it.
82+
// PVRTC1.
8283
KTX_GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
8384
KTX_GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
8485
KTX_GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
8586
KTX_GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
8687

87-
// Same with DXT1/3/5.
88-
KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
89-
KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
90-
KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
91-
88+
// DXT1, DXT3, and DXT5.
89+
KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
90+
KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
91+
KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
92+
KTX_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
93+
KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
94+
KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
95+
96+
// BC4 and BC5.
97+
KTX_GL_COMPRESSED_RED_RGTC1 = 0x8DBB,
98+
KTX_GL_COMPRESSED_SIGNED_RED_RGTC1 = 0x8DBC,
99+
KTX_GL_COMPRESSED_RG_RGTC2 = 0x8DBD,
100+
KTX_GL_COMPRESSED_SIGNED_RG_RGTC2 = 0x8DBE,
101+
102+
// BC6 and BC7.
103+
KTX_GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C,
104+
KTX_GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D,
105+
KTX_GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT = 0x8E8E,
106+
KTX_GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = 0x8E8F,
107+
108+
// ASTC.
92109
KTX_GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0,
93110
KTX_GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1,
94111
KTX_GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2,
@@ -129,6 +146,8 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB)
129146
{
130147
case KTX_GL_ETC1_RGB8_OES:
131148
return CompressedImageData::FORMAT_ETC1;
149+
150+
// EAC and ETC2.
132151
case KTX_GL_COMPRESSED_R11_EAC:
133152
return CompressedImageData::FORMAT_EAC_R;
134153
case KTX_GL_COMPRESSED_SIGNED_R11_EAC:
@@ -152,6 +171,8 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB)
152171
case KTX_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
153172
sRGB = true;
154173
return CompressedImageData::FORMAT_ETC2_RGBA;
174+
175+
// PVRTC.
155176
case KTX_GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
156177
return CompressedImageData::FORMAT_PVR1_RGB4;
157178
case KTX_GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
@@ -160,12 +181,42 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB)
160181
return CompressedImageData::FORMAT_PVR1_RGBA4;
161182
case KTX_GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
162183
return CompressedImageData::FORMAT_PVR1_RGBA2;
184+
185+
// DXT.
186+
case KTX_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
187+
sRGB = true;
163188
case KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
164189
return CompressedImageData::FORMAT_DXT1;
190+
case KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
191+
sRGB = true;
165192
case KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
166193
return CompressedImageData::FORMAT_DXT3;
194+
case KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
195+
sRGB = true;
167196
case KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
168197
return CompressedImageData::FORMAT_DXT5;
198+
199+
// BC4 and BC5.
200+
case KTX_GL_COMPRESSED_RED_RGTC1:
201+
return CompressedImageData::FORMAT_BC4;
202+
case KTX_GL_COMPRESSED_SIGNED_RED_RGTC1:
203+
return CompressedImageData::FORMAT_BC4s;
204+
case KTX_GL_COMPRESSED_RG_RGTC2:
205+
return CompressedImageData::FORMAT_BC5;
206+
case KTX_GL_COMPRESSED_SIGNED_RG_RGTC2:
207+
return CompressedImageData::FORMAT_BC5s;
208+
209+
// BC6 and BC7.
210+
case KTX_GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
211+
sRGB = true;
212+
case KTX_GL_COMPRESSED_RGBA_BPTC_UNORM:
213+
return CompressedImageData::FORMAT_BC7;
214+
case KTX_GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
215+
return CompressedImageData::FORMAT_BC6Hs;
216+
case KTX_GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
217+
return CompressedImageData::FORMAT_BC6H;
218+
219+
// ASTC.
169220
case KTX_GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
170221
sRGB = true;
171222
case KTX_GL_COMPRESSED_RGBA_ASTC_4x4_KHR:

0 commit comments

Comments
 (0)