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

Minor performance improvements #1079

Merged
merged 3 commits into from
Aug 26, 2013
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
2 changes: 1 addition & 1 deletion Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ define([

var offset = command.offset;
var count = command.count;
var hasIndexBuffer = (defined(indexBuffer));
var hasIndexBuffer = defined(indexBuffer);

if (hasIndexBuffer) {
offset = (offset || 0) * indexBuffer.getBytesPerIndex(); // in bytes
Expand Down
68 changes: 42 additions & 26 deletions Source/Scene/CentralBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define([
'../Core/ComponentDatatype',
'../Core/Ellipsoid',
'../Core/Extent',
'../Core/FeatureDetection',
'../Core/GeographicProjection',
'../Core/Geometry',
'../Core/GeometryAttribute',
Expand Down Expand Up @@ -60,6 +61,7 @@ define([
ComponentDatatype,
Ellipsoid,
Extent,
FeatureDetection,
GeographicProjection,
Geometry,
GeometryAttribute,
Expand Down Expand Up @@ -251,6 +253,8 @@ define([
return this._imageryLayerCollection;
};

var depthQuadScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(12) : [];

function computeDepthQuad(centralBody, frameState) {
var radii = centralBody._ellipsoid.getRadii();
var p = frameState.camera.getPositionWC();
Expand Down Expand Up @@ -279,7 +283,20 @@ define([
var upperRight = radii.multiplyComponents(center.add(northOffset).add(eastOffset));
var lowerLeft = radii.multiplyComponents(center.subtract(northOffset).subtract(eastOffset));
var lowerRight = radii.multiplyComponents(center.subtract(northOffset).add(eastOffset));
return [upperLeft.x, upperLeft.y, upperLeft.z, lowerLeft.x, lowerLeft.y, lowerLeft.z, upperRight.x, upperRight.y, upperRight.z, lowerRight.x, lowerRight.y, lowerRight.z];

depthQuadScratch[0] = upperLeft.x;
depthQuadScratch[1] = upperLeft.y;
depthQuadScratch[2] = upperLeft.z;
depthQuadScratch[3] = lowerLeft.x;
depthQuadScratch[4] = lowerLeft.y;
depthQuadScratch[5] = lowerLeft.z;
depthQuadScratch[6] = upperRight.x;
depthQuadScratch[7] = upperRight.y;
depthQuadScratch[8] = upperRight.z;
depthQuadScratch[9] = lowerRight.x;
depthQuadScratch[10] = lowerRight.y;
depthQuadScratch[11] = lowerRight.z;
return depthQuadScratch;
}

function computePoleQuad(centralBody, frameState, maxLat, maxGivenLat, viewProjMatrix, viewportTransformation) {
Expand Down Expand Up @@ -316,6 +333,8 @@ define([

var viewportScratch = new BoundingRectangle();
var vpTransformScratch = new Matrix4();
var polePositionsScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : [];

function fillPoles(centralBody, context, frameState) {
var terrainProvider = centralBody._surface._terrainProvider;
if (frameState.mode !== SceneMode.SCENE3D) {
Expand All @@ -339,10 +358,8 @@ define([
var frustumCull;
var occludeePoint;
var occluded;
var typedArray;
var geometry;
var rect;
var positions;
var occluder = centralBody._occluder;

// handle north pole
Expand All @@ -361,12 +378,14 @@ define([
centralBody._drawNorthPole = !frustumCull && !occluded;
if (centralBody._drawNorthPole) {
rect = computePoleQuad(centralBody, frameState, extent.north, extent.south - latitudeExtension, viewProjMatrix, viewportTransformation);
positions = [
rect.x, rect.y,
rect.x + rect.width, rect.y,
rect.x + rect.width, rect.y + rect.height,
rect.x, rect.y + rect.height
];
polePositionsScratch[0] = rect.x;
polePositionsScratch[1] = rect.y;
polePositionsScratch[2] = rect.x + rect.width;
polePositionsScratch[3] = rect.y;
polePositionsScratch[4] = rect.x + rect.width;
polePositionsScratch[5] = rect.y + rect.height;
polePositionsScratch[6] = rect.x;
polePositionsScratch[7] = rect.y + rect.height;

if (!defined(centralBody._northPoleCommand.vertexArray)) {
centralBody._northPoleCommand.boundingVolume = BoundingSphere.fromExtent3D(extent, centralBody._ellipsoid);
Expand All @@ -375,7 +394,7 @@ define([
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 2,
values : positions
values : polePositionsScratch
})
}
});
Expand All @@ -387,8 +406,7 @@ define([
bufferUsage : BufferUsage.STREAM_DRAW
});
} else {
typedArray = ComponentDatatype.createTypedArray(ComponentDatatype.FLOAT, positions);
centralBody._northPoleCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(typedArray);
centralBody._northPoleCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(polePositionsScratch);
}
}
}
Expand All @@ -409,12 +427,14 @@ define([
centralBody._drawSouthPole = !frustumCull && !occluded;
if (centralBody._drawSouthPole) {
rect = computePoleQuad(centralBody, frameState, extent.south, extent.north + latitudeExtension, viewProjMatrix, viewportTransformation);
positions = [
rect.x, rect.y,
rect.x + rect.width, rect.y,
rect.x + rect.width, rect.y + rect.height,
rect.x, rect.y + rect.height
];
polePositionsScratch[0] = rect.x;
polePositionsScratch[1] = rect.y;
polePositionsScratch[2] = rect.x + rect.width;
polePositionsScratch[3] = rect.y;
polePositionsScratch[4] = rect.x + rect.width;
polePositionsScratch[5] = rect.y + rect.height;
polePositionsScratch[6] = rect.x;
polePositionsScratch[7] = rect.y + rect.height;

if (!defined(centralBody._southPoleCommand.vertexArray)) {
centralBody._southPoleCommand.boundingVolume = BoundingSphere.fromExtent3D(extent, centralBody._ellipsoid);
Expand All @@ -423,7 +443,7 @@ define([
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.FLOAT,
componentsPerAttribute : 2,
values : positions
values : polePositionsScratch
})
}
});
Expand All @@ -435,8 +455,7 @@ define([
bufferUsage : BufferUsage.STREAM_DRAW
});
} else {
typedArray = ComponentDatatype.createTypedArray(ComponentDatatype.FLOAT, positions);
centralBody._southPoleCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(typedArray);
centralBody._southPoleCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(polePositionsScratch);
}
}
}
Expand Down Expand Up @@ -569,8 +588,7 @@ define([
bufferUsage : BufferUsage.DYNAMIC_DRAW
});
} else {
var typedArray = ComponentDatatype.createTypedArray(ComponentDatatype.FLOAT, depthQuad);
this._depthCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(typedArray);
this._depthCommand.vertexArray.getAttribute(0).vertexBuffer.copyFromArrayView(depthQuad);
}

var shaderCache = context.getShaderCache();
Expand Down Expand Up @@ -696,8 +714,6 @@ define([
}
}

var drawUniforms = this._drawUniforms;

// Don't show the ocean specular highlights when zoomed out in 2D and Columbus View.
if (mode === SceneMode.SCENE3D) {
this._zoomedOutOceanSpecularIntensity = 0.5;
Expand All @@ -710,7 +726,7 @@ define([
this._surface.update(context,
frameState,
colorCommandList,
drawUniforms,
this._drawUniforms,
this._surfaceShaderSet,
this._rsColor,
this._projection);
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/CentralBodySurface.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ define([
}
command.owner = tile;

command.debugShowBoundingVolume = tile === surface._debug.boundingSphereTile;
command.debugShowBoundingVolume = (tile === surface._debug.boundingSphereTile);

var uniformMap = tileCommandUniformMaps[tileCommandIndex];
mergeUniformMap(uniformMap, centralBodyUniformMap);
Expand Down