pass SGReaderWriterXMLOptions object to getGlobalProperty

This supports pathnames relative to a model in effect definitions.
This commit is contained in:
Tim Moore
2009-12-21 07:34:05 +01:00
parent fc4009aa50
commit cf9de25c25
3 changed files with 33 additions and 10 deletions

View 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();
}

View 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;

View 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;
}