Skip to content

Commit

Permalink
Move loading terrain and imagery to the end of the quadtree update. Q…
Browse files Browse the repository at this point in the history
…ueue any texture re-projections to be executed the next frame.
  • Loading branch information
bagnell committed Mar 10, 2016
1 parent 750dfc3 commit 71bcd26
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ define([

that._oceanNormalMap = that._oceanNormalMap && that._oceanNormalMap.destroy();
that._oceanNormalMap = new Texture({
context : context,
context : frameState.context,
source : image
});
});
Expand Down
9 changes: 9 additions & 0 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ define([
creditDisplay.addCredit(imageryProvider.credit);
}
}

imageryLayers.update(frameState);
};

/**
Expand Down Expand Up @@ -407,6 +409,13 @@ define([
}
};

/**
* Cancels any imagery re-projections in the queue.
*/
GlobeSurfaceTileProvider.prototype.cancelReprojections = function() {
this._imageryLayers.cancelReprojections();
};

/**
* Gets the maximum geometric error allowed in a tile at a given level, in meters. This function should not be
* called before {@link GlobeSurfaceTileProvider#ready} returns true.
Expand Down
31 changes: 29 additions & 2 deletions Source/Scene/ImageryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ define([
this._isBaseLayer = false;

this._requestImageError = undefined;

this._reprojectComputeCommands = [];
}

defineProperties(ImageryLayer.prototype, {
Expand Down Expand Up @@ -739,7 +741,7 @@ define([
}

/**
* Reproject a texture to a {@link GeographicProjection}, if necessary, and generate
* Enqueues a command re-projecting a texture to a {@link GeographicProjection} on the next update, if necessary, and generate
* mipmaps for the geographic texture.
*
* @private
Expand Down Expand Up @@ -773,12 +775,37 @@ define([
finalizeReprojectTexture(that, context, imagery, outputTexture);
}
});
frameState.commandList.push(computeCommand);
this._reprojectComputeCommands.push(computeCommand);
} else {
finalizeReprojectTexture(this, context, imagery, texture);
}
};

/**
* Updates frame state to execute any queued texture re-projections.
*
* @private
*
* @param {FrameState} frameState The frameState.
*/
ImageryLayer.prototype.update = function(frameState) {
var computeCommands = this._reprojectComputeCommands;
var length = computeCommands.length;
for (var i = 0; i < length; ++i) {
frameState.commandList.push(computeCommands[i]);
}
computeCommands.length = 0;
};

/**
* Cancels re-projection commands queued for the next frame.
*
* @private
*/
ImageryLayer.prototype.cancelReprojections = function() {
this._reprojectComputeCommands.length = 0;
};

ImageryLayer.prototype.getImageryFromCache = function(x, y, level, imageryRectangle) {
var cacheKey = getImageryCacheKey(x, y, level);
var imagery = this._imageryCache[cacheKey];
Expand Down
26 changes: 26 additions & 0 deletions Source/Scene/ImageryLayerCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,32 @@ define([
});
};

/**
* Updates frame state to execute any queued texture re-projections.
*
* @private
*
* @param {FrameState} frameState The frameState.
*/
ImageryLayerCollection.prototype.update = function(frameState) {
var layers = this._layers;
for (var i = 0, len = layers.length; i < len; ++i) {
layers[i].update(frameState);
}
};

/**
* Cancels re-projection commands queued for the next frame.
*
* @private
*/
ImageryLayerCollection.prototype.cancelReprojections = function() {
var layers = this._layers;
for (var i = 0, len = layers.length; i < len; ++i) {
layers[i].cancelReprojections();
}
};

/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
Expand Down
7 changes: 5 additions & 2 deletions Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ define([
}

this._levelZeroTiles = undefined;

this._tileProvider.cancelReprojections();
};

/**
Expand Down Expand Up @@ -268,6 +270,7 @@ define([
return;
}

// Gets commands for any texture re-projections and updates the credit display
this._tileProvider.initialize(frameState);

var debug = this._debug;
Expand All @@ -281,8 +284,6 @@ define([
debug.tilesRendered = 0;
debug.tilesWaitingForChildren = 0;

processTileLoadQueue(this, frameState);

this._tileLoadQueue.length = 0;
this._tileReplacementQueue.markStartOfRenderFrame();
};
Expand Down Expand Up @@ -316,6 +317,8 @@ define([
return;
}

// Load/create resources for terrain and imagery. Prepare texture re-projections for the next frame.
processTileLoadQueue(this, frameState);
updateHeights(this, frameState);

var debug = this._debug;
Expand Down
1 change: 1 addition & 0 deletions Specs/Scene/ImageryLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ defineSuite([
}).then(function() {
var textureBeforeReprojection = imagery.texture;
layer._reprojectTexture(frameState, imagery);
layer.update(frameState);
frameState.commandList[0].execute(computeEngine);

return pollToPromise(function() {
Expand Down

0 comments on commit 71bcd26

Please sign in to comment.