diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index e91a513cb..6d8e38400 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -283,6 +283,26 @@ unsigned int getLodFlags(QuadTreeNode* node, int ourLod, ViewData* vd) return lodFlags; } +void loadRenderingNode(ViewData::Entry& entry, ViewData* vd, ChunkManager* chunkManager) +{ + if (vd->hasChanged()) + { + // have to recompute the lodFlags in case a neighbour has changed LOD. + int ourLod = Log2(int(entry.mNode->getSize())); + unsigned int lodFlags = getLodFlags(entry.mNode, ourLod, vd); + if (lodFlags != entry.mLodFlags) + entry.mRenderingNode = NULL; + } + + if (!entry.mRenderingNode) + { + int ourLod = Log2(int(entry.mNode->getSize())); + unsigned int lodFlags = getLodFlags(entry.mNode, ourLod, vd); + entry.mRenderingNode = chunkManager->getChunk(entry.mNode->getSize(), entry.mNode->getCenter(), ourLod, lodFlags); + entry.mLodFlags = lodFlags; + } +} + void QuadTreeWorld::accept(osg::NodeVisitor &nv) { if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR)// && nv.getVisitorType() != osg::NodeVisitor::INTERSECTION_VISITOR) @@ -301,12 +321,8 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) for (unsigned int i=0; igetNumEntries(); ++i) { ViewData::Entry& entry = vd->getEntry(i); - if (!entry.mRenderingNode) - { - int ourLod = Log2(int(entry.mNode->getSize())); - unsigned int lodFlags = getLodFlags(entry.mNode, ourLod, vd); - entry.mRenderingNode = mChunkManager->getChunk(entry.mNode->getSize(), entry.mNode->getCenter(), ourLod, lodFlags); - } + + loadRenderingNode(entry, vd, mChunkManager.get()); if (entry.mVisible) { diff --git a/components/terrain/viewdata.cpp b/components/terrain/viewdata.cpp index e07e3c784..bd7e0b819 100644 --- a/components/terrain/viewdata.cpp +++ b/components/terrain/viewdata.cpp @@ -34,6 +34,11 @@ ViewData::Entry &ViewData::getEntry(unsigned int i) return mEntries[i]; } +bool ViewData::hasChanged() const +{ + return mChanged; +} + void ViewData::reset(unsigned int frame) { // clear any unused entries @@ -67,6 +72,7 @@ bool ViewData::contains(QuadTreeNode *node) ViewData::Entry::Entry() : mNode(NULL) , mVisible(true) + , mLodFlags(0) { } diff --git a/components/terrain/viewdata.hpp b/components/terrain/viewdata.hpp index 71433f61a..49b3722c8 100644 --- a/components/terrain/viewdata.hpp +++ b/components/terrain/viewdata.hpp @@ -33,6 +33,7 @@ namespace Terrain QuadTreeNode* mNode; bool mVisible; + unsigned int mLodFlags; osg::ref_ptr mRenderingNode; }; @@ -47,6 +48,9 @@ namespace Terrain unsigned int getFrameLastUsed() const { return mFrameLastUsed; } + /// @return Have any nodes changed since the last frame + bool hasChanged() const; + private: std::vector mEntries; unsigned int mNumEntries;