/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commercial and non commercial * applications, as long as this copyright notice is maintained. * * This application 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. */ #include #include #include #include #include #include using namespace osg; StateAttribute::StateAttribute() :Object(true) { } void StateAttribute::addParent(osg::StateSet* object) { OSG_DEBUG_FP<<"Adding parent"< lock(getRefMutex()); _parents.push_back(object); } void StateAttribute::removeParent(osg::StateSet* object) { OpenThreads::ScopedPointerLock lock(getRefMutex()); ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object); if (pitr!=_parents.end()) _parents.erase(pitr); } void StateAttribute::setUpdateCallback(StateAttributeCallback* uc) { OSG_DEBUG<<"StateAttribute::Setting Update callbacks"<setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta); } } } void StateAttribute::setEventCallback(StateAttributeCallback* ec) { OSG_DEBUG<<"StateAttribute::Setting Event callbacks"<setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta); } } } StateAttribute::ReassignToParents::ReassignToParents(osg::StateAttribute* attr) { if (!attr->isTextureAttribute() && !attr->getParents().empty()) { // take a reference to this clip plane to prevent it from going out of scope // when we remove it temporarily from its parents. attribute = attr; // copy the parents as they _parents list will be changed by the subsequent removeAttributes. parents = attr->getParents(); // remove this attribute from its parents as its position is being changed // and would no longer be valid. for(ParentList::iterator itr = parents.begin(); itr != parents.end(); ++itr) { osg::StateSet* stateset = *itr; stateset->removeAttribute(attr); OSG_NOTICE<<" Removed from parent "<setAttribute(attribute.get()); OSG_NOTICE<<" Added back to parent "<