]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/Effect.cxx
Terrasync: make whitespace in pathnames work under windows
[simgear.git] / simgear / scene / material / Effect.cxx
index 787a9ce2eb6834a9a9eda57b84d1a03b4207a326..6517bd2390171be9de11901dbfefcdaa0ddb643c 100644 (file)
@@ -279,7 +279,7 @@ struct ColorMaskBuilder : PassAttributeBuilder
 
         ColorMask *mask = new ColorMask;
         Vec4 m = getColor(realProp);
-        mask->setMask(m.r(), m.g(), m.b(), m.a());
+        mask->setMask(m.r() > 0.0, m.g() > 0.0, m.b() > 0.0, m.a() > 0.0);
         pass->setAttributeAndModes(mask);
     }    
 };
@@ -725,7 +725,7 @@ void reload_shaders()
     for(ShaderMap::iterator sitr = shaderMap.begin(); sitr != shaderMap.end(); ++sitr)
     {
        Shader *shader = sitr->second.get();
-        string fileName = osgDB::findDataFile(sitr->first.first);
+        string fileName = SGModelLib::findDataFile(sitr->first.first);
         if (!fileName.empty()) {
            shader->loadShaderSourceFromFile(fileName);
         }
@@ -775,11 +775,11 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
     ProgramKey prgKey;
     std::back_insert_iterator<vector<ShaderKey> > inserter(prgKey.shaders);
     transform(pVertShaders.begin(), pVertShaders.end(), inserter,
-              bind(makeShaderKey, _1, Shader::VERTEX));
+              boost::bind(makeShaderKey, _1, Shader::VERTEX));
     transform(pGeomShaders.begin(), pGeomShaders.end(), inserter,
-              bind(makeShaderKey, _1, Shader::GEOMETRY));
+              boost::bind(makeShaderKey, _1, Shader::GEOMETRY));
     transform(pFragShaders.begin(), pFragShaders.end(), inserter,
-              bind(makeShaderKey, _1, Shader::FRAGMENT));
+              boost::bind(makeShaderKey, _1, Shader::FRAGMENT));
     for (PropertyList::iterator itr = pAttributes.begin(),
              e = pAttributes.end();
          itr != e;
@@ -814,7 +814,7 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass,
     {
         const string& shaderName = shaderKey.first;
         Shader::Type stype = shaderKey.second;
-        string fileName = osgDB::findDataFile(shaderName, options);
+        string fileName = SGModelLib::findDataFile(shaderName, options);
         if (fileName.empty())
             throw BuilderException(string("couldn't find shader ") +
                                    shaderName);
@@ -889,11 +889,27 @@ EffectNameValue<Uniform::Type> uniformTypesInit[] =
 };
 EffectPropertyMap<Uniform::Type> uniformTypes(uniformTypesInit);
 
+// Optimization hack for common uniforms.
+// XXX protect these with a mutex?
+
+ref_ptr<Uniform> texture0;
+ref_ptr<Uniform> colorMode[3];
+
 struct UniformBuilder :public PassAttributeBuilder
 {
     void buildAttribute(Effect* effect, Pass* pass, const SGPropertyNode* prop,
                         const SGReaderWriterXMLOptions* options)
     {
+        if (!texture0.valid()) {
+            texture0 = new Uniform(Uniform::SAMPLER_2D, "texture");
+            texture0->set(0);
+            texture0->setDataVariance(Object::STATIC);
+            for (int i = 0; i < 3; ++i) {
+                colorMode[i] = new Uniform(Uniform::INT, "colorMode");
+                colorMode[i]->set(i);
+                colorMode[i]->setDataVariance(Object::STATIC);
+            }
+        }
         if (!isAttributeActive(effect, prop))
             return;
         const SGPropertyNode* nameProp = prop->getChild("name");
@@ -957,6 +973,7 @@ struct UniformBuilder :public PassAttributeBuilder
                                static_cast<bool (Uniform::*)(const Vec4&)>(&Uniform::set),
                                vec4Names, options);
             break;
+        case Uniform::INT:
         case Uniform::SAMPLER_1D:
         case Uniform::SAMPLER_2D:
         case Uniform::SAMPLER_3D:
@@ -970,6 +987,19 @@ struct UniformBuilder :public PassAttributeBuilder
         default: // avoid compiler warning
             break;
         }
+        // optimize common uniforms
+        if (uniformType == Uniform::SAMPLER_2D || uniformType == Uniform::INT)
+        {
+            int val;
+            uniform->get(val);
+            if (uniformType == Uniform::SAMPLER_2D && val == 0
+                && name == "texture") {
+                uniform = texture0;
+            } else if (uniformType == Uniform::INT && val >= 0 && val < 3
+                       && name == "colorMode") {
+                uniform = colorMode[val];
+            }
+        }
         pass->addUniform(uniform.get());
     }
 };