From 4b7d0bba53cb3d4f84da72b53828afce9ce6e80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Mocquillon?= Date: Mon, 6 Sep 2021 21:10:03 +0200 Subject: [PATCH] Avoid adding redundant osg;;Group in non debug mode --- components/terrain/chunkmanager.cpp | 7 ++++--- components/terrain/quadtreeworld.cpp | 11 ++++++++--- components/terrain/quadtreeworld.hpp | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index 53b743c03a..1f3279e5c5 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -238,19 +238,20 @@ osg::ref_ptr ChunkManager::createChunk(float chunkSize, const osg::Ve } geometry->setNodeMask(mNodeMask); - osg::ref_ptr result(new osg::Group); - result->addChild(geometry); if (mDebugChunks) { + osg::ref_ptr result(new osg::Group); + result->addChild(geometry); auto chunkBorder = CellBorder::createBorderGeometry(chunkCenter.x() - chunkSize / 2.f, chunkCenter.y() - chunkSize / 2.f, chunkSize, mStorage, mSceneManager, getNodeMask()); osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 }; osg::ref_ptr trans = new osg::MatrixTransform(osg::Matrixf::translate(-center*Constants::CellSizeInUnits)); trans->setDataVariance(osg::Object::STATIC); trans->addChild(chunkBorder); result->addChild(trans); + return result; } - return result; + return geometry; } } diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index ca28e1cc05..bbf212942e 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -252,6 +252,7 @@ QuadTreeWorld::QuadTreeWorld(osg::Group *parent, osg::Group *compileRoot, Resour , mVertexLodMod(vertexLodMod) , mViewDistance(std::numeric_limits::max()) , mMinSize(1/8.f) + , mDebugTerrainChunks(Settings::Manager::getBool("debug chunks", "Terrain")) { mChunkManager->setCompositeMapSize(compMapResolution); mChunkManager->setCompositeMapLevel(compMapLevel); @@ -351,7 +352,7 @@ void loadRenderingNode(ViewData::Entry& entry, ViewData* vd, int vertexLodMod, f } } -void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld) +void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld, bool debugTerrainChunk) { if (!(cv->getTraversalMask() & callback->getCullMask())) return; @@ -367,7 +368,11 @@ void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil: for (unsigned int i=0; igetNumEntries(); ++i) { ViewData::Entry& entry = vd->getEntry(i); - osg::BoundingBox bb = static_cast(entry.mRenderingNode->asGroup()->getChild(0)->asGroup()->getChild(0))->getWaterBoundingBox(); + osg::BoundingBox bb; + if(debugTerrainChunk) + bb = static_cast(entry.mRenderingNode->asGroup()->getChild(0)->asGroup()->getChild(0))->getWaterBoundingBox(); + else + bb = static_cast(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox(); if (!bb.valid()) continue; osg::Vec3f ofs (entry.mNode->getCenter().x()*cellworldsize, entry.mNode->getCenter().y()*cellworldsize, 0.f); @@ -443,7 +448,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) } if (mHeightCullCallback && isCullVisitor) - updateWaterCullingView(mHeightCullCallback, vd, static_cast(&nv), mStorage->getCellWorldSize(), !isGridEmpty()); + updateWaterCullingView(mHeightCullCallback, vd, static_cast(&nv), mStorage->getCellWorldSize(), !isGridEmpty(), mDebugTerrainChunks); vd->markUnchanged(); diff --git a/components/terrain/quadtreeworld.hpp b/components/terrain/quadtreeworld.hpp index 3dd96a0b84..f7cbf8097a 100644 --- a/components/terrain/quadtreeworld.hpp +++ b/components/terrain/quadtreeworld.hpp @@ -72,6 +72,7 @@ namespace Terrain int mVertexLodMod; float mViewDistance; float mMinSize; + bool mDebugTerrainChunks; }; }