]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectGeode.hxx
Partial fix for crash in SGPropertyNode::fireValueChanged
[simgear.git] / simgear / scene / material / EffectGeode.hxx
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 #ifndef SIMGEAR_EFFECT_GEODE_HXX
18 #define SIMGEAR_EFFECT_GEODE_HXX 1
19
20 #include <osg/Geode>
21 #include <osg/Version>
22
23 #include <boost/iterator/iterator_adaptor.hpp>
24
25 #include "Effect.hxx"
26
27 namespace simgear
28 {
29 class EffectGeode : public osg::Geode
30 {
31   public:
32
33 #if OSG_VERSION_LESS_THAN(3,3,2)
34     typedef DrawableList::iterator DrawablesIterator;
35 #else
36     class DrawablesIterator:
37       public boost::iterator_adaptor<
38         DrawablesIterator,
39         osg::NodeList::iterator,
40         osg::ref_ptr<osg::Drawable>,
41         boost::use_default,
42         osg::ref_ptr<osg::Drawable> // No reference as Reference type.
43                                     // The child list does not contain Drawable
44                                     // ref_ptr so we can not return any
45                                     // references to them.
46       >
47     {
48       public:
49
50         DrawablesIterator()
51         {}
52
53         explicit DrawablesIterator(osg::NodeList::iterator const& node_it):
54           DrawablesIterator::iterator_adaptor_(node_it)
55         {}
56
57       private:
58         friend class boost::iterator_core_access;
59         osg::ref_ptr<osg::Drawable> dereference() const
60         {
61           return base_reference()->get()->asDrawable();
62         }
63     };
64 #endif
65
66     EffectGeode();
67     EffectGeode(const EffectGeode& rhs,
68                 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
69     META_Node(simgear,EffectGeode);
70     Effect* getEffect() const { return _effect.get(); }
71     void setEffect(Effect* effect);
72     virtual void resizeGLObjectBuffers(unsigned int maxSize);
73     virtual void releaseGLObjects(osg::State* = 0) const;
74
75 #if OSG_VERSION_LESS_THAN(3,3,2)
76     DrawablesIterator drawablesBegin() { return _drawables.begin(); }
77     DrawablesIterator drawablesEnd() { return _drawables.end(); }
78 #else
79     DrawablesIterator drawablesBegin() { return DrawablesIterator(_children.begin()); }
80     DrawablesIterator drawablesEnd() { return DrawablesIterator(_children.end()); }
81 #endif
82
83     void runGenerators(osg::Geometry *geometry);
84 private:
85     osg::ref_ptr<Effect> _effect;
86 };
87 }
88 #endif