From b95fb48a162fcdea8ec1384c265dc799001c8bac Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Sun, 1 Apr 2012 23:06:32 +0200 Subject: [PATCH] Disable LOD when rendering to the shadow map. Produce few NaNs at start --- simgear/scene/material/EffectCullVisitor.cxx | 38 ++++++++++++++++++-- simgear/scene/material/EffectCullVisitor.hxx | 5 ++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/simgear/scene/material/EffectCullVisitor.cxx b/simgear/scene/material/EffectCullVisitor.cxx index c44d8d69..8f7637c9 100644 --- a/simgear/scene/material/EffectCullVisitor.cxx +++ b/simgear/scene/material/EffectCullVisitor.cxx @@ -20,6 +20,7 @@ #include #include +#include #include "EffectCullVisitor.hxx" @@ -34,14 +35,23 @@ namespace simgear using osgUtil::CullVisitor; -EffectCullVisitor::EffectCullVisitor(bool collectLights) : +EffectCullVisitor::EffectCullVisitor() : + _ignoreLOD(false), + _collectLights(false) +{ +} + +EffectCullVisitor::EffectCullVisitor(bool ignoreLOD, bool collectLights) : + _ignoreLOD(ignoreLOD), _collectLights(collectLights) { } EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) : osg::Referenced(rhs), - CullVisitor(rhs) + CullVisitor(rhs), + _ignoreLOD(rhs._ignoreLOD), + _collectLights(rhs._collectLights) { } @@ -50,6 +60,30 @@ CullVisitor* EffectCullVisitor::clone() const return new EffectCullVisitor(*this); } +void EffectCullVisitor::apply(osg::LOD& node) +{ + if (_ignoreLOD) { + if (isCulled(node)) return; + + // push the culling mode. + pushCurrentMask(); + + // push the node's state. + osg::StateSet* node_state = node.getStateSet(); + if (node_state) pushStateSet(node_state); + + if (_traversalMode==TRAVERSE_PARENTS) node.osg::Group::ascend(*this); + else if (_traversalMode!=TRAVERSE_NONE) node.osg::Group::traverse(*this); + // pop the node's state off the render graph stack. + if (node_state) popStateSet(); + + // pop the culling mode. + popCurrentMask(); + } + else + CullVisitor::apply(node); +} + void EffectCullVisitor::apply(osg::Geode& node) { if (isCulled(node)) diff --git a/simgear/scene/material/EffectCullVisitor.hxx b/simgear/scene/material/EffectCullVisitor.hxx index c4d3c630..341dfb02 100644 --- a/simgear/scene/material/EffectCullVisitor.hxx +++ b/simgear/scene/material/EffectCullVisitor.hxx @@ -33,10 +33,12 @@ class EffectGeode; class EffectCullVisitor : public osgUtil::CullVisitor { public: - EffectCullVisitor(bool collectLights = false); + EffectCullVisitor(); + EffectCullVisitor(bool ignoreLOD, bool collectLights = false); EffectCullVisitor(const EffectCullVisitor&); virtual osgUtil::CullVisitor* clone() const; using osgUtil::CullVisitor::apply; + virtual void apply(osg::LOD& node); virtual void apply(osg::Geode& node); virtual void reset(); @@ -47,6 +49,7 @@ public: private: std::map > _bufferList; std::vector > _lightList; + bool _ignoreLOD; bool _collectLights; }; }