openscenegraph
Effect
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
42namespace osgFX
43{
44
67 public:
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 virtual void resizeGLObjectBuffers(unsigned int maxSize);
123 virtual void releaseGLObjects(osg::State* state = 0) const;
124
125 protected:
126 virtual ~Effect();
127 Effect &operator=(const Effect &) { return *this; }
128
130 inline void dirtyTechniques();
131
133 inline void addTechnique(Technique* tech);
134
141 virtual bool define_techniques() = 0;
142
143 private:
144 friend class Validator;
145
146 bool _enabled;
147
148 typedef std::vector<osg::ref_ptr<Technique> > Technique_list;
149 Technique_list _techs;
150
151 mutable osg::buffered_value<int> _sel_tech;
152
153 // use int instead of bool to avoid errors
154 mutable osg::buffered_value<int> _tech_selected;
155
156 int _global_sel_tech;
157
158 bool _techs_defined;
159
160 osg::ref_ptr<osg::Geode> _dummy_for_validation;
161
162 void build_dummy_node();
163 };
164
165 // INLINE METHODS
166
167 inline bool Effect::getEnabled() const
168 {
169 return _enabled;
170 }
171
172 inline void Effect::setEnabled(bool v)
173 {
174 _enabled = v;
175 }
176
177 inline int Effect::getNumTechniques() const
178 {
179 return static_cast<int>(_techs.size());
180 }
181
183 {
184 return _techs[i].get();
185 }
186
187 inline const Technique* Effect::getTechnique(int i) const
188 {
189 return _techs[i].get();
190 }
191
193 {
194 return _global_sel_tech;
195 }
196
197 inline void Effect::selectTechnique(int i)
198 {
199 _global_sel_tech = i;
200 }
201
203 {
204 _techs.push_back(tech);
205 }
206
208 {
209 _techs_defined = false;
210 }
211
213 {
214 typedef osg::Group inherited;
215 inherited::traverse(nv);
216 }
217
218}
219
220#endif
Definition Effect:66
virtual const char * effectAuthor() const =0
bool getEnabled() const
Definition Effect:167
Effect(const Effect &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Technique * getTechnique(int i)
Definition Effect:182
int getNumTechniques() const
Definition Effect:177
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Effect:71
int getSelectedTechnique() const
Definition Effect:192
virtual const char * effectDescription() const =0
Effect & operator=(const Effect &)
Definition Effect:127
virtual void setUpDemo()
Definition Effect:95
virtual const char * effectName() const =0
void dirtyTechniques()
Definition Effect:207
virtual const char * libraryName() const
Definition Effect:72
void setEnabled(bool v)
Definition Effect:172
virtual bool define_techniques()=0
void selectTechnique(int i=AUTO_DETECT)
Definition Effect:197
virtual void resizeGLObjectBuffers(unsigned int maxSize)
void inherited_traverse(osg::NodeVisitor &nv)
Definition Effect:212
virtual ~Effect()
virtual const char * className() const
Definition Effect:73
void addTechnique(Technique *tech)
Definition Effect:202
virtual void traverse(osg::NodeVisitor &nv)
virtual void releaseGLObjects(osg::State *state=0) const
TechniqueSelection
Definition Effect:109
Definition Technique:57
Definition osgFX/Validator:35
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition Group:29
Definition NodeVisitor:82
Definition Object:61
Definition State:80
Definition buffered_value:27
Definition ref_ptr:32
Definition AnisotropicLighting:25
#define OSGFX_EXPORT
Definition osgFX/Export:27
#define NULL
Definition osg/Export:55