From cf9de25c250c2b2cd3181780d757c39b1ab59e42 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 21 Dec 2009 07:34:05 +0100 Subject: [PATCH] pass SGReaderWriterXMLOptions object to getGlobalProperty This supports pathnames relative to a model in effect definitions. --- simgear/scene/material/EffectBuilder.cxx | 18 +++++++++++++++++- simgear/scene/material/EffectBuilder.hxx | 13 ++++++++----- simgear/scene/material/TextureBuilder.cxx | 12 ++++++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/simgear/scene/material/EffectBuilder.cxx b/simgear/scene/material/EffectBuilder.cxx index 65ba71db..338fc9aa 100644 --- a/simgear/scene/material/EffectBuilder.cxx +++ b/simgear/scene/material/EffectBuilder.cxx @@ -42,13 +42,29 @@ const SGPropertyNode* getEffectPropertyChild(Effect* effect, return getEffectPropertyNode(effect, child); } -string getGlobalProperty(const SGPropertyNode* prop) +string getGlobalProperty(const SGPropertyNode* prop, + const SGReaderWriterXMLOptions* options) { if (!prop) return string(); const SGPropertyNode* useProp = prop->getChild("use"); if (!useProp) return string(); + string propName = useProp->getStringValue(); + SGPropertyNode_ptr propRoot; + if (propName[0] == '/') { + return propName; + } else if ((propRoot = options->getPropRoot())) { + string result = propRoot->getPath(); + result.append("/"); + result.append(propName); + return result; + } else { + throw effect:: + BuilderException("No property root to use with relative name " + + propName); + } + return useProp->getStringValue(); } diff --git a/simgear/scene/material/EffectBuilder.hxx b/simgear/scene/material/EffectBuilder.hxx index d16e3347..615b2157 100644 --- a/simgear/scene/material/EffectBuilder.hxx +++ b/simgear/scene/material/EffectBuilder.hxx @@ -46,6 +46,7 @@ namespace simgear { class Effect; class Pass; +class SGReaderWriterXMLOptions; /** * Builder that returns an object, probably an OSG object. @@ -240,7 +241,8 @@ const SGPropertyNode* getEffectPropertyChild(Effect* effect, * @return empty if prop doesn't contain a clause; otherwise the * mentioned node name. */ -std::string getGlobalProperty(const SGPropertyNode* prop); +std::string getGlobalProperty(const SGPropertyNode* prop, + const SGReaderWriterXMLOptions *); class PassAttributeBuilder : public SGReferenced { @@ -426,7 +428,8 @@ private: template void initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, - void (ObjType::*setter)(const OSGParamType)) + void (ObjType::*setter)(const OSGParamType), + const SGReaderWriterXMLOptions* options) { const SGPropertyNode* valProp = getEffectPropertyNode(effect, prop); if (!valProp) @@ -434,7 +437,7 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, if (valProp->nChildren() == 0) { obj->*setter(valProp->getValue()); } else { - std::string propName = getGlobalProperty(prop); + std::string propName = getGlobalProperty(prop, options); ScalarChangeListener* listener = new ScalarChangeListener(obj, setter, propName); @@ -446,7 +449,7 @@ template void initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, void (ObjType::*setter)(const OSGParamType&), - NameItrType nameItr) + NameItrType nameItr, const SGReaderWriterXMLOptions* options) { typedef typename OSGBridge::sg_type sg_type; const SGPropertyNode* valProp = getEffectPropertyNode(effect, prop); @@ -456,7 +459,7 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, (obj->*setter)(OSGBridge ::getOsgType(valProp->getValue())); } else { - string listenPropName = getGlobalProperty(valProp); + string listenPropName = getGlobalProperty(valProp, options); if (listenPropName.empty()) return; typedef OSGFunctor Functor; diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index f81f2b9b..7dc7aed6 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -51,7 +51,8 @@ using namespace osg; using namespace effect; TexEnvCombine* buildTexEnvCombine(Effect* effect, - const SGPropertyNode* envProp); + const SGPropertyNode* envProp, + const SGReaderWriterXMLOptions* options); TexGen* buildTexGen(Effect* Effect, const SGPropertyNode* tgenProp); // Hack to force inclusion of TextureBuilder.cxx in library @@ -142,7 +143,8 @@ void TextureUnitBuilder::buildAttribute(Effect* effect, Pass* pass, } const SGPropertyNode* combineProp = prop->getChild("texenv-combine"); TexEnvCombine* combiner = 0; - if (combineProp && ((combiner = buildTexEnvCombine(effect, combineProp)))) + if (combineProp && ((combiner = buildTexEnvCombine(effect, combineProp, + options)))) pass->setTextureAttributeAndModes(unit, combiner); const SGPropertyNode* tgenProp = prop->getChild("texgen"); TexGen* tgen = 0; @@ -444,7 +446,8 @@ EffectNameValue opParamInit[] = EffectPropertyMap operandParams(opParamInit); -TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp) +TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp, + const SGReaderWriterXMLOptions* options) { if (!isAttributeActive(effect, envProp)) return 0; @@ -539,7 +542,8 @@ TexEnvCombine* buildTexEnvCombine(Effect* effect, const SGPropertyNode* envProp) const SGPropertyNode* colorNode = envProp->getChild("constant-color"); if (colorNode) initFromParameters(effect, colorNode, result, - &TexEnvCombine::setConstantColor, colorFields); + &TexEnvCombine::setConstantColor, colorFields, + options); return result; } -- 2.39.5