00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SIMGEAR_TECHNIQUE_HXX
00018 #define SIMGEAR_TECHNIQUE_HXX 1
00019
00020 #include "EffectGeode.hxx"
00021
00022 #include <simgear/structure/SGAtomic.hxx>
00023 #include <simgear/structure/SGExpression.hxx>
00024
00025 #include <map>
00026 #include <vector>
00027 #include <string>
00028
00029 #include <OpenThreads/Mutex>
00030 #include <osg/buffered_value>
00031 #include <osg/Geode>
00032 #include <osg/Object>
00033 #include <osg/GraphicsThread>
00034
00035 namespace osg
00036 {
00037 class CopyOp;
00038 class Drawable;
00039 class RenderInfo;
00040 class StateSet;
00041 }
00042
00043 namespace osgUtil
00044 {
00045 class CullVisitor;
00046 }
00047
00048 namespace simgear
00049 {
00050 class Pass;
00051
00052 class Technique : public osg::Object
00053 {
00054 public:
00055 META_Object(simgear,Technique);
00056 Technique(bool alwaysValid = false);
00057 Technique(const Technique& rhs,
00058 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
00059 virtual ~Technique();
00060 enum Status
00061 {
00062 UNKNOWN,
00063 QUERY_IN_PROGRESS,
00064 INVALID,
00065 VALID
00066 };
00070 virtual Status valid(osg::RenderInfo* renderInfo);
00074 Status getValidStatus(const osg::RenderInfo* renderInfo) const;
00078 virtual void validateInContext(osg::GraphicsContext* gc);
00079
00080 virtual EffectGeode::DrawablesIterator
00081 processDrawables(const EffectGeode::DrawablesIterator& begin,
00082 const EffectGeode::DrawablesIterator& end,
00083 osgUtil::CullVisitor* cv,
00084 bool isCullingActive);
00085 std::vector<osg::ref_ptr<Pass> > passes;
00086 osg::StateSet* getShadowingStateSet() { return _shadowingStateSet.get(); }
00087 const osg::StateSet* getShadowingStateSet() const
00088 {
00089 return _shadowingStateSet.get();
00090 }
00091 void setShadowingStateSet(osg::StateSet* ss) { _shadowingStateSet = ss; }
00092 virtual void resizeGLObjectBuffers(unsigned int maxSize);
00093 virtual void releaseGLObjects(osg::State* state = 0) const;
00094 bool getAlwaysValid() const { return _alwaysValid; }
00095 void setAlwaysValid(bool val) { _alwaysValid = val; }
00096 void setValidExpression(SGExpressionb* exp,
00097 const simgear::expression::BindingLayout&);
00098 void setGLExtensionsPred(float glVersion,
00099 const std::vector<std::string>& extensions);
00100 void refreshValidity();
00101 protected:
00102
00103 struct ContextInfo : public osg::Referenced
00104 {
00105 ContextInfo() : valid(UNKNOWN) {}
00106 ContextInfo(const ContextInfo& rhs) : valid(rhs.valid()) {}
00107 ContextInfo& operator=(const ContextInfo& rhs)
00108 {
00109 valid = rhs.valid;
00110 return *this;
00111 }
00112 Swappable<Status> valid;
00113 };
00114 typedef osg::buffered_object<ContextInfo> ContextMap;
00115 mutable ContextMap _contextMap;
00116 bool _alwaysValid;
00117 osg::ref_ptr<osg::StateSet> _shadowingStateSet;
00118 SGSharedPtr<SGExpressionb> _validExpression;
00119 int _contextIdLocation;
00120 };
00121
00122 class TechniquePredParser : public expression::ExpressionParser
00123 {
00124 public:
00125 void setTechnique(Technique* tniq) { _tniq = tniq; }
00126 Technique* getTechnique() { return _tniq.get(); }
00127
00128
00129 protected:
00130 osg::ref_ptr<Technique> _tniq;
00131
00132 };
00133 }
00134 #endif