Dump texture attributes of StateSet into effect property tree

Also, decode blend function.
This commit is contained in:
Tim Moore
2009-09-08 12:59:58 +02:00
parent e7e81c6639
commit 14e5e87a4d
4 changed files with 40 additions and 1 deletions

View File

@@ -922,6 +922,17 @@ bool makeParametersFromStateSet(SGPropertyNode* paramRoot, const StateSet* ss)
}
}
paramRoot->getChild("cull-face", 0, true)->setStringValue(cullFaceString);
const BlendFunc* blendFunc = getStateAttribute<BlendFunc>(ss);
if (blendFunc) {
string sourceMode = findName(blendFuncModes, blendFunc->getSource());
string destMode = findName(blendFuncModes, blendFunc->getDestination());
SGPropertyNode* blendNode = paramRoot->getChild("blend", 0, true);
blendNode->getChild("source", 0, true)->setStringValue(sourceMode);
blendNode->getChild("destination", 0, true)->setStringValue(destMode);
blendNode->getChild("mode", 0, true)->setValue(true);
}
makeTextureParameters(paramRoot, ss);
return true;
}
// Walk the techniques property tree, building techniques and

View File

@@ -71,5 +71,8 @@ Effect* makeEffect(const std::string& name,
Effect* makeEffect(SGPropertyNode* prop,
bool realizeTechniques,
const osgDB::ReaderWriter::Options* options = 0);
bool makeParametersFromStateSet(SGPropertyNode* paramRoot,
const osg::StateSet* ss);
}
#endif

View File

@@ -31,8 +31,8 @@
#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/StateAttributeFactory.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/structure/OSGUtils.hxx>
#include "Noise.hxx"
@@ -283,4 +283,26 @@ namespace
TextureBuilder::Registrar installNoise("noise", new NoiseBuilder);
}
bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss)
{
const Texture* tex = getStateAttribute<Texture>(0, ss);
const Texture2D* texture = dynamic_cast<const Texture2D*>(tex);
if (!tex)
return false;
const Image* image = texture->getImage();
string imageName;
if (image)
imageName = image->getFileName();
string wrapS = findName(wrapModes, texture->getWrap(Texture::WRAP_S));
string wrapT = findName(wrapModes, texture->getWrap(Texture::WRAP_T));
string wrapR = findName(wrapModes, texture->getWrap(Texture::WRAP_R));
SGPropertyNode* texUnit = makeChild(paramRoot, "texture-unit");
makeChild(texUnit, "unit")->setValue(0);
makeChild(texUnit, "image")->setStringValue(imageName);
makeChild(texUnit, "wrap-s")->setStringValue(wrapS);
makeChild(texUnit, "wrap-t")->setStringValue(wrapT);
makeChild(texUnit, "wrap-r")->setStringValue(wrapR);
return true;
}
}

View File

@@ -17,6 +17,7 @@
#ifndef SIMGEAR_TEXTUREBUILDER_HXX
#define SIMGEAR_TEXTUREBUILDER_HXX 1
#include <osg/StateSet>
#include <osg/Texture>
#include "EffectBuilder.hxx"
@@ -30,5 +31,7 @@ public:
const SGPropertyNode*props,
const osgDB::ReaderWriter::Options* options);
};
bool makeTextureParameters(SGPropertyNode* paramRoot, const osg::StateSet* ss);
}
#endif