Skip to content

Commit

Permalink
Add support for s3tc, pvrtc, and etc1 compressed textures and loading…
Browse files Browse the repository at this point in the history
… them

from KTX files.
  • Loading branch information
bagnell committed Dec 19, 2016
1 parent 9d7348d commit 4cc7559
Show file tree
Hide file tree
Showing 29 changed files with 1,995 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Change Log
* Added `divideComponents` function to `Cartesian2`, `Cartesian3`, and `Cartesian4`. [#4750](https://github.com/AnalyticalGraphicsInc/cesium/pull/4750)
* Added `WebGLConstants` enum. Previously, this was part of the private Renderer API. [#4731](https://github.com/AnalyticalGraphicsInc/cesium/pull/4731)
* Fixed tooltips for gallery thumbnails in Sandcastle [#4702](https://github.com/AnalyticalGraphicsInc/cesium/pull/4702)
* 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)

### 1.28 - 2016-12-01

Expand Down
152 changes: 151 additions & 1 deletion Source/Core/PixelFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,78 @@ define([
*/
LUMINANCE_ALPHA : WebGLConstants.LUMINANCE_ALPHA,

/**
* A pixel format containing red, green, and blue channels that is DXT1 compressed.
*
* @type {Number}
* @constant
*/
RGB_DXT1 : WebGLConstants.COMPRESSED_RGB_S3TC_DXT1_EXT,

/**
* A pixel format containing red, green, blue, and alpha channels that is DXT1 compressed.
*
* @type {Number}
* @constant
*/
RGBA_DXT1 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT1_EXT,

/**
* A pixel format containing red, green, blue, and alpha channels that is DXT3 compressed.
*
* @type {Number}
* @constant
*/
RGBA_DXT3 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT3_EXT,

/**
* A pixel format containing red, green, blue, and alpha channels that is DXT5 compressed.
*
* @type {Number}
* @constant
*/
RGBA_DXT5 : WebGLConstants.COMPRESSED_RGBA_S3TC_DXT5_EXT,

/**
* A pixel format containing red, green, and blue channels that is PVR 4bpp compressed.
*
* @type {Number}
* @constant
*/
RGB_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_4BPPV1_IMG,

/**
* A pixel format containing red, green, and blue channels that is PVR 2bpp compressed.
*
* @type {Number}
* @constant
*/
RGB_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGB_PVRTC_2BPPV1_IMG,

/**
* A pixel format containing red, green, blue, and alpha channels that is PVR 4bpp compressed.
*
* @type {Number}
* @constant
*/
RGBA_PVRTC_4BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,

/**
* A pixel format containing red, green, blue, and alpha channels that is PVR 2bpp compressed.
*
* @type {Number}
* @constant
*/
RGBA_PVRTC_2BPPV1 : WebGLConstants.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,

/**
* A pixel format containing red, green, and blue channels that is ETC1 compressed.
*
* @type {Number}
* @constant
*/
RGB_ETC1 : WebGLConstants.COMPRESSED_RGB_ETC1_WEBGL,

/**
* @private
*/
Expand All @@ -79,7 +151,16 @@ define([
pixelFormat === PixelFormat.RGB ||
pixelFormat === PixelFormat.RGBA ||
pixelFormat === PixelFormat.LUMINANCE ||
pixelFormat === PixelFormat.LUMINANCE_ALPHA;
pixelFormat === PixelFormat.LUMINANCE_ALPHA ||
pixelFormat === PixelFormat.RGB_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT3 ||
pixelFormat === PixelFormat.RGBA_DXT5 ||
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
pixelFormat === PixelFormat.RGB_ETC1;
},

/**
Expand All @@ -99,6 +180,75 @@ define([
isDepthFormat : function(pixelFormat) {
return pixelFormat === PixelFormat.DEPTH_COMPONENT ||
pixelFormat === PixelFormat.DEPTH_STENCIL;
},

/**
* @private
*/
isCompressedFormat : function(pixelFormat) {
return pixelFormat === PixelFormat.RGB_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT3 ||
pixelFormat === PixelFormat.RGBA_DXT5 ||
pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1 ||
pixelFormat === PixelFormat.RGB_ETC1;
},

/**
* @private
*/
isDXTFormat : function(pixelFormat) {
return pixelFormat === PixelFormat.RGB_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT1 ||
pixelFormat === PixelFormat.RGBA_DXT3 ||
pixelFormat === PixelFormat.RGBA_DXT5;
},

/**
* @private
*/
isPVRTCFormat : function(pixelFormat) {
return pixelFormat === PixelFormat.RGB_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGB_PVRTC_2BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_4BPPV1 ||
pixelFormat === PixelFormat.RGBA_PVRTC_2BPPV1;
},

/**
* @private
*/
isETC1Format : function(pixelFormat) {
return pixelFormat === PixelFormat.RGB_ETC1;
},

/**
* @private
*/
compressedTextureSize : function(pixelFormat, width, height) {
switch (pixelFormat) {
case PixelFormat.RGB_DXT1:
case PixelFormat.RGBA_DXT1:
case PixelFormat.RGB_ETC1:
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;

case PixelFormat.RGBA_DXT3:
case PixelFormat.RGBA_DXT5:
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;

case PixelFormat.RGB_PVRTC_4BPPV1:
case PixelFormat.RGBA_PVRTC_4BPPV1:
return Math.floor((Math.max(width, 8) * Math.max(height, 8) * 4 + 7) / 8);

case PixelFormat.RGB_PVRTC_2BPPV1:
case PixelFormat.RGBA_PVRTC_2BPPV1:
return Math.floor((Math.max(width, 16) * Math.max(height, 8) * 2 + 7) / 8);

default:
return 0;
}
}
};

Expand Down
15 changes: 15 additions & 0 deletions Source/Core/WebGLConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ define([
UNPACK_COLORSPACE_CONVERSION_WEBGL : 0x9243,
BROWSER_DEFAULT_WEBGL : 0x9244,

// WEBGL_compressed_texture_s3tc
COMPRESSED_RGB_S3TC_DXT1_EXT : 0x83F0,
COMPRESSED_RGBA_S3TC_DXT1_EXT : 0x83F1,
COMPRESSED_RGBA_S3TC_DXT3_EXT : 0x83F2,
COMPRESSED_RGBA_S3TC_DXT5_EXT : 0x83F3,

// WEBGL_compressed_texture_pvrtc
COMPRESSED_RGB_PVRTC_4BPPV1_IMG : 0x8C00,
COMPRESSED_RGB_PVRTC_2BPPV1_IMG : 0x8C01,
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG : 0x8C02,
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG : 0x8C03,

// WEBGL_compressed_texture_etc1
COMPRESSED_RGB_ETC1_WEBGL : 0x8D64,

// Desktop OpenGL
DOUBLE : 0x140A,

Expand Down
Loading

0 comments on commit 4cc7559

Please sign in to comment.