| 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 | StateAttribute::StateAttribute() |
|---|
| 22 | :Object(true) |
|---|
| 23 | { |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | void StateAttribute::addParent(osg::StateSet* object) |
|---|
| 28 | { |
|---|
| 29 | OSG_DEBUG_FP<<"Adding parent"<<getRefMutex()<<std::endl; |
|---|
| 30 | OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex()); |
|---|
| 31 | |
|---|
| 32 | _parents.push_back(object); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void StateAttribute::removeParent(osg::StateSet* object) |
|---|
| 36 | { |
|---|
| 37 | OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex()); |
|---|
| 38 | |
|---|
| 39 | ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object); |
|---|
| 40 | if (pitr!=_parents.end()) _parents.erase(pitr); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | void StateAttribute::setUpdateCallback(StateAttributeCallback* uc) |
|---|
| 45 | { |
|---|
| 46 | OSG_INFO<<"StateAttribute::Setting Update callbacks"<<std::endl; |
|---|
| 47 | |
|---|
| 48 | if (_updateCallback==uc) return; |
|---|
| 49 | |
|---|
| 50 | int delta = 0; |
|---|
| 51 | if (_updateCallback.valid()) --delta; |
|---|
| 52 | if (uc) ++delta; |
|---|
| 53 | |
|---|
| 54 | _updateCallback = uc; |
|---|
| 55 | |
|---|
| 56 | if (delta!=0) |
|---|
| 57 | { |
|---|
| 58 | OSG_INFO<<"Going to set StateAttribute parents"<<std::endl; |
|---|
| 59 | |
|---|
| 60 | for(ParentList::iterator itr=_parents.begin(); |
|---|
| 61 | itr!=_parents.end(); |
|---|
| 62 | ++itr) |
|---|
| 63 | { |
|---|
| 64 | OSG_INFO<<" Setting StateAttribute parent"<<std::endl; |
|---|
| 65 | |
|---|
| 66 | (*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void StateAttribute::setEventCallback(StateAttributeCallback* ec) |
|---|
| 72 | { |
|---|
| 73 | OSG_INFO<<"StateAttribute::Setting Event callbacks"<<std::endl; |
|---|
| 74 | |
|---|
| 75 | if (_eventCallback==ec) return; |
|---|
| 76 | |
|---|
| 77 | int delta = 0; |
|---|
| 78 | if (_eventCallback.valid()) --delta; |
|---|
| 79 | if (ec) ++delta; |
|---|
| 80 | |
|---|
| 81 | _eventCallback = ec; |
|---|
| 82 | |
|---|
| 83 | if (delta!=0) |
|---|
| 84 | { |
|---|
| 85 | for(ParentList::iterator itr=_parents.begin(); |
|---|
| 86 | itr!=_parents.end(); |
|---|
| 87 | ++itr) |
|---|
| 88 | { |
|---|
| 89 | (*itr)->setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|