2 #include "Technique.hxx"
9 #include <boost/bind.hpp>
10 #include <boost/foreach.hpp>
12 #include <osg/Drawable>
13 #include <osg/RenderInfo>
14 #include <osg/StateSet>
15 #include <osgUtil/CullVisitor>
16 #include <osgDB/Registry>
17 #include <osgDB/Input>
18 #include <osgDB/ParameterOutput>
20 #include <simgear/structure/OSGUtils.hxx>
27 using namespace osgUtil;
33 Effect::Effect(const Effect& rhs, const CopyOp& copyop)
36 using namespace boost;
37 transform(rhs.techniques.begin(), rhs.techniques.end(),
38 backRefInsertIterator(techniques),
39 bind(simgear::clone_ref<Technique>, _1, copyop));
42 // Assume that the last technique is always valid.
43 StateSet* Effect::getDefaultStateSet()
45 Technique* tniq = techniques.back().get();
48 Pass* pass = tniq->passes.front().get();
51 return pass->getStateSet();
54 // There should always be a valid technique in an effect.
56 Technique* Effect::chooseTechnique(RenderInfo* info)
58 BOOST_FOREACH(ref_ptr<Technique>& technique, techniques)
60 if (technique->valid(info) == Technique::VALID)
61 return technique.get();
66 void Effect::resizeGLObjectBuffers(unsigned int maxSize)
68 BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
70 technique->resizeGLObjectBuffers(maxSize);
74 void Effect::releaseGLObjects(osg::State* state) const
76 BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
78 technique->releaseGLObjects(state);
86 bool Effect_writeLocalData(const Object& obj, osgDB::Output& fw)
88 const Effect& effect = static_cast<const Effect&>(obj);
90 fw.indent() << "techniques " << effect.techniques.size() << "\n";
91 BOOST_FOREACH(const ref_ptr<Technique>& technique, effect.techniques) {
92 fw.writeObject(*technique);
99 osgDB::RegisterDotOsgWrapperProxy effectProxy
103 "Object simgear::Effect",
105 &Effect_writeLocalData