1 // Copyright (C) 2008 Timothy Moore timoore@redhat.com
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.
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.
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.
17 #ifndef SIMGEAR_TECHNIQUE_HXX
18 #define SIMGEAR_TECHNIQUE_HXX 1
20 #include "EffectGeode.hxx"
22 #include <simgear/structure/SGAtomic.hxx>
23 #include <simgear/structure/SGExpression.hxx>
29 #include <OpenThreads/Mutex>
30 #include <osg/buffered_value>
33 #include <osg/GraphicsThread>
52 class Technique : public osg::Object
55 META_Object(simgear,Technique);
56 Technique(bool alwaysValid = false);
57 Technique(const Technique& rhs,
58 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
67 /** Returns the validity of a technique in a state. If we don't
68 * know, a query will be launched.
70 virtual Status valid(osg::RenderInfo* renderInfo);
71 /** Returns the validity of the technique without launching a
74 Status getValidStatus(const osg::RenderInfo* renderInfo) const;
75 /** Tests and sets the validity of the Technique. Must be run in a
78 virtual void validateInContext(osg::GraphicsContext* gc);
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
89 return _shadowingStateSet.get();
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();
102 // Validity of technique in a graphics context.
103 struct ContextInfo : public osg::Referenced
105 ContextInfo() : valid(UNKNOWN) {}
106 ContextInfo(const ContextInfo& rhs) : valid(rhs.valid()) {}
107 ContextInfo& operator=(const ContextInfo& rhs)
112 Swappable<Status> valid;
114 typedef osg::buffered_object<ContextInfo> ContextMap;
115 mutable ContextMap _contextMap;
117 osg::ref_ptr<osg::StateSet> _shadowingStateSet;
118 SGSharedPtr<SGExpressionb> _validExpression;
119 int _contextIdLocation;
122 class TechniquePredParser : public expression::ExpressionParser
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(); }
130 osg::ref_ptr<Technique> _tniq;
131 // osg::ref_ptr<Effect> _effect;