1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
13//osgFX - Copyright (C) 2003 Marco Jez
15#ifndef OSGFX_TECHNIQUE_
16#define OSGFX_TECHNIQUE_
18#include <osgFX/Export>
20#include <osg/Referenced>
23#include <osg/NodeVisitor>
29 An helper macro that defines the methods techniqueName() and
30 techniqueDescription() making them return the strings passed as parameters.
32#define META_Technique(name, description) \
33 inline virtual const char *techniqueName() { return name; } \
34 inline virtual const char *techniqueDescription() { return description; }
43 This is the base class for effect techniques. A technique represents one
44 of the possible ways to implement a special effect. This base class is
45 abstract, you will have to subclass your own techniques for your custom
47 Derived classes will have to implement the define_passes() method to
48 configure the rendering pass(es) that make up the technique. Usually
49 you will create one StateSet object for each rendering pass and then
50 you'll call addPass(stateset).
51 The validate() method should return true if the technique is valid within
52 the current rendering context, false otherwise. The default implementation
53 of validate() calls getRequiredExtensions() and tests whether all required
54 extensions are supported or not, returning false if at least one extension
57 class OSGFX_EXPORT Technique: public osg::Referenced {
61 /** get the name of this Technique */
62 virtual const char *techniqueName() { return "Default"; }
64 /** get a brief description of this Technique */
65 virtual const char *techniqueDescription() { return "This is the default technique"; }
68 collect the GL extension strings which are required for this technique
69 to work properly. This method is called from the default implementation
72 virtual void getRequiredExtensions(std::vector<std::string>& /*extensions*/) const {};
75 tests whether this technique is valid for the current rendering context.
76 The default behavior is to call getRequiredExtensions() and check for
77 extension availability.
79 virtual bool validate(osg::State& ) const;
81 /** get the number of rendering passes defined in this Technique */
82 inline int getNumPasses() const;
84 /** get the StateSet object associated to the i-th pass */
85 inline osg::StateSet* getPassStateSet(int i);
87 /** get the const StateSet object associated to the i-th pass */
88 inline const osg::StateSet* getPassStateSet(int i) const;
91 traverse children with multipass if necessary. By default this method
92 simply calls the protected method traverse_implementation(); you can
93 override it to change the default behavior.
94 Don't call this method directly as it is called by osgFX::Effect
96 inline virtual void traverse(osg::NodeVisitor& nv, Effect* fx);
99 Technique(const Technique &): osg::Referenced() {} // copying is nonsense ;)
100 virtual ~Technique() {}
101 Technique &operator=(const Technique &) { return *this; }
103 /** force rebuilding of pass nodes on next traversal */
104 inline void dirtyPasses();
106 /** create a new pass node, add it to the technique and associate a StateSet */
107 void addPass(osg::StateSet* ss = 0);
109 /** optional: return a node that overrides the child node on a specified pass */
110 inline virtual osg::Node* getOverrideChild(int) { return 0; }
113 define the rendering passes that make up this technique. You must
114 implement this method in derived classes to add the required passes.
116 virtual void define_passes() = 0;
119 traverse children with multipass if necessary. Don't call this method
120 directly unless you are in a customized version of traverse().
122 void traverse_implementation(osg::NodeVisitor& nv, Effect* fx);
125 typedef std::vector<osg::ref_ptr<osg::StateSet> > Pass_list;
126 OpenThreads::Mutex _mutex;
127 OpenThreads::Atomic _passesDefined;
133 inline int Technique::getNumPasses() const
135 return _passesDefined!=0 ? static_cast<int>(_passes.size()) : 0;
138 inline osg::StateSet* Technique::getPassStateSet(int i)
140 return _passesDefined!=0 ? _passes[i].get() : 0;
143 inline const osg::StateSet* Technique::getPassStateSet(int i) const
145 return _passesDefined!=0 ? _passes[i].get() : 0;
148 inline void Technique::dirtyPasses()
150 OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _mutex);
151 _passesDefined.exchange(0);
155 inline void Technique::traverse(osg::NodeVisitor& nv, Effect* fx)
157 traverse_implementation(nv, fx);