change to encodeTreeBitstreamRecursion() to allow calling without viewFrustum

This commit is contained in:
ZappoMan 2013-05-03 15:13:00 -07:00
parent 1366794bdc
commit f4099349e8
2 changed files with 26 additions and 26 deletions

View file

@ -666,8 +666,7 @@ int VoxelTree::encodeTreeBitstream(int maxEncodeLevel, VoxelNode* node, const Vi
int currentEncodeLevel = 0; int currentEncodeLevel = 0;
int childBytesWritten = encodeTreeBitstreamRecursion(maxEncodeLevel, currentEncodeLevel, int childBytesWritten = encodeTreeBitstreamRecursion(maxEncodeLevel, currentEncodeLevel,
node, viewFrustum, node, outputBuffer, availableBytes, bag, &viewFrustum);
outputBuffer, availableBytes, bag);
// if childBytesWritten == 1 then something went wrong... that's not possible // if childBytesWritten == 1 then something went wrong... that's not possible
assert(childBytesWritten != 1); assert(childBytesWritten != 1);
@ -689,9 +688,8 @@ int VoxelTree::encodeTreeBitstream(int maxEncodeLevel, VoxelNode* node, const Vi
} }
int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel, int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel,
VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNode* node, unsigned char* outputBuffer, int availableBytes,
unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag, const ViewFrustum* viewFrustum) const {
VoxelNodeBag& bag) const {
// How many bytes have we written so far at this level; // How many bytes have we written so far at this level;
int bytesAtThisLevel = 0; int bytesAtThisLevel = 0;
@ -703,7 +701,9 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
return bytesAtThisLevel; return bytesAtThisLevel;
} }
float distance = node->distanceToCamera(viewFrustum); // caller can pass NULL as viewFrustum if they want everything
if (viewFrustum) {
float distance = node->distanceToCamera(*viewFrustum);
float boundaryDistance = boundaryDistanceForRenderLevel(*node->octalCode + 1); float boundaryDistance = boundaryDistanceForRenderLevel(*node->octalCode + 1);
// If we're too far away for our render level, then just return // If we're too far away for our render level, then just return
@ -714,9 +714,10 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
// If we're at a node that is out of view, then we can return, because no nodes below us will be in view! // 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 // although technically, we really shouldn't ever be here, because our callers shouldn't be calling us if
// we're out of view // we're out of view
if (!node->isInView(viewFrustum)) { if (!node->isInView(*viewFrustum)) {
return bytesAtThisLevel; return bytesAtThisLevel;
} }
}
bool keepDiggingDeeper = true; // Assuming we're in view we have a great work ethic, we're always ready for more! bool keepDiggingDeeper = true; // Assuming we're in view we have a great work ethic, we're always ready for more!
@ -745,11 +746,11 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
for (int i = 0; i < MAX_CHILDREN; i++) { for (int i = 0; i < MAX_CHILDREN; i++) {
VoxelNode* childNode = node->children[i]; VoxelNode* childNode = node->children[i];
bool childExists = (childNode != NULL); bool childExists = (childNode != NULL);
bool childIsInView = (childExists && childNode->isInView(viewFrustum)); bool childIsInView = (childExists && (!viewFrustum || childNode->isInView(*viewFrustum)));
if (childIsInView) { if (childIsInView) {
// Before we determine consider this further, let's see if it's in our LOD scope... // Before we determine consider this further, let's see if it's in our LOD scope...
float distance = childNode->distanceToCamera(viewFrustum); float distance = viewFrustum ? 0 : childNode->distanceToCamera(*viewFrustum);
float boundaryDistance = boundaryDistanceForRenderLevel(*childNode->octalCode + 1); float boundaryDistance = viewFrustum ? 1 : boundaryDistanceForRenderLevel(*childNode->octalCode + 1);
if (distance < boundaryDistance) { if (distance < boundaryDistance) {
inViewCount++; inViewCount++;
@ -822,7 +823,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco
int thisLevel = currentEncodeLevel; int thisLevel = currentEncodeLevel;
int childTreeBytesOut = encodeTreeBitstreamRecursion(maxEncodeLevel, thisLevel, childNode, int childTreeBytesOut = encodeTreeBitstreamRecursion(maxEncodeLevel, thisLevel, childNode,
viewFrustum, outputBuffer, availableBytes, bag); outputBuffer, availableBytes, bag, viewFrustum);
// if the child wrote 0 bytes, it means that nothing below exists or was in view, or we ran out of space, // if the child wrote 0 bytes, it means that nothing below exists or was in view, or we ran out of space,
// basically, the children below don't contain any info. // basically, the children below don't contain any info.

View file

@ -64,12 +64,11 @@ public:
void clearDirtyBit() { _isDirty = false; }; void clearDirtyBit() { _isDirty = false; };
unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; };
private:
int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel, int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel,
VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNode* node, unsigned char* outputBuffer, int availableBytes,
unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag, const ViewFrustum* viewFrustum) const;
VoxelNodeBag& bag) const;
private:
int searchForColoredNodesRecursion(int maxSearchLevel, int& currentSearchLevel, int searchForColoredNodesRecursion(int maxSearchLevel, int& currentSearchLevel,
VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag); VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag);