]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/Technique.hxx
Random buildings - initial commit.
[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 #include <simgear/structure/SGExpression.hxx>
24
25 #include <map>
26 #include <vector>
27 #include <string>
28
29 #include <OpenThreads/Mutex>
30 #include <osg/buffered_value>
31 #include <osg/Geode>
32 #include <osg/Object>
33 #include <osg/GraphicsThread>
34
35 namespace osg
36 {
37 class CopyOp;
38 class Drawable;
39 class RenderInfo;
40 class StateSet;
41 }
42
43 namespace osgUtil
44 {
45 class CullVisitor;
46 }
47
48 namespace simgear
49 {
50 class Pass;
51
52 class Technique : public osg::Object
53 {
54 public:
55     META_Object(simgear,Technique);
56     Technique(bool alwaysValid = false);
57     Technique(const Technique& rhs,
58               const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
59     virtual ~Technique();
60     enum Status
61     {
62         UNKNOWN,
63         QUERY_IN_PROGRESS,
64         INVALID,
65         VALID
66     };
67     /** Returns the validity of a technique in a state. If we don't
68      * know, a query will be launched.
69      */
70     virtual Status valid(osg::RenderInfo* renderInfo);
71     /** Returns the validity of the technique without launching a
72      * query.
73      */
74     Status getValidStatus(const osg::RenderInfo* renderInfo) const;
75     /** Tests and sets the validity of the Technique. Must be run in a
76      *graphics context.
77      */
78     virtual void validateInContext(osg::GraphicsContext* gc);
79
80     virtual EffectGeode::DrawablesIterator
81     processDrawables(const EffectGeode::DrawablesIterator& begin,
82                      const EffectGeode::DrawablesIterator& end,
83                      osgUtil::CullVisitor* cv,
84                      bool isCullingActive);
85     std::vector<osg::ref_ptr<Pass> > passes;
86     osg::StateSet* getShadowingStateSet() { return _shadowingStateSet.get(); }
87     const osg::StateSet* getShadowingStateSet() const
88     {
89         return _shadowingStateSet.get();
90     }
91     void setShadowingStateSet(osg::StateSet* ss) { _shadowingStateSet = ss; }
92     virtual void resizeGLObjectBuffers(unsigned int maxSize);
93     virtual void releaseGLObjects(osg::State* state = 0) const;
94     bool getAlwaysValid() const { return _alwaysValid; }
95     void setAlwaysValid(bool val) { _alwaysValid = val; }
96     void setValidExpression(SGExpressionb* exp,
97                             const simgear::expression::BindingLayout&);
98     void setGLExtensionsPred(float glVersion,
99                              const std::vector<std::string>& extensions);
100     void refreshValidity();
101 protected:
102     // Validity of technique in a graphics context.
103     struct ContextInfo : public osg::Referenced
104     {
105         ContextInfo() : valid(UNKNOWN) {}
106         ContextInfo(const ContextInfo& rhs) : osg::Referenced(rhs), valid(rhs.valid()) {}
107         ContextInfo& operator=(const ContextInfo& rhs)
108         {
109             valid = rhs.valid;
110             return *this;
111         }
112         Swappable<Status> valid;
113     };
114     typedef osg::buffered_object<ContextInfo> ContextMap;
115     mutable ContextMap _contextMap;
116     bool _alwaysValid;
117     osg::ref_ptr<osg::StateSet> _shadowingStateSet;
118     SGSharedPtr<SGExpressionb> _validExpression;
119     int _contextIdLocation;
120 };
121
122 class TechniquePredParser : public expression::ExpressionParser
123 {
124 public:
125     void setTechnique(Technique* tniq) { _tniq = tniq; }
126     Technique* getTechnique() { return _tniq.get(); }
127 //    void setEffect(Effect* effect) { _effect = effect; }
128 //    Effect* getEffect() { return _effect.get(); }
129 protected:
130     osg::ref_ptr<Technique> _tniq;
131     // osg::ref_ptr<Effect> _effect;
132 };
133 }
134 #endif