mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 23:46:26 +02:00
added dirty bit support to VoxelTree, use it to determine when to call treeToArrays
This commit is contained in:
parent
c353c1d2bf
commit
5a14c71225
4 changed files with 35 additions and 7 deletions
|
@ -149,7 +149,12 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
|
|
||||||
void VoxelSystem::setupNewVoxelsForDrawing() {
|
void VoxelSystem::setupNewVoxelsForDrawing() {
|
||||||
double start = usecTimestampNow();
|
double start = usecTimestampNow();
|
||||||
_voxelsUpdated = newTreeToArrays(_tree->rootNode);
|
if (_tree->isDirty()) {
|
||||||
|
_voxelsUpdated = newTreeToArrays(_tree->rootNode);
|
||||||
|
_tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean
|
||||||
|
} else {
|
||||||
|
_voxelsUpdated = 0;
|
||||||
|
}
|
||||||
if (_voxelsUpdated) {
|
if (_voxelsUpdated) {
|
||||||
_voxelsDirty=true;
|
_voxelsDirty=true;
|
||||||
}
|
}
|
||||||
|
@ -248,8 +253,8 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
||||||
_voxelsInArrays++; // our know vertices in the arrays
|
_voxelsInArrays++; // our know vertices in the arrays
|
||||||
}
|
}
|
||||||
voxelsUpdated++;
|
voxelsUpdated++;
|
||||||
node->clearDirtyBit();
|
|
||||||
}
|
}
|
||||||
|
node->clearDirtyBit(); // always clear the dirty bit, even if it doesn't need to be rendered
|
||||||
return voxelsUpdated;
|
return voxelsUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,8 @@ void VoxelNode::setFalseColored(bool isFalseColored) {
|
||||||
|
|
||||||
void VoxelNode::setColor(const nodeColor& color) {
|
void VoxelNode::setColor(const nodeColor& color) {
|
||||||
if (_trueColor[0] != color[0] || _trueColor[1] != color[1] || _trueColor[2] != color[2]) {
|
if (_trueColor[0] != color[0] || _trueColor[1] != color[1] || _trueColor[2] != color[2]) {
|
||||||
|
//printLog("VoxelNode::setColor() was: (%d,%d,%d) is: (%d,%d,%d)\n",
|
||||||
|
// _trueColor[0],_trueColor[1],_trueColor[2],color[0],color[1],color[2]);
|
||||||
memcpy(&_trueColor,&color,sizeof(nodeColor));
|
memcpy(&_trueColor,&color,sizeof(nodeColor));
|
||||||
if (!_falseColored) {
|
if (!_falseColored) {
|
||||||
memcpy(&_currentColor,&color,sizeof(nodeColor));
|
memcpy(&_currentColor,&color,sizeof(nodeColor));
|
||||||
|
|
|
@ -35,7 +35,8 @@ VoxelTree::VoxelTree() :
|
||||||
voxelsBytesRead(0),
|
voxelsBytesRead(0),
|
||||||
voxelsCreatedStats(100),
|
voxelsCreatedStats(100),
|
||||||
voxelsColoredStats(100),
|
voxelsColoredStats(100),
|
||||||
voxelsBytesReadStats(100) {
|
voxelsBytesReadStats(100),
|
||||||
|
_isDirty(true) {
|
||||||
|
|
||||||
rootNode = new VoxelNode();
|
rootNode = new VoxelNode();
|
||||||
rootNode->octalCode = new unsigned char[1];
|
rootNode->octalCode = new unsigned char[1];
|
||||||
|
@ -127,10 +128,13 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode,
|
||||||
// check the colors mask to see if we have a child to color in
|
// check the colors mask to see if we have a child to color in
|
||||||
if (oneAtBit(*nodeData, i)) {
|
if (oneAtBit(*nodeData, i)) {
|
||||||
// create the child if it doesn't exist
|
// create the child if it doesn't exist
|
||||||
if (destinationNode->children[i] == NULL) {
|
if (!destinationNode->children[i]) {
|
||||||
destinationNode->addChildAtIndex(i);
|
destinationNode->addChildAtIndex(i);
|
||||||
this->voxelsCreated++;
|
if (destinationNode->isDirty()) {
|
||||||
this->voxelsCreatedStats.updateAverage(1);
|
_isDirty = true;
|
||||||
|
}
|
||||||
|
voxelsCreated++;
|
||||||
|
voxelsCreatedStats.updateAverage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pull the color for this child
|
// pull the color for this child
|
||||||
|
@ -138,6 +142,9 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode,
|
||||||
memcpy(newColor, nodeData + bytesRead, 3);
|
memcpy(newColor, nodeData + bytesRead, 3);
|
||||||
newColor[3] = 1;
|
newColor[3] = 1;
|
||||||
destinationNode->children[i]->setColor(newColor);
|
destinationNode->children[i]->setColor(newColor);
|
||||||
|
if (destinationNode->children[i]->isDirty()) {
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
this->voxelsColored++;
|
this->voxelsColored++;
|
||||||
this->voxelsColoredStats.updateAverage(1);
|
this->voxelsColoredStats.updateAverage(1);
|
||||||
|
|
||||||
|
@ -146,6 +153,9 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode,
|
||||||
}
|
}
|
||||||
// average node's color based on color of children
|
// average node's color based on color of children
|
||||||
destinationNode->setColorFromAverageOfChildren();
|
destinationNode->setColorFromAverageOfChildren();
|
||||||
|
if (destinationNode->isDirty()) {
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// give this destination node the child mask from the packet
|
// give this destination node the child mask from the packet
|
||||||
unsigned char childMask = *(nodeData + bytesRead);
|
unsigned char childMask = *(nodeData + bytesRead);
|
||||||
|
@ -157,9 +167,12 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode,
|
||||||
// check the exists mask to see if we have a child to traverse into
|
// check the exists mask to see if we have a child to traverse into
|
||||||
|
|
||||||
if (oneAtBit(childMask, childIndex)) {
|
if (oneAtBit(childMask, childIndex)) {
|
||||||
if (destinationNode->children[childIndex] == NULL) {
|
if (!destinationNode->children[childIndex]) {
|
||||||
// add a child at that index, if it doesn't exist
|
// add a child at that index, if it doesn't exist
|
||||||
destinationNode->addChildAtIndex(childIndex);
|
destinationNode->addChildAtIndex(childIndex);
|
||||||
|
if (destinationNode->isDirty()) {
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
this->voxelsCreated++;
|
this->voxelsCreated++;
|
||||||
this->voxelsCreatedStats.updateAverage(this->voxelsCreated);
|
this->voxelsCreatedStats.updateAverage(this->voxelsCreated);
|
||||||
}
|
}
|
||||||
|
@ -193,6 +206,9 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, int bufferSizeByt
|
||||||
// Note: we need to create this node relative to root, because we're assuming that the bitstream for the initial
|
// Note: we need to create this node relative to root, because we're assuming that the bitstream for the initial
|
||||||
// octal code is always relative to root!
|
// octal code is always relative to root!
|
||||||
bitstreamRootNode = createMissingNode(rootNode, (unsigned char*) bitstreamAt);
|
bitstreamRootNode = createMissingNode(rootNode, (unsigned char*) bitstreamAt);
|
||||||
|
if (bitstreamRootNode->isDirty()) {
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt);
|
int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt);
|
||||||
|
|
|
@ -54,6 +54,9 @@ public:
|
||||||
VoxelNodeBag& bag);
|
VoxelNodeBag& bag);
|
||||||
|
|
||||||
int searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag);
|
int searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag);
|
||||||
|
|
||||||
|
bool isDirty() const { return _isDirty; };
|
||||||
|
void clearDirtyBit() { _isDirty = false; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel,
|
int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel,
|
||||||
|
@ -68,6 +71,8 @@ private:
|
||||||
VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode);
|
VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode);
|
||||||
VoxelNode* createMissingNode(VoxelNode* lastParentNode, unsigned char* deepestCodeToCreate);
|
VoxelNode* createMissingNode(VoxelNode* lastParentNode, unsigned char* deepestCodeToCreate);
|
||||||
int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes);
|
int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes);
|
||||||
|
|
||||||
|
bool _isDirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
int boundaryDistanceForRenderLevel(unsigned int renderLevel);
|
int boundaryDistanceForRenderLevel(unsigned int renderLevel);
|
||||||
|
|
Loading…
Reference in a new issue