Skip to content

Commit

Permalink
Merge pull request #4361 from AnalyticalGraphicsInc/batch-table-primi…
Browse files Browse the repository at this point in the history
…tive

Update Primitive and GroundPrimitive to use BatchTable
  • Loading branch information
pjcozzi authored Sep 27, 2016
2 parents 52066e9 + a1d0f2e commit 18ebb49
Show file tree
Hide file tree
Showing 18 changed files with 441 additions and 818 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ define([
/**
* @private
*/
this.boundingSphereCV = undefined;
this.boundingSphereCV = options.boundingSphereCV;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/GeometryPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ define([
var instance = instances[i];
if (defined(instance.geometry)) {
instanceGeometry.push(instance);
} else {
} else if (defined(instance.westHemisphereGeometry) && defined(instance.eastHemisphereGeometry)) {
instanceSplitGeometry.push(instance);
}
}
Expand Down
12 changes: 10 additions & 2 deletions Source/Scene/DebugAppearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define([
*
* @param {Object} options Object with the following properties:
* @param {String} options.attributeName The name of the attribute to visualize.
* @param {Boolean} options.perInstanceAttribute Boolean that determines whether this attribute is a per-instance geometry attribute.
* @param {String} [options.glslDatatype='vec3'] The GLSL datatype of the attribute. Supported datatypes are <code>float</code>, <code>vec2</code>, <code>vec3</code>, and <code>vec4</code>.
* @param {String} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.
* @param {String} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.
Expand All @@ -44,11 +45,15 @@ define([
function DebugAppearance(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
var attributeName = options.attributeName;
var perInstanceAttribute = options.perInstanceAttribute;

//>>includeStart('debug', pragmas.debug);
if (!defined(attributeName)) {
throw new DeveloperError('options.attributeName is required.');
}
if (!defined(perInstanceAttribute)) {
throw new DeveloperError('options.perInstanceAttribute is required.');
}
//>>includeEnd('debug');

var glslDatatype = defaultValue(options.glslDatatype, 'vec3');
Expand Down Expand Up @@ -85,12 +90,15 @@ define([
var vs =
'attribute vec3 position3DHigh;\n' +
'attribute vec3 position3DLow;\n' +
'attribute ' + glslDatatype + ' ' + attributeName + ';\n' +
'attribute float batchId;\n' +
(perInstanceAttribute ? '' : 'attribute ' + glslDatatype + ' ' + attributeName + ';\n') +
'varying ' + glslDatatype + ' ' + varyingName + ';\n' +
'void main()\n' +
'{\n' +
'vec4 p = czm_translateRelativeToEye(position3DHigh, position3DLow);\n' +
varyingName + ' = ' + attributeName + ';\n' +
(perInstanceAttribute ?
varyingName + ' = czm_batchTable_' + attributeName + '(batchId);\n' :
varyingName + ' = ' + attributeName + ';\n') +
'gl_Position = czm_modelViewProjectionRelativeToEye * p;\n' +
'}';
var fs =
Expand Down
21 changes: 14 additions & 7 deletions Source/Scene/GroundPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,10 @@ define([
var context = frameState.context;

var vs = ShadowVolumeVS;
vs = primitive._primitive._batchTable.getVertexShaderCallback()(vs);
vs = Primitive._modifyShaderPosition(primitive, vs, frameState.scene3DOnly);
vs = Primitive._appendShowToShader(primitive._primitive, vs);
vs = Primitive._updateColorAttribute(primitive._primitive, vs);

var fs = ShadowVolumeFS;
var attributeLocations = primitive._primitive._attributeLocations;
Expand All @@ -755,14 +757,17 @@ define([
});

if (primitive._primitive.allowPicking) {
var vsPick = ShaderSource.createPickVertexShaderSource(vs);
vsPick = Primitive._updatePickColorAttribute(vsPick);

var pickFS = new ShaderSource({
sources : [fs],
pickColorQualifier : 'varying'
});
primitive._spPick = ShaderProgram.replaceCache({
context : context,
shaderProgram : primitive._spPick,
vertexShaderSource : ShaderSource.createPickVertexShaderSource(vs),
vertexShaderSource : vsPick,
fragmentShaderSource : pickFS,
attributeLocations : attributeLocations
});
Expand All @@ -782,6 +787,7 @@ define([
colorCommands.length = length;

var vaIndex = 0;
var uniformMap = primitive._batchTable.getUniformMapCallback()(groundPrimitive._uniformMap);

for (var i = 0; i < length; i += 3) {
var vertexArray = primitive._va[vaIndex++];
Expand All @@ -798,7 +804,7 @@ define([
command.vertexArray = vertexArray;
command.renderState = groundPrimitive._rsStencilPreloadPass;
command.shaderProgram = groundPrimitive._sp;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;

// stencil depth command
Expand All @@ -813,7 +819,7 @@ define([
command.vertexArray = vertexArray;
command.renderState = groundPrimitive._rsStencilDepthPass;
command.shaderProgram = groundPrimitive._sp;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;

// color command
Expand All @@ -828,7 +834,7 @@ define([
command.vertexArray = vertexArray;
command.renderState = groundPrimitive._rsColorPass;
command.shaderProgram = groundPrimitive._sp;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;
}
}
Expand All @@ -840,6 +846,7 @@ define([
pickCommands.length = length;

var pickIndex = 0;
var uniformMap = primitive._batchTable.getUniformMapCallback()(groundPrimitive._uniformMap);

for (var j = 0; j < length; j += 3) {
var pickOffset = pickOffsets[pickIndex++];
Expand All @@ -862,7 +869,7 @@ define([
command.count = count;
command.renderState = groundPrimitive._rsStencilPreloadPass;
command.shaderProgram = groundPrimitive._sp;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;

// stencil depth command
Expand All @@ -879,7 +886,7 @@ define([
command.count = count;
command.renderState = groundPrimitive._rsStencilDepthPass;
command.shaderProgram = groundPrimitive._sp;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;

// color command
Expand All @@ -896,7 +903,7 @@ define([
command.count = count;
command.renderState = groundPrimitive._rsPickPass;
command.shaderProgram = groundPrimitive._spPick;
command.uniformMap = groundPrimitive._uniformMap;
command.uniformMap = uniformMap;
command.pass = Pass.GROUND;
}
}
Expand Down
16 changes: 15 additions & 1 deletion Source/Scene/PolylineCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ define([
'../Core/Math',
'../Core/Matrix4',
'../Core/Plane',
'../Core/RuntimeError',
'../Renderer/Buffer',
'../Renderer/BufferUsage',
'../Renderer/ContextLimits',
'../Renderer/DrawCommand',
'../Renderer/RenderState',
'../Renderer/ShaderProgram',
Expand Down Expand Up @@ -53,8 +55,10 @@ define([
CesiumMath,
Matrix4,
Plane,
RuntimeError,
Buffer,
BufferUsage,
ContextLimits,
DrawCommand,
RenderState,
ShaderProgram,
Expand Down Expand Up @@ -392,7 +396,14 @@ define([
}

/**
* @private
* Called when {@link Viewer} or {@link CesiumWidget} render the scene to
* get the draw commands needed to render this primitive.
* <p>
* Do not call this function directly. This is documented just to
* list the exceptions that may be propagated when the scene is rendered:
* </p>
*
* @exception {RuntimeError} Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.
*/
PolylineCollection.prototype.update = function(frameState) {
removePolylines(this);
Expand All @@ -409,6 +420,9 @@ define([
var properties = this._propertiesChanged;

if (this._createBatchTable) {
if (ContextLimits.maximumVertexTextureImageUnits === 0) {
throw new RuntimeError('Vertex texture fetch support is required to render polylines. The maximum number of vertex texture image units must be greater than zero.');
}
createBatchTable(this, context);
this._createBatchTable = false;
}
Expand Down
Loading

0 comments on commit 18ebb49

Please sign in to comment.