| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include <osg/StateAttribute> |
|---|
| 13 | #include <osg/StateSet> |
|---|
| 14 | #include <osg/State> |
|---|
| 15 | #include <osg/Notify> |
|---|
| 16 | |
|---|
| 17 | #include <algorithm> |
|---|
| 18 | |
|---|
| 19 | using namespace osg; |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | StateAttribute::StateAttribute() |
|---|
| 23 | :Object(true) |
|---|
| 24 | { |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | void StateAttribute::addParent(osg::StateSet* object) |
|---|
| 29 | { |
|---|
| 30 | osg::notify(osg::DEBUG_FP)<<"Adding parent"<<getRefMutex()<<std::endl; |
|---|
| 31 | OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex()); |
|---|
| 32 | |
|---|
| 33 | _parents.push_back(object); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | void StateAttribute::removeParent(osg::StateSet* object) |
|---|
| 37 | { |
|---|
| 38 | OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex()); |
|---|
| 39 | |
|---|
| 40 | ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object); |
|---|
| 41 | if (pitr!=_parents.end()) _parents.erase(pitr); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | void StateAttribute::setUpdateCallback(StateAttributeCallback* uc) |
|---|
| 46 | { |
|---|
| 47 | osg::notify(osg::INFO)<<"StateAttribute::Setting Update callbacks"<<std::endl; |
|---|
| 48 | |
|---|
| 49 | if (_updateCallback==uc) return; |
|---|
| 50 | |
|---|
| 51 | int delta = 0; |
|---|
| 52 | if (_updateCallback.valid()) --delta; |
|---|
| 53 | if (uc) ++delta; |
|---|
| 54 | |
|---|
| 55 | _updateCallback = uc; |
|---|
| 56 | |
|---|
| 57 | if (delta!=0) |
|---|
| 58 | { |
|---|
| 59 | osg::notify(osg::INFO)<<"Going to set StateAttribute parents"<<std::endl; |
|---|
| 60 | |
|---|
| 61 | for(ParentList::iterator itr=_parents.begin(); |
|---|
| 62 | itr!=_parents.end(); |
|---|
| 63 | ++itr) |
|---|
| 64 | { |
|---|
| 65 | osg::notify(osg::INFO)<<" Setting StateAttribute parent"<<std::endl; |
|---|
| 66 | |
|---|
| 67 | (*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void StateAttribute::setEventCallback(StateAttributeCallback* ec) |
|---|
| 73 | { |
|---|
| 74 | osg::notify(osg::INFO)<<"StateAttribute::Setting Event callbacks"<<std::endl; |
|---|
| 75 | |
|---|
| 76 | if (_eventCallback==ec) return; |
|---|
| 77 | |
|---|
| 78 | int delta = 0; |
|---|
| 79 | if (_eventCallback.valid()) --delta; |
|---|
| 80 | if (ec) ++delta; |
|---|
| 81 | |
|---|
| 82 | _eventCallback = ec; |
|---|
| 83 | |
|---|
| 84 | if (delta!=0) |
|---|
| 85 | { |
|---|
| 86 | for(ParentList::iterator itr=_parents.begin(); |
|---|
| 87 | itr!=_parents.end(); |
|---|
| 88 | ++itr) |
|---|
| 89 | { |
|---|
| 90 | (*itr)->setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | } |
|---|