]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectCullVisitor.cxx
Use of copy-constructors
[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 #ifdef HAVE_CONFIG_H
18 #  include <simgear_config.h>
19 #endif
20
21 #include <osg/StateSet>
22
23 #include "EffectCullVisitor.hxx"
24
25 #include "EffectGeode.hxx"
26 #include "Effect.hxx"
27 #include "Technique.hxx"
28
29 namespace simgear
30 {
31
32 using osgUtil::CullVisitor;
33
34 EffectCullVisitor::EffectCullVisitor()
35 {
36 }
37
38 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
39     osg::Referenced(rhs),
40     CullVisitor(rhs)
41 {
42 }
43
44 CullVisitor* EffectCullVisitor::clone() const
45 {
46     return new EffectCullVisitor(*this);
47 }
48
49 void EffectCullVisitor::apply(osg::Geode& node)
50 {
51     if (isCulled(node))
52         return;
53     EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
54     if (!eg) {
55         CullVisitor::apply(node);
56         return;
57     }
58     Effect* effect = eg->getEffect();
59     Technique* technique = 0;
60     if (!effect) {
61         CullVisitor::apply(node);
62         return;
63     } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
64         return;
65     }
66     // push the node's state.
67     osg::StateSet* node_state = node.getStateSet();
68     if (node_state)
69         pushStateSet(node_state);
70     for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
71              e = eg->drawablesEnd();
72          beginItr != e;
73          beginItr = technique->processDrawables(beginItr, e, this,
74                                                 eg->isCullingActive()))
75         ;
76     // pop the node's state off the geostate stack.
77     if (node_state)
78         popStateSet();
79
80 }
81 }