Skip to content

Commit

Permalink
Added ComputeCommand specs
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 4, 2015
1 parent 8f20940 commit 984861b
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 74 deletions.
12 changes: 6 additions & 6 deletions Source/Renderer/ComputeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ define([
this.outputTexture = options.outputTexture;

/**
* Function that is called after the ComputeCommand is executed. Takes the output
* texture as its single argument.
* Function that is called immediately before the ComputeCommand is executed. Used to
* update any renderer resources. Takes the ComputeCommand as its single argument.
*
* @type {Function}
* @default undefined
*/
this.callback = options.callback;
this.preExecute = options.preExecute;

/**
* Function that is called immediately before the ComputeCommand is executed. Used to
* update any renderer resources. Takes the ComputeCommand as its single argument.
* Function that is called after the ComputeCommand is executed. Takes the output
* texture as its single argument.
*
* @type {Function}
* @default undefined
*/
this.preExecutionCallback = options.preExecutionCallback;
this.postExecute = options.postExecute;

/**
* Whether the renderer resources will persist beyond this call. If not, they
Expand Down
33 changes: 15 additions & 18 deletions Source/Renderer/ComputeEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ define([
vertexArray = VertexArray.fromGeometry({
context : computeEngine._context,
geometry : geometry,
attributeLocations : {
position : 0,
textureCoordinates : 1
},
attributeLocations : viewportQuadAttributeLocations,
bufferUsage : BufferUsage.STATIC_DRAW,
interleave : true
});
Expand All @@ -111,12 +108,12 @@ define([
return vertexArray;
}

function createFramebuffer(context, texture) {
function createFramebuffer(context, outputTexture) {
var fbo = new Framebuffer({
context : context,
colorTextures : [texture]
colorTextures : [outputTexture],
destroyAttachments : false
});
fbo.destroyAttachments = false;
return fbo;
}

Expand Down Expand Up @@ -148,8 +145,8 @@ define([
}
//>>includeEnd('debug');

if (defined(computeCommand.preExecutionCallback)) {
computeCommand.preExecutionCallback(computeCommand);
if (defined(computeCommand.preExecute)) {
computeCommand.preExecute(computeCommand);
}

//>>includeStart('debug', pragmas.debug);
Expand All @@ -162,30 +159,30 @@ define([
}
//>>includeEnd('debug');

var texture = computeCommand.outputTexture;
var width = texture.width;
var height = texture.height;
var outputTexture = computeCommand.outputTexture;
var width = outputTexture.width;
var height = outputTexture.height;

var context = this._context;
var vertexArray = defined(computeCommand.vertexArray) ? computeCommand.vertexArray : getViewportQuadVertexArray(this);
var shaderProgram = defined(computeCommand.shaderProgram) ? computeCommand.shaderProgram : createViewportQuadShader(context, computeCommand.fragmentShaderSource);
var framebuffer = createFramebuffer(context, texture);
var framebuffer = createFramebuffer(context, outputTexture);
var renderState = createRenderState(width, height);
var uniformMap = defaultValue(computeCommand.uniformMap, defaultValue.EMPTY_OBJECT);
var uniformMap = computeCommand.uniformMap;

var clearCommand = clearCommandScratch;
clearCommand.framebuffer = framebuffer;
clearCommand.renderState = renderState;
clearCommand.execute(context);

var drawCommand = drawCommandScratch;
drawCommand.vertexArray = vertexArray;
drawCommand.renderState = renderState;
drawCommand.shaderProgram = shaderProgram;
drawCommand.uniformMap = uniformMap;
drawCommand.framebuffer = framebuffer;

clearCommand.execute(context);
drawCommand.execute(context);

framebuffer.destroy();

if (!computeCommand.persists) {
Expand All @@ -195,8 +192,8 @@ define([
}
}

if (defined(computeCommand.callback)) {
computeCommand.callback(texture);
if (defined(computeCommand.postExecute)) {
computeCommand.postExecute(outputTexture);
}
};

Expand Down
3 changes: 2 additions & 1 deletion Source/Renderer/VertexArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ define([
* context : context,
* sizeInBytes : 12,
* usage : BufferUsage.STATIC_DRAW
* }); * var attributes = [
* });
* var attributes = [
* {
* index : 0,
* vertexBuffer : positionBuffer,
Expand Down
5 changes: 2 additions & 3 deletions Source/Scene/ImageryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ define([
* @param {Context} context The rendered context to use.
* @param {Imagery} imagery The imagery instance to reproject.
*/

ImageryLayer.prototype._reprojectTexture = function(context, commandList, imagery) {
var texture = imagery.texture;
var rectangle = imagery.rectangle;
Expand All @@ -741,10 +740,10 @@ define([
owner : this,
// Update render resources right before execution instead of now.
// This allows different ImageryLayers to share the same vao and buffers.
preExecutionCallback : function(command) {
preExecute : function(command) {
reprojectToGeographic(command, context, texture, imagery.rectangle);
},
callback : function(outputTexture) {
postExecute : function(outputTexture) {
texture.destroy();
imagery.texture = outputTexture;
finalizeReprojectTexture(that, context, imagery, outputTexture);
Expand Down
25 changes: 7 additions & 18 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ define([

this._sunPostProcess = undefined;

this._computeCommandList = [];
this._commandList = [];
this._frustumCommandsList = [];
this._overlayCommandList = [];
this._computeCommandList = [];

this._pickFramebuffer = undefined;

Expand Down Expand Up @@ -815,17 +815,6 @@ define([
}
},


/**
* @memberof Scene.prototype
* @type {ComputeEngine}
*/
computeEngine : {
get : function() {
return this._computeEngine;
}
},

/**
* This property is for debugging only; it is not for production use.
* <p>
Expand Down Expand Up @@ -1044,9 +1033,9 @@ define([
var distances = new Interval();

function createPotentiallyVisibleSet(scene) {
var computeList = scene._computeCommandList;
var commandList = scene._commandList;
var overlayList = scene._overlayCommandList;
var computeList = scene._computeCommandList;

var cullingVolume = scene._frameState.cullingVolume;
var camera = scene._camera;
Expand All @@ -1069,8 +1058,9 @@ define([
frustumCommandsList[n].indices[p] = 0;
}
}
overlayList.length = 0;

computeList.length = 0;
overlayList.length = 0;

var near = Number.MAX_VALUE;
var far = Number.MIN_VALUE;
Expand Down Expand Up @@ -1493,7 +1483,7 @@ define([
}

if (defined(sunComputeCommand)) {
sunComputeCommand.execute(scene.computeEngine);
sunComputeCommand.execute(scene._computeEngine);
}

if (sunVisible) {
Expand Down Expand Up @@ -1641,11 +1631,10 @@ define([
}

function executeComputeCommands(scene) {
var context = scene.context;
var commandList = scene._computeCommandList;
var length = commandList.length;
for (var i = 0; i < length; ++i) {
commandList[i].execute(scene.computeEngine);
commandList[i].execute(scene._computeEngine);
}
}

Expand Down Expand Up @@ -1727,9 +1716,9 @@ define([
var context = scene.context;
us.update(context, frameState);

scene._computeCommandList.length = 0;
scene._commandList.length = 0;
scene._overlayCommandList.length = 0;
scene._computeCommandList.length = 0;

updatePrimitives(scene);
createPotentiallyVisibleSet(scene);
Expand Down
45 changes: 25 additions & 20 deletions Source/Scene/Sun.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@ define([
*/
this.show = true;

this._command = new DrawCommand({
this._drawCommand = new DrawCommand({
primitiveType : PrimitiveType.TRIANGLES,
boundingVolume : new BoundingSphere(),
owner : this
});
this._computeCommand = new ComputeCommand({
persists : false,
owner : this
});
this._commands = {
drawCommand : undefined,
computeCommand : undefined
};
this._boundingVolume = new BoundingSphere();
this._boundingVolume2D = new BoundingSphere();

Expand Down Expand Up @@ -195,17 +203,15 @@ define([
}
};

computeCommand = new ComputeCommand({
fragmentShaderSource : SunTextureFS,
outputTexture : this._texture,
uniformMap : uniformMap,
owner : this
});
computeCommand = this._computeCommand;
computeCommand.fragmentShaderSource = SunTextureFS;
computeCommand.outputTexture = this._texture;
computeCommand.uniformMap = uniformMap;
}

var command = this._command;
var drawCommand = this._drawCommand;

if (!defined(command.vertexArray)) {
if (!defined(drawCommand.vertexArray)) {
var attributeLocations = {
direction : 0
};
Expand Down Expand Up @@ -242,23 +248,23 @@ define([
usage : BufferUsage.STATIC_DRAW,
indexDatatype : IndexDatatype.UNSIGNED_SHORT
});
command.vertexArray = new VertexArray({
drawCommand.vertexArray = new VertexArray({
context : context,
attributes : attributes,
indexBuffer : indexBuffer
});

command.shaderProgram = ShaderProgram.fromCache({
drawCommand.shaderProgram = ShaderProgram.fromCache({
context : context,
vertexShaderSource : SunVS,
fragmentShaderSource : SunFS,
attributeLocations : attributeLocations
});

command.renderState = RenderState.fromCache({
drawCommand.renderState = RenderState.fromCache({
blending : BlendingState.ALPHA_BLEND
});
command.uniformMap = this._uniformMap;
drawCommand.uniformMap = this._uniformMap;
}

var sunPosition = context.uniformState.sunPositionWC;
Expand All @@ -276,9 +282,9 @@ define([
boundingVolume2D.radius = boundingVolume.radius;

if (mode === SceneMode.SCENE3D) {
BoundingSphere.clone(boundingVolume, command.boundingVolume);
BoundingSphere.clone(boundingVolume, drawCommand.boundingVolume);
} else if (mode === SceneMode.COLUMBUS_VIEW) {
BoundingSphere.clone(boundingVolume2D, command.boundingVolume);
BoundingSphere.clone(boundingVolume2D, drawCommand.boundingVolume);
}

var position = SceneTransforms.computeActualWgs84Position(frameState, sunPosition, scratchCartesian4);
Expand All @@ -302,10 +308,9 @@ define([
this._size = Math.ceil(Cartesian2.magnitude(Cartesian2.subtract(limbWC, positionWC, scratchCartesian4)));
this._size = 2.0 * this._size * (1.0 + 2.0 * this._glowLengthTS);

return {
computeCommand : computeCommand,
drawCommand : command
};
this._commands.drawCommand = drawCommand;
this._commands.computeCommand = computeCommand;
return this._commands;
};

/**
Expand Down Expand Up @@ -340,7 +345,7 @@ define([
* sun = sun && sun.destroy();
*/
Sun.prototype.destroy = function() {
var command = this._command;
var command = this._drawCommand;
command.vertexArray = command.vertexArray && command.vertexArray.destroy();
command.shaderProgram = command.shaderProgram && command.shaderProgram.destroy();

Expand Down
Loading

0 comments on commit 984861b

Please sign in to comment.