1 // Copyright (C) 2008 - 2010 Tim Moore timoore33@gmail.com
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library 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.
18 # include <simgear_config.h>
22 #include "EffectBuilder.hxx"
23 #include "EffectGeode.hxx"
24 #include "Technique.hxx"
26 #include "TextureBuilder.hxx"
33 #include <boost/tr1/unordered_map.hpp>
35 #include <boost/bind.hpp>
36 #include <boost/foreach.hpp>
37 #include <boost/functional/hash.hpp>
38 #include <boost/tuple/tuple.hpp>
39 #include <boost/tuple/tuple_comparison.hpp>
41 #include <osg/AlphaFunc>
42 #include <osg/BlendFunc>
43 #include <osg/CullFace>
45 #include <osg/Drawable>
46 #include <osg/Material>
48 #include <osg/PolygonMode>
49 #include <osg/Program>
50 #include <osg/Referenced>
51 #include <osg/RenderInfo>
52 #include <osg/ShadeModel>
53 #include <osg/StateSet>
54 #include <osg/Stencil>
56 #include <osg/Texture1D>
57 #include <osg/Texture2D>
58 #include <osg/Texture3D>
59 #include <osg/TextureRectangle>
60 #include <osg/Uniform>
62 #include <osgUtil/CullVisitor>
63 #include <osgDB/FileUtils>
64 #include <osgDB/Input>
65 #include <osgDB/ParameterOutput>
66 #include <osgDB/ReadFile>
67 #include <osgDB/Registry>
69 #include <simgear/scene/model/SGReaderWriterXMLOptions.hxx>
70 #include <simgear/scene/tgdb/userdata.hxx>
71 #include <simgear/scene/util/SGSceneFeatures.hxx>
72 #include <simgear/scene/util/StateAttributeFactory.hxx>
73 #include <simgear/structure/OSGUtils.hxx>
74 #include <simgear/structure/SGExpression.hxx>
82 using namespace osgUtil;
84 using namespace effect;
87 : _cache(0), _isRealized(false)
91 Effect::Effect(const Effect& rhs, const CopyOp& copyop)
92 : root(rhs.root), parametersProp(rhs.parametersProp), _cache(0),
93 _isRealized(rhs._isRealized)
95 typedef vector<ref_ptr<Technique> > TechniqueList;
96 for (TechniqueList::const_iterator itr = rhs.techniques.begin(),
97 end = rhs.techniques.end();
100 techniques.push_back(static_cast<Technique*>(copyop(itr->get())));
102 generator = rhs.generator;
105 // Assume that the last technique is always valid.
106 StateSet* Effect::getDefaultStateSet()
108 Technique* tniq = techniques.back().get();
111 Pass* pass = tniq->passes.front().get();
115 int Effect::getGenerator(Effect::Generator what) const
117 std::map<Generator,int>::const_iterator it = generator.find(what);
118 if(it == generator.end()) return -1;
119 else return it->second;
122 // There should always be a valid technique in an effect.
124 Technique* Effect::chooseTechnique(RenderInfo* info)
126 BOOST_FOREACH(ref_ptr<Technique>& technique, techniques)
128 if (technique->valid(info) == Technique::VALID)
129 return technique.get();
134 void Effect::resizeGLObjectBuffers(unsigned int maxSize)
136 BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
138 technique->resizeGLObjectBuffers(maxSize);
142 void Effect::releaseGLObjects(osg::State* state) const
144 BOOST_FOREACH(const ref_ptr<Technique>& technique, techniques)
146 technique->releaseGLObjects(state);
155 void buildPass(Effect* effect, Technique* tniq, const SGPropertyNode* prop,
156 const SGReaderWriterXMLOptions* options)
158 Pass* pass = new Pass;
159 tniq->passes.push_back(pass);
160 for (int i = 0; i < prop->nChildren(); ++i) {
161 const SGPropertyNode* attrProp = prop->getChild(i);
162 PassAttributeBuilder* builder
163 = PassAttributeBuilder::find(attrProp->getNameString());
165 builder->buildAttribute(effect, pass, attrProp, options);
167 SG_LOG(SG_INPUT, SG_ALERT,
168 "skipping unknown pass attribute " << attrProp->getName());
172 // Default names for vector property components
173 const char* vec3Names[] = {"x", "y", "z"};
174 const char* vec4Names[] = {"x", "y", "z", "w"};
176 osg::Vec4f getColor(const SGPropertyNode* prop)
178 if (prop->nChildren() == 0) {
179 if (prop->getType() == props::VEC4D) {
180 return osg::Vec4f(toOsg(prop->getValue<SGVec4d>()));
181 } else if (prop->getType() == props::VEC3D) {
182 return osg::Vec4f(toOsg(prop->getValue<SGVec3d>()), 1.0f);
184 SG_LOG(SG_INPUT, SG_ALERT,
185 "invalid color property " << prop->getName() << " "
186 << prop->getStringValue());
187 return osg::Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
191 static const char* colors[] = {"r", "g", "b"};
192 for (int i = 0; i < 3; ++i) {
193 const SGPropertyNode* componentProp = prop->getChild(colors[i]);
194 result[i] = componentProp ? componentProp->getValue<float>() : 0.0f;
196 const SGPropertyNode* alphaProp = prop->getChild("a");
197 result[3] = alphaProp ? alphaProp->getValue<float>() : 1.0f;
202 struct LightingBuilder : public PassAttributeBuilder
204 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
205 const SGReaderWriterXMLOptions* options);
208 void LightingBuilder::buildAttribute(Effect* effect, Pass* pass,
209 const SGPropertyNode* prop,
210 const SGReaderWriterXMLOptions* options)
212 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
215 pass->setMode(GL_LIGHTING, (realProp->getValue<bool>() ? StateAttribute::ON
216 : StateAttribute::OFF));
219 InstallAttributeBuilder<LightingBuilder> installLighting("lighting");
221 struct ShadeModelBuilder : public PassAttributeBuilder
223 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
224 const SGReaderWriterXMLOptions* options)
226 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
229 StateAttributeFactory *attrFact = StateAttributeFactory::instance();
230 string propVal = realProp->getStringValue();
231 if (propVal == "flat")
232 pass->setAttribute(attrFact->getFlatShadeModel());
233 else if (propVal == "smooth")
234 pass->setAttribute(attrFact->getSmoothShadeModel());
236 SG_LOG(SG_INPUT, SG_ALERT,
237 "invalid shade model property " << propVal);
241 InstallAttributeBuilder<ShadeModelBuilder> installShadeModel("shade-model");
243 struct CullFaceBuilder : PassAttributeBuilder
245 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
246 const SGReaderWriterXMLOptions* options)
248 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
250 pass->setMode(GL_CULL_FACE, StateAttribute::OFF);
253 StateAttributeFactory *attrFact = StateAttributeFactory::instance();
254 string propVal = realProp->getStringValue();
255 if (propVal == "front")
256 pass->setAttributeAndModes(attrFact->getCullFaceFront());
257 else if (propVal == "back")
258 pass->setAttributeAndModes(attrFact->getCullFaceBack());
259 else if (propVal == "front-back")
260 pass->setAttributeAndModes(new CullFace(CullFace::FRONT_AND_BACK));
261 else if (propVal == "off")
262 pass->setMode(GL_CULL_FACE, StateAttribute::OFF);
264 SG_LOG(SG_INPUT, SG_ALERT,
265 "invalid cull face property " << propVal);
269 InstallAttributeBuilder<CullFaceBuilder> installCullFace("cull-face");
271 struct ColorMaskBuilder : PassAttributeBuilder
273 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
274 const SGReaderWriterXMLOptions* options)
276 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
280 ColorMask *mask = new ColorMask;
281 Vec4 m = getColor(realProp);
282 mask->setMask(m.r() > 0.0, m.g() > 0.0, m.b() > 0.0, m.a() > 0.0);
283 pass->setAttributeAndModes(mask);
287 InstallAttributeBuilder<ColorMaskBuilder> installColorMask("color-mask");
289 EffectNameValue<StateSet::RenderingHint> renderingHintInit[] =
291 { "default", StateSet::DEFAULT_BIN },
292 { "opaque", StateSet::OPAQUE_BIN },
293 { "transparent", StateSet::TRANSPARENT_BIN }
296 EffectPropertyMap<StateSet::RenderingHint> renderingHints(renderingHintInit);
298 struct HintBuilder : public PassAttributeBuilder
300 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
301 const SGReaderWriterXMLOptions* options)
303 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
306 StateSet::RenderingHint renderingHint = StateSet::DEFAULT_BIN;
307 findAttr(renderingHints, realProp, renderingHint);
308 pass->setRenderingHint(renderingHint);
312 InstallAttributeBuilder<HintBuilder> installHint("rendering-hint");
314 struct RenderBinBuilder : public PassAttributeBuilder
316 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
317 const SGReaderWriterXMLOptions* options)
319 if (!isAttributeActive(effect, prop))
321 const SGPropertyNode* binProp = prop->getChild("bin-number");
322 binProp = getEffectPropertyNode(effect, binProp);
323 const SGPropertyNode* nameProp = prop->getChild("bin-name");
324 nameProp = getEffectPropertyNode(effect, nameProp);
325 if (binProp && nameProp) {
326 pass->setRenderBinDetails(binProp->getIntValue(),
327 nameProp->getStringValue());
330 SG_LOG(SG_INPUT, SG_ALERT,
331 "No render bin number specified in render bin section");
333 SG_LOG(SG_INPUT, SG_ALERT,
334 "No render bin name specified in render bin section");
339 InstallAttributeBuilder<RenderBinBuilder> installRenderBin("render-bin");
341 struct MaterialBuilder : public PassAttributeBuilder
343 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
344 const SGReaderWriterXMLOptions* options);
347 EffectNameValue<Material::ColorMode> colorModeInit[] =
349 { "ambient", Material::AMBIENT },
350 { "ambient-and-diffuse", Material::AMBIENT_AND_DIFFUSE },
351 { "diffuse", Material::DIFFUSE },
352 { "emissive", Material::EMISSION },
353 { "specular", Material::SPECULAR },
354 { "off", Material::OFF }
356 EffectPropertyMap<Material::ColorMode> colorModes(colorModeInit);
358 void MaterialBuilder::buildAttribute(Effect* effect, Pass* pass,
359 const SGPropertyNode* prop,
360 const SGReaderWriterXMLOptions* options)
362 if (!isAttributeActive(effect, prop))
364 Material* mat = new Material;
365 const SGPropertyNode* color = 0;
366 if ((color = getEffectPropertyChild(effect, prop, "ambient")))
367 mat->setAmbient(Material::FRONT_AND_BACK, getColor(color));
368 if ((color = getEffectPropertyChild(effect, prop, "ambient-front")))
369 mat->setAmbient(Material::FRONT, getColor(color));
370 if ((color = getEffectPropertyChild(effect, prop, "ambient-back")))
371 mat->setAmbient(Material::BACK, getColor(color));
372 if ((color = getEffectPropertyChild(effect, prop, "diffuse")))
373 mat->setDiffuse(Material::FRONT_AND_BACK, getColor(color));
374 if ((color = getEffectPropertyChild(effect, prop, "diffuse-front")))
375 mat->setDiffuse(Material::FRONT, getColor(color));
376 if ((color = getEffectPropertyChild(effect, prop, "diffuse-back")))
377 mat->setDiffuse(Material::BACK, getColor(color));
378 if ((color = getEffectPropertyChild(effect, prop, "specular")))
379 mat->setSpecular(Material::FRONT_AND_BACK, getColor(color));
380 if ((color = getEffectPropertyChild(effect, prop, "specular-front")))
381 mat->setSpecular(Material::FRONT, getColor(color));
382 if ((color = getEffectPropertyChild(effect, prop, "specular-back")))
383 mat->setSpecular(Material::BACK, getColor(color));
384 if ((color = getEffectPropertyChild(effect, prop, "emissive")))
385 mat->setEmission(Material::FRONT_AND_BACK, getColor(color));
386 if ((color = getEffectPropertyChild(effect, prop, "emissive-front")))
387 mat->setEmission(Material::FRONT, getColor(color));
388 if ((color = getEffectPropertyChild(effect, prop, "emissive-back")))
389 mat->setEmission(Material::BACK, getColor(color));
390 const SGPropertyNode* shininess = 0;
391 mat->setShininess(Material::FRONT_AND_BACK, 0.0f);
392 if ((shininess = getEffectPropertyChild(effect, prop, "shininess")))
393 mat->setShininess(Material::FRONT_AND_BACK, shininess->getFloatValue());
394 if ((shininess = getEffectPropertyChild(effect, prop, "shininess-front")))
395 mat->setShininess(Material::FRONT, shininess->getFloatValue());
396 if ((shininess = getEffectPropertyChild(effect, prop, "shininess-back")))
397 mat->setShininess(Material::BACK, shininess->getFloatValue());
398 Material::ColorMode colorMode = Material::OFF;
399 findAttr(colorModes, getEffectPropertyChild(effect, prop, "color-mode"),
401 mat->setColorMode(colorMode);
402 pass->setAttribute(mat);
405 InstallAttributeBuilder<MaterialBuilder> installMaterial("material");
407 EffectNameValue<BlendFunc::BlendFuncMode> blendFuncModesInit[] =
409 {"dst-alpha", BlendFunc::DST_ALPHA},
410 {"dst-color", BlendFunc::DST_COLOR},
411 {"one", BlendFunc::ONE},
412 {"one-minus-dst-alpha", BlendFunc::ONE_MINUS_DST_ALPHA},
413 {"one-minus-dst-color", BlendFunc::ONE_MINUS_DST_COLOR},
414 {"one-minus-src-alpha", BlendFunc::ONE_MINUS_SRC_ALPHA},
415 {"one-minus-src-color", BlendFunc::ONE_MINUS_SRC_COLOR},
416 {"src-alpha", BlendFunc::SRC_ALPHA},
417 {"src-alpha-saturate", BlendFunc::SRC_ALPHA_SATURATE},
418 {"src-color", BlendFunc::SRC_COLOR},
419 {"constant-color", BlendFunc::CONSTANT_COLOR},
420 {"one-minus-constant-color", BlendFunc::ONE_MINUS_CONSTANT_COLOR},
421 {"constant-alpha", BlendFunc::CONSTANT_ALPHA},
422 {"one-minus-constant-alpha", BlendFunc::ONE_MINUS_CONSTANT_ALPHA},
423 {"zero", BlendFunc::ZERO}
425 EffectPropertyMap<BlendFunc::BlendFuncMode> blendFuncModes(blendFuncModesInit);
427 struct BlendBuilder : public PassAttributeBuilder
429 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
430 const SGReaderWriterXMLOptions* options)
432 if (!isAttributeActive(effect, prop))
434 // XXX Compatibility with early <blend> syntax; should go away
436 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
439 if (realProp->nChildren() == 0) {
440 pass->setMode(GL_BLEND, (realProp->getBoolValue()
442 : StateAttribute::OFF));
446 const SGPropertyNode* pmode = getEffectPropertyChild(effect, prop,
448 // XXX When dynamic parameters are supported, this code should
449 // create the blend function even if the mode is off.
450 if (pmode && !pmode->getValue<bool>()) {
451 pass->setMode(GL_BLEND, StateAttribute::OFF);
454 const SGPropertyNode* psource
455 = getEffectPropertyChild(effect, prop, "source");
456 const SGPropertyNode* pdestination
457 = getEffectPropertyChild(effect, prop, "destination");
458 const SGPropertyNode* psourceRGB
459 = getEffectPropertyChild(effect, prop, "source-rgb");
460 const SGPropertyNode* psourceAlpha
461 = getEffectPropertyChild(effect, prop, "source-alpha");
462 const SGPropertyNode* pdestRGB
463 = getEffectPropertyChild(effect, prop, "destination-rgb");
464 const SGPropertyNode* pdestAlpha
465 = getEffectPropertyChild(effect, prop, "destination-alpha");
466 BlendFunc::BlendFuncMode sourceMode = BlendFunc::ONE;
467 BlendFunc::BlendFuncMode destMode = BlendFunc::ZERO;
469 findAttr(blendFuncModes, psource, sourceMode);
471 findAttr(blendFuncModes, pdestination, destMode);
472 if (psource && pdestination
473 && !(psourceRGB || psourceAlpha || pdestRGB || pdestAlpha)
474 && sourceMode == BlendFunc::SRC_ALPHA
475 && destMode == BlendFunc::ONE_MINUS_SRC_ALPHA) {
476 pass->setAttributeAndModes(StateAttributeFactory::instance()
477 ->getStandardBlendFunc());
480 BlendFunc* blendFunc = new BlendFunc;
482 blendFunc->setSource(sourceMode);
484 blendFunc->setDestination(destMode);
486 BlendFunc::BlendFuncMode sourceRGBMode;
487 findAttr(blendFuncModes, psourceRGB, sourceRGBMode);
488 blendFunc->setSourceRGB(sourceRGBMode);
491 BlendFunc::BlendFuncMode destRGBMode;
492 findAttr(blendFuncModes, pdestRGB, destRGBMode);
493 blendFunc->setDestinationRGB(destRGBMode);
496 BlendFunc::BlendFuncMode sourceAlphaMode;
497 findAttr(blendFuncModes, psourceAlpha, sourceAlphaMode);
498 blendFunc->setSourceAlpha(sourceAlphaMode);
501 BlendFunc::BlendFuncMode destAlphaMode;
502 findAttr(blendFuncModes, pdestAlpha, destAlphaMode);
503 blendFunc->setDestinationAlpha(destAlphaMode);
505 pass->setAttributeAndModes(blendFunc);
509 InstallAttributeBuilder<BlendBuilder> installBlend("blend");
512 EffectNameValue<Stencil::Function> stencilFunctionInit[] =
514 {"never", Stencil::NEVER },
515 {"less", Stencil::LESS},
516 {"equal", Stencil::EQUAL},
517 {"less-or-equal", Stencil::LEQUAL},
518 {"greater", Stencil::GREATER},
519 {"not-equal", Stencil::NOTEQUAL},
520 {"greater-or-equal", Stencil::GEQUAL},
521 {"always", Stencil::ALWAYS}
524 EffectPropertyMap<Stencil::Function> stencilFunction(stencilFunctionInit);
526 EffectNameValue<Stencil::Operation> stencilOperationInit[] =
528 {"keep", Stencil::KEEP},
529 {"zero", Stencil::ZERO},
530 {"replace", Stencil::REPLACE},
531 {"increase", Stencil::INCR},
532 {"decrease", Stencil::DECR},
533 {"invert", Stencil::INVERT},
534 {"increase-wrap", Stencil::INCR_WRAP},
535 {"decrease-wrap", Stencil::DECR_WRAP}
538 EffectPropertyMap<Stencil::Operation> stencilOperation(stencilOperationInit);
540 struct StencilBuilder : public PassAttributeBuilder
542 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
543 const SGReaderWriterXMLOptions* options)
545 if (!isAttributeActive(effect, prop))
548 const SGPropertyNode* pmode = getEffectPropertyChild(effect, prop,
550 if (pmode && !pmode->getValue<bool>()) {
551 pass->setMode(GL_STENCIL, StateAttribute::OFF);
554 const SGPropertyNode* pfunction
555 = getEffectPropertyChild(effect, prop, "function");
556 const SGPropertyNode* pvalue
557 = getEffectPropertyChild(effect, prop, "value");
558 const SGPropertyNode* pmask
559 = getEffectPropertyChild(effect, prop, "mask");
560 const SGPropertyNode* psfail
561 = getEffectPropertyChild(effect, prop, "stencil-fail");
562 const SGPropertyNode* pzfail
563 = getEffectPropertyChild(effect, prop, "z-fail");
564 const SGPropertyNode* ppass
565 = getEffectPropertyChild(effect, prop, "pass");
567 Stencil::Function func = Stencil::ALWAYS; // Always pass
569 unsigned int mask = ~0u; // All bits on
570 Stencil::Operation sfailop = Stencil::KEEP; // Keep the old values as default
571 Stencil::Operation zfailop = Stencil::KEEP;
572 Stencil::Operation passop = Stencil::KEEP;
574 ref_ptr<Stencil> stencilFunc = new Stencil;
577 findAttr(stencilFunction, pfunction, func);
579 ref = pvalue->getIntValue();
581 mask = pmask->getIntValue();
584 findAttr(stencilOperation, psfail, sfailop);
586 findAttr(stencilOperation, pzfail, zfailop);
588 findAttr(stencilOperation, ppass, passop);
590 // Set the stencil operation
591 stencilFunc->setFunction(func, ref, mask);
593 // Set the operation, s-fail, s-pass/z-fail, s-pass/z-pass
594 stencilFunc->setOperation(sfailop, zfailop, passop);
596 // Add the operation to pass
597 pass->setAttributeAndModes(stencilFunc.get());
601 InstallAttributeBuilder<StencilBuilder> installStencil("stencil");
604 EffectNameValue<AlphaFunc::ComparisonFunction> alphaComparisonInit[] =
606 {"never", AlphaFunc::NEVER},
607 {"less", AlphaFunc::LESS},
608 {"equal", AlphaFunc::EQUAL},
609 {"lequal", AlphaFunc::LEQUAL},
610 {"greater", AlphaFunc::GREATER},
611 {"notequal", AlphaFunc::NOTEQUAL},
612 {"gequal", AlphaFunc::GEQUAL},
613 {"always", AlphaFunc::ALWAYS}
615 EffectPropertyMap<AlphaFunc::ComparisonFunction>
616 alphaComparison(alphaComparisonInit);
618 struct AlphaTestBuilder : public PassAttributeBuilder
620 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
621 const SGReaderWriterXMLOptions* options)
623 if (!isAttributeActive(effect, prop))
625 // XXX Compatibility with early <alpha-test> syntax; should go away
627 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
630 if (realProp->nChildren() == 0) {
631 pass->setMode(GL_ALPHA_TEST, (realProp->getBoolValue()
633 : StateAttribute::OFF));
637 const SGPropertyNode* pmode = getEffectPropertyChild(effect, prop,
639 // XXX When dynamic parameters are supported, this code should
640 // create the blend function even if the mode is off.
641 if (pmode && !pmode->getValue<bool>()) {
642 pass->setMode(GL_ALPHA_TEST, StateAttribute::OFF);
645 const SGPropertyNode* pComp = getEffectPropertyChild(effect, prop,
647 const SGPropertyNode* pRef = getEffectPropertyChild(effect, prop,
649 AlphaFunc::ComparisonFunction func = AlphaFunc::ALWAYS;
650 float refValue = 1.0f;
652 findAttr(alphaComparison, pComp, func);
654 refValue = pRef->getValue<float>();
655 if (func == AlphaFunc::GREATER && osg::equivalent(refValue, 1.0f)) {
656 pass->setAttributeAndModes(StateAttributeFactory::instance()
657 ->getStandardAlphaFunc());
659 AlphaFunc* alphaFunc = new AlphaFunc;
660 alphaFunc->setFunction(func);
661 alphaFunc->setReferenceValue(refValue);
662 pass->setAttributeAndModes(alphaFunc);
667 InstallAttributeBuilder<AlphaTestBuilder> installAlphaTest("alpha-test");
669 InstallAttributeBuilder<TextureUnitBuilder> textureUnitBuilder("texture-unit");
671 // Shader key, used both for shaders with relative and absolute names
672 typedef pair<string, Shader::Type> ShaderKey;
674 inline ShaderKey makeShaderKey(SGPropertyNode_ptr& ptr, Shader::Type shaderType)
676 return ShaderKey(ptr->getStringValue(), shaderType);
681 typedef pair<string, int> AttribKey;
682 osgDB::FilePathList paths;
683 vector<ShaderKey> shaders;
684 vector<AttribKey> attributes;
687 bool operator()(const ProgramKey& lhs, const ProgramKey& rhs) const
689 return (lhs.paths.size() == rhs.paths.size()
690 && equal(lhs.paths.begin(), lhs.paths.end(),
692 && lhs.shaders.size() == rhs.shaders.size()
693 && equal (lhs.shaders.begin(), lhs.shaders.end(),
695 && lhs.attributes.size() == rhs.attributes.size()
696 && equal(lhs.attributes.begin(), lhs.attributes.end(),
697 rhs.attributes.begin()));
702 size_t hash_value(const ProgramKey& key)
705 boost::hash_range(seed, key.paths.begin(), key.paths.end());
706 boost::hash_range(seed, key.shaders.begin(), key.shaders.end());
707 boost::hash_range(seed, key.attributes.begin(), key.attributes.end());
711 // XXX Should these be protected by a mutex? Probably
713 typedef tr1::unordered_map<ProgramKey, ref_ptr<Program>,
714 boost::hash<ProgramKey>, ProgramKey::EqualTo>
716 ProgramMap programMap;
717 ProgramMap resolvedProgramMap; // map with resolved shader file names
719 typedef tr1::unordered_map<ShaderKey, ref_ptr<Shader>, boost::hash<ShaderKey> >
723 void reload_shaders()
725 for(ShaderMap::iterator sitr = shaderMap.begin(); sitr != shaderMap.end(); ++sitr)
727 Shader *shader = sitr->second.get();
728 string fileName = SGModelLib::findDataFile(sitr->first.first);
729 if (!fileName.empty()) {
730 shader->loadShaderSourceFromFile(fileName);
735 struct ShaderProgramBuilder : PassAttributeBuilder
737 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
738 const SGReaderWriterXMLOptions* options);
742 EffectNameValue<GLint> geometryInputTypeInit[] =
744 {"points", GL_POINTS},
746 {"lines-adjacency", GL_LINES_ADJACENCY_EXT},
747 {"triangles", GL_TRIANGLES},
748 {"triangles-adjacency", GL_TRIANGLES_ADJACENCY_EXT},
750 EffectPropertyMap<GLint>
751 geometryInputType(geometryInputTypeInit);
754 EffectNameValue<GLint> geometryOutputTypeInit[] =
756 {"points", GL_POINTS},
757 {"line-strip", GL_LINE_STRIP},
758 {"triangle-strip", GL_TRIANGLE_STRIP}
760 EffectPropertyMap<GLint>
761 geometryOutputType(geometryOutputTypeInit);
763 void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
764 const SGPropertyNode* prop,
765 const SGReaderWriterXMLOptions*
768 using namespace boost;
769 if (!isAttributeActive(effect, prop))
771 PropertyList pVertShaders = prop->getChildren("vertex-shader");
772 PropertyList pGeomShaders = prop->getChildren("geometry-shader");
773 PropertyList pFragShaders = prop->getChildren("fragment-shader");
774 PropertyList pAttributes = prop->getChildren("attribute");
776 std::back_insert_iterator<vector<ShaderKey> > inserter(prgKey.shaders);
777 transform(pVertShaders.begin(), pVertShaders.end(), inserter,
778 boost::bind(makeShaderKey, _1, Shader::VERTEX));
779 transform(pGeomShaders.begin(), pGeomShaders.end(), inserter,
780 boost::bind(makeShaderKey, _1, Shader::GEOMETRY));
781 transform(pFragShaders.begin(), pFragShaders.end(), inserter,
782 boost::bind(makeShaderKey, _1, Shader::FRAGMENT));
783 for (PropertyList::iterator itr = pAttributes.begin(),
784 e = pAttributes.end();
787 const SGPropertyNode* pName = getEffectPropertyChild(effect, *itr,
789 const SGPropertyNode* pIndex = getEffectPropertyChild(effect, *itr,
791 if (!pName || ! pIndex)
792 throw BuilderException("malformed attribute property");
794 .push_back(ProgramKey::AttribKey(pName->getStringValue(),
795 pIndex->getValue<int>()));
798 prgKey.paths = options->getDatabasePathList();
799 Program* program = 0;
800 ProgramMap::iterator pitr = programMap.find(prgKey);
801 if (pitr != programMap.end()) {
802 program = pitr->second.get();
803 pass->setAttributeAndModes(program);
806 // The program wasn't in the map using the load path passed in with
807 // the options, but it might have already been loaded using a
808 // different load path i.e., its shaders were found in the fg data
809 // directory. So, resolve the shaders' file names and look in the
810 // resolvedProgramMap for a program using those shaders.
811 ProgramKey resolvedKey;
812 resolvedKey.attributes = prgKey.attributes;
813 BOOST_FOREACH(const ShaderKey& shaderKey, prgKey.shaders)
815 const string& shaderName = shaderKey.first;
816 Shader::Type stype = shaderKey.second;
817 string fileName = SGModelLib::findDataFile(shaderName, options);
818 if (fileName.empty())
819 throw BuilderException(string("couldn't find shader ") +
821 resolvedKey.shaders.push_back(ShaderKey(fileName, stype));
823 ProgramMap::iterator resitr = resolvedProgramMap.find(resolvedKey);
824 if (resitr != resolvedProgramMap.end()) {
825 program = resitr->second.get();
826 programMap.insert(ProgramMap::value_type(prgKey, program));
827 pass->setAttributeAndModes(program);
830 program = new Program;
831 BOOST_FOREACH(const ShaderKey& skey, resolvedKey.shaders)
833 const string& fileName = skey.first;
834 Shader::Type stype = skey.second;
835 ShaderMap::iterator sitr = shaderMap.find(skey);
836 if (sitr != shaderMap.end()) {
837 program->addShader(sitr->second.get());
839 ref_ptr<Shader> shader = new Shader(stype);
840 if (shader->loadShaderSourceFromFile(fileName)) {
841 program->addShader(shader.get());
842 shaderMap.insert(ShaderMap::value_type(skey, shader));
846 BOOST_FOREACH(const ProgramKey::AttribKey& key, prgKey.attributes) {
847 program->addBindAttribLocation(key.first, key.second);
849 const SGPropertyNode* pGeometryVerticesOut
850 = getEffectPropertyChild(effect, prop, "geometry-vertices-out");
851 if (pGeometryVerticesOut)
852 program->setParameter(GL_GEOMETRY_VERTICES_OUT_EXT,
853 pGeometryVerticesOut->getIntValue());
854 const SGPropertyNode* pGeometryInputType
855 = getEffectPropertyChild(effect, prop, "geometry-input-type");
856 if (pGeometryInputType) {
858 findAttr(geometryInputType, pGeometryInputType->getStringValue(), type);
859 program->setParameter(GL_GEOMETRY_INPUT_TYPE_EXT, type);
861 const SGPropertyNode* pGeometryOutputType
862 = getEffectPropertyChild(effect, prop, "geometry-output-type");
863 if (pGeometryOutputType) {
865 findAttr(geometryOutputType, pGeometryOutputType->getStringValue(),
867 program->setParameter(GL_GEOMETRY_OUTPUT_TYPE_EXT, type);
869 programMap.insert(ProgramMap::value_type(prgKey, program));
870 resolvedProgramMap.insert(ProgramMap::value_type(resolvedKey, program));
871 pass->setAttributeAndModes(program);
874 InstallAttributeBuilder<ShaderProgramBuilder> installShaderProgram("program");
876 EffectNameValue<Uniform::Type> uniformTypesInit[] =
878 {"bool", Uniform::BOOL},
879 {"int", Uniform::INT},
880 {"float", Uniform::FLOAT},
881 {"float-vec3", Uniform::FLOAT_VEC3},
882 {"float-vec4", Uniform::FLOAT_VEC4},
883 {"sampler-1d", Uniform::SAMPLER_1D},
884 {"sampler-1d-shadow", Uniform::SAMPLER_1D_SHADOW},
885 {"sampler-2d", Uniform::SAMPLER_2D},
886 {"sampler-2d-shadow", Uniform::SAMPLER_2D_SHADOW},
887 {"sampler-3d", Uniform::SAMPLER_3D},
888 {"sampler-cube", Uniform::SAMPLER_CUBE}
890 EffectPropertyMap<Uniform::Type> uniformTypes(uniformTypesInit);
892 // Optimization hack for common uniforms.
893 // XXX protect these with a mutex?
895 ref_ptr<Uniform> texture0;
896 ref_ptr<Uniform> colorMode[3];
898 struct UniformBuilder :public PassAttributeBuilder
900 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
901 const SGReaderWriterXMLOptions* options)
903 if (!texture0.valid()) {
904 texture0 = new Uniform(Uniform::SAMPLER_2D, "texture");
906 texture0->setDataVariance(Object::STATIC);
907 for (int i = 0; i < 3; ++i) {
908 colorMode[i] = new Uniform(Uniform::INT, "colorMode");
909 colorMode[i]->set(i);
910 colorMode[i]->setDataVariance(Object::STATIC);
913 if (!isAttributeActive(effect, prop))
915 const SGPropertyNode* nameProp = prop->getChild("name");
916 const SGPropertyNode* typeProp = prop->getChild("type");
917 const SGPropertyNode* valProp = prop->getChild("value");
919 Uniform::Type uniformType = Uniform::FLOAT;
921 name = nameProp->getStringValue();
923 SG_LOG(SG_INPUT, SG_ALERT, "No name for uniform property ");
927 SG_LOG(SG_INPUT, SG_ALERT, "No value for uniform property "
932 props::Type propType = valProp->getType();
935 uniformType = Uniform::BOOL;
938 uniformType = Uniform::INT;
942 break; // default float type;
944 uniformType = Uniform::FLOAT_VEC3;
947 uniformType = Uniform::FLOAT_VEC4;
950 SG_LOG(SG_INPUT, SG_ALERT, "Can't deduce type of uniform "
955 findAttr(uniformTypes, typeProp, uniformType);
957 ref_ptr<Uniform> uniform = new Uniform;
958 uniform->setName(name);
959 uniform->setType(uniformType);
960 switch (uniformType) {
962 initFromParameters(effect, valProp, uniform.get(),
963 static_cast<bool (Uniform::*)(float)>(&Uniform::set),
966 case Uniform::FLOAT_VEC3:
967 initFromParameters(effect, valProp, uniform.get(),
968 static_cast<bool (Uniform::*)(const Vec3&)>(&Uniform::set),
971 case Uniform::FLOAT_VEC4:
972 initFromParameters(effect, valProp, uniform.get(),
973 static_cast<bool (Uniform::*)(const Vec4&)>(&Uniform::set),
977 case Uniform::SAMPLER_1D:
978 case Uniform::SAMPLER_2D:
979 case Uniform::SAMPLER_3D:
980 case Uniform::SAMPLER_1D_SHADOW:
981 case Uniform::SAMPLER_2D_SHADOW:
982 case Uniform::SAMPLER_CUBE:
983 initFromParameters(effect, valProp, uniform.get(),
984 static_cast<bool (Uniform::*)(int)>(&Uniform::set),
987 default: // avoid compiler warning
990 // optimize common uniforms
991 if (uniformType == Uniform::SAMPLER_2D || uniformType == Uniform::INT)
995 if (uniformType == Uniform::SAMPLER_2D && val == 0
996 && name == "texture") {
998 } else if (uniformType == Uniform::INT && val >= 0 && val < 3
999 && name == "colorMode") {
1000 uniform = colorMode[val];
1003 pass->addUniform(uniform.get());
1007 InstallAttributeBuilder<UniformBuilder> installUniform("uniform");
1009 // Not sure what to do with "name". At one point I wanted to use it to
1010 // order the passes, but I do support render bin and stuff too...
1012 struct NameBuilder : public PassAttributeBuilder
1014 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
1015 const SGReaderWriterXMLOptions* options)
1017 // name can't use <use>
1018 string name = prop->getStringValue();
1020 pass->setName(name);
1024 InstallAttributeBuilder<NameBuilder> installName("name");
1026 EffectNameValue<PolygonMode::Mode> polygonModeModesInit[] =
1028 {"fill", PolygonMode::FILL},
1029 {"line", PolygonMode::LINE},
1030 {"point", PolygonMode::POINT}
1032 EffectPropertyMap<PolygonMode::Mode> polygonModeModes(polygonModeModesInit);
1034 struct PolygonModeBuilder : public PassAttributeBuilder
1036 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
1037 const SGReaderWriterXMLOptions* options)
1039 if (!isAttributeActive(effect, prop))
1041 const SGPropertyNode* frontProp
1042 = getEffectPropertyChild(effect, prop, "front");
1043 const SGPropertyNode* backProp
1044 = getEffectPropertyChild(effect, prop, "back");
1045 ref_ptr<PolygonMode> pmode = new PolygonMode;
1046 PolygonMode::Mode frontMode = PolygonMode::FILL;
1047 PolygonMode::Mode backMode = PolygonMode::FILL;
1049 findAttr(polygonModeModes, frontProp, frontMode);
1050 pmode->setMode(PolygonMode::FRONT, frontMode);
1053 findAttr(polygonModeModes, backProp, backMode);
1054 pmode->setMode(PolygonMode::BACK, backMode);
1056 pass->setAttribute(pmode.get());
1060 InstallAttributeBuilder<PolygonModeBuilder> installPolygonMode("polygon-mode");
1062 struct VertexProgramTwoSideBuilder : public PassAttributeBuilder
1064 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
1065 const SGReaderWriterXMLOptions* options)
1067 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
1070 pass->setMode(GL_VERTEX_PROGRAM_TWO_SIDE,
1071 (realProp->getValue<bool>()
1072 ? StateAttribute::ON : StateAttribute::OFF));
1076 InstallAttributeBuilder<VertexProgramTwoSideBuilder>
1077 installTwoSide("vertex-program-two-side");
1079 struct VertexProgramPointSizeBuilder : public PassAttributeBuilder
1081 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
1082 const SGReaderWriterXMLOptions* options)
1084 const SGPropertyNode* realProp = getEffectPropertyNode(effect, prop);
1087 pass->setMode(GL_VERTEX_PROGRAM_POINT_SIZE,
1088 (realProp->getValue<bool>()
1089 ? StateAttribute::ON : StateAttribute::OFF));
1093 InstallAttributeBuilder<VertexProgramPointSizeBuilder>
1094 installPointSize("vertex-program-point-size");
1096 EffectNameValue<Depth::Function> depthFunctionInit[] =
1098 {"never", Depth::NEVER},
1099 {"less", Depth::LESS},
1100 {"equal", Depth::EQUAL},
1101 {"lequal", Depth::LEQUAL},
1102 {"greater", Depth::GREATER},
1103 {"notequal", Depth::NOTEQUAL},
1104 {"gequal", Depth::GEQUAL},
1105 {"always", Depth::ALWAYS}
1107 EffectPropertyMap<Depth::Function> depthFunction(depthFunctionInit);
1109 struct DepthBuilder : public PassAttributeBuilder
1111 void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
1112 const SGReaderWriterXMLOptions* options)
1114 if (!isAttributeActive(effect, prop))
1116 ref_ptr<Depth> depth = new Depth;
1117 const SGPropertyNode* pfunc
1118 = getEffectPropertyChild(effect, prop, "function");
1120 Depth::Function func = Depth::LESS;
1121 findAttr(depthFunction, pfunc, func);
1122 depth->setFunction(func);
1124 const SGPropertyNode* pnear
1125 = getEffectPropertyChild(effect, prop, "near");
1127 depth->setZNear(pnear->getValue<double>());
1128 const SGPropertyNode* pfar
1129 = getEffectPropertyChild(effect, prop, "far");
1131 depth->setZFar(pnear->getValue<double>());
1132 const SGPropertyNode* pmask
1133 = getEffectPropertyChild(effect, prop, "write-mask");
1135 depth->setWriteMask(pmask->getValue<bool>());
1136 pass->setAttribute(depth.get());
1140 InstallAttributeBuilder<DepthBuilder> installDepth("depth");
1142 void buildTechnique(Effect* effect, const SGPropertyNode* prop,
1143 const SGReaderWriterXMLOptions* options)
1145 Technique* tniq = new Technique;
1146 effect->techniques.push_back(tniq);
1147 const SGPropertyNode* predProp = prop->getChild("predicate");
1149 tniq->setAlwaysValid(true);
1152 TechniquePredParser parser;
1153 parser.setTechnique(tniq);
1154 expression::BindingLayout& layout = parser.getBindingLayout();
1155 /*int contextLoc = */layout.addBinding("__contextId", expression::INT);
1156 SGExpressionb* validExp
1157 = dynamic_cast<SGExpressionb*>(parser.read(predProp
1160 tniq->setValidExpression(validExp, layout);
1162 throw expression::ParseError("technique predicate is not a boolean expression");
1164 catch (expression::ParseError& except)
1166 SG_LOG(SG_INPUT, SG_ALERT,
1167 "parsing technique predicate " << except.getMessage());
1168 tniq->setAlwaysValid(false);
1171 PropertyList passProps = prop->getChildren("pass");
1172 for (PropertyList::iterator itr = passProps.begin(), e = passProps.end();
1175 buildPass(effect, tniq, itr->ptr(), options);
1179 // Specifically for .ac files...
1180 bool makeParametersFromStateSet(SGPropertyNode* effectRoot, const StateSet* ss)
1182 SGPropertyNode* paramRoot = makeChild(effectRoot, "parameters");
1183 SGPropertyNode* matNode = paramRoot->getChild("material", 0, true);
1184 Vec4f ambVal, difVal, specVal, emisVal;
1185 float shininess = 0.0f;
1186 const Material* mat = getStateAttribute<Material>(ss);
1188 ambVal = mat->getAmbient(Material::FRONT_AND_BACK);
1189 difVal = mat->getDiffuse(Material::FRONT_AND_BACK);
1190 specVal = mat->getSpecular(Material::FRONT_AND_BACK);
1191 emisVal = mat->getEmission(Material::FRONT_AND_BACK);
1192 shininess = mat->getShininess(Material::FRONT_AND_BACK);
1193 makeChild(matNode, "active")->setValue(true);
1194 makeChild(matNode, "ambient")->setValue(toVec4d(toSG(ambVal)));
1195 makeChild(matNode, "diffuse")->setValue(toVec4d(toSG(difVal)));
1196 makeChild(matNode, "specular")->setValue(toVec4d(toSG(specVal)));
1197 makeChild(matNode, "emissive")->setValue(toVec4d(toSG(emisVal)));
1198 makeChild(matNode, "shininess")->setValue(shininess);
1199 matNode->getChild("color-mode", 0, true)->setStringValue("diffuse");
1201 makeChild(matNode, "active")->setValue(false);
1203 const ShadeModel* sm = getStateAttribute<ShadeModel>(ss);
1204 string shadeModelString("smooth");
1206 ShadeModel::Mode smMode = sm->getMode();
1207 if (smMode == ShadeModel::FLAT)
1208 shadeModelString = "flat";
1210 makeChild(paramRoot, "shade-model")->setStringValue(shadeModelString);
1211 string cullFaceString("off");
1212 const CullFace* cullFace = getStateAttribute<CullFace>(ss);
1214 switch (cullFace->getMode()) {
1215 case CullFace::FRONT:
1216 cullFaceString = "front";
1218 case CullFace::BACK:
1219 cullFaceString = "back";
1221 case CullFace::FRONT_AND_BACK:
1222 cullFaceString = "front-back";
1228 makeChild(paramRoot, "cull-face")->setStringValue(cullFaceString);
1229 // Macintosh ATI workaround
1230 bool vertexTwoSide = cullFaceString == "off";
1231 makeChild(paramRoot, "vertex-program-two-side")->setValue(vertexTwoSide);
1232 const BlendFunc* blendFunc = getStateAttribute<BlendFunc>(ss);
1233 SGPropertyNode* blendNode = makeChild(paramRoot, "blend");
1235 string sourceMode = findName(blendFuncModes, blendFunc->getSource());
1236 string destMode = findName(blendFuncModes, blendFunc->getDestination());
1237 makeChild(blendNode, "active")->setValue(true);
1238 makeChild(blendNode, "source")->setStringValue(sourceMode);
1239 makeChild(blendNode, "destination")->setStringValue(destMode);
1240 makeChild(blendNode, "mode")->setValue(true);
1242 makeChild(blendNode, "active")->setValue(false);
1244 string renderingHint = findName(renderingHints, ss->getRenderingHint());
1245 makeChild(paramRoot, "rendering-hint")->setStringValue(renderingHint);
1246 makeTextureParameters(paramRoot, ss);
1250 // Walk the techniques property tree, building techniques and
1252 bool Effect::realizeTechniques(const SGReaderWriterXMLOptions* options)
1256 PropertyList tniqList = root->getChildren("technique");
1257 for (PropertyList::iterator itr = tniqList.begin(), e = tniqList.end();
1260 buildTechnique(this, *itr, options);
1265 void Effect::InitializeCallback::doUpdate(osg::Node* node, osg::NodeVisitor* nv)
1267 EffectGeode* eg = dynamic_cast<EffectGeode*>(node);
1270 Effect* effect = eg->getEffect();
1273 SGPropertyNode* root = getPropertyRoot();
1274 for (vector<SGSharedPtr<Updater> >::iterator itr = effect->_extraData.begin(),
1275 end = effect->_extraData.end();
1278 InitializeWhenAdded* adder
1279 = dynamic_cast<InitializeWhenAdded*>(itr->ptr());
1281 adder->initOnAdd(effect, root);
1285 bool Effect::Key::EqualTo::operator()(const Effect::Key& lhs,
1286 const Effect::Key& rhs) const
1288 if (lhs.paths.size() != rhs.paths.size()
1289 || !equal(lhs.paths.begin(), lhs.paths.end(), rhs.paths.begin()))
1291 if (lhs.unmerged.valid() && rhs.unmerged.valid())
1292 return props::Compare()(lhs.unmerged, rhs.unmerged);
1294 return lhs.unmerged == rhs.unmerged;
1297 size_t hash_value(const Effect::Key& key)
1300 if (key.unmerged.valid())
1301 boost::hash_combine(seed, *key.unmerged);
1302 boost::hash_range(seed, key.paths.begin(), key.paths.end());
1306 bool Effect_writeLocalData(const Object& obj, osgDB::Output& fw)
1308 const Effect& effect = static_cast<const Effect&>(obj);
1310 fw.indent() << "techniques " << effect.techniques.size() << "\n";
1311 BOOST_FOREACH(const ref_ptr<Technique>& technique, effect.techniques) {
1312 fw.writeObject(*technique);
1319 osgDB::RegisterDotOsgWrapperProxy effectProxy
1323 "Object simgear::Effect",
1325 &Effect_writeLocalData
1329 // Property expressions for technique predicates
1330 template<typename T>
1331 class PropertyExpression : public SGExpression<T>
1334 PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {}
1336 void eval(T& value, const expression::Binding*) const
1338 value = _pnode->getValue<T>();
1341 SGPropertyNode_ptr _pnode;
1344 class EffectPropertyListener : public SGPropertyChangeListener
1347 EffectPropertyListener(Technique* tniq) : _tniq(tniq) {}
1349 void valueChanged(SGPropertyNode* node)
1351 _tniq->refreshValidity();
1354 osg::ref_ptr<Technique> _tniq;
1357 template<typename T>
1358 Expression* propertyExpressionParser(const SGPropertyNode* exp,
1359 expression::Parser* parser)
1361 SGPropertyNode_ptr pnode = getPropertyRoot()->getNode(exp->getStringValue(),
1363 PropertyExpression<T>* pexp = new PropertyExpression<T>(pnode);
1364 TechniquePredParser* predParser
1365 = dynamic_cast<TechniquePredParser*>(parser);
1367 pnode->addChangeListener(new EffectPropertyListener(predParser
1372 expression::ExpParserRegistrar propertyRegistrar("property",
1373 propertyExpressionParser<bool>);
1375 expression::ExpParserRegistrar propvalueRegistrar("float-property",
1376 propertyExpressionParser<float>);