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..c28722a385ec 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(8) : []; + function fillPoles(centralBody, context, frameState) { var terrainProvider = centralBody._surface._terrainProvider; if (frameState.mode !== SceneMode.SCENE3D) { @@ -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 @@ -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); @@ -375,7 +394,7 @@ define([ position : new GeometryAttribute({ componentDatatype : ComponentDatatype.FLOAT, componentsPerAttribute : 2, - values : positions + values : polePositionsScratch }) } }); @@ -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); } } } @@ -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); @@ -423,7 +443,7 @@ define([ position : new GeometryAttribute({ componentDatatype : ComponentDatatype.FLOAT, componentsPerAttribute : 2, - values : positions + values : polePositionsScratch }) } }); @@ -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); } } } @@ -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(); @@ -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; @@ -710,7 +726,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);