OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Technique.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_TECHNIQUE_
16 #define OSGFX_TECHNIQUE_
17 
18 #include <osgFX/Export>
19 
20 #include <osg/Referenced>
21 #include <osg/State>
22 #include <osg/Group>
23 #include <osg/NodeVisitor>
24 
25 #include <vector>
26 #include <string>
27 
32 #define META_Technique(name, description) \
33  inline virtual const char *techniqueName() { return name; } \
34  inline virtual const char *techniqueDescription() { return description; }
35 
36 
37 namespace osgFX
38 {
39 
40  class Effect;
41 
58  public:
59  Technique();
60 
62  virtual const char *techniqueName() { return "Default"; }
63 
65  virtual const char *techniqueDescription() { return "This is the default technique"; }
66 
72  virtual void getRequiredExtensions(std::vector<std::string>& /*extensions*/) const {};
73 
79  virtual bool validate(osg::State& ) const;
80 
82  inline int getNumPasses() const;
83 
85  inline osg::StateSet* getPassStateSet(int i);
86 
88  inline const osg::StateSet* getPassStateSet(int i) const;
89 
96  inline virtual void traverse(osg::NodeVisitor& nv, Effect* fx);
97 
98  protected:
99  Technique(const Technique &): osg::Referenced() {} // copying is nonsense ;)
100  virtual ~Technique() {}
101  Technique &operator=(const Technique &) { return *this; }
102 
104  inline void dirtyPasses();
105 
107  void addPass(osg::StateSet* ss = 0);
108 
110  inline virtual osg::Node* getOverrideChild(int) { return 0; }
111 
116  virtual void define_passes() = 0;
117 
122  void traverse_implementation(osg::NodeVisitor& nv, Effect* fx);
123 
124  private:
125  typedef std::vector<osg::ref_ptr<osg::StateSet> > Pass_list;
126  Pass_list _passes;
127  };
128 
129  // INLINE METHODS
130 
131  inline int Technique::getNumPasses() const
132  {
133  return static_cast<int>(_passes.size());
134  }
135 
137  {
138  return _passes[i].get();
139  }
140 
141  inline const osg::StateSet* Technique::getPassStateSet(int i) const
142  {
143  return _passes[i].get();
144  }
145 
147  {
148  _passes.clear();
149  }
150 
152  {
153  traverse_implementation(nv, fx);
154  }
155 
156 }
157 
158 #endif
virtual osg::Node * getOverrideChild(int)
Definition: Technique.h:110
virtual void getRequiredExtensions(std::vector< std::string > &) const
Definition: Technique.h:72
virtual const char * techniqueName()
Definition: Technique.h:62
osg::StateSet * getPassStateSet(int i)
Definition: Technique.h:136
virtual const char * techniqueDescription()
Definition: Technique.h:65
Technique(const Technique &)
Definition: Technique.h:99
virtual ~Technique()
Definition: Technique.h:100
virtual void traverse(osg::NodeVisitor &nv, Effect *fx)
Definition: Technique.h:151
int getNumPasses() const
Definition: Technique.h:131
void traverse_implementation(osg::NodeVisitor &nv, Effect *fx)
void dirtyPasses()
Definition: Technique.h:146
#define OSGFX_EXPORT
Definition: Export.h:27
Definition: Node.h:71
Definition: AlphaFunc.h:19
Technique & operator=(const Technique &)
Definition: Technique.h:101