/* -*-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(unsigned int mode): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { setShareMode(mode); _mutex=0; } void SharedStateManager::setShareMode(unsigned int mode) { _shareMode = mode; _shareTexture[osg::Object::DYNAMIC] = (_shareMode & SHARE_DYNAMIC_TEXTURES)!=0; _shareTexture[osg::Object::STATIC] = (_shareMode & SHARE_STATIC_TEXTURES)!=0; _shareTexture[osg::Object::UNSPECIFIED] = (_shareMode & SHARE_UNSPECIFIED_TEXTURES)!=0; _shareStateSet[osg::Object::DYNAMIC] = (_shareMode & SHARE_DYNAMIC_STATESETS)!=0; _shareStateSet[osg::Object::STATIC] = (_shareMode & SHARE_STATIC_STATESETS)!=0; _shareStateSet[osg::Object::UNSPECIFIED] = (_shareMode & SHARE_UNSPECIFIED_STATESETS)!=0; } //---------------------------------------------------------------- // SharedStateManager::prune //---------------------------------------------------------------- void SharedStateManager::prune() { StateSetSet::iterator sitr; OpenThreads::ScopedLock lock(_listMutex); for(sitr=_sharedStateSetList.begin(); sitr!=_sharedStateSetList.end();) { if ((*sitr)->referenceCount()<=1) _sharedStateSetList.erase(sitr++); else ++sitr; } TextureSet::iterator titr; for(titr=_sharedTextureList.begin(); titr!=_sharedTextureList.end();) { if ((*titr)->referenceCount()<=1) _sharedTextureList.erase(titr++); else ++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; node->accept(*this); tmpSharedTextureList.clear(); tmpSharedStateSetList.clear(); _mutex = 0; // osg::Timer_t end_tick = timer.tick(); // std::cout << "SHARING TIME = "<