]> git.mxchange.org Git - simgear.git/commitdiff
Runtime VBO option in BTG loading.
authorJames Turner <zakalawe@mac.com>
Wed, 19 Feb 2014 03:58:19 +0000 (19:58 -0800)
committerJames Turner <zakalawe@mac.com>
Wed, 19 Feb 2014 03:58:19 +0000 (19:58 -0800)
simgear/scene/tgdb/SGTexturedTriangleBin.hxx
simgear/scene/tgdb/obj.cxx

index 3ab6153c891cb282bfafb918c143c7e15eb63acf..777ee41fc085cf81469e0040b7541514c6e8744c 100644 (file)
@@ -315,7 +315,7 @@ public:
     }
   }
 
-  osg::Geometry* buildGeometry(const TriangleVector& triangles) const
+  osg::Geometry* buildGeometry(const TriangleVector& triangles, bool useVBOs) const
   {
     // Do not build anything if there is nothing in here ...
     if (empty() || triangles.empty())
@@ -330,6 +330,10 @@ public:
     colors->push_back(osg::Vec4(1, 1, 1, 1));
 
     osg::Geometry* geometry = new osg::Geometry;
+    geometry->setUseDisplayList(false);
+    if (useVBOs) 
+        geometry->setUseVertexBufferObjects(true);
+    
     geometry->setDataVariance(osg::Object::STATIC);
     geometry->setVertexArray(vertices);
     geometry->setNormalArray(normals);
@@ -373,8 +377,8 @@ public:
     return geometry;
   }
 
-  osg::Geometry* buildGeometry() const
-  { return buildGeometry(getTriangles()); }
+  osg::Geometry* buildGeometry(bool useVBOs) const
+  { return buildGeometry(getTriangles(), useVBOs); }
   
   int getTextureIndex() const
   {
index 4a9d8b5957d1f0e36682620090bc109fa93e5baf..05b88f85e8096546ce9b4382256c19840d7cca18 100644 (file)
@@ -95,7 +95,7 @@ public:
   SGDirectionalLightListBin reilLights;
   SGMatModelBin randomModels;
   SGBuildingBinList randomBuildings;
-
+  
   static SGVec4f
   getMaterialLightColor(const SGMaterial* material)
   {
@@ -387,7 +387,7 @@ public:
     return true;
   }
 
-  osg::Node* getSurfaceGeometry(SGMaterialLib* matlib) const
+  osg::Node* getSurfaceGeometry(SGMaterialLib* matlib, bool useVBOs) const
   {
     if (materialTriangleMap.empty())
       return 0;
@@ -397,7 +397,7 @@ public:
     //osg::Geode* geode = new osg::Geode;
     SGMaterialTriangleMap::const_iterator i;
     for (i = materialTriangleMap.begin(); i != materialTriangleMap.end(); ++i) {
-      osg::Geometry* geometry = i->second.buildGeometry();
+      osg::Geometry* geometry = i->second.buildGeometry(useVBOs);
       SGMaterial *mat = 0;
       if (matlib)
         mat = matlib->findCached(i->first);
@@ -1187,6 +1187,8 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
       matlib = options->getMaterialLib();
     }
 
+    bool useVBOs = (options->getPluginStringData("SimGear::USE_VBOS") == "ON");
+
     SGVec3d center = tile.get_gbs_center();
     SGGeod geodPos = SGGeod::fromCart(center);
     SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180);
@@ -1212,7 +1214,7 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
     osg::Group* terrainGroup = new osg::Group;
     terrainGroup->setName("BTGTerrainGroup");
 
-    osg::Node* node = tileGeometryBin->getSurfaceGeometry(matlib);
+    osg::Node* node = tileGeometryBin->getSurfaceGeometry(matlib, useVBOs);
     if (node)
       terrainGroup->addChild(node);