root/OpenSceneGraph/trunk/include/osgFX/Technique @ 13041

Revision 13041, 5.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
28/**
29 An helper macro that defines the methods techniqueName() and
30 techniqueDescription() making them return the strings passed as parameters.
31 */
32#define META_Technique(name, description) \
33    inline virtual const char *techniqueName() { return name; } \
34    inline virtual const char *techniqueDescription() { return description; }
35
36
37namespace osgFX
38{
39
40    class Effect;
41
42    /**
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
46     effects.
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
55     is not supported.
56     */
57    class OSGFX_EXPORT Technique: public osg::Referenced {
58    public:
59        Technique();
60
61        /** get the name of this Technique */
62        virtual const char *techniqueName()        { return "Default"; }
63
64        /** get a brief description of this Technique */
65        virtual const char *techniqueDescription() { return "This is the default technique"; }
66
67        /**
68         collect the GL extension strings which are required for this technique
69         to work properly. This method is called from the default implementation
70         of validate().
71         */
72        virtual void getRequiredExtensions(std::vector<std::string>&  /*extensions*/) const {};
73
74        /**
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.
78         */
79        virtual bool validate(osg::State& ) const;
80
81        /** get the number of rendering passes defined in this Technique */
82        inline int getNumPasses() const;
83
84        /** get the StateSet object associated to the i-th pass */
85        inline osg::StateSet* getPassStateSet(int i);
86
87        /** get the const StateSet object associated to the i-th pass */
88        inline const osg::StateSet* getPassStateSet(int i) const;
89
90        /**
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
95         */
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
103        /** force rebuilding of pass nodes on next traversal */
104        inline void dirtyPasses();
105
106        /** create a new pass node, add it to the technique and associate a StateSet */
107        void addPass(osg::StateSet* ss = 0);
108
109        /** optional: return a node that overrides the child node on a specified pass */
110        inline virtual osg::Node* getOverrideChild(int)  { return 0; }
111
112        /**
113         define the rendering passes that make up this technique. You must
114         implement this method in derived classes to add the required passes.
115         */
116        virtual void define_passes() = 0;
117
118        /**
119         traverse children with multipass if necessary. Don't call this method
120         directly unless you are in a customized version of traverse().
121         */
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
136    inline osg::StateSet* Technique::getPassStateSet(int i)
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
146    inline void Technique::dirtyPasses()
147    {
148        _passes.clear();
149    }
150
151    inline void Technique::traverse(osg::NodeVisitor& nv, Effect* fx)
152    {
153        traverse_implementation(nv, fx);
154    }
155
156}
157
158#endif
Note: See TracBrowser for help on using the browser.