Skip to content

Commit

Permalink
Merge pull request #4758 from AnalyticalGraphicsInc/texture-compression
Browse files Browse the repository at this point in the history
Texture compression
  • Loading branch information
pjcozzi authored Feb 2, 2017
2 parents e2c5ccc + ffa2554 commit b6b3ad2
Show file tree
Hide file tree
Showing 44 changed files with 3,129 additions and 66 deletions.
31 changes: 30 additions & 1 deletion Apps/Sandcastle/gallery/Materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@
});
}

function applyCompressedTextureMaterial(primitive, scene) {
Sandcastle.declare(applyCompressedTextureMaterial); // For highlighting in Sandcastle.

var compressedImageUrl;
if (scene.getCompressedTextureFormatSupported('s3tc')) {
compressedImageUrl = '../images/LogoDXT1.ktx';
} else if (scene.getCompressedTextureFormatSupported('etc1')) {
compressedImageUrl = '../images/LogoETC1.ktx';
} else if (scene.getCompressedTextureFormatSupported('pvrtc')) {
compressedImageUrl = '../images/LogoPVR.ktx';
}

primitive.appearance.material = new Cesium.Material({
fabric : {
type : 'Image',
uniforms : {
image : compressedImageUrl
}
}
});
}

function applyNormalMapMaterial(primitive, scene) {
Sandcastle.declare(applyNormalMapMaterial); // For highlighting in Sandcastle.
primitive.appearance.material = new Cesium.Material({
Expand Down Expand Up @@ -310,6 +332,13 @@
applyImageMaterial(rectangle, scene);
Sandcastle.highlight(applyImageMaterial);
}
}, {
text : 'Compressed Image',
onselect : function() {
toggleRectangleVisibility();
applyCompressedTextureMaterial(rectangle, scene);
Sandcastle.highlight(applyCompressedTextureMaterial);
}
}]);

Sandcastle.addToolbarMenu([{
Expand Down Expand Up @@ -443,7 +472,7 @@
Sandcastle.highlight(applyPolylineOutlineMaterial);
}
}]);

document.getElementById('toolbar').style.width = '10%';
}

Expand Down
Binary file added Apps/Sandcastle/images/LogoDXT1.ktx
Binary file not shown.
Binary file added Apps/Sandcastle/images/LogoETC1.ktx
Binary file not shown.
Binary file added Apps/Sandcastle/images/LogoPVR.ktx
Binary file not shown.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Change Log
### 1.31 - 2017-03-01

* Enable rendering `GroundPrimitives` on hardware without the `EXT_frag_depth` extension; however, this could cause artifacts for certain viewing angles.
* Added compressed texture support. [#4758](https://github.com/AnalyticalGraphicsInc/cesium/pull/4758)
* glTF models and imagery layers can now reference [KTX](https://www.khronos.org/opengles/sdk/tools/KTX/) textures and textures compressed with [crunch](https://github.com/BinomialLLC/crunch).
* Added `loadKTX`, to load KTX textures, and `loadCRN` to load crunch compressed textures.
* Added new `PixelFormat` and `WebGLConstants` enums from WebGL extensions `WEBGL_compressed_s3tc`, `WEBGL_compressed_texture_pvrtc`, and `WEBGL_compressed_texture_etc1`.
* Added `CompressedTextureBuffer`.

### 1.30 - 2017-02-01

Expand Down
79 changes: 79 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,85 @@ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

### crunch

https://github.com/BinomialLLC/crunch

>crunch/crnlib uses the ZLIB license:
>http://opensource.org/licenses/Zlib
>
>Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
>
>This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
>
>Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
>
>1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
>
>2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
>
>3. This notice may not be removed or altered from any source distribution.
### crunch_lib.cpp

https://github.com/Apress/html5-game-dev-insights/blob/master/jones_ch21/crunch_webgl/crunch_js/crunch_lib.cpp

>Copyright (c) 2013, Evan Parker, Brandon Jones. All rights reserved.
>
>Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
>
> * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
> * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
>
>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

### texture-tester

https://github.com/toji/texture-tester

>Copyright (c) 2014, Brandon Jones. All rights reserved.
>
>Redistribution and use in source and binary forms, with or without modification,
>are permitted provided that the following conditions are met:
>
>* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
>* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
>
>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Tests
=====

Expand Down
93 changes: 93 additions & 0 deletions Source/Core/CompressedTextureBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*global define*/
define([
'./defined',
'./defineProperties'
], function(
defined,
defineProperties
) {
'use strict';

/**
* Describes a compressed texture and contains a compressed texture buffer.
*
* @param {PixelFormat} internalFormat The pixel format of the compressed texture.
* @param {Number} width The width of the texture.
* @param {Number} height The height of the texture.
* @param {Uint8Array} buffer The compressed texture buffer.
*/
function CompressedTextureBuffer(internalFormat, width, height, buffer) {
this._format = internalFormat;
this._width = width;
this._height = height;
this._buffer = buffer;
}

defineProperties(CompressedTextureBuffer.prototype, {
/**
* The format of the compressed texture.
* @type PixelFormat
* @readonly
*/
internalFormat : {
get : function() {
return this._format;
}
},
/**
* The width of the texture.
* @type Number
* @readonly
*/
width : {
get : function() {
return this._width;
}
},
/**
* The height of the texture.
* @type Number
* @readonly
*/
height : {
get : function() {
return this._height;
}
},
/**
* The compressed texture buffer.
* @type Uint8Array
* @readonly
*/
bufferView : {
get : function() {
return this._buffer;
}
}
});

/**
* Creates a shallow clone of a compressed texture buffer.
*
* @param {CompressedTextureBuffer} object The compressed texture buffer to be cloned.
* @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
*/
CompressedTextureBuffer.clone = function(object) {
if (!defined(object)) {
return undefined;
}

return new CompressedTextureBuffer(object._format, object._width, object._height, object._buffer);
};

/**
* Creates a shallow clone of this compressed texture buffer.
*
* @return {CompressedTextureBuffer} A shallow clone of the compressed texture buffer.
*/
CompressedTextureBuffer.prototype.clone = function() {
return CompressedTextureBuffer.clone(this);
};

return CompressedTextureBuffer;
});
Loading

0 comments on commit b6b3ad2

Please sign in to comment.