From c09974bcda41415f23e6c073f76528e7eb0ce855 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 17 Mar 2014 17:51:09 -0700 Subject: [PATCH] use parents inFrustum status to optimize children --- libraries/octree/src/Octree.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 63a7fb8e88..2776af6dab 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -892,6 +892,8 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node, return bytesAtThisLevel; } } + + ViewFrustum::location nodeLocationThisView = ViewFrustum::INSIDE; // assume we're inside // caller can pass NULL as viewFrustum if they want everything if (params.viewFrustum) { @@ -907,11 +909,13 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node, params.stopReason = EncodeBitstreamParams::LOD_SKIP; return bytesAtThisLevel; } + + nodeLocationThisView = node->inFrustum(*params.viewFrustum); // If we're at a node that is out of view, then we can return, because no nodes below us will be in view! // although technically, we really shouldn't ever be here, because our callers shouldn't be calling us if // we're out of view - if (!node->isInView(*params.viewFrustum)) { + if (nodeLocationThisView == ViewFrustum::OUTSIDE) { if (params.stats) { params.stats->skippedOutOfView(node); } @@ -1065,7 +1069,11 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node, OctreeElement* childNode = sortedChildren[i]; int originalIndex = indexOfChildren[i]; - bool childIsInView = (childNode && (!params.viewFrustum || childNode->isInView(*params.viewFrustum))); + bool childIsInView = (childNode && + ( !params.viewFrustum || // no view frustum was given, everything is assumed in view + (nodeLocationThisView == ViewFrustum::INSIDE) || // the parent was fully in view, we can assume ALL children are + (nodeLocationThisView == ViewFrustum::INTERSECT && childNode->isInView(*params.viewFrustum)) // the parent intersects and the child is in view + )); if (!childIsInView) { // must check childNode here, because it could be we got here because there was no childNode