Recompute the LOD stitching when the view changes

pull/185/head
scrawl 8 years ago
parent ef704db877
commit 9db71e3f62

@ -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; i<vd->getNumEntries(); ++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)
{

@ -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)
{
}

@ -33,6 +33,7 @@ namespace Terrain
QuadTreeNode* mNode;
bool mVisible;
unsigned int mLodFlags;
osg::ref_ptr<osg::Node> 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<Entry> mEntries;
unsigned int mNumEntries;

Loading…
Cancel
Save