2003-08-27 06:09:15 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
//osgFX - Copyright (C) 2003 Marco Jez
|
|
|
|
|
|
|
|
#ifndef OSGFX_TECHNIQUE_
|
|
|
|
#define OSGFX_TECHNIQUE_
|
|
|
|
|
|
|
|
#include <osgFX/Export>
|
|
|
|
|
|
|
|
#include <osg/Referenced>
|
|
|
|
#include <osg/State>
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
/**
|
|
|
|
An helper macro that defines the methods techniqueName() and
|
|
|
|
techniqueDescription() making them return the strings passed as parameters.
|
|
|
|
*/
|
|
|
|
#define META_Technique(name, description) \
|
|
|
|
inline virtual const char *techniqueName() { return name; } \
|
|
|
|
inline virtual const char *techniqueDescription() { return description; }
|
|
|
|
|
|
|
|
|
|
|
|
namespace osgFX
|
|
|
|
{
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
class Effect;
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/**
|
|
|
|
This is the base class for effect techniques. A technique represents one
|
|
|
|
of the possible ways to implement a special effect. This base class is
|
|
|
|
abstract, you will have to subclass your own techniques for your custom
|
|
|
|
effects.
|
|
|
|
Derived classes will have to implement the define_passes() method to
|
|
|
|
configure the rendering pass(es) that make up the technique. Usually
|
|
|
|
you will create one StateSet object for each rendering pass and then
|
|
|
|
you'll call addPass(stateset).
|
|
|
|
The validate() method should return true if the technique is valid within
|
|
|
|
the current rendering context, false otherwise. The default implementation
|
|
|
|
of validate() calls getRequiredExtensions() and tests whether all required
|
|
|
|
extensions are supported or not, returning false if at least one extension
|
|
|
|
is not supported.
|
|
|
|
*/
|
|
|
|
class OSGFX_EXPORT Technique: public osg::Referenced {
|
|
|
|
public:
|
|
|
|
Technique();
|
|
|
|
|
|
|
|
/** get the name of this technique */
|
|
|
|
virtual const char *techniqueName() { return "Default"; }
|
|
|
|
|
|
|
|
/** get a brief description of this technique */
|
|
|
|
virtual const char *techniqueDescription() { return "This is the default technique"; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
collect the GL extension strings which are required for this technique
|
|
|
|
to work properly. This method is called from the default implementation
|
|
|
|
of validate().
|
|
|
|
*/
|
|
|
|
virtual void getRequiredExtensions(std::vector<std::string> & /*extensions*/) const {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
tests whether this technique is valid for the current rendering context.
|
|
|
|
The default behavior is to call getRequiredExtensions() and check for
|
|
|
|
extension availability.
|
|
|
|
*/
|
|
|
|
virtual bool validate(osg::State &) const;
|
|
|
|
|
|
|
|
/** get the number of rendering passes defined in this technique */
|
|
|
|
inline int getNumPasses() const;
|
|
|
|
|
|
|
|
/** get the StateSet object associated to the i-th pass */
|
|
|
|
inline osg::StateSet *getPassStateSet(int i);
|
|
|
|
|
|
|
|
/** get the const StateSet object associated to the i-th pass */
|
|
|
|
inline const osg::StateSet *getPassStateSet(int i) const;
|
|
|
|
|
|
|
|
/**
|
2003-09-09 19:54:05 +08:00
|
|
|
traverse children with multipass if necessary. By default this method
|
|
|
|
simply calls the protected method traverse_implementation(); you can
|
|
|
|
override it to change the default behavior.
|
2003-08-27 06:09:15 +08:00
|
|
|
Don't call this method directly as it is called by osgFX::Effect
|
|
|
|
*/
|
2003-09-09 19:54:05 +08:00
|
|
|
inline virtual void traverse(osg::NodeVisitor &nv, Effect *fx);
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
protected:
|
|
|
|
Technique(const Technique &): osg::Referenced() {} // copying is nonsense ;)
|
|
|
|
virtual ~Technique() {}
|
|
|
|
Technique &operator=(const Technique &) { return *this; }
|
|
|
|
|
|
|
|
/** force rebuilding of pass nodes on next traversal */
|
|
|
|
inline void dirtyPasses();
|
|
|
|
|
|
|
|
/** create a new pass node, add it to the technique and associate a StateSet */
|
|
|
|
void addPass(osg::StateSet *ss = 0);
|
2003-09-09 19:54:05 +08:00
|
|
|
|
|
|
|
/** optional: return a node that overrides the child node on a specified pass */
|
|
|
|
inline virtual osg::Node *getOverrideChild(int) { return 0; }
|
2003-08-27 06:09:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
define the rendering passes that make up this technique. You must
|
|
|
|
implement this method in derived classes to add the required passes.
|
|
|
|
*/
|
|
|
|
virtual void define_passes() = 0;
|
2003-09-09 19:54:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
traverse children with multipass if necessary. Don't call this method
|
|
|
|
directly unless you are in a customized version of traverse().
|
|
|
|
*/
|
|
|
|
void traverse_implementation(osg::NodeVisitor &nv, Effect *fx);
|
2003-08-27 06:09:15 +08:00
|
|
|
|
|
|
|
private:
|
2003-09-09 19:54:05 +08:00
|
|
|
typedef std::vector<osg::ref_ptr<osg::StateSet> > Pass_list;
|
|
|
|
Pass_list passes_;
|
2003-08-27 06:09:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
|
|
|
inline int Technique::getNumPasses() const
|
|
|
|
{
|
2003-09-09 19:54:05 +08:00
|
|
|
return static_cast<int>(passes_.size());
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::StateSet *Technique::getPassStateSet(int i)
|
|
|
|
{
|
2003-09-09 19:54:05 +08:00
|
|
|
return passes_[i].get();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const osg::StateSet *Technique::getPassStateSet(int i) const
|
|
|
|
{
|
2003-09-09 19:54:05 +08:00
|
|
|
return passes_[i].get();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2003-09-09 19:54:05 +08:00
|
|
|
|
|
|
|
inline void Technique::dirtyPasses()
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2003-09-09 19:54:05 +08:00
|
|
|
passes_.clear();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
inline void Technique::traverse(osg::NodeVisitor &nv, Effect *fx)
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2003-09-09 19:54:05 +08:00
|
|
|
traverse_implementation(nv, fx);
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|