From 771c6041212110d833214bcb8d01c12d3088a840 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 2 May 2013 18:12:55 -0700 Subject: [PATCH] more render pipeline optimizations --- interface/src/VoxelSystem.cpp | 7 ++++++- libraries/voxels/src/VoxelNode.cpp | 12 ++++++------ libraries/voxels/src/VoxelTree.cpp | 25 ++++++++++++++++++++++--- libraries/voxels/src/VoxelTree.h | 2 ++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 2195c7fe1a..ebcc12a707 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -101,6 +101,11 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { double start = usecTimestampNow(); // ask the VoxelTree to read the bitstream into the tree _tree->readBitstreamToTree(voxelData, numBytes - 1); + if (_renderWarningsOn && _tree->getNodesChangedFromBitstream()) { + printLog("readBitstreamToTree()... getNodesChangedFromBitstream=%ld _tree->isDirty()=%s \n", + _tree->getNodesChangedFromBitstream(), (_tree->isDirty() ? "yes" : "no") ); + } + double end = usecTimestampNow(); double elapsedmsec = (end - start)/1000.0; if (_renderWarningsOn && elapsedmsec > 1) { @@ -178,7 +183,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { void VoxelSystem::copyWrittenDataToReadArrays() { double start = usecTimestampNow(); - if (_voxelsDirty) { + if (_voxelsDirty && _voxelsUpdated) { // lock on the buffer write lock so we can't modify the data when the GPU is reading it pthread_mutex_lock(&_bufferWriteLock); int bytesOfVertices = (_voxelsInArrays * VERTEX_POINTS_PER_VOXEL) * sizeof(GLfloat); diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 7e411d9c4b..3d0e400782 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -125,9 +125,9 @@ void VoxelNode::setFalseColor(colorPart red, colorPart green, colorPart blue) { _currentColor[1] = green; _currentColor[2] = blue; _currentColor[3] = 1; // XXXBHG - False colors are always considered set - if (_shouldRender) { + //if (_shouldRender) { _isDirty = true; - } + //} } } @@ -138,9 +138,9 @@ void VoxelNode::setFalseColored(bool isFalseColored) { memcpy(&_currentColor,&_trueColor,sizeof(nodeColor)); } _falseColored = isFalseColored; - if (_shouldRender) { + //if (_shouldRender) { _isDirty = true; - } + //} } }; @@ -153,9 +153,9 @@ void VoxelNode::setColor(const nodeColor& color) { if (!_falseColored) { memcpy(&_currentColor,&color,sizeof(nodeColor)); } - if (_shouldRender) { + //if (_shouldRender) { _isDirty = true; - } + //} } } #endif diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index f781c16b0d..87e87ff1a7 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -132,6 +132,7 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, destinationNode->addChildAtIndex(i); if (destinationNode->isDirty()) { _isDirty = true; + _nodesChangedFromBitstream++; } voxelsCreated++; voxelsCreatedStats.updateAverage(1); @@ -141,9 +142,14 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, nodeColor newColor; memcpy(newColor, nodeData + bytesRead, 3); newColor[3] = 1; + bool nodeWasDirty = destinationNode->children[i]->isDirty(); destinationNode->children[i]->setColor(newColor); - if (destinationNode->children[i]->isDirty()) { + bool nodeIsDirty = destinationNode->children[i]->isDirty(); + if (nodeIsDirty) { _isDirty = true; + } + if (!nodeWasDirty && nodeIsDirty) { + _nodesChangedFromBitstream++; } this->voxelsColored++; this->voxelsColoredStats.updateAverage(1); @@ -152,10 +158,15 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, } } // average node's color based on color of children + bool nodeWasDirty = destinationNode->isDirty(); destinationNode->setColorFromAverageOfChildren(); - if (destinationNode->isDirty()) { + bool nodeIsDirty = destinationNode->isDirty(); + if (nodeIsDirty) { _isDirty = true; } + if (!nodeWasDirty && nodeIsDirty) { + _nodesChangedFromBitstream++; + } // give this destination node the child mask from the packet unsigned char childMask = *(nodeData + bytesRead); @@ -169,10 +180,15 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, if (oneAtBit(childMask, childIndex)) { if (!destinationNode->children[childIndex]) { // add a child at that index, if it doesn't exist + bool nodeWasDirty = destinationNode->isDirty(); destinationNode->addChildAtIndex(childIndex); - if (destinationNode->isDirty()) { + bool nodeIsDirty = destinationNode->isDirty(); + if (nodeIsDirty) { _isDirty = true; } + if (!nodeWasDirty && nodeIsDirty) { + _nodesChangedFromBitstream++; + } this->voxelsCreated++; this->voxelsCreatedStats.updateAverage(this->voxelsCreated); } @@ -192,6 +208,8 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, void VoxelTree::readBitstreamToTree(unsigned char * bitstream, int bufferSizeBytes) { int bytesRead = 0; unsigned char* bitstreamAt = bitstream; + + _nodesChangedFromBitstream = 0; // Keep looping through the buffer calling readNodeData() this allows us to pack multiple root-relative Octal codes // into a single network packet. readNodeData() basically goes down a tree from the root, and fills things in from there @@ -208,6 +226,7 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, int bufferSizeByt bitstreamRootNode = createMissingNode(rootNode, (unsigned char*) bitstreamAt); if (bitstreamRootNode->isDirty()) { _isDirty = true; + _nodesChangedFromBitstream++; } } diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 1209868c62..e5b18b86c0 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -57,6 +57,7 @@ public: bool isDirty() const { return _isDirty; }; void clearDirtyBit() { _isDirty = false; }; + unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }; private: int encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEncodeLevel, @@ -73,6 +74,7 @@ private: int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes); bool _isDirty; + unsigned long int _nodesChangedFromBitstream; }; int boundaryDistanceForRenderLevel(unsigned int renderLevel);