From d4030e72e46618250f66bca1994e7b362b9b4176 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 18 Feb 2014 19:58:19 -0800 Subject: [PATCH] Runtime VBO option in BTG loading. --- simgear/scene/tgdb/SGTexturedTriangleBin.hxx | 10 +++++++--- simgear/scene/tgdb/obj.cxx | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx index 3ab6153c..777ee41f 100644 --- a/simgear/scene/tgdb/SGTexturedTriangleBin.hxx +++ b/simgear/scene/tgdb/SGTexturedTriangleBin.hxx @@ -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 { diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 4a9d8b59..05b88f85 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -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);