]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/Technique.cxx
Merge branch 'frohlich/weak' into next
[simgear.git] / simgear / scene / material / Technique.cxx
index 19699607c9a4415df051e4ac97fd73afbd07abbe..4c1dbe169c3a6f0eef2f5009fe168ccdcc086f87 100644 (file)
@@ -1,9 +1,15 @@
+
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include "Technique.hxx"
 #include "Pass.hxx"
 
 #include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 
+#include <iterator>
 #include <vector>
 #include <string>
 
@@ -60,7 +66,7 @@ Technique::Technique(const Technique& rhs, const osg::CopyOp& copyop) :
     using namespace std;
     using namespace boost;
     transform(rhs.passes.begin(), rhs.passes.end(),
-              backRefInsertIterator(passes),
+              back_inserter(passes),
               bind(simgear::clone_ref<Pass>, _1, copyop));
 
 }
@@ -186,7 +192,7 @@ void Technique::releaseGLObjects(osg::State* state) const
         pass->releaseGLObjects(state);
     }
     if (state == 0) {
-        for (int i = 0; i < _contextMap.size(); ++i) {
+        for (int i = 0; i < (int)_contextMap.size(); ++i) {
             ContextInfo& info = _contextMap[i];
             Status oldVal = info.valid();
             info.valid.compareAndSwap(oldVal, UNKNOWN);
@@ -214,7 +220,11 @@ class GLVersionExpression : public SGExpression<float>
 public:
     void eval(float& value, const expression::Binding*) const
     {
+#ifdef TECHNIQUE_TEST_EXTENSIONS
+        value = 1.1;
+#else
         value = getGLVersionNumber();
+#endif
     }
 };
 
@@ -250,8 +260,16 @@ Expression* extensionSupportedParser(const SGPropertyNode* exp,
                                      expression::Parser* parser)
 {
     if (exp->getType() == props::STRING
-        || exp->getType() == props::UNSPECIFIED)
-        return new ExtensionSupportedExpression(exp->getStringValue());
+        || exp->getType() == props::UNSPECIFIED) {
+        ExtensionSupportedExpression* esp
+            = new ExtensionSupportedExpression(exp->getStringValue());
+        int location = parser->getBindingLayout().addBinding("__contextId",
+                                                             expression::INT);
+        VariableExpression<int>* contextExp
+            = new VariableExpression<int>(location);
+        esp->addOperand(contextExp);
+        return esp;
+    }
     throw expression::ParseError("extension-supported expression has wrong type");
 }
 
@@ -270,11 +288,6 @@ void Technique::setGLExtensionsPred(float glVersion,
     SGExpression<bool>* versionTest
         = makePredicate<std::less_equal>(new SGConstExpression<float>(glVersion),
                         new GLVersionExpression);
-#if 0
-    LessEqualExpression<float>* versionTest
-        = new LessEqualExpression<float>(new SGConstExpression<float>(glVersion),
-                                         new GLVersionExpression);
-#endif
     AndExpression* extensionsExp = 0;
     for (vector<string>::const_iterator itr = extensions.begin(),
              e = extensions.end();
@@ -299,6 +312,16 @@ void Technique::setGLExtensionsPred(float glVersion,
     setValidExpression(predicate, layout);
 }
 
+void Technique::refreshValidity()
+{
+    for (int i = 0; i < (int)_contextMap.size(); ++i) {
+        ContextInfo& info = _contextMap[i];
+        Status oldVal = info.valid();
+        // What happens if we lose the race here?
+        info.valid.compareAndSwap(oldVal, UNKNOWN);
+    }
+}
+
 bool Technique_writeLocalData(const Object& obj, osgDB::Output& fw)
 {
     const Technique& tniq = static_cast<const Technique&>(obj);