Do not store a ViewDataMap in the every QuadTreeNode

pull/2325/head
bzzt 6 years ago committed by Andrei Kortunov
parent cb6d27fb12
commit ebcf8ca062

@ -61,7 +61,6 @@ QuadTreeNode::QuadTreeNode(QuadTreeNode* parent, ChildDirection direction, float
, mValidBounds(false)
, mSize(size)
, mCenter(center)
, mViewDataMap(nullptr)
{
for (unsigned int i=0; i<4; ++i)
mNeighbours[i] = 0;
@ -181,34 +180,6 @@ LodCallback *QuadTreeNode::getLodCallback()
return mLodCallback;
}
void QuadTreeNode::setViewDataMap(ViewDataMap *map)
{
mViewDataMap = map;
}
ViewDataMap *QuadTreeNode::getViewDataMap()
{
return mViewDataMap;
}
ViewData* QuadTreeNode::getView(osg::NodeVisitor &nv, bool& needsUpdate)
{
ViewData* vd = NULL;
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(&nv);
vd = mViewDataMap->getViewData(cv->getCurrentCamera(), nv.getViewPoint(), needsUpdate);
}
else // INTERSECTION_VISITOR
{
osg::Vec3f viewPoint = nv.getViewPoint();
static osg::ref_ptr<osg::Object> dummyObj = new osg::DummyObject;
vd = mViewDataMap->getViewData(dummyObj.get(), viewPoint, needsUpdate);
needsUpdate = true;
}
return vd;
}
void QuadTreeNode::setBoundingBox(const osg::BoundingBox &boundingBox)
{
mBoundingBox = boundingBox;

@ -106,14 +106,6 @@ namespace Terrain
LodCallback* getLodCallback();
/// Set the view data map that the finally used nodes for a given camera/intersection are pushed onto.
void setViewDataMap(ViewDataMap* map);
ViewDataMap* getViewDataMap();
/// Create or retrieve a view for the given traversal.
ViewData* getView(osg::NodeVisitor& nv, bool& needsUpdate);
private:
QuadTreeNode* mParent;
@ -127,8 +119,6 @@ namespace Terrain
osg::Vec2f mCenter;
osg::ref_ptr<LodCallback> mLodCallback;
ViewDataMap* mViewDataMap;
};
}

@ -97,12 +97,11 @@ private:
class QuadTreeBuilder
{
public:
QuadTreeBuilder(Terrain::Storage* storage, ViewDataMap* viewDataMap, float lodFactor, float minSize)
QuadTreeBuilder(Terrain::Storage* storage, float lodFactor, float minSize)
: mStorage(storage)
, mLodFactor(lodFactor)
, mMinX(0.f), mMaxX(0.f), mMinY(0.f), mMaxY(0.f)
, mMinSize(minSize)
, mViewDataMap(viewDataMap)
{
}
@ -120,7 +119,6 @@ public:
float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f;
mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY));
mRootNode->setViewDataMap(mViewDataMap);
mRootNode->setLodCallback(new DefaultLodCallback(mLodFactor, mMinSize));
addChildren(mRootNode);
@ -171,7 +169,6 @@ public:
osg::ref_ptr<QuadTreeNode> node = new QuadTreeNode(parent, direction, size, center);
node->setLodCallback(parent->getLodCallback());
node->setViewDataMap(mViewDataMap);
if (center.x() - halfSize > mMaxX
|| center.x() + halfSize < mMinX
@ -220,7 +217,6 @@ private:
float mLodFactor;
float mMinX, mMaxX, mMinY, mMaxY;
float mMinSize;
ViewDataMap* mViewDataMap;
osg::ref_ptr<RootNode> mRootNode;
};
@ -337,8 +333,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
return;
}
bool needsUpdate = false;
ViewData* vd = mRootNode->getView(nv, needsUpdate);
bool needsUpdate = true;
ViewData* vd = nullptr;
if (isCullVisitor)
vd = mViewDataMap->getViewData(static_cast<osgUtil::CullVisitor*>(&nv)->getCurrentCamera(), nv.getViewPoint(), needsUpdate);
else
{
static ViewData sIntersectionViewData;
vd = &sIntersectionViewData;
}
if (needsUpdate)
{
@ -403,7 +406,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
}
if (!isCullVisitor)
vd->reset(); // we can't reuse intersection views in the next frame because they only contain what is touched by the intersection ray.
vd->clear(); // we can't reuse intersection views in the next frame because they only contain what is touched by the intersection ray.
vd->markUnchanged();
@ -422,7 +425,7 @@ void QuadTreeWorld::ensureQuadTreeBuilt()
return;
const float minSize = 1/8.f;
QuadTreeBuilder builder(mStorage, mViewDataMap.get(), mLodFactor, minSize);
QuadTreeBuilder builder(mStorage, mLodFactor, minSize);
builder.build();
mRootNode = builder.getRootNode();

Loading…
Cancel
Save