From 1e22d1fa25c62cb6ee28d5eaeb94d3cb85bc56d0 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Fri, 13 Dec 2013 09:39:53 -0500 Subject: [PATCH 01/11] ShaderCache tweak. Still want to do a frame count per shader at some point. --- Source/Renderer/ShaderCache.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/Renderer/ShaderCache.js b/Source/Renderer/ShaderCache.js index d0266873abc9..57093a4bdf8f 100644 --- a/Source/Renderer/ShaderCache.js +++ b/Source/Renderer/ShaderCache.js @@ -68,6 +68,9 @@ define([ if (this._shaders[keyword]) { cachedShader = this._shaders[keyword]; + + // No longer want to release this if it was previously released. + delete this._shadersToRelease[keyword]; } else { var sp = this._context.createShaderProgram(vertexShaderSource, fragmentShaderSource, attributeLocations); @@ -96,13 +99,9 @@ define([ for ( var keyword in shadersToRelease) { if (shadersToRelease.hasOwnProperty(keyword)) { - // Check the count again here because the shader may have been requested - // after it was released, in which case, we are avoiding thrashing the cache. var cachedShader = shadersToRelease[keyword]; - if (cachedShader.count === 0) { - delete this._shaders[cachedShader.keyword]; - cachedShader.shaderProgram.destroy(); - } + delete this._shaders[cachedShader.keyword]; + cachedShader.shaderProgram.destroy(); } } From fe6a862ab49ab6f5a0440a0fb2d1afc6edf1a56d Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Fri, 13 Dec 2013 09:40:17 -0500 Subject: [PATCH 02/11] Start of debugShowCommands --- Source/Scene/Scene.js | 69 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index c1df45426d91..91e7ed064b2f 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -260,6 +260,12 @@ define([ */ this.debugCommandFilter = undefined; + /** + * DOC_TBA + */ + this.debugShowCommands = true; + // TODO: make enum? + /** * This property is for debugging only; it is not for production use. *

@@ -571,6 +577,51 @@ define([ } } + function getAttributeLocations(shaderProgram) { + var attributeLocations = {}; + var attributes = shaderProgram.getVertexAttributes(); + for (var a in attributes) { + if (attributes.hasOwnProperty(a)) { + attributeLocations[a] = attributes[a].index; + } + } + + return attributeLocations; + } + + function createCommandDebugFragmentShaderSource(command) { + var fragmentShaderSource = command.shaderProgram.fragmentShaderSource; + var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_commandDebug_main()'); + + if (!defined(command._debugColor)) { + command._debugColor = Color.fromRandom(); + } + var c = command._debugColor; + + var pickMain = + 'void main() \n' + + '{ \n' + + ' czm_commandDebug_main(); \n' + + ' gl_FragColor.rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n' + + '}'; + + return renamedFS + '\n' + pickMain; + } + + function executeDebugCommandCommand(command, context, passState) { + if (defined(command.shaderProgram)) { + // Replace shader for command visualization + var sp = command.shaderProgram; + var attributeLocations = getAttributeLocations(sp); + + command.shaderProgram = context.getShaderCache().getShaderProgram( + sp.vertexShaderSource, createCommandDebugFragmentShaderSource(command), attributeLocations); + command.execute(context, passState); + command.shaderProgram.release(); + command.shaderProgram = sp; + } + } + function createFrustumDebugFragmentShaderSource(command) { var fragmentShaderSource = command.shaderProgram.fragmentShaderSource; var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_frustumDebug_main()'); @@ -595,19 +646,11 @@ define([ if (defined(command.shaderProgram)) { // Replace shader for frustum visualization var sp = command.shaderProgram; - var attributeLocations = {}; - var attributes = sp.getVertexAttributes(); - for (var a in attributes) { - if (attributes.hasOwnProperty(a)) { - attributeLocations[a] = attributes[a].index; - } - } + var attributeLocations = getAttributeLocations(sp); command.shaderProgram = context.getShaderCache().getShaderProgram( sp.vertexShaderSource, createFrustumDebugFragmentShaderSource(command), attributeLocations); - command.execute(context, passState); - command.shaderProgram.release(); command.shaderProgram = sp; } @@ -618,10 +661,12 @@ define([ return; } - if (!scene.debugShowFrustums) { - command.execute(context, passState); - } else { + if (scene.debugShowCommands) { + executeDebugCommandCommand(command, context, passState); + } else if (scene.debugShowFrustums) { executeFrustumDebugCommand(command, context, passState); + } else { + command.execute(context, passState); } if (command.debugShowBoundingVolume && (defined(command.boundingVolume))) { From d309953eef9435c7635c7f054c3177cd0cfb3dd2 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Fri, 13 Dec 2013 09:54:31 -0500 Subject: [PATCH 03/11] Allow both debugShowFrustums and debugShowCommands --- Source/Scene/Scene.js | 75 +++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 91e7ed064b2f..1365b7c889c5 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -263,8 +263,7 @@ define([ /** * DOC_TBA */ - this.debugShowCommands = true; - // TODO: make enum? + this.debugShowCommands = false; /** * This property is for debugging only; it is not for production use. @@ -589,67 +588,45 @@ define([ return attributeLocations; } - function createCommandDebugFragmentShaderSource(command) { + function createDebugFragmentShaderSource(command, scene) { var fragmentShaderSource = command.shaderProgram.fragmentShaderSource; - var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_commandDebug_main()'); + var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_Debug_main()'); - if (!defined(command._debugColor)) { - command._debugColor = Color.fromRandom(); - } - var c = command._debugColor; - - var pickMain = + var newMain = 'void main() \n' + '{ \n' + - ' czm_commandDebug_main(); \n' + - ' gl_FragColor.rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n' + - '}'; - - return renamedFS + '\n' + pickMain; - } + ' czm_Debug_main(); \n'; - function executeDebugCommandCommand(command, context, passState) { - if (defined(command.shaderProgram)) { - // Replace shader for command visualization - var sp = command.shaderProgram; - var attributeLocations = getAttributeLocations(sp); - - command.shaderProgram = context.getShaderCache().getShaderProgram( - sp.vertexShaderSource, createCommandDebugFragmentShaderSource(command), attributeLocations); - command.execute(context, passState); - command.shaderProgram.release(); - command.shaderProgram = sp; + if (scene.debugShowCommands) { + if (!defined(command._debugColor)) { + command._debugColor = Color.fromRandom(); + } + var c = command._debugColor; + newMain += ' gl_FragColor.rgb *= vec3(' + c.red + ', ' + c.green + ', ' + c.blue + '); \n'; } - } - - function createFrustumDebugFragmentShaderSource(command) { - var fragmentShaderSource = command.shaderProgram.fragmentShaderSource; - var renamedFS = fragmentShaderSource.replace(/void\s+main\s*\(\s*(?:void)?\s*\)/g, 'void czm_frustumDebug_main()'); - // Support up to three frustums. If a command overlaps all - // three, it's code is not changed. - var r = (command.debugOverlappingFrustums & (1 << 0)) ? '1.0' : '0.0'; - var g = (command.debugOverlappingFrustums & (1 << 1)) ? '1.0' : '0.0'; - var b = (command.debugOverlappingFrustums & (1 << 2)) ? '1.0' : '0.0'; + if (scene.debugShowFrustums) { + // Support up to three frustums. If a command overlaps all + // three, it's code is not changed. + var r = (command.debugOverlappingFrustums & (1 << 0)) ? '1.0' : '0.0'; + var g = (command.debugOverlappingFrustums & (1 << 1)) ? '1.0' : '0.0'; + var b = (command.debugOverlappingFrustums & (1 << 2)) ? '1.0' : '0.0'; + newMain += ' gl_FragColor.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n'; + } - var pickMain = - 'void main() \n' + - '{ \n' + - ' czm_frustumDebug_main(); \n' + - ' gl_FragColor.rgb *= vec3(' + r + ', ' + g + ', ' + b + '); \n' + - '}'; + newMain += '}'; - return renamedFS + '\n' + pickMain; + return renamedFS + '\n' + newMain; } - function executeFrustumDebugCommand(command, context, passState) { + function executeDebugCommand(command, scene, context, passState) { if (defined(command.shaderProgram)) { // Replace shader for frustum visualization var sp = command.shaderProgram; var attributeLocations = getAttributeLocations(sp); command.shaderProgram = context.getShaderCache().getShaderProgram( - sp.vertexShaderSource, createFrustumDebugFragmentShaderSource(command), attributeLocations); + sp.vertexShaderSource, createDebugFragmentShaderSource(command, scene), attributeLocations); command.execute(context, passState); command.shaderProgram.release(); command.shaderProgram = sp; @@ -661,10 +638,8 @@ define([ return; } - if (scene.debugShowCommands) { - executeDebugCommandCommand(command, context, passState); - } else if (scene.debugShowFrustums) { - executeFrustumDebugCommand(command, context, passState); + if (scene.debugShowCommands || scene.debugShowFrustums) { + executeDebugCommand(command, scene, context, passState); } else { command.execute(context, passState); } From 22d66ad1b10a2e50db9519f28f53fc13498f9b3b Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Fri, 13 Dec 2013 10:41:27 -0500 Subject: [PATCH 04/11] debugShowCommands test and doc --- Source/Scene/Scene.js | 12 ++++++++++-- Specs/Scene/SceneSpec.js | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 1365b7c889c5..46147e83b880 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -261,7 +261,16 @@ define([ this.debugCommandFilter = undefined; /** - * DOC_TBA + * This property is for debugging only; it is not for production use. + *

+ * When true, commands are randomly shaded. This is useful + * for performance analysis to see what parts of a scene or model are + * command-dense and could benefit from batching. + *

+ * + * @type Boolean + * + * @default false */ this.debugShowCommands = false; @@ -726,7 +735,6 @@ define([ var sunCommand = (frameState.passes.color && defined(scene.sun)) ? scene.sun.update(context, frameState) : undefined; var sunVisible = isVisible(sunCommand, frameState); - if (sunVisible && scene.sunBloom) { passState.framebuffer = scene._sunPostProcess.update(context); } diff --git a/Specs/Scene/SceneSpec.js b/Specs/Scene/SceneSpec.js index 35ec298fa7e7..4f47dde3c5be 100644 --- a/Specs/Scene/SceneSpec.js +++ b/Specs/Scene/SceneSpec.js @@ -193,6 +193,24 @@ defineSuite([ expect(scene.getContext().readPixels()[0]).not.toEqual(0); // Red bounding sphere }); + it('debugShowCommands tints commands', function() { + var c = new DrawCommand(); + c.execute = function() {}; + c.shaderProgram = scene.getContext().getShaderCache().getShaderProgram( + 'void main() { gl_Position = vec4(1.0); }', + 'void main() { gl_FragColor = vec4(1.0); }'); + + scene.getPrimitives().add(getMockPrimitive({ + command : c + })); + + scene.debugShowCommands = true; + scene.initializeFrame(); + scene.render(); + expect(c._debugColor).toBeDefined(); + scene.debugShowCommands = false; + }); + it('opaque/translucent render order (1)', function() { var extent = Extent.fromDegrees(-100.0, 30.0, -90.0, 40.0); From adaa0d6122a872ecc255046727ccdff0d47c9c0d Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Fri, 13 Dec 2013 11:00:17 -0500 Subject: [PATCH 05/11] Fix tabs --- Specs/Scene/SceneSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Specs/Scene/SceneSpec.js b/Specs/Scene/SceneSpec.js index 4f47dde3c5be..79aa63344125 100644 --- a/Specs/Scene/SceneSpec.js +++ b/Specs/Scene/SceneSpec.js @@ -197,8 +197,8 @@ defineSuite([ var c = new DrawCommand(); c.execute = function() {}; c.shaderProgram = scene.getContext().getShaderCache().getShaderProgram( - 'void main() { gl_Position = vec4(1.0); }', - 'void main() { gl_FragColor = vec4(1.0); }'); + 'void main() { gl_Position = vec4(1.0); }', + 'void main() { gl_FragColor = vec4(1.0); }'); scene.getPrimitives().add(getMockPrimitive({ command : c From 9a6caa862e192040fb1fc919572b8b1a32d363a2 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 14:04:31 -0500 Subject: [PATCH 06/11] Update enableLighting shadow property to detect changes. --- Source/Scene/CentralBody.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Scene/CentralBody.js b/Source/Scene/CentralBody.js index 7363a6804610..7e67a629cacd 100644 --- a/Source/Scene/CentralBody.js +++ b/Source/Scene/CentralBody.js @@ -725,6 +725,7 @@ define([ this._showingPrettyOcean = defined(this._oceanNormalMap); this._hasWaterMask = hasWaterMask; + this._enableLighting = this.enableLighting; } var cameraPosition = frameState.camera.positionWC; From 31020873b66e8adc613e6c36e5ed13123d3f9543 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 14:49:42 -0500 Subject: [PATCH 07/11] Update CHANGES.md. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 0903079c4f62..1210ec89370b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ Beta Releases * Added `Billboard.setPixelOffsetScaleByDistance`, `Label.setPixelOffsetScaleByDistance`, `DynamicBillboard.pixelOffsetScaleByDistance`, and `DynamicLabel.pixelOffsetScaleByDistance` to control minimum/maximum pixelOffset scaling based on camera distance. * The `Viewer` widget now clears `Geocoder` input when the user clicks the home button. * The `Geocoder` input type has been changed to `search`, which improves usability (particularly on mobile devices). There were also some other minor styling improvements. +* Fix disabling `CentralBody.enableLighting`. ### b23 - 2013-12-02 From e23fdebdac4578046d8dad754cdc775b7b4d5603 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 15:20:38 -0500 Subject: [PATCH 08/11] Remove frustum allocation each frame. --- Source/Scene/OrthographicFrustum.js | 22 +++++++++------- Source/Scene/PerspectiveFrustum.js | 24 ++++++++++------- Source/Scene/PerspectiveOffCenterFrustum.js | 26 +++++++++++-------- Source/Scene/Scene.js | 16 +++++++++++- Specs/Scene/OrthographicFrustumSpec.js | 17 ++++++++---- Specs/Scene/PerspectiveFrustumSpec.js | 12 +++++++++ .../Scene/PerspectiveOffCenterFrustumSpec.js | 12 +++++++++ 7 files changed, 93 insertions(+), 36 deletions(-) diff --git a/Source/Scene/OrthographicFrustum.js b/Source/Scene/OrthographicFrustum.js index 9c36bc4c17fc..057bb99aa2b0 100644 --- a/Source/Scene/OrthographicFrustum.js +++ b/Source/Scene/OrthographicFrustum.js @@ -321,15 +321,19 @@ define([ * * @returns {OrthographicFrustum} A new copy of the OrthographicFrustum instance. */ - OrthographicFrustum.prototype.clone = function() { - var frustum = new OrthographicFrustum(); - frustum.left = this.left; - frustum.right = this.right; - frustum.top = this.top; - frustum.bottom = this.bottom; - frustum.near = this.near; - frustum.far = this.far; - return frustum; + OrthographicFrustum.prototype.clone = function(result) { + if (!defined(result)) { + result = new OrthographicFrustum(); + } + + result.left = this.left; + result.right = this.right; + result.top = this.top; + result.bottom = this.bottom; + result.near = this.near; + result.far = this.far; + + return result; }; /** diff --git a/Source/Scene/PerspectiveFrustum.js b/Source/Scene/PerspectiveFrustum.js index 96c1a1226aec..1f64a05f8afd 100644 --- a/Source/Scene/PerspectiveFrustum.js +++ b/Source/Scene/PerspectiveFrustum.js @@ -197,19 +197,23 @@ define([ /** * Returns a duplicate of a PerspectiveFrustum instance. - * * @memberof PerspectiveFrustum * - * @returns {PerspectiveFrustum} A new copy of the PerspectiveFrustum instance. + * @param {PerspectiveFrustum} [result] The object onto which to store the result. + * @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided. */ - PerspectiveFrustum.prototype.clone = function() { - var frustum = new PerspectiveFrustum(); - frustum.fovy = this.fovy; - frustum.aspectRatio = this.aspectRatio; - frustum.near = this.near; - frustum.far = this.far; - frustum._offCenterFrustum = this._offCenterFrustum.clone(); - return frustum; + PerspectiveFrustum.prototype.clone = function(result) { + if (!defined(result)) { + result = new PerspectiveFrustum(); + } + + result.fovy = this.fovy; + result.aspectRatio = this.aspectRatio; + result.near = this.near; + result.far = this.far; + this._offCenterFrustum.clone(result._offCenterFrustum); + + return result; }; /** diff --git a/Source/Scene/PerspectiveOffCenterFrustum.js b/Source/Scene/PerspectiveOffCenterFrustum.js index 39aa0dc7cad6..838afe0112df 100644 --- a/Source/Scene/PerspectiveOffCenterFrustum.js +++ b/Source/Scene/PerspectiveOffCenterFrustum.js @@ -365,20 +365,24 @@ define([ /** * Returns a duplicate of a PerspectiveOffCenterFrustum instance. - * * @memberof PerspectiveOffCenterFrustum * - * @returns {PerspectiveOffCenterFrustum} A new copy of the PerspectiveOffCenterFrustum instance. + * @param {PerspectiveOffCenterFrustum} [result] The object onto which to store the result. + * @returns {PerspectiveOffCenterFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided. */ - PerspectiveOffCenterFrustum.prototype.clone = function() { - var frustum = new PerspectiveOffCenterFrustum(); - frustum.right = this.right; - frustum.left = this.left; - frustum.top = this.top; - frustum.bottom = this.bottom; - frustum.near = this.near; - frustum.far = this.far; - return frustum; + PerspectiveOffCenterFrustum.prototype.clone = function(result) { + if (!defined(result)) { + result = new PerspectiveOffCenterFrustum(); + } + + result.right = this.right; + result.left = this.left; + result.top = this.top; + result.bottom = this.bottom; + result.near = this.near; + result.far = this.far; + + return result; }; /** diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 46147e83b880..fc222dd6d28d 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -34,6 +34,7 @@ define([ './SceneTransforms', './FrameState', './OrthographicFrustum', + './PerspectiveFrustum', './PerspectiveOffCenterFrustum', './FrustumCommands', './Primitive', @@ -75,6 +76,7 @@ define([ SceneTransforms, FrameState, OrthographicFrustum, + PerspectiveFrustum, PerspectiveOffCenterFrustum, FrustumCommands, Primitive, @@ -710,13 +712,25 @@ define([ (!defined(occluder) || occluder.isBoundingSphereVisible(boundingVolume))))); } + var scratchPerspectiveFrustum = new PerspectiveFrustum(); + var scratchPerspectiveOffCenterFrustum = new PerspectiveOffCenterFrustum(); + var scratchOrthographicFrustum = new OrthographicFrustum(); + function executeCommands(scene, passState, clearColor) { var frameState = scene._frameState; var camera = scene._camera; - var frustum = camera.frustum.clone(); var context = scene._context; var us = context.getUniformState(); + var frustum; + if (defined(camera.frustum.fovy)) { + frustum = camera.frustum.clone(scratchPerspectiveFrustum); + } else if (defined(camera.frustum.infiniteProjectionMatrix)){ + frustum = camera.frustum.clone(scratchPerspectiveOffCenterFrustum); + } else { + frustum = camera.frustum.clone(scratchOrthographicFrustum); + } + if (defined(scene.sun) && scene.sunBloom !== scene._sunBloom) { if (scene.sunBloom) { scene._sunPostProcess = new SunPostProcess(); diff --git a/Specs/Scene/OrthographicFrustumSpec.js b/Specs/Scene/OrthographicFrustumSpec.js index f17eb00fb370..02fc8625abd9 100644 --- a/Specs/Scene/OrthographicFrustumSpec.js +++ b/Specs/Scene/OrthographicFrustumSpec.js @@ -146,15 +146,22 @@ defineSuite([ expect(pixelSize.y).toEqual(2.0); }); - it('clone', function() { - var clone = frustum.clone(); - expect(clone).toEqual(frustum); - }); - it('throws with undefined frustum parameters', function() { var frustum = new OrthographicFrustum(); expect(function() { return frustum.projectionMatrix; }).toThrow(); }); + + it('clone', function() { + var frustum2 = frustum.clone(); + expect(frustum).toEqual(frustum2); + }); + + it('clone with result parameter', function() { + var result = new OrthographicFrustum(); + var frustum2 = frustum.clone(result); + expect(frustum2).toBe(result); + expect(frustum).toEqual(frustum2); + }); }); diff --git a/Specs/Scene/PerspectiveFrustumSpec.js b/Specs/Scene/PerspectiveFrustumSpec.js index 1b35e6fd562c..640f4f108fa1 100644 --- a/Specs/Scene/PerspectiveFrustumSpec.js +++ b/Specs/Scene/PerspectiveFrustumSpec.js @@ -167,4 +167,16 @@ defineSuite([ return frustum.infiniteProjectionMatrix; }).toThrow(); }); + + it('clone', function() { + var frustum2 = frustum.clone(); + expect(frustum).toEqual(frustum2); + }); + + it('clone with result parameter', function() { + var result = new PerspectiveFrustum(); + var frustum2 = frustum.clone(result); + expect(frustum2).toBe(result); + expect(frustum).toEqual(frustum2); + }); }); diff --git a/Specs/Scene/PerspectiveOffCenterFrustumSpec.js b/Specs/Scene/PerspectiveOffCenterFrustumSpec.js index cb924c4182f2..a46fdacd23ec 100644 --- a/Specs/Scene/PerspectiveOffCenterFrustumSpec.js +++ b/Specs/Scene/PerspectiveOffCenterFrustumSpec.js @@ -171,4 +171,16 @@ defineSuite([ return frustum.infiniteProjectionMatrix; }).toThrow(); }); + + it('clone', function() { + var frustum2 = frustum.clone(); + expect(frustum).toEqual(frustum2); + }); + + it('clone with result parameter', function() { + var result = new PerspectiveOffCenterFrustum(); + var frustum2 = frustum.clone(result); + expect(frustum2).toBe(result); + expect(frustum).toEqual(frustum2); + }); }); From efb348fc720d66b9cec5c0003464e1cff3983ba0 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 15:32:47 -0500 Subject: [PATCH 09/11] Update doc. --- Source/Scene/OrthographicFrustum.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Scene/OrthographicFrustum.js b/Source/Scene/OrthographicFrustum.js index 057bb99aa2b0..f3edb0a102b6 100644 --- a/Source/Scene/OrthographicFrustum.js +++ b/Source/Scene/OrthographicFrustum.js @@ -316,10 +316,10 @@ define([ /** * Returns a duplicate of a OrthographicFrustum instance. - * * @memberof OrthographicFrustum * - * @returns {OrthographicFrustum} A new copy of the OrthographicFrustum instance. + * @param {OrthographicFrustum} [result] The object onto which to store the result. + * @returns {OrthographicFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided. */ OrthographicFrustum.prototype.clone = function(result) { if (!defined(result)) { From bd7312b2ad99b61ab323f0e4beabf7242c60483c Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 15:38:52 -0500 Subject: [PATCH 10/11] Set shadow properties on cloned frustums to undefined to force matrix updates. --- Source/Scene/OrthographicFrustum.js | 8 ++++++++ Source/Scene/PerspectiveFrustum.js | 7 +++++++ Source/Scene/PerspectiveOffCenterFrustum.js | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/Source/Scene/OrthographicFrustum.js b/Source/Scene/OrthographicFrustum.js index f3edb0a102b6..bb71da984a32 100644 --- a/Source/Scene/OrthographicFrustum.js +++ b/Source/Scene/OrthographicFrustum.js @@ -333,6 +333,14 @@ define([ result.near = this.near; result.far = this.far; + // force update of clone to compute matrices + result._left = this.left; + result._right = this.right; + result._top = this.top; + result._bottom = this.bottom; + result._near = this.near; + result._far = this.far; + return result; }; diff --git a/Source/Scene/PerspectiveFrustum.js b/Source/Scene/PerspectiveFrustum.js index 1f64a05f8afd..cd9c6acde293 100644 --- a/Source/Scene/PerspectiveFrustum.js +++ b/Source/Scene/PerspectiveFrustum.js @@ -211,6 +211,13 @@ define([ result.aspectRatio = this.aspectRatio; result.near = this.near; result.far = this.far; + + // force update of clone to compute matrices + result._fovy = undefined; + result._aspectRatio = undefined; + result._near = undefined; + result._far = undefined; + this._offCenterFrustum.clone(result._offCenterFrustum); return result; diff --git a/Source/Scene/PerspectiveOffCenterFrustum.js b/Source/Scene/PerspectiveOffCenterFrustum.js index 838afe0112df..3a999d743776 100644 --- a/Source/Scene/PerspectiveOffCenterFrustum.js +++ b/Source/Scene/PerspectiveOffCenterFrustum.js @@ -382,6 +382,14 @@ define([ result.near = this.near; result.far = this.far; + // force update of clone to compute matrices + result._left = this.left; + result._right = this.right; + result._top = this.top; + result._bottom = this.bottom; + result._near = this.near; + result._far = this.far; + return result; }; From 78892664e4fb152b17839df6efa5ef9b357857f7 Mon Sep 17 00:00:00 2001 From: Dan Bagnell Date: Mon, 16 Dec 2013 16:32:26 -0500 Subject: [PATCH 11/11] Set shadow properties to undefined. --- Source/Scene/OrthographicFrustum.js | 12 ++++++------ Source/Scene/PerspectiveOffCenterFrustum.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Scene/OrthographicFrustum.js b/Source/Scene/OrthographicFrustum.js index bb71da984a32..18f9ad0809f6 100644 --- a/Source/Scene/OrthographicFrustum.js +++ b/Source/Scene/OrthographicFrustum.js @@ -334,12 +334,12 @@ define([ result.far = this.far; // force update of clone to compute matrices - result._left = this.left; - result._right = this.right; - result._top = this.top; - result._bottom = this.bottom; - result._near = this.near; - result._far = this.far; + result._left = undefined; + result._right = undefined; + result._top = undefined; + result._bottom = undefined; + result._near = undefined; + result._far = undefined; return result; }; diff --git a/Source/Scene/PerspectiveOffCenterFrustum.js b/Source/Scene/PerspectiveOffCenterFrustum.js index 3a999d743776..68be7c02b68f 100644 --- a/Source/Scene/PerspectiveOffCenterFrustum.js +++ b/Source/Scene/PerspectiveOffCenterFrustum.js @@ -383,12 +383,12 @@ define([ result.far = this.far; // force update of clone to compute matrices - result._left = this.left; - result._right = this.right; - result._top = this.top; - result._bottom = this.bottom; - result._near = this.near; - result._far = this.far; + result._left = undefined; + result._right = undefined; + result._top = undefined; + result._bottom = undefined; + result._near = undefined; + result._far = undefined; return result; };