]> git.mxchange.org Git - simgear.git/commitdiff
Dump texture attributes of StateSet into effect property tree
authorTim Moore <timoore@redhat.com>
Tue, 8 Sep 2009 10:59:58 +0000 (12:59 +0200)
committerTim Moore <timoore@redhat.com>
Fri, 13 Nov 2009 21:41:11 +0000 (22:41 +0100)
Also, decode blend function.

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

index eba40dd74d10634e445e5cac9ad5aee12c4bbb96..2e68223431718685d65d750251ae143ca70ba511 100644 (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
index 2a3c896ec58d2a9b8c59f5f8318245cbee902318..2b3942fee89dec17040d2bfdf320bfc6ed36bf19 100644 (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
index cc927341ede6c631247c6e3d92739e95fc347370..9103fe59ba099934f8512333da6acecbe631d05a 100644 (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;
+}
+
 }
index 259ef61417caad04094ff850bf43c7a511d93dc7..395ca38260b8fb9a4bb4aa7c8cb2c1400061324d 100644 (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