]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectCullVisitor.cxx
Improved tile cache priority scheme.
[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     CullVisitor(rhs)
40 {
41 }
42
43 CullVisitor* EffectCullVisitor::clone() const
44 {
45     return new EffectCullVisitor(*this);
46 }
47
48 void EffectCullVisitor::apply(osg::Geode& node)
49 {
50     if (isCulled(node))
51         return;
52     EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
53     if (!eg) {
54         CullVisitor::apply(node);
55         return;
56     }
57     Effect* effect = eg->getEffect();
58     Technique* technique = 0;
59     if (!effect) {
60         CullVisitor::apply(node);
61         return;
62     } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
63         return;
64     }
65     // push the node's state.
66     osg::StateSet* node_state = node.getStateSet();
67     if (node_state)
68         pushStateSet(node_state);
69     for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
70              e = eg->drawablesEnd();
71          beginItr != e;
72          beginItr = technique->processDrawables(beginItr, e, this,
73                                                 eg->isCullingActive()))
74         ;
75     // pop the node's state off the geostate stack.
76     if (node_state)
77         popStateSet();
78
79 }
80 }