From cb7f94d488b1151b765be3b06256ca807b9d3db7 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 4 Sep 2018 18:44:24 -0400 Subject: [PATCH] Derived command crash fix --- Source/Renderer/DrawCommand.js | 16 ++++++++++++++++ Source/Scene/ClassificationPrimitive.js | 9 ++++++--- Source/Scene/EllipsoidPrimitive.js | 3 ++- Source/Scene/Scene.js | 23 +++++++++++++---------- Source/Scene/Vector3DTilePrimitive.js | 9 ++++++--- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Source/Renderer/DrawCommand.js b/Source/Renderer/DrawCommand.js index d9fc70db0d4e..8fd820f697fb 100644 --- a/Source/Renderer/DrawCommand.js +++ b/Source/Renderer/DrawCommand.js @@ -39,8 +39,10 @@ define([ this._castShadows = defaultValue(options.castShadows, false); this._receiveShadows = defaultValue(options.receiveShadows, false); this._pickId = options.pickId; + this._pickOnly = defaultValue(options.pickOnly, false); this.dirty = true; + this.derivedCommandsDirty = true; this.lastDirtyTime = 0; /** @@ -471,6 +473,19 @@ define([ this.dirty = true; } } + }, + /** + * Whether this command should be executed in the pick pass only. + * + * @memberof DrawCommand.prototype + * @type {Boolean} + * @default false + * @readonly + */ + pickOnly : { + get : function() { + return this._pickOnly; + } } }); @@ -506,6 +521,7 @@ define([ result._castShadows = command._castShadows; result._receiveShadows = command._receiveShadows; result._pickId = command._pickId; + result._pickOnly = command._pickOnly; result.dirty = true; result.lastDirtyTime = 0; diff --git a/Source/Scene/ClassificationPrimitive.js b/Source/Scene/ClassificationPrimitive.js index 675e2f9d5ef5..edbe1a840460 100644 --- a/Source/Scene/ClassificationPrimitive.js +++ b/Source/Scene/ClassificationPrimitive.js @@ -802,7 +802,8 @@ define([ if (!defined(command)) { command = pickCommands[j] = new DrawCommand({ owner : classificationPrimitive, - primitiveType : primitive._primitiveType + primitiveType : primitive._primitiveType, + pickOnly : true }); } @@ -820,7 +821,8 @@ define([ if (!defined(command)) { command = pickCommands[j + 1] = new DrawCommand({ owner : classificationPrimitive, - primitiveType : primitive._primitiveType + primitiveType : primitive._primitiveType, + pickOnly : true }); } @@ -838,7 +840,8 @@ define([ if (!defined(command)) { command = pickCommands[j + 2] = new DrawCommand({ owner : classificationPrimitive, - primitiveType : primitive._primitiveType + primitiveType : primitive._primitiveType, + pickOnly : true }); } diff --git a/Source/Scene/EllipsoidPrimitive.js b/Source/Scene/EllipsoidPrimitive.js index 8b1ca28e4043..c5250a58fd92 100644 --- a/Source/Scene/EllipsoidPrimitive.js +++ b/Source/Scene/EllipsoidPrimitive.js @@ -209,7 +209,8 @@ define([ owner : defaultValue(options._owner, this) }); this._pickCommand = new DrawCommand({ - owner : defaultValue(options._owner, this) + owner : defaultValue(options._owner, this), + pickOnly : true }); var that = this; diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 5a7ff2e75670..f0390f30206a 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -1475,16 +1475,16 @@ define([ var useLogDepth = frameState.useLogDepth; var derivedCommands = command.derivedCommands; - if (frameState.useLogDepthDirty && !command.dirty) { - var needsLogDepthDerivedCommands = useLogDepth && !defined(derivedCommands.logDepth); - var needsDerivedCommands = !useLogDepth && !defined(derivedCommands.depth); - command.dirty = needsLogDepthDerivedCommands || needsDerivedCommands; - } + var logDepthObject = command.derivedCommands.logDepth; + var logDepthCommand = defined(logDepthObject) ? logDepthObject.command : undefined; + + var needsLogDepthDerivedCommands = useLogDepth && (!defined(logDepthCommand) || logDepthCommand.derivedCommandsDirty); + var needsDerivedCommands = !useLogDepth && command.derivedCommandsDirty; + command.dirty = command.dirty || needsLogDepthDerivedCommands || needsDerivedCommands; if (command.dirty) { command.dirty = false; - var logDepthCommand; var logDepthDerivedCommands; if (useLogDepth) { derivedCommands.logDepth = DerivedCommand.createLogDepthCommand(command, context, derivedCommands.logDepth); @@ -1492,6 +1492,11 @@ define([ logDepthDerivedCommands = logDepthCommand.derivedCommands; } + command.derivedCommandsDirty = useLogDepth; + if (defined(logDepthCommand)) { + logDepthCommand.derivedCommandsDirty = !useLogDepth; + } + if (shadowsEnabled && (command.receiveShadows || command.castShadows)) { derivedCommands.shadows = ShadowMap.createDerivedCommands(shadowMaps, lightShadowMaps, command, shadowsDirty, context, derivedCommands.shadows); if (useLogDepth) { @@ -1518,11 +1523,9 @@ define([ } } - if (frameState.passes.pick && !defined(command.pickId)) { - return; + if (!command.pickOnly) { + derivedCommands.depth = DerivedCommand.createDepthOnlyDerivedCommand(this, command, context, derivedCommands.depth); } - - derivedCommands.depth = DerivedCommand.createDepthOnlyDerivedCommand(this, command, context, derivedCommands.depth); } }; diff --git a/Source/Scene/Vector3DTilePrimitive.js b/Source/Scene/Vector3DTilePrimitive.js index 91cee93c9a62..41459814c3a5 100644 --- a/Source/Scene/Vector3DTilePrimitive.js +++ b/Source/Scene/Vector3DTilePrimitive.js @@ -819,7 +819,8 @@ define([ var stencilPreloadCommand = pickCommands[j * 3]; if (!defined(stencilPreloadCommand)) { stencilPreloadCommand = pickCommands[j * 3] = new DrawCommand({ - owner : primitive + owner : primitive, + pickOnly : true }); } @@ -835,7 +836,8 @@ define([ var stencilDepthCommand = pickCommands[j * 3 + 1]; if (!defined(stencilDepthCommand)) { stencilDepthCommand = pickCommands[j * 3 + 1] = new DrawCommand({ - owner : primitive + owner : primitive, + pickOnly : true }); } @@ -851,7 +853,8 @@ define([ var colorCommand = pickCommands[j * 3 + 2]; if (!defined(colorCommand)) { colorCommand = pickCommands[j * 3 + 2] = new DrawCommand({ - owner : primitive + owner : primitive, + pickOnly : true }); }