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

Update Primitive and GroundPrimitive to use BatchTable #4361

Merged
merged 16 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from 11 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
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
Loading