Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AnalyticalGraphicsInc/cesium into…
Browse files Browse the repository at this point in the history
… texture-map-fix
  • Loading branch information
lasalvavida committed May 12, 2016
2 parents 2aa1df0 + f7abdd4 commit 2a0f13c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change Log
* Fixed exaggerated terrain tiles disappearing. [#3676](https://github.com/AnalyticalGraphicsInc/cesium/issues/3676)
* Fixed infinite horizontal 2D scrolling in IE/Edge. [#3893](https://github.com/AnalyticalGraphicsInc/cesium/issues/3893)
* Fixed a bug that could cause incorrect normals to be computed for exaggerated terrain, especially for low-detail tiles. [#3904](https://github.com/AnalyticalGraphicsInc/cesium/pull/3904)
* Fixed a bug that was causing errors to be thrown when picking and terrain was enabled. [#3779](https://github.com/AnalyticalGraphicsInc/cesium/issues/3779)
* Fixed issue where labels were disappearing. [3730](https://github.com/AnalyticalGraphicsInc/cesium/issues/3730)

### 1.21 - 2016-05-02
Expand Down
28 changes: 23 additions & 5 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ define([
}
};

GlobeSurfaceTile.processStateMachine = function(tile, frameState, terrainProvider, imageryLayerCollection) {
GlobeSurfaceTile.processStateMachine = function(tile, frameState, terrainProvider, imageryLayerCollection, vertexArraysToDestroy) {
var surfaceTile = tile.data;
if (!defined(surfaceTile)) {
surfaceTile = tile.data = new GlobeSurfaceTile();
Expand All @@ -253,7 +253,7 @@ define([
}

if (tile.state === QuadtreeTileLoadState.LOADING) {
processTerrainStateMachine(tile, frameState, terrainProvider);
processTerrainStateMachine(tile, frameState, terrainProvider, vertexArraysToDestroy);
}

// The terrain is renderable as soon as we have a valid vertex array.
Expand Down Expand Up @@ -298,7 +298,7 @@ define([
isRenderable = isRenderable && (thisTileDoneLoading || defined(tileImagery.readyImagery));

isUpsampledOnly = isUpsampledOnly && defined(tileImagery.loadingImagery) &&
(tileImagery.loadingImagery.state === ImageryState.FAILED || tileImagery.loadingImagery.state === ImageryState.INVALID);
(tileImagery.loadingImagery.state === ImageryState.FAILED || tileImagery.loadingImagery.state === ImageryState.INVALID);
}

tile.upsampledFromParent = isUpsampledOnly;
Expand Down Expand Up @@ -336,7 +336,7 @@ define([
}
}

function processTerrainStateMachine(tile, frameState, terrainProvider) {
function processTerrainStateMachine(tile, frameState, terrainProvider, vertexArraysToDestroy) {
var surfaceTile = tile.data;
var loaded = surfaceTile.loadedTerrain;
var upsampled = surfaceTile.upsampledTerrain;
Expand All @@ -363,6 +363,15 @@ define([
if (loaded.state === TerrainState.READY) {
loaded.publishToTile(tile);

if (defined(tile.data.vertexArray)) {
// Free the tiles existing vertex array on next render.
vertexArraysToDestroy.push(tile.data.vertexArray);
}

// Transfer ownership of the vertex array to the tile itself.
tile.data.vertexArray = loaded.vertexArray;
loaded.vertexArray = undefined;

// No further loading or upsampling is necessary.
surfaceTile.pickTerrain = defaultValue(surfaceTile.loadedTerrain, surfaceTile.upsampledTerrain);
surfaceTile.loadedTerrain = undefined;
Expand Down Expand Up @@ -399,6 +408,15 @@ define([
if (upsampled.state === TerrainState.READY) {
upsampled.publishToTile(tile);

if (defined(tile.data.vertexArray)) {
// Free the tiles existing vertex array on next render.
vertexArraysToDestroy.push(tile.data.vertexArray);
}

// Transfer ownership of the vertex array to the tile itself.
tile.data.vertexArray = upsampled.vertexArray;
upsampled.vertexArray = undefined;

// No further upsampling is necessary. We need to continue loading, though.
surfaceTile.pickTerrain = surfaceTile.upsampledTerrain;
surfaceTile.upsampledTerrain = undefined;
Expand Down Expand Up @@ -654,4 +672,4 @@ define([
}

return GlobeSurfaceTile;
});
});
27 changes: 24 additions & 3 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ define([
this._usedDrawCommands = 0;
this._usedPickCommands = 0;

this._vertexArraysToDestroy = [];

this._debug = {
wireframe : false,
boundingSphereTile : undefined
Expand Down Expand Up @@ -282,6 +284,18 @@ define([
return aImagery.imageryLayer._layerIndex - bImagery.imageryLayer._layerIndex;
}

function freeVertexArray(vertexArray) {
var indexBuffer = vertexArray.indexBuffer;
vertexArray.destroy();

if (!indexBuffer.isDestroyed() && defined(indexBuffer.referenceCount)) {
--indexBuffer.referenceCount;
if (indexBuffer.referenceCount === 0) {
indexBuffer.destroy();
}
}
}

/**
* Called at the beginning of each render frame, before {@link QuadtreeTileProvider#showTileThisFrame}
* @param {FrameState} frameState The frame state.
Expand Down Expand Up @@ -316,6 +330,13 @@ define([
creditDisplay.addCredit(imageryProvider.credit);
}
}

var vertexArraysToDestroy = this._vertexArraysToDestroy;
var length = vertexArraysToDestroy.length;
for (var j = 0; j < length; ++j) {
freeVertexArray(vertexArraysToDestroy[j]);
}
vertexArraysToDestroy.length = 0;
};

/**
Expand Down Expand Up @@ -438,7 +459,7 @@ define([
* @exception {DeveloperError} <code>loadTile</code> must not be called before the tile provider is ready.
*/
GlobeSurfaceTileProvider.prototype.loadTile = function(frameState, tile) {
GlobeSurfaceTile.processStateMachine(tile, frameState, this._terrainProvider, this._imageryLayers);
GlobeSurfaceTile.processStateMachine(tile, frameState, this._terrainProvider, this._imageryLayers, this._vertexArraysToDestroy);
};

var boundingSphereScratch = new BoundingSphere();
Expand Down Expand Up @@ -1154,11 +1175,11 @@ define([
pickCommand.vertexArray = drawCommand.vertexArray;
pickCommand.uniformMap = drawCommand.uniformMap;
pickCommand.boundingVolume = drawCommand.boundingVolume;
pickCommand.orientedBoundingBox = pickCommand.orientedBoundingBox;
pickCommand.orientedBoundingBox = drawCommand.orientedBoundingBox;
pickCommand.pass = drawCommand.pass;

frameState.commandList.push(pickCommand);
}

return GlobeSurfaceTileProvider;
});
});
21 changes: 7 additions & 14 deletions Source/Scene/TileTerrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ define([
});

tile.data.occludeePointInScaledSpace = Cartesian3.clone(mesh.occludeePointInScaledSpace, surfaceTile.occludeePointInScaledSpace);

// Free the tile's existing vertex array, if any.
surfaceTile.freeVertexArray();

// Transfer ownership of the vertex array to the tile itself.
surfaceTile.vertexArray = this.vertexArray;
this.vertexArray = undefined;
};

TileTerrain.prototype.processLoadStateMachine = function(frameState, terrainProvider, x, y, level) {
Expand Down Expand Up @@ -129,12 +122,12 @@ define([

var message = 'Failed to obtain terrain tile X: ' + x + ' Y: ' + y + ' Level: ' + level + '.';
terrainProvider._requestError = TileProviderError.handleError(
terrainProvider._requestError,
terrainProvider,
terrainProvider.errorEvent,
message,
x, y, level,
doRequest);
terrainProvider._requestError,
terrainProvider,
terrainProvider.errorEvent,
message,
x, y, level,
doRequest);
}

function doRequest() {
Expand Down Expand Up @@ -256,4 +249,4 @@ define([
}

return TileTerrain;
});
});

0 comments on commit 2a0f13c

Please sign in to comment.