root/OpenSceneGraph/trunk/src/osg/StateAttribute.cpp @ 13041

Revision 13041, 2.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This application is open source and may be redistributed and/or modified
4 * freely and without restriction, both in commercial and non commercial
5 * applications, as long as this copyright notice is maintained.
6 *
7 * This application is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10*/
11
12#include <osg/StateAttribute>
13#include <osg/StateSet>
14#include <osg/State>
15#include <osg/Notify>
16
17#include <algorithm>
18
19using namespace osg;
20
21StateAttribute::StateAttribute()
22    :Object(true)
23{
24}
25
26
27void 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
35void 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
44void 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
71void 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}
Note: See TracBrowser for help on using the browser.