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>
24 #include "EffectCullVisitor.hxx"
26 #include "EffectGeode.hxx"
28 #include "Technique.hxx"
30 #include <simgear/scene/util/RenderConstants.hxx>
35 using osgUtil::CullVisitor;
37 EffectCullVisitor::EffectCullVisitor(bool collectLights) :
38 _collectLights(collectLights)
42 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
48 CullVisitor* EffectCullVisitor::clone() const
50 return new EffectCullVisitor(*this);
53 void EffectCullVisitor::apply(osg::Geode& node)
57 EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
59 CullVisitor::apply(node);
62 if (_collectLights && ( eg->getNodeMask() & MODELLIGHT_BIT ) ) {
63 _lightList.push_back( eg );
65 Effect* effect = eg->getEffect();
66 Technique* technique = 0;
68 CullVisitor::apply(node);
70 } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
73 // push the node's state.
74 osg::StateSet* node_state = node.getStateSet();
76 pushStateSet(node_state);
77 for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
78 e = eg->drawablesEnd();
80 beginItr = technique->processDrawables(beginItr, e, this,
81 eg->isCullingActive()))
83 // pop the node's state off the geostate stack.
89 void EffectCullVisitor::reset()
93 osgUtil::CullVisitor::reset();
96 void EffectCullVisitor::clearBufferList()
101 void EffectCullVisitor::addBuffer(int i, osg::Texture2D* tex)
103 _bufferList.insert(std::make_pair(i,tex));
106 osg::Texture2D* EffectCullVisitor::getBuffer(int i)
108 return _bufferList[i];