OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Effect.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgFX - Copyright (C) 2003 Marco Jez
14 
15 #ifndef OSGFX__effect
16 #define OSGFX__effect
17 
18 #include <osgFX/Export>
19 #include <osgFX/Technique>
20 
21 #include <osg/buffered_value>
22 #include <osg/ref_ptr>
23 #include <osg/Node>
24 #include <osg/Group>
25 #include <osg/Geode>
26 #include <osg/OccluderNode>
27 
28 #include <vector>
29 
35 #define META_Effect(library, classname, effectname, effectdescription, effectauthor) \
36  META_Node(library, classname) \
37  virtual const char *effectName() const { return effectname; } \
38  virtual const char *effectDescription() const { return effectdescription; } \
39  virtual const char *effectAuthor() const { return effectauthor; }
40 
41 
42 namespace osgFX
43 {
44 
66  class OSGFX_EXPORT Effect: public osg::Group {
67  public:
68  Effect();
69  Effect(const Effect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
70 
71  virtual inline bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Effect*>(obj) != NULL; }
72  virtual inline const char* libraryName() const { return "osgFX"; }
73  virtual inline const char* className() const { return "Effect"; }
74 
76  virtual const char *effectName() const = 0;
77 
79  virtual const char *effectDescription() const = 0;
80 
82  virtual const char *effectAuthor() const = 0;
83 
85  inline bool getEnabled() const;
86 
88  inline void setEnabled(bool v);
89 
95  inline virtual void setUpDemo() {}
96 
98  inline int getNumTechniques() const;
99 
101  inline Technique* getTechnique(int i);
102 
104  inline const Technique* getTechnique(int i) const;
105 
107  inline int getSelectedTechnique() const;
108 
110  AUTO_DETECT = -1
111  };
112 
114  inline void selectTechnique(int i = AUTO_DETECT);
115 
117  virtual void traverse(osg::NodeVisitor& nv);
118 
120  inline void inherited_traverse(osg::NodeVisitor& nv);
121 
122  protected:
123  virtual ~Effect();
124  Effect &operator=(const Effect &) { return *this; }
125 
127  inline void dirtyTechniques();
128 
130  inline void addTechnique(Technique* tech);
131 
138  virtual bool define_techniques() = 0;
139 
140  private:
141  friend class Validator;
142 
143  bool _enabled;
144 
145  typedef std::vector<osg::ref_ptr<Technique> > Technique_list;
146  Technique_list _techs;
147 
148  mutable osg::buffered_value<int> _sel_tech;
149 
150  // use int instead of bool to avoid errors
151  mutable osg::buffered_value<int> _tech_selected;
152 
153  int _global_sel_tech;
154 
155  bool _techs_defined;
156 
157  osg::ref_ptr<osg::Geode> _dummy_for_validation;
158 
159  void build_dummy_node();
160  };
161 
162  // INLINE METHODS
163 
164  inline bool Effect::getEnabled() const
165  {
166  return _enabled;
167  }
168 
169  inline void Effect::setEnabled(bool v)
170  {
171  _enabled = v;
172  }
173 
174  inline int Effect::getNumTechniques() const
175  {
176  return static_cast<int>(_techs.size());
177  }
178 
180  {
181  return _techs[i].get();
182  }
183 
184  inline const Technique* Effect::getTechnique(int i) const
185  {
186  return _techs[i].get();
187  }
188 
189  inline int Effect::getSelectedTechnique() const
190  {
191  return _global_sel_tech;
192  }
193 
194  inline void Effect::selectTechnique(int i)
195  {
196  _global_sel_tech = i;
197  }
198 
199  inline void Effect::addTechnique(Technique* tech)
200  {
201  _techs.push_back(tech);
202  }
203 
205  {
206  _techs_defined = false;
207  }
208 
210  {
211  typedef osg::Group inherited;
212  inherited::traverse(nv);
213  }
214 
215 }
216 
217 #endif
#define NULL
Definition: Export.h:59
int getNumTechniques() const
Definition: Effect.h:174
virtual void setUpDemo()
Definition: Effect.h:95
void selectTechnique(int i=AUTO_DETECT)
Definition: Effect.h:194
virtual const char * libraryName() const
Definition: Effect.h:72
TechniqueSelection
Definition: Effect.h:109
void addTechnique(Technique *tech)
Definition: Effect.h:199
Effect & operator=(const Effect &)
Definition: Effect.h:124
void inherited_traverse(osg::NodeVisitor &nv)
Definition: Effect.h:209
Technique * getTechnique(int i)
Definition: Effect.h:179
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: Effect.h:71
void setEnabled(bool v)
Definition: Effect.h:169
void dirtyTechniques()
Definition: Effect.h:204
#define OSGFX_EXPORT
Definition: Export.h:27
virtual const char * className() const
Definition: Effect.h:73
bool getEnabled() const
Definition: Effect.h:164
int getSelectedTechnique() const
Definition: Effect.h:189