]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/Effect.cxx
Random buildings - initial commit.
[simgear.git] / simgear / scene / material / Effect.cxx
index c021b98e46e252b5f185a6c6665d55a3fadcab11..978aa064e7d7f4851842dc4784e9c5eab649bfea 100644 (file)
@@ -69,6 +69,7 @@
 
 #include <simgear/scene/util/SGReaderWriterOptions.hxx>
 #include <simgear/scene/tgdb/userdata.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
 #include <simgear/scene/util/SGSceneFeatures.hxx>
 #include <simgear/scene/util/StateAttributeFactory.hxx>
 #include <simgear/structure/OSGUtils.hxx>
@@ -838,6 +839,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
             program->addShader(sitr->second.get());
         } else {
             ref_ptr<Shader> shader = new Shader(stype);
+                       shader->setName(fileName);
             if (shader->loadShaderSourceFromFile(fileName)) {
                 program->addShader(shader.get());
                 shaderMap.insert(ShaderMap::value_type(skey, shader));
@@ -915,6 +917,7 @@ struct UniformBuilder :public PassAttributeBuilder
             return;
         const SGPropertyNode* nameProp = prop->getChild("name");
         const SGPropertyNode* typeProp = prop->getChild("type");
+        const SGPropertyNode* positionedProp = prop->getChild("positioned");
         const SGPropertyNode* valProp = prop->getChild("value");
         string name;
         Uniform::Type uniformType = Uniform::FLOAT;
@@ -959,6 +962,11 @@ struct UniformBuilder :public PassAttributeBuilder
         uniform->setName(name);
         uniform->setType(uniformType);
         switch (uniformType) {
+        case Uniform::BOOL:
+            initFromParameters(effect, valProp, uniform.get(),
+                               static_cast<bool (Uniform::*)(bool)>(&Uniform::set),
+                               options);
+            break;
         case Uniform::FLOAT:
             initFromParameters(effect, valProp, uniform.get(),
                                static_cast<bool (Uniform::*)(float)>(&Uniform::set),
@@ -991,8 +999,8 @@ struct UniformBuilder :public PassAttributeBuilder
         // optimize common uniforms
         if (uniformType == Uniform::SAMPLER_2D || uniformType == Uniform::INT)
         {
-            int val;
-            uniform->get(val);
+            int val = 0;
+            uniform->get(val); // 'val' remains unchanged in case of error (Uniform is a non-scalar)
             if (uniformType == Uniform::SAMPLER_2D && val == 0
                 && name == "texture") {
                 uniform = texture0;
@@ -1002,6 +1010,11 @@ struct UniformBuilder :public PassAttributeBuilder
             }
         }
         pass->addUniform(uniform.get());
+        if (positionedProp && positionedProp->getBoolValue() && uniformType == Uniform::FLOAT_VEC4) {
+            osg::Vec4 offset;
+            uniform->get(offset);
+            pass->addPositionedUniform( name, offset );
+        }
     }
 };
 
@@ -1162,7 +1175,10 @@ struct DepthBuilder : public PassAttributeBuilder
             = getEffectPropertyChild(effect, prop, "write-mask");
         if (pmask)
             depth->setWriteMask(pmask->getValue<bool>());
-        pass->setAttribute(depth.get());
+        const SGPropertyNode* penabled
+            = getEffectPropertyChild(effect, prop, "enabled");
+        bool enabled = ( penabled == 0 || penabled->getBoolValue() );
+        pass->setAttributeAndModes(depth.get(), enabled ? osg::StateAttribute::ON : osg::StateAttribute::OFF);
     }
 };
 
@@ -1377,10 +1393,11 @@ public:
     
     void valueChanged(SGPropertyNode* node)
     {
-        _tniq->refreshValidity();
+        if (_tniq.valid())
+            _tniq->refreshValidity();
     }
 protected:
-    osg::ref_ptr<Technique> _tniq;
+    osg::observer_ptr<Technique> _tniq;
 };
 
 template<typename T>