Skip to content

Commit

Permalink
Don't regenerate fill tiles every frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 5, 2018
1 parent 237f8de commit 0328cc9
Show file tree
Hide file tree
Showing 9 changed files with 881 additions and 32 deletions.
6 changes: 5 additions & 1 deletion Source/Core/TileEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ define([
WEST: 0,
NORTH: 1,
EAST: 2,
SOUTH: 3
SOUTH: 3,
NORTHWEST: 4,
NORTHEAST: 5,
SOUTHWEST: 6,
SOUTHEAST: 7
};

return TileEdge;
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/GlobeSurfaceShaderSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ define([
var quantization = 0;
var quantizationDefine = '';

var mesh = surfaceTile.vertexArray !== undefined ? surfaceTile.mesh : surfaceTile.fillMesh;
var mesh = surfaceTile.vertexArray !== undefined ? surfaceTile.mesh : surfaceTile.fill.mesh;
var terrainEncoding = mesh.encoding;
var quantizationMode = terrainEncoding.quantization;
if (quantizationMode === TerrainQuantization.BITS12) {
Expand All @@ -80,7 +80,7 @@ define([

var vertexLogDepth = 0;
var vertexLogDepthDefine = '';
if (surfaceTile.terrainData !== undefined && surfaceTile.terrainData._createdByUpsampling) {
if (surfaceTile.terrainData === undefined || surfaceTile.terrainData._createdByUpsampling) {
vertexLogDepth = 1;
vertexLogDepthDefine = 'DISABLE_GL_POSITION_LOG_DEPTH';
}
Expand Down
12 changes: 3 additions & 9 deletions Source/Scene/GlobeSurfaceTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ define([

this.terrainState = TerrainState.UNLOADED;
this.mesh = undefined;
this.fillMesh = undefined;
this.fill = undefined;
this.vertexArray = undefined;
this.fillVertexArray = undefined;

// TODO: probably better to have a bounding sphere for 2D rather than one for picking.
this.pickBoundingSphere = new BoundingSphere();
Expand Down Expand Up @@ -182,7 +181,7 @@ define([
var scratchResult = new Cartesian3();

GlobeSurfaceTile.prototype.pick = function(ray, mode, projection, cullBackFaces, result) {
var mesh = this.mesh || this.fillMesh;
var mesh = this.mesh || this.fill.mesh;
if (!defined(mesh)) {
return undefined;
}
Expand Down Expand Up @@ -223,7 +222,7 @@ define([

this.terrainState = TerrainState.UNLOADED;
this.mesh = undefined;
this.fillMesh = undefined;
this.fill = this.fill && this.fill.destroy();

var imageryList = this.imagery;
for (var i = 0, len = imageryList.length; i < len; ++i) {
Expand All @@ -250,11 +249,6 @@ define([
}
}

if (defined(this.fillVertexArray)) {
this.fillVertexArray.destroy();
this.fillVertexArray = undefined;
}

if (defined(this.wireframeVertexArray)) {
indexBuffer = this.wireframeVertexArray.indexBuffer;

Expand Down
63 changes: 55 additions & 8 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ define([
'./ImageryLayer',
'./QuadtreeTileLoadState',
'./SceneMode',
'./ShadowMode'
'./ShadowMode',
'./TerrainFillMesh'
], function(
AttributeCompression,
BoundingSphere,
Expand Down Expand Up @@ -109,7 +110,8 @@ define([
ImageryLayer,
QuadtreeTileLoadState,
SceneMode,
ShadowMode) {
ShadowMode,
TerrainFillMesh) {
'use strict';

/**
Expand Down Expand Up @@ -224,6 +226,9 @@ define([
* @private
*/
this._clippingPlanes = undefined;

this._hasLoadedTilesThisFrame = false;
this._hasFillTilesThisFrame = false;
}

defineProperties(GlobeSurfaceTileProvider.prototype, {
Expand Down Expand Up @@ -468,6 +473,9 @@ define([
clippingPlanes.update(frameState);
}
this._usedDrawCommands = 0;

this._hasLoadedTilesThisFrame = false;
this._hasFillTilesThisFrame = false;
};

/**
Expand Down Expand Up @@ -500,6 +508,12 @@ define([
});
}

// If this frame has a mix of loaded and fill tiles, we need to propagate
// loaded heights to the fill tiles.
if (this._hasFillTilesThisFrame && this._hasLoadedTilesThisFrame) {
TerrainFillMesh.updateFillTiles(this, this._quadtree._tilesToRender, frameState);
}

// Add the tile render commands to the command list, sorted by texture count.
var tilesToRenderByTextureCount = this._tilesToRenderByTextureCount;
for (var textureCountIndex = 0, textureCountLength = tilesToRenderByTextureCount.length; textureCountIndex < textureCountLength; ++textureCountIndex) {
Expand Down Expand Up @@ -723,6 +737,8 @@ define([

var surfaceTile = tile.data;
if (nearestRenderableTile !== undefined && nearestRenderableTile !== tile) {
this._hasFillTilesThisFrame = true;

surfaceTile.renderableTile = nearestRenderableTile;

// The renderable tile may have previously deferred to an ancestor.
Expand All @@ -738,6 +754,7 @@ define([
ancestorSubset.z = (myRectangle.east - ancestorRectangle.west) / (ancestorRectangle.east - ancestorRectangle.west);
ancestorSubset.w = (myRectangle.north - ancestorRectangle.south) / (ancestorRectangle.north - ancestorRectangle.south);
} else {
this._hasLoadedTilesThisFrame = true;
surfaceTile.renderableTile = undefined;
}

Expand Down Expand Up @@ -1270,9 +1287,9 @@ define([
if (surfaceTile.vertexArray !== undefined) {
mesh = surfaceTile.mesh;
vertexArray = surfaceTile.vertexArray;
} else if (surfaceTile.fillVertexArray !== undefined) {
mesh = surfaceTile.fillMesh;
vertexArray = surfaceTile.fillVertexArray;
} else if (surfaceTile.fill !== undefined && surfaceTile.fill.vertexArray !== undefined) {
mesh = surfaceTile.fill.mesh;
vertexArray = surfaceTile.fill.vertexArray;
}

if (!defined(mesh) || !defined(vertexArray)) {
Expand Down Expand Up @@ -1843,7 +1860,37 @@ define([
addDrawCommandsForTile(tileProvider, surfaceTile.renderableTile, frameState, surfaceTile.renderableTileSubset);
return;
} else if (missingTileStrategy === MissingTileStrategy.CREATE_FILL_TILE) {
createFillTile(tileProvider, tile, frameState);
// if (surfaceTile.fillMesh === undefined) {
// if (tile.renderable) {
// console.log(`Frame ${frameState.frameNumber} L${tile.level}X${tile.x}Y${tile.y} renderable`);
// } else {
// console.log(`Frame ${frameState.frameNumber} L${tile.level}X${tile.x}Y${tile.y} no mesh`);
// }

// for (var i = 0; i < tileProvider._quadtree._tilesToRender.length; ++i) {
// var foo = tileProvider._quadtree._tilesToRender[i];
// if (foo.data && foo.data.fillMesh) {
// foo.data.fillMesh.visitedFrame = undefined;
// }
// }

// TerrainFillMesh.updateFillTiles(tileProvider, tileProvider._quadtree._tilesToRender, frameState);
// } else if (surfaceTile.fillMesh.changedThisFrame) {
// console.log(`Frame ${frameState.frameNumber} L${tile.level}X${tile.x}Y${tile.y} changed`);
// }
if (surfaceTile.fill == undefined) {
// No fill was created for this tile, probably because this tile is not connected to
// any renderable tiles. So create a simple tile in the middle of the tile's possible
// height range.
surfaceTile.fill = new TerrainFillMesh();
surfaceTile.fill.tile = tile;
return; // TODO
}
surfaceTile.fill.update(tileProvider, frameState);
//return;
//createFillTile(tileProvider, tile, frameState);
} else {
return;
}
}

Expand Down Expand Up @@ -1882,7 +1929,7 @@ define([
--maxTextures;
}

var mesh = surfaceTile.vertexArray ? surfaceTile.mesh : surfaceTile.fillMesh;
var mesh = surfaceTile.vertexArray ? surfaceTile.mesh : surfaceTile.fill.mesh;
var rtc = mesh.center;
var encoding = mesh.encoding;

Expand Down Expand Up @@ -2127,7 +2174,7 @@ define([
command.receiveShadows = receiveShadows;
command.renderState = renderState;
command.primitiveType = PrimitiveType.TRIANGLES;
command.vertexArray = surfaceTile.vertexArray || surfaceTile.fillVertexArray;
command.vertexArray = surfaceTile.vertexArray || surfaceTile.fill.vertexArray;
command.uniformMap = uniformMap;
command.pass = Pass.GLOBE;

Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/Imagery.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ define([
return this.referenceCount;
};

Imagery.prototype.processStateMachine = function(frameState, needGeographicProjection) {
if (this.state === ImageryState.UNLOADED) {
Imagery.prototype.processStateMachine = function(frameState, needGeographicProjection, skipLoading) {
if (this.state === ImageryState.UNLOADED && !skipLoading) {
this.state = ImageryState.TRANSITIONING;
this.imageryLayer._requestImagery(this);
}
Expand Down
16 changes: 13 additions & 3 deletions Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,18 @@ define([
/**
* Gets or sets a value indicating whether the ancestors of rendered tiles should be preloaded.
* Setting this to true optimizes the zoom-out experience and provides more detail in
* newly-exposed areas when panning. The down side is that is requires loading more tiles.
* newly-exposed areas when panning. The down side is that it requires loading more tiles.
* @type {Boolean}
* @default false
*/
this.preloadAncestors = false;

/**
* Gets or sets a value indicating whether the siblings of rendered tiles should be preloaded.
* Setting this to true
*/
this.preloadSiblings = false;

this._occluders = new QuadtreeOccluders({
ellipsoid : ellipsoid
});
Expand Down Expand Up @@ -819,14 +825,14 @@ define([

// EXCEPT if we're waiting on heaps of descendants, the above will take too long. So in that case,
// load this tile INSTEAD of loading any of the descendants, and tell the up-level we're only waiting
// on this tile.
// on this tile. Keep doing this until we actually manage to render this tile.
var wasRenderedLastFrame = tile._frameRendered === primitive._lastSelectionFrameNumber;
if (!wasRenderedLastFrame && notYetRenderableCount > primitive.loadingDescendantLimit) {
primitive._tileLoadQueueLow.length = loadIndexLow;
primitive._tileLoadQueueMedium.length = loadIndexMedium;
primitive._tileLoadQueueHigh.length = loadIndexHigh;
queueTileLoad(primitive, primitive._tileLoadQueueMedium, tile, frameState);
traversalDetails.notYetRenderableCount = 1;
traversalDetails.notYetRenderableCount = tile.renderable ? 0 : 1;
}

traversalDetails.anyAreRenderable = tile.renderable;
Expand Down Expand Up @@ -921,6 +927,10 @@ define([
traversalDetails.allAreRenderable = true;
traversalDetails.anyWereRenderedLastFrame = false;
traversalDetails.notYetRenderableCount = 0;

if (primitive.preloadSiblings) {
queueTileLoad(primitive, primitive._tileLoadQueueLow, tile, frameState);
}
}

function screenSpaceError(primitive, frameState, tile) {
Expand Down
Loading

0 comments on commit 0328cc9

Please sign in to comment.