From 28fd49271169e768fc78aa989f9bf4b83d838130 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 9 Mar 2017 20:30:38 +0100 Subject: [PATCH] Don't use terrain LOD for the map camera --- apps/openmw/mwrender/localmap.cpp | 1 + components/terrain/quadtreeworld.cpp | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 0f77efafe..b53e16c4e 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -160,6 +160,7 @@ void LocalMap::saveFogOfWar(MWWorld::CellStore* cell) osg::ref_ptr LocalMap::createOrthographicCamera(float x, float y, float width, float height, const osg::Vec3d& upVector, float zmin, float zmax) { osg::ref_ptr camera (new osg::Camera); + camera->getOrCreateUserDataContainer()->addDescription("NoTerrainLod"); camera->setProjectionMatrixAsOrtho(-width/2, width/2, -height/2, height/2, 5, (zmax-zmin) + 10); camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR); diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 3df49c41c..00311711a 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -133,6 +133,7 @@ public: mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); mRootNode->setViewDataMap(mViewDataMap); + mRootNode->setLodCallback(new DefaultLodCallback); addChildren(mRootNode); mRootNode->initNeighbours(); @@ -238,7 +239,7 @@ QuadTreeWorld::~QuadTreeWorld() } -void traverse(QuadTreeNode* node, ViewData* vd, osg::NodeVisitor* nv, const osg::Vec3f& eyePoint, bool visible) +void traverse(QuadTreeNode* node, ViewData* vd, osg::NodeVisitor* nv, LodCallback* lodCallback, const osg::Vec3f& eyePoint, bool visible, bool traverseNonVisible) { if (!node->hasValidBounds()) return; @@ -246,14 +247,17 @@ void traverse(QuadTreeNode* node, ViewData* vd, osg::NodeVisitor* nv, const osg: if (nv && nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR) visible = visible && !static_cast(nv)->isCulled(node->getBoundingBox()); - bool stopTraversal = (node->getLodCallback() && node->getLodCallback()->isSufficientDetail(node, eyePoint)) || !node->getNumChildren(); + if (!visible && !traverseNonVisible) + return; + + bool stopTraversal = (lodCallback && lodCallback->isSufficientDetail(node, eyePoint)) || !node->getNumChildren(); if (stopTraversal) vd->add(node, visible); else { for (unsigned int i=0; igetNumChildren(); ++i) - traverse(node->getChild(i), vd, nv, eyePoint, visible); + traverse(node->getChild(i), vd, nv, lodCallback, eyePoint, visible, traverseNonVisible); } } @@ -315,7 +319,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) { osgUtil::CullVisitor* cv = static_cast(&nv); - traverse(mRootNode.get(), vd, cv, cv->getEyePoint(), true); + + LodCallback* lodCallback = mRootNode->getLodCallback(); + if (osg::UserDataContainer* udc = cv->getCurrentCamera()->getUserDataContainer()) + { + if (udc->getNumDescriptions() && udc->getDescriptions()[0] == "NoTerrainLod") + lodCallback = NULL; + } + + traverse(mRootNode.get(), vd, cv, lodCallback, cv->getEyePoint(), true, lodCallback != NULL); } else mRootNode->traverse(nv); @@ -389,7 +401,7 @@ void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint) ensureQuadTreeBuilt(); ViewData* vd = static_cast(view); - traverse(mRootNode.get(), vd, NULL, eyePoint, false); + traverse(mRootNode.get(), vd, NULL, mRootNode->getLodCallback(), eyePoint, false, true); for (unsigned int i=0; igetNumEntries(); ++i) {