Skip to content

Commit

Permalink
Merge master to 3d-tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Feb 2, 2017
2 parents ef1863a + b6b3ad2 commit e05898a
Show file tree
Hide file tree
Showing 45 changed files with 741 additions and 1,143 deletions.
Binary file added Apps/Sandcastle/gallery/Custom Geocoder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions Apps/Sandcastle/gallery/Materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@
Sandcastle.declare(applyCompressedTextureMaterial); // For highlighting in Sandcastle.

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

Expand Down Expand Up @@ -473,7 +472,7 @@
Sandcastle.highlight(applyPolylineOutlineMaterial);
}
}]);

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

Expand Down
10 changes: 5 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Change Log
==========

### TODO
### 1.31 - 2017-03-01

* Added compressed texture support.
* 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.
* Added `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`. [#4758](https://github.com/AnalyticalGraphicsInc/cesium/pull/4758)
* 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`.
* Added support for [3D Tiles](https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/README.md) for streaming massive heterogeneous 3D geospatial datasets. The new Cesium APIs are:
* `Cesium3DTileset`
Expand Down
2 changes: 1 addition & 1 deletion Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ define([
this._fragDepth = !!getExtension(gl, ['EXT_frag_depth']);
this._debugShaders = getExtension(gl, ['WEBGL_debug_shaders']);

this._s3tc = !!getExtension(gl, ['WEBGL_compressed_s3tc', 'MOZ_WEBGL_compressed_texture_s3tc', 'WEBKIT_WEBGL_compressed_texture_s3tc']);
this._s3tc = !!getExtension(gl, ['WEBGL_compressed_texture_s3tc', 'MOZ_WEBGL_compressed_texture_s3tc', 'WEBKIT_WEBGL_compressed_texture_s3tc']);
this._pvrtc = !!getExtension(gl, ['WEBGL_compressed_texture_pvrtc', 'WEBKIT_WEBGL_compressed_texture_pvrtc']);
this._etc1 = !!getExtension(gl, ['WEBGL_compressed_texture_etc1']);

Expand Down
5 changes: 5 additions & 0 deletions Source/Scene/BatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'../Core/defineProperties',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/FeatureDetection',
'../Core/Math',
'../Core/PixelFormat',
'../Core/RuntimeError',
Expand All @@ -28,6 +29,7 @@ define([
defineProperties,
destroyObject,
DeveloperError,
FeatureDetection,
CesiumMath,
PixelFormat,
RuntimeError,
Expand Down Expand Up @@ -273,6 +275,9 @@ define([
return Cartesian4.fromElements(x, y, z, w, result);
}

if (!FeatureDetection.supportsTypedArrays()) {
return;
}
var scratchFloatArray = new Float32Array(1);

function packFloat(value, result) {
Expand Down
58 changes: 40 additions & 18 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,21 +1449,25 @@ define([
this._blendOption = this.blendOption;

if (blendOptionChanged) {
this._rsOpaque = RenderState.fromCache({
depthTest : {
enabled : true,
func : WebGLConstants.LEQUAL // Allows label glyphs and billboards to overlap.
},
depthMask : true
});
if (this._blendOption === BlendOption.OPAQUE || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
this._rsOpaque = RenderState.fromCache({
depthTest : {
enabled : true,
func : WebGLConstants.LEQUAL // Allows label glyphs and billboards to overlap.
},
depthMask : true
});
} else {
this._rsOpaque = undefined;
}

if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
this._rsTranslucent = RenderState.fromCache({
depthTest : {
enabled : true,
func : WebGLConstants.LEQUAL // Allows label glyphs and billboards to overlap.
},
depthMask : false,
depthMask : this._blendOption === BlendOption.TRANSLUCENT,
blending : BlendingState.ALPHA_BLEND
});
} else {
Expand Down Expand Up @@ -1504,7 +1508,7 @@ define([
vs.defines.push('DISTANCE_DISPLAY_CONDITION');
}

if (this._blendOption === BlendOption.OPAQUE || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['OPAQUE'],
sources : [BillboardCollectionFS]
Expand All @@ -1516,12 +1520,7 @@ define([
fragmentShaderSource : fs,
attributeLocations : attributeLocations
});
} else {
this._sp = this._sp && this._sp.destroy();
this._sp = undefined;
}

if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['TRANSLUCENT'],
sources : [BillboardCollectionFS]
Expand All @@ -1533,9 +1532,32 @@ define([
fragmentShaderSource : fs,
attributeLocations : attributeLocations
});
} else {
this._spTranslucent = this._spTranslucent && this._spTranslucent.destroy();
this._spTranslucent = undefined;
}

if (this._blendOption === BlendOption.OPAQUE) {
fs = new ShaderSource({
sources : [BillboardCollectionFS]
});
this._sp = ShaderProgram.replaceCache({
context : context,
shaderProgram : this._sp,
vertexShaderSource : vs,
fragmentShaderSource : fs,
attributeLocations : attributeLocations
});
}

if (this._blendOption === BlendOption.TRANSLUCENT) {
fs = new ShaderSource({
sources : [BillboardCollectionFS]
});
this._spTranslucent = ShaderProgram.replaceCache({
context : context,
shaderProgram : this._spTranslucent,
vertexShaderSource : vs,
fragmentShaderSource : fs,
attributeLocations : attributeLocations
});
}

this._compiledShaderRotation = this._shaderRotation;
Expand Down Expand Up @@ -1629,7 +1651,7 @@ define([

var opaqueCommand = opaque || (opaqueAndTranslucent && j % 2 === 0);

command.pass = opaqueCommand ? Pass.OPAQUE : Pass.TRANSLUCENT;
command.pass = opaqueCommand || !opaqueAndTranslucent ? Pass.OPAQUE : Pass.TRANSLUCENT;
command.owner = this;

var index = opaqueAndTranslucent ? Math.floor(j / 2.0) : j;
Expand Down
10 changes: 4 additions & 6 deletions Source/Scene/GroundPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ define([
* is supported at this time.
* </p>
* <p>
* Because of the cutting edge nature of this feature in WebGL, it requires the EXT_frag_depth extension, which is currently only supported in Chrome,
* Firefox, Edge, and Safari 10. It's not yet supported in iOS 10. Android support varies by hardware and IE11 will most likely never support
* it. You can use webglreport.com to verify support for your hardware.
* For correct rendering, this feature requires the EXT_frag_depth WebGL extension. For hardware that do not support this extension, there
* will be rendering artifacts for some viewing angles.
* </p>
* <p>
* Valid geometries are {@link CircleGeometry}, {@link CorridorGeometry}, {@link EllipseGeometry}, {@link PolygonGeometry}, and {@link RectangleGeometry}.
Expand Down Expand Up @@ -400,7 +399,7 @@ define([
* @returns {Boolean} <code>true</code> if GroundPrimitives are supported; otherwise, returns <code>false</code>
*/
GroundPrimitive.isSupported = function(scene) {
return scene.context.fragmentDepth && scene.context.stencilBuffer;
return scene.context.stencilBuffer;
};

GroundPrimitive._defaultMaxTerrainHeight = 9000.0;
Expand Down Expand Up @@ -1032,8 +1031,7 @@ define([
* @exception {DeveloperError} Not all of the geometry instances have the same color attribute.
*/
GroundPrimitive.prototype.update = function(frameState) {
var context = frameState.context;
if (!context.fragmentDepth || !this.show || (!defined(this._primitive) && !defined(this.geometryInstances))) {
if (!this.show || (!defined(this._primitive) && !defined(this.geometryInstances))) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions Source/Scene/LabelCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,8 @@ define([

billboardCollection.modelMatrix = this.modelMatrix;
billboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
billboardCollection.blendOption = this.blendOption;
backgroundBillboardCollection.modelMatrix = this.modelMatrix;
backgroundBillboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
backgroundBillboardCollection.blendOption = this.blendOption;

var context = frameState.context;

Expand Down Expand Up @@ -805,6 +803,10 @@ define([
this._totalGlyphCount += glyphCountDifference;
}

var blendOption = backgroundBillboardCollection.length > 0 ? BlendOption.TRANSLUCENT : this.blendOption;
billboardCollection.blendOption = blendOption;
backgroundBillboardCollection.blendOption = blendOption;

this._labelsToUpdate.length = 0;
backgroundBillboardCollection.update(frameState);
billboardCollection.update(frameState);
Expand Down
58 changes: 52 additions & 6 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1458,16 +1458,62 @@ define([
var ktxRegex = /(^data:image\/ktx)|(\.ktx$)/i;
var crnRegex = /(^data:image\/crn)|(\.crn$)/i;

function parseTextures(model) {
function parseTextures(model, context) {
var images = model.gltf.images;
var textures = model.gltf.textures;
for (var id in textures) {
if (textures.hasOwnProperty(id)) {
var gltfImage = images[textures[id].source];
var extras = gltfImage.extras;

var binary = undefined;
var uri = undefined;

// First check for a compressed texture
if (defined(extras) && defined(extras.compressedImage3DTiles)) {
var crunch = extras.compressedImage3DTiles.crunch;
var s3tc = extras.compressedImage3DTiles.s3tc;
var pvrtc = extras.compressedImage3DTiles.pvrtc1;
var etc1 = extras.compressedImage3DTiles.etc1;

if (context.s3tc && defined(crunch)) {
if (defined(crunch.extensions)&& defined(crunch.extensions.KHR_binary_glTF)) {
binary = crunch.extensions.KHR_binary_glTF;
} else {
uri = crunch.uri;
}
} else if (context.s3tc && defined(s3tc)) {
if (defined(s3tc.extensions)&& defined(s3tc.extensions.KHR_binary_glTF)) {
binary = s3tc.extensions.KHR_binary_glTF;
} else {
uri = s3tc.uri;
}
} else if (context.pvrtc && defined(pvrtc)) {
if (defined(pvrtc.extensions)&& defined(pvrtc.extensions.KHR_binary_glTF)) {
binary = pvrtc.extensions.KHR_binary_glTF;
} else {
uri = pvrtc.uri;
}
} else if (context.etc1 && defined(etc1)) {
if (defined(etc1.extensions)&& defined(etc1.extensions.KHR_binary_glTF)) {
binary = etc1.extensions.KHR_binary_glTF;
} else {
uri = etc1.uri;
}
}
}

// No compressed texture, so image references either uri (external or base64-encoded) or bufferView
if (!defined(binary) && !defined(uri)) {
if (defined(gltfImage.extensions) && defined(gltfImage.extensions.KHR_binary_glTF)) {
binary = gltfImage.extensions.KHR_binary_glTF;
} else {
uri = new Uri(gltfImage.uri);
}
}

// Image references either uri (external or base64-encoded) or bufferView
if (defined(gltfImage.extensions) && defined(gltfImage.extensions.KHR_binary_glTF)) {
var binary = gltfImage.extensions.KHR_binary_glTF;
if (defined(binary)) {
model._loadResources.texturesToCreateFromBufferView.enqueue({
id : id,
image : undefined,
Expand Down Expand Up @@ -1625,13 +1671,13 @@ define([
model._runtime.meshesByName = runtimeMeshesByName;
}

function parse(model) {
function parse(model, context) {
if (!model._loadRendererResourcesFromCache) {
parseBuffers(model);
parseBufferViews(model);
parseShaders(model);
parsePrograms(model);
parseTextures(model);
parseTextures(model, context);
}
parseMaterials(model);
parseMeshes(model);
Expand Down Expand Up @@ -4329,7 +4375,7 @@ define([
}

this._loadResources = new LoadResources();
parse(this);
parse(this, context);
}
}

Expand Down
Loading

0 comments on commit e05898a

Please sign in to comment.