/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include using namespace osgDB; SharedStateManager::SharedStateManager(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { shareMode = SHARE_TEXTURES; //shareMode = SHARE_STATESETS; mutex=0; } //---------------------------------------------------------------- // SharedStateManager::prune //---------------------------------------------------------------- void SharedStateManager::prune() { StateSetSet::iterator sitr, sitr1; for(sitr=_sharedStateSetList.begin(); sitr!=_sharedStateSetList.end(); sitr=sitr1) { sitr1=sitr; ++sitr1; if((*sitr)->referenceCount()<=1) _sharedStateSetList.erase(sitr); } TextureSet::iterator titr, titr1; for(titr=_sharedTextureList.begin(); titr!=_sharedTextureList.end(); titr=titr1) { titr1=titr; ++titr1; if((*titr)->referenceCount()<=1) _sharedTextureList.erase(titr); } } //---------------------------------------------------------------- // SharedStateManager::share //---------------------------------------------------------------- void SharedStateManager::share(osg::Node *node, OpenThreads::Mutex *mt) { // const osg::Timer& timer = *osg::Timer::instance(); // osg::Timer_t start_tick = timer.tick(); mutex = mt; apply(*node); tmpSharedTextureList.clear(); tmpSharedStateSetList.clear(); mutex = 0; // osg::Timer_t end_tick = timer.tick(); // std::cout << "SHARING TIME = "<