mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:36:49 +02:00
optimized performance of VoxelNode::isLeaf()
This commit is contained in:
parent
b9a023af37
commit
ef20b3e4b3
3 changed files with 28 additions and 18 deletions
|
@ -292,6 +292,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
||||||
assert(_viewFrustum); // you must set up _viewFrustum before calling this
|
assert(_viewFrustum); // you must set up _viewFrustum before calling this
|
||||||
int voxelsUpdated = 0;
|
int voxelsUpdated = 0;
|
||||||
bool shouldRender = false; // assume we don't need to render it
|
bool shouldRender = false; // assume we don't need to render it
|
||||||
|
bool isLeaf = node->isLeaf();
|
||||||
// if it's colored, we might need to render it!
|
// if it's colored, we might need to render it!
|
||||||
if (node->isColored()) {
|
if (node->isColored()) {
|
||||||
float distanceToNode = node->distanceToCamera(*_viewFrustum);
|
float distanceToNode = node->distanceToCamera(*_viewFrustum);
|
||||||
|
@ -299,13 +300,15 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
||||||
float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);
|
float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);
|
||||||
bool inBoundary = (distanceToNode <= boundary);
|
bool inBoundary = (distanceToNode <= boundary);
|
||||||
bool inChildBoundary = (distanceToNode <= childBoundary);
|
bool inChildBoundary = (distanceToNode <= childBoundary);
|
||||||
shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
|
shouldRender = (isLeaf && inChildBoundary) || (inBoundary && !inChildBoundary);
|
||||||
}
|
}
|
||||||
node->setShouldRender(shouldRender && !node->isStagedForDeletion());
|
node->setShouldRender(shouldRender && !node->isStagedForDeletion());
|
||||||
// let children figure out their renderness
|
// let children figure out their renderness
|
||||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
if (!isLeaf) {
|
||||||
if (node->getChildAtIndex(i)) {
|
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||||
voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));
|
if (node->getChildAtIndex(i)) {
|
||||||
|
voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_renderFullVBO) {
|
if (_renderFullVBO) {
|
||||||
|
@ -886,7 +889,8 @@ public:
|
||||||
coloredNodes(0),
|
coloredNodes(0),
|
||||||
nodesInVBO(0),
|
nodesInVBO(0),
|
||||||
nodesInVBOOverExpectedMax(0),
|
nodesInVBOOverExpectedMax(0),
|
||||||
duplicateVBOIndex(0)
|
duplicateVBOIndex(0),
|
||||||
|
leafNodes(0)
|
||||||
{
|
{
|
||||||
memset(hasIndexFound, false, MAX_VOXELS_PER_SYSTEM * sizeof(bool));
|
memset(hasIndexFound, false, MAX_VOXELS_PER_SYSTEM * sizeof(bool));
|
||||||
};
|
};
|
||||||
|
@ -898,9 +902,10 @@ public:
|
||||||
unsigned long nodesInVBO;
|
unsigned long nodesInVBO;
|
||||||
unsigned long nodesInVBOOverExpectedMax;
|
unsigned long nodesInVBOOverExpectedMax;
|
||||||
unsigned long duplicateVBOIndex;
|
unsigned long duplicateVBOIndex;
|
||||||
|
unsigned long leafNodes;
|
||||||
|
|
||||||
unsigned long expectedMax;
|
unsigned long expectedMax;
|
||||||
|
|
||||||
bool colorThis;
|
|
||||||
bool hasIndexFound[MAX_VOXELS_PER_SYSTEM];
|
bool hasIndexFound[MAX_VOXELS_PER_SYSTEM];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -908,6 +913,10 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex
|
||||||
collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;
|
collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;
|
||||||
args->totalNodes++;
|
args->totalNodes++;
|
||||||
|
|
||||||
|
if (node->isLeaf()) {
|
||||||
|
args->leafNodes++;
|
||||||
|
}
|
||||||
|
|
||||||
if (node->isColored()) {
|
if (node->isColored()) {
|
||||||
args->coloredNodes++;
|
args->coloredNodes++;
|
||||||
}
|
}
|
||||||
|
@ -939,6 +948,7 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::collectStatsForTreesAndVBOs() {
|
void VoxelSystem::collectStatsForTreesAndVBOs() {
|
||||||
|
PerformanceWarning warn(true, "collectStatsForTreesAndVBOs()", true);
|
||||||
|
|
||||||
glBufferIndex minDirty = GLBUFFER_INDEX_UNKNOWN;
|
glBufferIndex minDirty = GLBUFFER_INDEX_UNKNOWN;
|
||||||
glBufferIndex maxDirty = 0;
|
glBufferIndex maxDirty = 0;
|
||||||
|
@ -957,8 +967,10 @@ void VoxelSystem::collectStatsForTreesAndVBOs() {
|
||||||
printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", (_voxelsDirty ? "yes" : "no"),
|
printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", (_voxelsDirty ? "yes" : "no"),
|
||||||
_voxelsInWriteArrays, minDirty, maxDirty);
|
_voxelsInWriteArrays, minDirty, maxDirty);
|
||||||
|
|
||||||
printLog("stats: total %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n",
|
printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n",
|
||||||
args.totalNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes,
|
args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);
|
||||||
|
|
||||||
|
printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n",
|
||||||
args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex);
|
args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex);
|
||||||
|
|
||||||
glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
|
glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
|
||||||
|
|
|
@ -40,6 +40,7 @@ void VoxelNode::init(unsigned char * octalCode) {
|
||||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||||
_children[i] = NULL;
|
_children[i] = NULL;
|
||||||
}
|
}
|
||||||
|
_childCount = 0;
|
||||||
|
|
||||||
_glBufferIndex = GLBUFFER_INDEX_UNKNOWN;
|
_glBufferIndex = GLBUFFER_INDEX_UNKNOWN;
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
@ -87,6 +88,8 @@ void VoxelNode::deleteChildAtIndex(int childIndex) {
|
||||||
if (_children[childIndex]) {
|
if (_children[childIndex]) {
|
||||||
delete _children[childIndex];
|
delete _children[childIndex];
|
||||||
_children[childIndex] = NULL;
|
_children[childIndex] = NULL;
|
||||||
|
_isDirty = true;
|
||||||
|
_childCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +99,7 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) {
|
||||||
if (_children[childIndex]) {
|
if (_children[childIndex]) {
|
||||||
_children[childIndex] = NULL;
|
_children[childIndex] = NULL;
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
_childCount--;
|
||||||
}
|
}
|
||||||
return returnedChild;
|
return returnedChild;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +115,7 @@ void VoxelNode::addChildAtIndex(int childIndex) {
|
||||||
_children[childIndex]->setFalseColored(false);
|
_children[childIndex]->setFalseColored(false);
|
||||||
|
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
_childCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +220,7 @@ bool VoxelNode::collapseIdenticalLeaves() {
|
||||||
delete _children[i]; // delete all the child nodes
|
delete _children[i]; // delete all the child nodes
|
||||||
_children[i]=NULL; // set it to NULL
|
_children[i]=NULL; // set it to NULL
|
||||||
}
|
}
|
||||||
|
_childCount = 0;
|
||||||
nodeColor collapsedColor;
|
nodeColor collapsedColor;
|
||||||
collapsedColor[0]=red;
|
collapsedColor[0]=red;
|
||||||
collapsedColor[1]=green;
|
collapsedColor[1]=green;
|
||||||
|
@ -235,15 +241,6 @@ void VoxelNode::setRandomColor(int minimumBrightness) {
|
||||||
setColor(newColor);
|
setColor(newColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoxelNode::isLeaf() const {
|
|
||||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
|
||||||
if (_children[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelNode::printDebugDetails(const char* label) const {
|
void VoxelNode::printDebugDetails(const char* label) const {
|
||||||
printLog("%s - Voxel at corner=(%f,%f,%f) size=%f octcode=", label,
|
printLog("%s - Voxel at corner=(%f,%f,%f) size=%f octcode=", label,
|
||||||
_box.getCorner().x, _box.getCorner().y, _box.getCorner().z, _box.getSize().x);
|
_box.getCorner().x, _box.getCorner().y, _box.getCorner().z, _box.getSize().x);
|
||||||
|
|
|
@ -31,6 +31,7 @@ private:
|
||||||
AABox _box;
|
AABox _box;
|
||||||
unsigned char* _octalCode;
|
unsigned char* _octalCode;
|
||||||
VoxelNode* _children[8];
|
VoxelNode* _children[8];
|
||||||
|
int _childCount;
|
||||||
|
|
||||||
void calculateAABox();
|
void calculateAABox();
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public:
|
||||||
bool isInView(const ViewFrustum& viewFrustum) const;
|
bool isInView(const ViewFrustum& viewFrustum) const;
|
||||||
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;
|
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;
|
||||||
float distanceToCamera(const ViewFrustum& viewFrustum) const;
|
float distanceToCamera(const ViewFrustum& viewFrustum) const;
|
||||||
bool isLeaf() const;
|
bool isLeaf() const { return _childCount == 0; }
|
||||||
void printDebugDetails(const char* label) const;
|
void printDebugDetails(const char* label) const;
|
||||||
bool isDirty() const { return _isDirty; };
|
bool isDirty() const { return _isDirty; };
|
||||||
void clearDirtyBit() { _isDirty = false; };
|
void clearDirtyBit() { _isDirty = false; };
|
||||||
|
|
Loading…
Reference in a new issue