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>
28 #include <OpenThreads/Mutex>
29 #include <osg/buffered_value>
32 #include <osg/GraphicsThread>
51 class Technique : public osg::Object
54 META_Object(simgear,Technique);
55 Technique(bool alwaysValid = false);
56 Technique(const Technique& rhs,
57 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
66 /** Returns the validity of a technique in a state. If we don't
67 * know, a query will be launched.
69 virtual Status valid(osg::RenderInfo* renderInfo);
70 /** Returns the validity of the technique without launching a
73 Status getValidStatus(const osg::RenderInfo* renderInfo) const;
74 /** Tests and sets the validity of the Technique. Must be run in a
77 virtual void validateInContext(osg::GraphicsContext* gc);
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 const osg::StateSet* getShadowingStateSet() const
88 return _shadowingStateSet.get();
90 void setShadowingStateSet(osg::StateSet* ss) { _shadowingStateSet = ss; }
91 virtual void resizeGLObjectBuffers(unsigned int maxSize);
92 virtual void releaseGLObjects(osg::State* state = 0) const;
93 // Initial validity testing. Either the minimum OpenGL version
94 // must be supported, or the list of extensions must be supported.
95 float getGLVersion() const { return _glVersion; }
96 void setGLVersion(float glVersion) { _glVersion = glVersion; }
97 std::vector<std::string> glExtensions;
98 bool getAlwaysValid() const { return _alwaysValid; }
99 void setAlwaysValid(bool val) { _alwaysValid = val; }
101 // Validity of technique in a graphics context.
102 struct ContextInfo : public osg::Referenced
104 ContextInfo() : valid(UNKNOWN) {}
105 ContextInfo(const ContextInfo& rhs) : valid(rhs.valid()) {}
106 ContextInfo& operator=(const ContextInfo& rhs)
110 Swappable<Status> valid;
112 typedef osg::buffered_object<ContextInfo> ContextMap;
113 mutable ContextMap _contextMap;
115 osg::ref_ptr<osg::StateSet> _shadowingStateSet;