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) , mValidBounds(false)
, mSize(size) , mSize(size)
, mCenter(center) , mCenter(center)
, mViewDataMap(nullptr)
{ {
for (unsigned int i=0; i<4; ++i) for (unsigned int i=0; i<4; ++i)
mNeighbours[i] = 0; mNeighbours[i] = 0;
@ -181,34 +180,6 @@ LodCallback *QuadTreeNode::getLodCallback()
return mLodCallback; 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) void QuadTreeNode::setBoundingBox(const osg::BoundingBox &boundingBox)
{ {
mBoundingBox = boundingBox; mBoundingBox = boundingBox;

@ -106,14 +106,6 @@ namespace Terrain
LodCallback* getLodCallback(); 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: private:
QuadTreeNode* mParent; QuadTreeNode* mParent;
@ -127,8 +119,6 @@ namespace Terrain
osg::Vec2f mCenter; osg::Vec2f mCenter;
osg::ref_ptr<LodCallback> mLodCallback; osg::ref_ptr<LodCallback> mLodCallback;
ViewDataMap* mViewDataMap;
}; };
} }

@ -97,12 +97,11 @@ private:
class QuadTreeBuilder class QuadTreeBuilder
{ {
public: public:
QuadTreeBuilder(Terrain::Storage* storage, ViewDataMap* viewDataMap, float lodFactor, float minSize) QuadTreeBuilder(Terrain::Storage* storage, float lodFactor, float minSize)
: mStorage(storage) : mStorage(storage)
, mLodFactor(lodFactor) , mLodFactor(lodFactor)
, mMinX(0.f), mMaxX(0.f), mMinY(0.f), mMaxY(0.f) , mMinX(0.f), mMaxX(0.f), mMinY(0.f), mMaxY(0.f)
, mMinSize(minSize) , mMinSize(minSize)
, mViewDataMap(viewDataMap)
{ {
} }
@ -120,7 +119,6 @@ public:
float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f; float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f;
mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY));
mRootNode->setViewDataMap(mViewDataMap);
mRootNode->setLodCallback(new DefaultLodCallback(mLodFactor, mMinSize)); mRootNode->setLodCallback(new DefaultLodCallback(mLodFactor, mMinSize));
addChildren(mRootNode); addChildren(mRootNode);
@ -171,7 +169,6 @@ public:
osg::ref_ptr<QuadTreeNode> node = new QuadTreeNode(parent, direction, size, center); osg::ref_ptr<QuadTreeNode> node = new QuadTreeNode(parent, direction, size, center);
node->setLodCallback(parent->getLodCallback()); node->setLodCallback(parent->getLodCallback());
node->setViewDataMap(mViewDataMap);
if (center.x() - halfSize > mMaxX if (center.x() - halfSize > mMaxX
|| center.x() + halfSize < mMinX || center.x() + halfSize < mMinX
@ -220,7 +217,6 @@ private:
float mLodFactor; float mLodFactor;
float mMinX, mMaxX, mMinY, mMaxY; float mMinX, mMaxX, mMinY, mMaxY;
float mMinSize; float mMinSize;
ViewDataMap* mViewDataMap;
osg::ref_ptr<RootNode> mRootNode; osg::ref_ptr<RootNode> mRootNode;
}; };
@ -337,8 +333,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
return; return;
} }
bool needsUpdate = false; bool needsUpdate = true;
ViewData* vd = mRootNode->getView(nv, needsUpdate); 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) if (needsUpdate)
{ {
@ -403,7 +406,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
} }
if (!isCullVisitor) 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(); vd->markUnchanged();
@ -422,7 +425,7 @@ void QuadTreeWorld::ensureQuadTreeBuilt()
return; return;
const float minSize = 1/8.f; const float minSize = 1/8.f;
QuadTreeBuilder builder(mStorage, mViewDataMap.get(), mLodFactor, minSize); QuadTreeBuilder builder(mStorage, mLodFactor, minSize);
builder.build(); builder.build();
mRootNode = builder.getRootNode(); mRootNode = builder.getRootNode();

Loading…
Cancel
Save