From 98d14d6b821f1bc3f57f1bf8c673f9ac7e3ce297 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Mon, 26 Aug 2013 14:51:30 -0400 Subject: [PATCH 1/2] Removed typed array allocation for depth quad --- Source/Renderer/Context.js | 2 +- Source/Scene/CentralBody.js | 57 +++++++++++++++++------------- Source/Scene/CentralBodySurface.js | 2 +- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Source/Renderer/Context.js b/Source/Renderer/Context.js index 630ad41bec3f..e60ce856f61b 100644 --- a/Source/Renderer/Context.js +++ b/Source/Renderer/Context.js @@ -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 diff --git a/Source/Scene/CentralBody.js b/Source/Scene/CentralBody.js index ace7cb9862ef..da2bf45eaec7 100644 --- a/Source/Scene/CentralBody.js +++ b/Source/Scene/CentralBody.js @@ -14,6 +14,7 @@ define([ '../Core/ComponentDatatype', '../Core/Ellipsoid', '../Core/Extent', + '../Core/FeatureDetection', '../Core/GeographicProjection', '../Core/Geometry', '../Core/GeometryAttribute', @@ -60,6 +61,7 @@ define([ ComponentDatatype, Ellipsoid, Extent, + FeatureDetection, GeographicProjection, Geometry, GeometryAttribute, @@ -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(); @@ -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) { @@ -316,6 +333,8 @@ define([ var viewportScratch = new BoundingRectangle(); var vpTransformScratch = new Matrix4(); + var polePositionsScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(4) : []; + function fillPoles(centralBody, context, frameState) { var terrainProvider = centralBody._surface._terrainProvider; if (frameState.mode !== SceneMode.SCENE3D) { @@ -342,7 +361,6 @@ define([ var typedArray; var geometry; var rect; - var positions; var occluder = centralBody._occluder; // handle north pole @@ -361,12 +379,10 @@ 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, rect.y; + polePositionsScratch[1] = rect.x + rect.width, rect.y; + polePositionsScratch[2] = rect.x + rect.width, rect.y + rect.height; + polePositionsScratch[3] = rect.x, rect.y + rect.height; if (!defined(centralBody._northPoleCommand.vertexArray)) { centralBody._northPoleCommand.boundingVolume = BoundingSphere.fromExtent3D(extent, centralBody._ellipsoid); @@ -375,7 +391,7 @@ define([ position : new GeometryAttribute({ componentDatatype : ComponentDatatype.FLOAT, componentsPerAttribute : 2, - values : positions + values : polePositionsScratch }) } }); @@ -387,8 +403,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); } } } @@ -409,12 +424,10 @@ 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, rect.y; + polePositionsScratch[1] = rect.x + rect.width, rect.y; + polePositionsScratch[2] = rect.x + rect.width, rect.y + rect.height; + polePositionsScratch[3] = rect.x, rect.y + rect.height; if (!defined(centralBody._southPoleCommand.vertexArray)) { centralBody._southPoleCommand.boundingVolume = BoundingSphere.fromExtent3D(extent, centralBody._ellipsoid); @@ -435,8 +448,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); } } } @@ -569,8 +581,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(); @@ -696,8 +707,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; @@ -710,7 +719,7 @@ define([ this._surface.update(context, frameState, colorCommandList, - drawUniforms, + this._drawUniforms, this._surfaceShaderSet, this._rsColor, this._projection); diff --git a/Source/Scene/CentralBodySurface.js b/Source/Scene/CentralBodySurface.js index 392f6a9cc276..2f245ec0a004 100644 --- a/Source/Scene/CentralBodySurface.js +++ b/Source/Scene/CentralBodySurface.js @@ -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); From 40abfe91a6a51a0fff34ccc70111d9c56c35c4c9 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Mon, 26 Aug 2013 14:56:53 -0400 Subject: [PATCH 2/2] Fixed poles --- Source/Scene/CentralBody.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Source/Scene/CentralBody.js b/Source/Scene/CentralBody.js index da2bf45eaec7..c28722a385ec 100644 --- a/Source/Scene/CentralBody.js +++ b/Source/Scene/CentralBody.js @@ -333,7 +333,7 @@ define([ var viewportScratch = new BoundingRectangle(); var vpTransformScratch = new Matrix4(); - var polePositionsScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(4) : []; + var polePositionsScratch = FeatureDetection.supportsTypedArrays() ? new Float32Array(8) : []; function fillPoles(centralBody, context, frameState) { var terrainProvider = centralBody._surface._terrainProvider; @@ -358,7 +358,6 @@ define([ var frustumCull; var occludeePoint; var occluded; - var typedArray; var geometry; var rect; var occluder = centralBody._occluder; @@ -379,10 +378,14 @@ define([ centralBody._drawNorthPole = !frustumCull && !occluded; if (centralBody._drawNorthPole) { rect = computePoleQuad(centralBody, frameState, extent.north, extent.south - latitudeExtension, viewProjMatrix, viewportTransformation); - polePositionsScratch[0] = rect.x, rect.y; - polePositionsScratch[1] = rect.x + rect.width, rect.y; - polePositionsScratch[2] = rect.x + rect.width, rect.y + rect.height; - polePositionsScratch[3] = 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); @@ -424,10 +427,14 @@ define([ centralBody._drawSouthPole = !frustumCull && !occluded; if (centralBody._drawSouthPole) { rect = computePoleQuad(centralBody, frameState, extent.south, extent.north + latitudeExtension, viewProjMatrix, viewportTransformation); - polePositionsScratch[0] = rect.x, rect.y; - polePositionsScratch[1] = rect.x + rect.width, rect.y; - polePositionsScratch[2] = rect.x + rect.width, rect.y + rect.height; - polePositionsScratch[3] = 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); @@ -436,7 +443,7 @@ define([ position : new GeometryAttribute({ componentDatatype : ComponentDatatype.FLOAT, componentsPerAttribute : 2, - values : positions + values : polePositionsScratch }) } });