]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/Technique.hxx
Effects framework
[simgear.git] / simgear / scene / material / Technique.hxx
1 // Copyright (C) 2008  Timothy Moore timoore@redhat.com
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #ifndef SIMGEAR_TECHNIQUE_HXX
18 #define SIMGEAR_TECHNIQUE_HXX 1
19
20 #include "EffectGeode.hxx"
21
22 #include <simgear/structure/SGAtomic.hxx>
23
24 #include <map>
25 #include <vector>
26 #include <string>
27
28 #include <OpenThreads/Mutex>
29 #include <osg/buffered_value>
30 #include <osg/Geode>
31 #include <osg/Object>
32 #include <osg/GraphicsThread>
33
34 namespace osg
35 {
36 class CopyOp;
37 class Drawable;
38 class RenderInfo;
39 class StateSet;
40 }
41
42 namespace osgUtil
43 {
44 class CullVisitor;
45 }
46
47 namespace simgear
48 {
49 class Pass;
50
51 class Technique : public osg::Object
52 {
53 public:
54     META_Object(simgear,Technique);
55     Technique();
56     Technique(const Technique& rhs,
57               const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
58     virtual ~Technique();
59     enum Status
60     {
61         UNKNOWN,
62         QUERY_IN_PROGRESS,
63         INVALID,
64         VALID
65     };
66     /** Returns the validity of a technique in a state. If we don't
67      * know, a query will be launched.
68      */
69     virtual Status valid(osg::RenderInfo* renderInfo);
70     /** Returns the validity of the technique without launching a
71      * query.
72      */
73     Status getValidStatus(const osg::RenderInfo* renderInfo) const;
74     /** Tests and sets the validity of the Technique. Must be run in a
75      *graphics context.
76      */
77     virtual void validateInContext(osg::GraphicsContext* gc);
78
79     virtual EffectGeode::DrawablesIterator
80     processDrawables(const EffectGeode::DrawablesIterator& begin,
81                      const EffectGeode::DrawablesIterator& end,
82                      osgUtil::CullVisitor* cv,
83                      bool isCullingActive);
84     std::vector<osg::ref_ptr<Pass> > passes;
85     osg::StateSet* getShadowingStateSet() { return _shadowingStateSet.get(); }
86     void setShadowingStateSet(osg::StateSet* ss) { _shadowingStateSet = ss; }
87     virtual void resizeGLObjectBuffers(unsigned int maxSize);
88     virtual void releaseGLObjects(osg::State* state = 0) const;
89     // Initial validity testing. Either the minimum OpenGL version
90     // must be supported, or the list of extensions must be supported.
91     float getGLVersion() { return _glVersion; }
92     void setGLVersion(float glVersion) { _glVersion = glVersion; }
93     std::vector<std::string> glExtensions;
94 protected:
95     // Validity of technique in a graphics context.
96     struct ContextInfo : public osg::Referenced
97     {
98         ContextInfo() : valid(UNKNOWN) {}
99         ContextInfo(const ContextInfo& rhs) : valid(rhs.valid()) {}
100         ContextInfo& operator=(const ContextInfo& rhs)
101         {
102             valid = rhs.valid();
103         }
104         Swappable<Status> valid;
105     };
106     typedef osg::buffered_object<ContextInfo> ContextMap;
107     mutable ContextMap _contextMap;
108     osg::ref_ptr<osg::StateSet> _shadowingStateSet;
109     float _glVersion;
110 };
111 }
112 #endif