Add osgobjectcache example.

This commit is contained in:
Ralf Habacker 2016-06-17 17:45:06 +02:00 committed by Robert Osfield
parent e499333036
commit fff9cd7d38
3 changed files with 73 additions and 0 deletions

View File

@ -75,6 +75,7 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgmultitexturecontrol)
ADD_SUBDIRECTORY(osgmultitouch)
ADD_SUBDIRECTORY(osgmultiviewpaging)
ADD_SUBDIRECTORY(osgobjectcache)
ADD_SUBDIRECTORY(osgoccluder)
ADD_SUBDIRECTORY(osgocclusionquery)
ADD_SUBDIRECTORY(osgoit)

View File

@ -0,0 +1,7 @@
#this file is automatically generated
SET(TARGET_SRC osgobjectcache.cpp )
SET(TARGET_EXTERNAL_LIBRARIES ${OPENGL_LIBRARIES} )
#### end var setup ###
SETUP_EXAMPLE(osgobjectcache)

View File

@ -0,0 +1,65 @@
/* OpenSceneGraph example, osgobjectcache.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
osg::Group* createObjectCache()
{
osg::Group* group = new osg::Group();
if (osgDB::Registry::instance()->getOptions()==0)
osgDB::Registry::instance()->setOptions(new osgDB::Options());
osgDB::Registry::instance()->getOptions()->setObjectCacheHint(osgDB::Options::CACHE_ALL);
osg::ref_ptr<osgDB::Options> options1 = new osgDB::Options("a=1 b=2 c=3");
options1->setObjectCacheHint(osgDB::Options::CACHE_ALL);
osg::ref_ptr<osgDB::Options> options2 = new osgDB::Options("a=6 b=7 c=8");
options2->setObjectCacheHint(osgDB::Options::CACHE_ALL);
osg::ref_ptr<osgDB::Options> options3 = new osgDB::Options("b=7 a=6 c=8");
options3->setObjectCacheHint(osgDB::Options::CACHE_ALL);
osg::ref_ptr<osg::Node> node1 = osgDB::readRefNodeFile("cessna.osg");
osg::ref_ptr<osg::Node> node2 = osgDB::readRefNodeFile("cessna.osg", options1);
osg::ref_ptr<osg::Node> node3 = osgDB::readRefNodeFile("cessna.osg", options2);
osg::ref_ptr<osg::Node> node4 = osgDB::readRefNodeFile("cessna.osg", options1);
osg::ref_ptr<osg::Node> node5 = osgDB::readRefNodeFile("cessna.osg", options2);
osg::ref_ptr<osg::Node> node6 = osgDB::readRefNodeFile("cessna.osg", options3);
group->addChild(node1);
group->addChild(node2);
group->addChild(node3);
group->addChild(node4);
group->addChild(node5);
group->addChild(node6);
return group;
}
int main(int , char **)
{
// construct the viewer.
osgViewer::Viewer viewer;
// add model to viewer.
viewer.setSceneData(createObjectCache());
// create the windows and run the threads.
return viewer.run();
}