]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/shadanim.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / model / shadanim.cxx
index 1eae56de7602523f5bf8016ff4c445ee4f963df3..ea1f1c2617479af9b37c965874d634fa1e5e5a3a 100644 (file)
 #include <osg/Texture1D>
 #include <osgUtil/HighlightMapGenerator>
 
+#include <OpenThreads/Mutex>
+#include <OpenThreads/ScopedLock>
+
 #include <simgear/scene/util/SGUpdateVisitor.hxx>
-#include <simgear/threads/SGThread.hxx>
-#include <simgear/threads/SGGuard.hxx>
 
 #include <simgear/props/condition.hxx>
 #include <simgear/props/props.hxx>
 
 #include "animation.hxx"
 #include "model.hxx"
+
+using OpenThreads::Mutex;
+using OpenThreads::ScopedLock;
+
 /*
     <animation>
         <type>shader</type>
@@ -102,8 +107,8 @@ public:
     // FIXME: need an update or callback ...
     // generate the six highlight map images (light direction = [1, 1, -1])
     osg::ref_ptr<osgUtil::HighlightMapGenerator> mapgen;
-    mapgen = new osgUtil::HighlightMapGenerator(_lastLightDirection.osg(),
-                                                _lastLightColor.osg(), 5);
+    mapgen = new osgUtil::HighlightMapGenerator(toOsg(_lastLightDirection),
+                                                toOsg(_lastLightColor), 5);
     mapgen->generateMap();
 
     // assign the six images to the texture object
@@ -125,6 +130,9 @@ private:
   SGVec4f _lastLightColor;
 };
 
+static Mutex cubeMutex;
+
+#if 0
 static osg::TextureCubeMap*
 getOrCreateTextureCubeMap()
 {
@@ -132,8 +140,7 @@ getOrCreateTextureCubeMap()
   if (textureCubeMap.get())
     return textureCubeMap.get();
 
-  static SGMutex mutex;
-  SGGuard<SGMutex> locker(mutex);
+  ScopedLock<Mutex> lock(cubeMutex);
   if (textureCubeMap.get())
     return textureCubeMap.get();
 
@@ -175,11 +182,12 @@ static void create_specular_highlights(osg::Node *node)
   te->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);
   ss->setTextureAttributeAndModes(0, te, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
 }
+#endif
 
 
 SGShaderAnimation::SGShaderAnimation(const SGPropertyNode* configNode,
                                      SGPropertyNode* modelRoot,
-                                     const osgDB::ReaderWriter::Options*
+                                     const osgDB::Options*
                                      options) :
   SGAnimation(configNode, modelRoot)
 {
@@ -201,8 +209,8 @@ public:
     if (!combine)
        return;
     // An approximation for light reflected back by chrome.
-    osg::Vec4 globalColor = (updateVisitor->getAmbientLight().osg() * .4f
-                            + updateVisitor->getDiffuseLight().osg());
+    osg::Vec4 globalColor = toOsg(updateVisitor->getAmbientLight() * .4f
+                                  + updateVisitor->getDiffuseLight());
     globalColor.a() = 1.0f;
     combine->setConstantColor(globalColor);
   }
@@ -212,13 +220,14 @@ typedef std::map<osg::ref_ptr<osg::Texture2D>, osg::ref_ptr<osg::StateSet> >
 StateSetMap;
 }
 
+static Mutex chromeMutex;
+
 // The chrome effect is mixed by the alpha channel of the texture
 // on the model, which will be attached to a node lower in the scene
 // graph: 0 -> completely chrome, 1 -> completely model texture.
 static void create_chrome(osg::Group* group, osg::Texture2D* texture)
 {
-    static SGMutex mutex;
-    SGGuard<SGMutex> locker(mutex);
+    ScopedLock<Mutex> lock(chromeMutex);
     static StateSetMap chromeMap;
     osg::StateSet *stateSet;
     StateSetMap::iterator iterator = chromeMap.find(texture);