Skip to content

Commit 4cc7559

Browse files
committed
Add support for s3tc, pvrtc, and etc1 compressed textures and loading them
from KTX files.
1 parent 9d7348d commit 4cc7559

29 files changed

+1995
-52
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Change Log
1919
* Added `divideComponents` function to `Cartesian2`, `Cartesian3`, and `Cartesian4`. [#4750](https://github.com/AnalyticalGraphicsInc/cesium/pull/4750)
2020
* Added `WebGLConstants` enum. Previously, this was part of the private Renderer API. [#4731](https://github.com/AnalyticalGraphicsInc/cesium/pull/4731)
2121
* Fixed tooltips for gallery thumbnails in Sandcastle [#4702](https://github.com/AnalyticalGraphicsInc/cesium/pull/4702)
22+
* Added compressed texture support. The supported extensions are `WEBGL_compressed_s3tc`, `WEBGL_compressed_texture_pvrtc`, and `WEBGL_compressed_texture_etc1`. [#4758](https://github.com/AnalyticalGraphicsInc/cesium/pull/4758)
2223

2324
### 1.28 - 2016-12-01
2425

Source/Core/PixelFormat.js

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,78 @@ define([
6969
*/
7070
LUMINANCE_ALPHA : WebGLConstants.LUMINANCE_ALPHA,
7171

72+
/**
73+
* A pixel format containing red, green, and blue channels that is DXT1 compressed.
74+
*
75+
* @type {Number}
76+
* @constant
77+
*/
78+
RGB_DXT1 : WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,
79+
80+
/**
81+
* A pixel format containing red, green, blue, and alpha channels that is DXT1 compressed.
82+
*
83+
* @type {Number}
84+
* @constant
85+
*/
86+
RGBA_DXT1 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,
87+
88+
/**
89+
* A pixel format containing red, green, blue, and alpha channels that is DXT3 compressed.
90+
*
91+
* @type {Number}
92+
* @constant
93+
*/
94+
RGBA_DXT3 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,
95+
96+
/**
97+
* A pixel format containing red, green, blue, and alpha channels that is DXT5 compressed.
98+
*
99+
* @type {Number}
100+
* @constant
101+
*/
102+
RGBA_DXT5 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,
103+
104+
/**
105+
* A pixel format containing red, green, and blue channels that is PVR 4bpp compressed.
106+
*
107+
* @type {Number}
108+
* @constant
109+
*/
110+
RGB_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
111+
112+
/**
113+
* A pixel format containing red, green, and blue channels that is PVR 2bpp compressed.
114+
*
115+
* @type {Number}
116+
* @constant
117+
*/
118+
RGB_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
119+
120+
/**
121+
* A pixel format containing red, green, blue, and alpha channels that is PVR 4bpp compressed.
122+
*
123+
* @type {Number}
124+
* @constant
125+
*/
126+
RGBA_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
127+
128+
/**
129+
* A pixel format containing red, green, blue, and alpha channels that is PVR 2bpp compressed.
130+
*
131+
* @type {Number}
132+
* @constant
133+
*/
134+
RGBA_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
135+
136+
/**
137+
* A pixel format containing red, green, and blue channels that is ETC1 compressed.
138+
*
139+
* @type {Number}
140+
* @constant
141+
*/
142+
RGB_ETC1 : WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,
143+
72144
/**
73145
* @private
74146
*/
@@ -79,7 +151,16 @@ define([
79151
pixelFormat === PixelFormat.RGB ||
80152
pixelFormat === PixelFormat.RGBA ||
81153
pixelFormat === PixelFormat.LUMINANCE ||
82-
pixelFormat === PixelFormat.LUMINANCE_ALPHA;
154+
pixelFormat === PixelFormat.LUMINANCE_ALPHA ||
155+
pixelFormat === PixelFormat.RGB_DXT1 ||
156+
pixelFormat === PixelFormat.RGBA_DXT1 ||
157+
pixelFormat === PixelFormat.RGBA_DXT3 ||
158+
pixelFormat === PixelFormat.RGBA_DXT5 ||
159+
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
160+
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
161+
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
162+
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
163+
pixelFormat === PixelFormat.RGB_ETC1;
83164
},
84165

85166
/**
@@ -99,6 +180,75 @@ define([
99180
isDepthFormat : function(pixelFormat) {
100181
return pixelFormat === PixelFormat.DEPTH_COMPONENT ||
101182
pixelFormat === PixelFormat.DEPTH_STENCIL;
183+
},
184+
185+
/**
186+
* @private
187+
*/
188+
isCompressedFormat : function(pixelFormat) {
189+
return pixelFormat === PixelFormat.RGB_DXT1 ||
190+
pixelFormat === PixelFormat.RGBA_DXT1 ||
191+
pixelFormat === PixelFormat.RGBA_DXT3 ||
192+
pixelFormat === PixelFormat.RGBA_DXT5 ||
193+
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
194+
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
195+
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
196+
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
197+
pixelFormat === PixelFormat.RGB_ETC1;
198+
},
199+
200+
/**
201+
* @private
202+
*/
203+
isDXTFormat : function(pixelFormat) {
204+
return pixelFormat === PixelFormat.RGB_DXT1 ||
205+
pixelFormat === PixelFormat.RGBA_DXT1 ||
206+
pixelFormat === PixelFormat.RGBA_DXT3 ||
207+
pixelFormat === PixelFormat.RGBA_DXT5;
208+
},
209+
210+
/**
211+
* @private
212+
*/
213+
isPVRTCFormat : function(pixelFormat) {
214+
return pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
215+
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
216+
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
217+
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1;
218+
},
219+
220+
/**
221+
* @private
222+
*/
223+
isETC1Format : function(pixelFormat) {
224+
return pixelFormat === PixelFormat.RGB_ETC1;
225+
},
226+
227+
/**
228+
* @private
229+
*/
230+
compressedTextureSize : function(pixelFormat, width, height) {
231+
switch (pixelFormat) {
232+
case PixelFormat.RGB_DXT1:
233+
case PixelFormat.RGBA_DXT1:
234+
case PixelFormat.RGB_ETC1:
235+
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
236+
237+
case PixelFormat.RGBA_DXT3:
238+
case PixelFormat.RGBA_DXT5:
239+
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
240+
241+
case PixelFormat.RGB_PVRTC_4BPPV1:
242+
case PixelFormat.RGBA_PVRTC_4BPPV1:
243+
return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);
244+
245+
case PixelFormat.RGB_PVRTC_2BPPV1:
246+
case PixelFormat.RGBA_PVRTC_2BPPV1:
247+
return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);
248+
249+
default:
250+
return 0;
251+
}
102252
}
103253
};
104254

Source/Core/WebGLConstants.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ define([
315315
UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
316316
BROWSER_DEFAULT_WEBGL : 0x9244,
317317

318+
// WEBGL_compressed_texture_s3tc
319+
COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
320+
COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
321+
COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
322+
COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,
323+
324+
// WEBGL_compressed_texture_pvrtc
325+
COMPRESSED_RGB_PVRTC_4BPPV1_IMG : 0x8C00,
326+
COMPRESSED_RGB_PVRTC_2BPPV1_IMG : 0x8C01,
327+
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : 0x8C02,
328+
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG : 0x8C03,
329+
330+
// WEBGL_compressed_texture_etc1
331+
COMPRESSED_RGB_ETC1_WEBGL : 0x8D64,
332+
318333
// Desktop OpenGL
319334
DOUBLE : 0x140A,
320335

0 commit comments

Comments
 (0)