Added --static and --vbo options to allow the user to toggle on/off dynamic updating

of geometry and use of vertex buffer objects.
This commit is contained in:
Robert Osfield 2007-04-25 15:32:33 +00:00
parent e316a8617c
commit 2ca0075426

View File

@ -13,6 +13,7 @@
#include <osgUtil/Optimizer> #include <osgUtil/Optimizer>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osgViewer/StatsHandler>
#include <iostream> #include <iostream>
@ -87,7 +88,7 @@ class UniformVarying : public osg::Uniform::Callback
} }
}; };
osg::Node* createModel(const std::string& shader, const std::string& textureFileName, const std::string& terrainFileName) osg::Node* createModel(const std::string& shader, const std::string& textureFileName, const std::string& terrainFileName, bool dynamic, bool vbo)
{ {
osg::Geode* geode = new osg::Geode; osg::Geode* geode = new osg::Geode;
@ -112,9 +113,16 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
program->addShader(vertex_shader); program->addShader(vertex_shader);
osg::Uniform* coeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f)); osg::Uniform* coeff = new osg::Uniform("coeff",osg::Vec4(1.0,-1.0f,-1.0f,1.0f));
coeff->setUpdateCallback(new UniformVarying);
stateset->addUniform(coeff); stateset->addUniform(coeff);
stateset->setDataVariance(osg::Object::DYNAMIC);
if (dynamic)
{
coeff->setUpdateCallback(new UniformVarying);
coeff->setDataVariance(osg::Object::DYNAMIC);
stateset->setDataVariance(osg::Object::DYNAMIC);
}
} }
else if (shader=="matrix") else if (shader=="matrix")
{ {
@ -225,7 +233,7 @@ osg::Node* createModel(const std::string& shader, const std::string& textureFile
geom->addPrimitiveSet(elements); geom->addPrimitiveSet(elements);
} }
// geom->setUseVertexBufferObjects(true); geom->setUseVertexBufferObjects(vbo);
return geode; return geode;
} }
@ -243,6 +251,9 @@ int main(int argc, char *argv[])
// construct the viewer. // construct the viewer.
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
// add the stats handler
viewer.addEventHandler(new osgViewer::StatsHandler);
std::string shader("simple"); std::string shader("simple");
while(arguments.read("-s",shader)) {} while(arguments.read("-s",shader)) {}
@ -252,6 +263,12 @@ int main(int argc, char *argv[])
std::string terrainFileName(""); std::string terrainFileName("");
while(arguments.read("-d",terrainFileName)) {} while(arguments.read("-d",terrainFileName)) {}
bool dynamic = true;
while(arguments.read("--static")) { dynamic = false; }
bool vbo = false;
while(arguments.read("--vbo")) { vbo = true; }
// if user request help write it out to cout. // if user request help write it out to cout.
if (arguments.read("-h") || arguments.read("--help")) if (arguments.read("-h") || arguments.read("--help"))
{ {
@ -260,7 +277,7 @@ int main(int argc, char *argv[])
} }
// load the nodes from the commandline arguments. // load the nodes from the commandline arguments.
osg::Node* model = createModel(shader,textureFileName,terrainFileName); osg::Node* model = createModel(shader,textureFileName,terrainFileName, dynamic, vbo);
if (!model) if (!model)
{ {
return 1; return 1;