From fff9cd7d38e64bddb4e4c89e66d0ee804911d10e Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 17 Jun 2016 17:45:06 +0200 Subject: [PATCH] Add osgobjectcache example. --- examples/CMakeLists.txt | 1 + examples/osgobjectcache/CMakeLists.txt | 7 +++ examples/osgobjectcache/osgobjectcache.cpp | 65 ++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 examples/osgobjectcache/CMakeLists.txt create mode 100644 examples/osgobjectcache/osgobjectcache.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 44ca77f60..39dcadabf 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) diff --git a/examples/osgobjectcache/CMakeLists.txt b/examples/osgobjectcache/CMakeLists.txt new file mode 100644 index 000000000..f3eed1314 --- /dev/null +++ b/examples/osgobjectcache/CMakeLists.txt @@ -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) diff --git a/examples/osgobjectcache/osgobjectcache.cpp b/examples/osgobjectcache/osgobjectcache.cpp new file mode 100644 index 000000000..2e992a6e0 --- /dev/null +++ b/examples/osgobjectcache/osgobjectcache.cpp @@ -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 +#include + +#include + + +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 options1 = new osgDB::Options("a=1 b=2 c=3"); + options1->setObjectCacheHint(osgDB::Options::CACHE_ALL); + osg::ref_ptr options2 = new osgDB::Options("a=6 b=7 c=8"); + options2->setObjectCacheHint(osgDB::Options::CACHE_ALL); + osg::ref_ptr options3 = new osgDB::Options("b=7 a=6 c=8"); + options3->setObjectCacheHint(osgDB::Options::CACHE_ALL); + osg::ref_ptr node1 = osgDB::readRefNodeFile("cessna.osg"); + osg::ref_ptr node2 = osgDB::readRefNodeFile("cessna.osg", options1); + osg::ref_ptr node3 = osgDB::readRefNodeFile("cessna.osg", options2); + osg::ref_ptr node4 = osgDB::readRefNodeFile("cessna.osg", options1); + osg::ref_ptr node5 = osgDB::readRefNodeFile("cessna.osg", options2); + osg::ref_ptr 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(); +}