]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectCullVisitor.cxx
Add positioned uniforms and G-buffer textures to Effects
[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 #include <osg/Texture2D>
23
24 #include "EffectCullVisitor.hxx"
25
26 #include "EffectGeode.hxx"
27 #include "Effect.hxx"
28 #include "Technique.hxx"
29
30 namespace simgear
31 {
32
33 using osgUtil::CullVisitor;
34
35 EffectCullVisitor::EffectCullVisitor()
36 {
37 }
38
39 EffectCullVisitor::EffectCullVisitor(const EffectCullVisitor& rhs) :
40     osg::Referenced(rhs),
41     CullVisitor(rhs)
42 {
43 }
44
45 CullVisitor* EffectCullVisitor::clone() const
46 {
47     return new EffectCullVisitor(*this);
48 }
49
50 void EffectCullVisitor::apply(osg::Geode& node)
51 {
52     if (isCulled(node))
53         return;
54     EffectGeode *eg = dynamic_cast<EffectGeode*>(&node);
55     if (!eg) {
56         CullVisitor::apply(node);
57         return;
58     }
59     Effect* effect = eg->getEffect();
60     Technique* technique = 0;
61     if (!effect) {
62         CullVisitor::apply(node);
63         return;
64     } else if (!(technique = effect->chooseTechnique(&getRenderInfo()))) {
65         return;
66     }
67     // push the node's state.
68     osg::StateSet* node_state = node.getStateSet();
69     if (node_state)
70         pushStateSet(node_state);
71     for (EffectGeode::DrawablesIterator beginItr = eg->drawablesBegin(),
72              e = eg->drawablesEnd();
73          beginItr != e;
74          beginItr = technique->processDrawables(beginItr, e, this,
75                                                 eg->isCullingActive()))
76         ;
77     // pop the node's state off the geostate stack.
78     if (node_state)
79         popStateSet();
80
81 }
82
83 void EffectCullVisitor::clearBufferList()
84 {
85     _bufferList.clear();
86 }
87
88 void EffectCullVisitor::addBuffer(int i, osg::Texture2D* tex)
89 {
90     _bufferList.insert(std::make_pair(i,tex));
91 }
92
93 osg::Texture2D* EffectCullVisitor::getBuffer(int i)
94 {
95     return _bufferList[i];
96 }
97
98 }