Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Globe updates #3593

Merged
merged 4 commits into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,11 @@ define([
/**
* @private
*/
Globe.prototype.update = function(frameState) {
Globe.prototype.beginFrame = function(frameState) {
if (!this.show) {
return;
}

var context = frameState.context;
var width = context.drawingBufferWidth;
var height = context.drawingBufferHeight;

if (width === 0 || height === 0) {
return;
}

var surface = this._surface;
var tileProvider = surface.tileProvider;
var terrainProvider = this.terrainProvider;
Expand Down Expand Up @@ -465,6 +457,22 @@ define([
tileProvider.oceanNormalMap = this._oceanNormalMap;
tileProvider.enableLighting = this.enableLighting;

surface.beginFrame(frameState);
}
};

/**
* @private
*/
Globe.prototype.update = function(frameState) {
if (!this.show) {
return;
}

var surface = this._surface;
var pass = frameState.passes;

if (pass.render) {
surface.update(frameState);
}

Expand All @@ -473,6 +481,19 @@ define([
}
};

/**
* @private
*/
Globe.prototype.endFrame = function(frameState) {
if (!this.show) {
return;
}

if (frameState.passes.render) {
this._surface.endFrame(frameState);
}
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
Expand Down Expand Up @@ -502,7 +523,7 @@ define([
*
* @example
* globe = globe && globe.destroy();
*
*
* @see Globe#isDestroyed
*/
Globe.prototype.destroy = function() {
Expand Down
39 changes: 22 additions & 17 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ define([
}

/**
* Called at the beginning of the update cycle for each render frame, before {@link QuadtreeTileProvider#showTileThisFrame}
* Called at the beginning of each render frame, before {@link QuadtreeTileProvider#showTileThisFrame}
* or any other functions.
*
* @param {FrameState} frameState The frame state.
*/
GlobeSurfaceTileProvider.prototype.beginUpdate = function(frameState) {
GlobeSurfaceTileProvider.prototype.initialize = function(frameState) {
this._imageryLayers._update();

if (this._layerOrderChanged) {
Expand All @@ -300,19 +300,6 @@ define([
});
}

var i;
var len;

var tilesToRenderByTextureCount = this._tilesToRenderByTextureCount;
for (i = 0, len = tilesToRenderByTextureCount.length; i < len; ++i) {
var tiles = tilesToRenderByTextureCount[i];
if (defined(tiles)) {
tiles.length = 0;
}
}

this._usedDrawCommands = 0;

// Add credits for terrain and imagery providers.
var creditDisplay = frameState.creditDisplay;

Expand All @@ -321,14 +308,32 @@ define([
}

var imageryLayers = this._imageryLayers;
for (i = 0, len = imageryLayers.length; i < len; ++i) {
for (var i = 0, len = imageryLayers.length; i < len; ++i) {
var imageryProvider = imageryLayers.get(i).imageryProvider;
if (imageryProvider.ready && defined(imageryProvider.credit)) {
creditDisplay.addCredit(imageryProvider.credit);
}
}
};

/**
* Called at the beginning of the update cycle for each render frame, before {@link QuadtreeTileProvider#showTileThisFrame}
* or any other functions.
*
* @param {FrameState} frameState The frame state.
*/
GlobeSurfaceTileProvider.prototype.beginUpdate = function(frameState) {
var tilesToRenderByTextureCount = this._tilesToRenderByTextureCount;
for (var i = 0, len = tilesToRenderByTextureCount.length; i < len; ++i) {
var tiles = tilesToRenderByTextureCount[i];
if (defined(tiles)) {
tiles.length = 0;
}
}

this._usedDrawCommands = 0;
};

/**
* Called at the end of the update cycle for each render frame, after {@link QuadtreeTileProvider#showTileThisFrame}
* and any other functions.
Expand Down Expand Up @@ -567,7 +572,7 @@ define([
*
* @example
* provider = provider && provider();
*
*
* @see GlobeSurfaceTileProvider#isDestroyed
*/
GlobeSurfaceTileProvider.prototype.destroy = function() {
Expand Down
107 changes: 67 additions & 40 deletions Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,35 @@ define([
};

/**
* Updates the primitive.
*
* @param {Context} context The rendering context to use.
* @param {FrameState} frameState The state of the current frame.
* @param {DrawCommand[]} commandList The list of draw commands. The primitive will usually add
* commands to this array during the update call.
* @private
*/
QuadtreePrimitive.prototype.beginFrame = function(frameState) {
var passes = frameState.passes;
if (!passes.render) {
return;
}

this._tileProvider.initialize(frameState);

var debug = this._debug;
if (debug.suspendLodUpdate) {
return;
}

debug.maxDepth = 0;
debug.tilesVisited = 0;
debug.tilesCulled = 0;
debug.tilesRendered = 0;
debug.tilesWaitingForChildren = 0;

processTileLoadQueue(this, frameState);

this._tileLoadQueue.length = 0;
this._tileReplacementQueue.markStartOfRenderFrame();
};

/**
* @private
*/
QuadtreePrimitive.prototype.update = function(frameState) {
var passes = frameState.passes;
Expand All @@ -274,7 +297,6 @@ define([
this._tileProvider.beginUpdate(frameState);

selectTilesForRendering(this, frameState);
processTileLoadQueue(this, frameState);
createRenderCommandsForSelectedTiles(this, frameState);

this._tileProvider.endUpdate(frameState);
Expand All @@ -285,6 +307,40 @@ define([
}
};

/**
* @private
*/
QuadtreePrimitive.prototype.endFrame = function(frameState) {
var passes = frameState.passes;
if (!passes.render) {
return;
}

updateHeights(this, frameState);

var debug = this._debug;
if (debug.suspendLodUpdate) {
return;
}

if (debug.enableDebugOutput) {
if (debug.tilesVisited !== debug.lastTilesVisited ||
debug.tilesRendered !== debug.lastTilesRendered ||
debug.tilesCulled !== debug.lastTilesCulled ||
debug.maxDepth !== debug.lastMaxDepth ||
debug.tilesWaitingForChildren !== debug.lastTilesWaitingForChildren) {

console.log('Visited ' + debug.tilesVisited + ', Rendered: ' + debug.tilesRendered + ', Culled: ' + debug.tilesCulled + ', Max Depth: ' + debug.maxDepth + ', Waiting for children: ' + debug.tilesWaitingForChildren);

debug.lastTilesVisited = debug.tilesVisited;
debug.lastTilesRendered = debug.tilesRendered;
debug.lastTilesCulled = debug.tilesCulled;
debug.lastMaxDepth = debug.maxDepth;
debug.lastTilesWaitingForChildren = debug.tilesWaitingForChildren;
}
}
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
Expand Down Expand Up @@ -318,7 +374,7 @@ define([
*
* @example
* primitive = primitive && primitive.destroy();
*
*
* @see QuadtreePrimitive#isDestroyed
*/
QuadtreePrimitive.prototype.destroy = function() {
Expand All @@ -327,7 +383,6 @@ define([

function selectTilesForRendering(primitive, frameState) {
var debug = primitive._debug;

if (debug.suspendLodUpdate) {
return;
}
Expand All @@ -342,15 +397,6 @@ define([
var traversalQueue = primitive._tileTraversalQueue;
traversalQueue.clear();

debug.maxDepth = 0;
debug.tilesVisited = 0;
debug.tilesCulled = 0;
debug.tilesRendered = 0;
debug.tilesWaitingForChildren = 0;

primitive._tileLoadQueue.length = 0;
primitive._tileReplacementQueue.markStartOfRenderFrame();

// We can't render anything before the level zero tiles exist.
if (!defined(primitive._levelZeroTiles)) {
if (primitive._tileProvider.ready) {
Expand Down Expand Up @@ -440,23 +486,6 @@ define([
}

raiseTileLoadProgressEvent(primitive);

if (debug.enableDebugOutput) {
if (debug.tilesVisited !== debug.lastTilesVisited ||
debug.tilesRendered !== debug.lastTilesRendered ||
debug.tilesCulled !== debug.lastTilesCulled ||
debug.maxDepth !== debug.lastMaxDepth ||
debug.tilesWaitingForChildren !== debug.lastTilesWaitingForChildren) {

console.log('Visited ' + debug.tilesVisited + ', Rendered: ' + debug.tilesRendered + ', Culled: ' + debug.tilesCulled + ', Max Depth: ' + debug.maxDepth + ', Waiting for children: ' + debug.tilesWaitingForChildren);

debug.lastTilesVisited = debug.tilesVisited;
debug.lastTilesRendered = debug.tilesRendered;
debug.lastTilesCulled = debug.tilesCulled;
debug.lastMaxDepth = debug.maxDepth;
debug.lastTilesWaitingForChildren = debug.tilesWaitingForChildren;
}
}
}

/**
Expand Down Expand Up @@ -634,9 +663,9 @@ define([

var tileDataAvailable = terrainProvider.getTileDataAvailable(child.x, child.y, child.level);
if ((defined(tileDataAvailable) && !tileDataAvailable) ||
(defined(parent) && defined(parent.data) && defined(parent.data.terrainData) &&
!parent.data.terrainData.isChildAvailable(parent.x, parent.y, child.x, child.y))) {
data.removeFunc();
(defined(parent) && defined(parent.data) && defined(parent.data.terrainData) &&
!parent.data.terrainData.isChildAvailable(parent.x, parent.y, child.x, child.y))) {
data.removeFunc();
}
}

Expand Down Expand Up @@ -676,8 +705,6 @@ define([
}
tile._frameRendered = frameState.frameNumber;
}

updateHeights(primitive, frameState);
}

return QuadtreePrimitive;
Expand Down
10 changes: 9 additions & 1 deletion Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,10 @@ define([
viewport.width = context.drawingBufferWidth;
viewport.height = context.drawingBufferHeight;

if (defined(scene.globe)) {
scene.globe.beginFrame(frameState);
}

updateEnvironment(scene);
updatePrimitives(scene);
createPotentiallyVisibleSet(scene);
Expand All @@ -1946,6 +1950,10 @@ define([
resolveFramebuffers(scene, passState);
executeOverlayCommands(scene, passState);

if (defined(scene.globe)) {
scene.globe.endFrame(frameState);
}

frameState.creditDisplay.endFrame();

if (scene.debugShowFramesPerSecond) {
Expand Down Expand Up @@ -2120,10 +2128,10 @@ define([
scratchRectangle.y = (this.drawingBufferHeight - drawingBufferPosition.y) - ((rectangleHeight - 1.0) * 0.5);

var passState = this._pickFramebuffer.begin(scratchRectangle);

updatePrimitives(this);
createPotentiallyVisibleSet(this);
updateAndClearFramebuffers(this, passState, scratchColorZero, true);

executeCommands(this, passState);
resolveFramebuffers(this, passState);

Expand Down
2 changes: 2 additions & 0 deletions Specs/Scene/GlobeSurfaceTileProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ defineSuite([
function updateUntilDone(globe) {
// update until the load queue is empty.
return pollToPromise(function() {
globe.beginFrame(frameState);
globe.update(frameState);
globe.endFrame(frameState);
return globe._surface.tileProvider.ready && !defined(globe._surface._tileLoadQueue.head) && globe._surface._debug.tilesWaitingForChildren === 0;
});
}
Expand Down
Loading