Skip to content

Commit

Permalink
Improve frustum stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Aug 26, 2013
1 parent 9e59e5f commit 4a4ac0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Source/Renderer/DrawCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ define(function() {
/**
* @private
*
* Used for to implement {@see Scene.debugShowFrustums}.
* Used to implement {@see Scene.debugShowFrustums}.
*/
this.debugOverlappingFrustums = 0;
};
Expand Down
18 changes: 10 additions & 8 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ define([
* When {@see Scene.debugShowFrustums} is <code>true</code>, this contains
* properties with statistics about the number of command execute per frustum.
* <code>totalCommands</code> is the total number of commands executed, ignoring
* overlap. <code>commandsInFrustums</code> is an array with the number of commands
* executed in each frustum.
* overlap. <code>commandsInFrustums</code> is an array with the number of times
* commands are executed redundantly, e.g., how many commands overlap two or
* three frustums.
* </p>
*
* @type Object
Expand Down Expand Up @@ -437,7 +438,6 @@ define([

if (scene.debugShowFrustums) {
command.debugOverlappingFrustums |= (1 << i);
++scene.debugFrustumStatistics.commandsInFrustums[i];
}

if (command.executeInClosestFrustum) {
Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/MultifrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4a4ac0c

Please sign in to comment.