]> git.mxchange.org Git - simgear.git/commitdiff
pass SGReaderWriterXMLOptions object to getGlobalProperty
authorTim Moore <timoore33@gmail.com>
Mon, 21 Dec 2009 06:34:05 +0000 (07:34 +0100)
committerTim Moore <timoore33@gmail.com>
Tue, 9 Mar 2010 10:02:56 +0000 (11:02 +0100)
This supports pathnames relative to a model in effect definitions.

simgear/scene/material/EffectBuilder.cxx
simgear/scene/material/EffectBuilder.hxx
simgear/scene/material/TextureBuilder.cxx

index 65ba71dbcb773bae4134de21fc4c63798ef6e562..338fc9aa33a34f274598225bc967e7cb89d86e5c 100644 (file)
@@ -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();
 }
 
index d16e3347a46f0ddbcad36f8789202650cf01b34d..615b2157a5d57f6a12ae46a0ea6dca817e03f021 100644 (file)
@@ -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 <use> 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<typename ObjType, typename OSGParamType>
 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<OSGParamType>());
     } else {
-        std::string propName = getGlobalProperty(prop);
+        std::string propName = getGlobalProperty(prop, options);
         ScalarChangeListener<ObjType, OSGParamType>* listener
             = new ScalarChangeListener<ObjType, OSGParamType>(obj, setter,
                                                               propName);
@@ -446,7 +449,7 @@ template<typename ObjType, typename OSGParamType, typename NameItrType>
 void
 initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj,
                    void (ObjType::*setter)(const OSGParamType&),
-                   NameItrType nameItr)
+                   NameItrType nameItr, const SGReaderWriterXMLOptions* options)
 {
     typedef typename OSGBridge<OSGParamType>::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<OSGParamType>
                      ::getOsgType(valProp->getValue<sg_type>()));
     } else {
-        string listenPropName = getGlobalProperty(valProp);
+        string listenPropName = getGlobalProperty(valProp, options);
         if (listenPropName.empty())
             return;
         typedef OSGFunctor<ObjType, OSGParamType> Functor;
index f81f2b9bfaedb42eb035a9b9e0718a5560f35358..7dc7aed64b1e5d15284b9049eb1757c215ceaeac 100644 (file)
@@ -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<TexEnvCombine::OperandParam> opParamInit[] =
 
 EffectPropertyMap<TexEnvCombine::OperandParam> 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;
 }