From 4a4ac0c3c69db47dd3bc810b3583efecd4390967 Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Mon, 26 Aug 2013 08:02:23 -0400 Subject: [PATCH] Improve frustum stats --- Source/Renderer/DrawCommand.js | 2 +- Source/Scene/Scene.js | 18 ++++++++++-------- Specs/Scene/MultifrustumSpec.js | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Renderer/DrawCommand.js b/Source/Renderer/DrawCommand.js index 2bb96b57e5a9..52e1cdb03aa6 100644 --- a/Source/Renderer/DrawCommand.js +++ b/Source/Renderer/DrawCommand.js @@ -167,7 +167,7 @@ define(function() { /** * @private * - * Used for to implement {@see Scene.debugShowFrustums}. + * Used to implement {@see Scene.debugShowFrustums}. */ this.debugOverlappingFrustums = 0; }; diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 19cb098a0b98..736a520fdf9f 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -265,8 +265,9 @@ define([ * When {@see Scene.debugShowFrustums} is true, this contains * properties with statistics about the number of command execute per frustum. * totalCommands is the total number of commands executed, ignoring - * overlap. commandsInFrustums is an array with the number of commands - * executed in each frustum. + * overlap. commandsInFrustums is an array with the number of times + * commands are executed redundantly, e.g., how many commands overlap two or + * three frustums. *

* * @type Object @@ -437,7 +438,6 @@ define([ if (scene.debugShowFrustums) { command.debugOverlappingFrustums |= (1 << i); - ++scene.debugFrustumStatistics.commandsInFrustums[i]; } if (command.executeInClosestFrustum) { @@ -446,6 +446,8 @@ define([ } if (scene.debugShowFrustums) { + var cf = scene.debugFrustumStatistics.commandsInFrustums; + cf[command.debugOverlappingFrustums] = defined(cf[command.debugOverlappingFrustums]) ? cf[command.debugOverlappingFrustums] + 1 : 1; ++scene.debugFrustumStatistics.totalCommands; } } @@ -464,13 +466,13 @@ define([ if (scene.debugShowFrustums) { scene.debugFrustumStatistics = { totalCommands : 0, - commandsInFrustums : [0, 0, 0, 0] + commandsInFrustums : {} }; } var frustumCommandsList = scene._frustumCommandsList; - var frustumsLength = frustumCommandsList.length; - for (var n = 0; n < frustumsLength; ++n) { + var numberOfFrustums = frustumCommandsList.length; + for (var n = 0; n < numberOfFrustums; ++n) { frustumCommandsList[n].index = 0; } @@ -537,8 +539,8 @@ define([ // last frame, else compute the new frustums and sort them by frustum again. var farToNearRatio = scene.farToNearRatio; var numFrustums = Math.ceil(Math.log(far / near) / Math.log(farToNearRatio)); - if (near !== Number.MAX_VALUE && (numFrustums !== frustumsLength || (frustumCommandsList.length !== 0 && - (near < frustumCommandsList[0].near || far > frustumCommandsList[frustumsLength - 1].far)))) { + if (near !== Number.MAX_VALUE && (numFrustums !== numberOfFrustums || (frustumCommandsList.length !== 0 && + (near < frustumCommandsList[0].near || far > frustumCommandsList[numberOfFrustums - 1].far)))) { updateFrustums(near, far, farToNearRatio, numFrustums, frustumCommandsList); createPotentiallyVisibleSet(scene, listName); } diff --git a/Specs/Scene/MultifrustumSpec.js b/Specs/Scene/MultifrustumSpec.js index 9297672d25c0..d7420557a63f 100644 --- a/Specs/Scene/MultifrustumSpec.js +++ b/Specs/Scene/MultifrustumSpec.js @@ -193,7 +193,7 @@ defineSuite([ scene.render(); expect(context.readPixels()).toEqual([0, 0, 255, 255]); expect(scene.debugFrustumStatistics.totalCommands).toEqual(3); - expect(scene.debugFrustumStatistics.commandsInFrustums).toEqual([1, 1, 1, 0]); + expect(scene.debugFrustumStatistics.commandsInFrustums).toEqual({ 1 : 1, 2 : 1, 4 : 1}); }); function createPrimitive(bounded, closestFrustum) {