]> git.mxchange.org Git - simgear.git/commitdiff
Modified Files:
authorfrohlich <frohlich>
Sun, 28 Jan 2007 20:04:56 +0000 (20:04 +0000)
committerfrohlich <frohlich>
Sun, 28 Jan 2007 20:04:56 +0000 (20:04 +0000)
  model.cxx: Better texture sharing, fix problem with rotation order

simgear/scene/model/model.cxx

index f1d6144488006d6250932d32556ab217c878d2a5..7a35768a38000480bc42b3fa7658db7235ccf396 100644 (file)
@@ -7,8 +7,6 @@
 #include <simgear_config.h>
 #endif
 
-#include <string.h>             // for strcmp()
-
 #include <osg/observer_ptr>
 #include <osg/ref_ptr>
 #include <osg/Group>
@@ -346,7 +344,7 @@ osg::Texture2D*
 SGLoadTexture2D(const std::string& path, bool wrapu, bool wrapv, int)
 {
   osg::Image* image = osgDB::readImageFile(path);
-  osg::Texture2D* texture = new osg::Texture2D;
+  osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
   texture->setImage(image);
   if (wrapu)
     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
@@ -376,7 +374,28 @@ SGLoadTexture2D(const std::string& path, bool wrapu, bool wrapv, int)
       }
     }
   }
-  return texture;
+
+  // Make sure the texture is shared if we already have the same texture
+  // somewhere ...
+  {
+    osg::ref_ptr<osg::Node> tmpNode = new osg::Node;
+    osg::StateSet* stateSet = tmpNode->getOrCreateStateSet();
+    stateSet->setTextureAttribute(0, texture.get());
+
+    // OSGFIXME: don't forget that mutex here
+    osgDB::Registry* registry = osgDB::Registry::instance();
+    registry->getOrCreateSharedStateManager()->share(tmpNode.get(), 0);
+
+    // should be the same, but be paranoid ...
+    stateSet = tmpNode->getStateSet();
+    osg::StateAttribute* stateAttr;
+    stateAttr = stateSet->getTextureAttribute(0, osg::StateAttribute::TEXTURE);
+    osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(stateAttr);
+    if (texture2D)
+      texture = texture2D;
+  }
+
+  return texture.release();
 }
 
 class SGSwitchUpdateCallback : public osg::NodeCallback {
@@ -465,12 +484,12 @@ sgLoad3DModel( const string &fg_root, const string &path,
   alignmainmodel->addChild(model);
   osg::Matrix res_matrix;
   res_matrix.makeRotate(
-    props.getFloatValue("/offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-    osg::Vec3(0, 0, 1),
+    props.getFloatValue("/offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+    osg::Vec3(0, 1, 0),
     props.getFloatValue("/offsets/roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
     osg::Vec3(1, 0, 0),
-    props.getFloatValue("/offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-    osg::Vec3(0, 1, 0));
+    props.getFloatValue("/offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+    osg::Vec3(0, 0, 1));
 
   osg::Matrix tmat;
   tmat.makeTranslate(props.getFloatValue("/offsets/x-m", 0.0),
@@ -485,12 +504,12 @@ sgLoad3DModel( const string &fg_root, const string &path,
     osg::MatrixTransform* align = new osg::MatrixTransform;
     res_matrix.makeIdentity();
     res_matrix.makeRotate(
-      node->getDoubleValue("offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-      osg::Vec3(0, 0, 1),
+      node->getDoubleValue("offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+      osg::Vec3(0, 1, 0),
       node->getDoubleValue("offsets/roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
       osg::Vec3(1, 0, 0),
-      node->getDoubleValue("offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-      osg::Vec3(0, 1, 0));
+      node->getDoubleValue("offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+      osg::Vec3(0, 0, 1));
     
     tmat.makeIdentity();
     tmat.makeTranslate(node->getDoubleValue("offsets/x-m", 0),