]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectCullVisitor.cxx
Use Effect to implement point lights
[simgear.git] / simgear / scene / material / EffectCullVisitor.cxx
1 // Copyright (C) 2008  Timothy Moore timoore@redhat.com
2 //
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.
7 //
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.
12 //
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.
16
17 #include <osg/StateSet>
18
19 #include "EffectCullVisitor.hxx"
20
21 #include "EffectGeode.hxx"
22 #include "Effect.hxx"
23 #include "Technique.hxx"
24
25 namespace simgear
26 {
27
28 using osgUtil::CullVisitor;
29
30 EffectCullVisitor::EffectCullVisitor()
31 {
32 }
33
34 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
35     CullVisitor(rhs)
36 {
37 }
38
39 CullVisitor* EffectCullVisitor::clone() const
40 {
41     return new EffectCullVisitor(*this);
42 }
43
44 void EffectCullVisitor::apply(osg::Geode& node)
45 {
46     if (isCulled(node))
47         return;
48     EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
49     if (!eg) {
50         CullVisitor::apply(node);
51         return;
52     }
53     Technique* technique = eg->getEffect()->chooseTechnique(&getRenderInfo());
54     if (!technique) {
55         CullVisitor::apply(node);
56         return;
57     }
58     // push the node's state.
59     osg::StateSet* node_state = node.getStateSet();
60     if (node_state)
61         pushStateSet(node_state);
62     for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
63              e = eg->drawablesEnd();
64          beginItr != e;
65          beginItr = technique->processDrawables(beginItr, e, this,
66                                                 eg->isCullingActive()))
67         ;
68     // pop the node's state off the geostate stack.
69     if (node_state)
70         popStateSet();
71
72 }
73 }