1 // Copyright (C) 2008 Timothy Moore timoore@redhat.com
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # include <simgear_config.h>
21 #include <osg/StateSet>
22 #include <osg/Texture2D>
25 #include "EffectCullVisitor.hxx"
27 #include "EffectGeode.hxx"
29 #include "Technique.hxx"
31 #include <simgear/scene/util/RenderConstants.hxx>
36 using osgUtil::CullVisitor;
38 EffectCullVisitor::EffectCullVisitor() :
44 EffectCullVisitor::EffectCullVisitor(bool ignoreLOD, bool collectLights) :
45 _ignoreLOD(ignoreLOD),
46 _collectLights(collectLights)
50 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
53 _ignoreLOD(rhs._ignoreLOD),
54 _collectLights(rhs._collectLights)
58 CullVisitor* EffectCullVisitor::clone() const
60 return new EffectCullVisitor(*this);
63 void EffectCullVisitor::apply(osg::LOD& node)
66 if (isCulled(node)) return;
68 // push the culling mode.
71 // push the node's state.
72 osg::StateSet* node_state = node.getStateSet();
73 if (node_state) pushStateSet(node_state);
75 if (_traversalMode==TRAVERSE_PARENTS) node.osg::Group::ascend(*this);
76 else if (_traversalMode!=TRAVERSE_NONE) node.osg::Group::traverse(*this);
77 // pop the node's state off the render graph stack.
78 if (node_state) popStateSet();
80 // pop the culling mode.
84 CullVisitor::apply(node);
87 void EffectCullVisitor::apply(osg::Geode& node)
91 EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
93 CullVisitor::apply(node);
96 if (_collectLights && ( eg->getNodeMask() & MODELLIGHT_BIT ) ) {
97 _lightList.push_back( eg );
99 Effect* effect = eg->getEffect();
100 Technique* technique = 0;
102 CullVisitor::apply(node);
104 } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
107 // push the node's state.
108 osg::StateSet* node_state = node.getStateSet();
110 pushStateSet(node_state);
111 for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
112 e = eg->drawablesEnd();
114 beginItr = technique->processDrawables(beginItr, e, this,
115 eg->isCullingActive()))
117 // pop the node's state off the geostate stack.
123 void EffectCullVisitor::reset()
127 osgUtil::CullVisitor::reset();
130 void EffectCullVisitor::clearBufferList()
135 void EffectCullVisitor::addBuffer(int i, osg::Texture2D* tex)
137 _bufferList.insert(std::make_pair(i,tex));
140 osg::Texture2D* EffectCullVisitor::getBuffer(int i)
142 return _bufferList[i];