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

Revision 10671, 2.5 kB (checked in by robert, 5 years ago)

From Cedric Pinson, "Here a patch to be able to clone stateattribute, in order to do that i
moved the StateAttribute::Callback structure to a file
StateAttributeCallback? with the same behavior as NodeCallback?.
"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5328]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[4091]2 *
3 * This application is open source and may be redistributed and/or modified   
4 * freely and without restriction, both in commericial and non commericial
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>
[4094]13#include <osg/StateSet>
[5573]14#include <osg/State>
[4094]15#include <osg/Notify>
[4091]16
17#include <algorithm>
18
19using namespace osg;
20
[7263]21
22StateAttribute::StateAttribute()
23    :Object(true)
24{
25}
26
27
[4091]28void StateAttribute::addParent(osg::StateSet* object)
29{
[9354]30    osg::notify(osg::DEBUG_FP)<<"Adding parent"<<getRefMutex()<<std::endl;
[9023]31    OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());
32   
[4091]33    _parents.push_back(object);
34}
35
36void StateAttribute::removeParent(osg::StateSet* object)
37{
[9023]38    OpenThreads::ScopedPointerLock<OpenThreads::Mutex> lock(getRefMutex());
39   
[4091]40    ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),object);
41    if (pitr!=_parents.end()) _parents.erase(pitr);
42}
[4094]43
44
[10671]45void StateAttribute::setUpdateCallback(StateAttributeCallback* uc)
[4094]46{
[4096]47    osg::notify(osg::INFO)<<"StateAttribute::Setting Update callbacks"<<std::endl;
[4094]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    {
[4096]59        osg::notify(osg::INFO)<<"Going to set StateAttribute parents"<<std::endl;
[4094]60
61        for(ParentList::iterator itr=_parents.begin();
62            itr!=_parents.end();
63            ++itr)
64        {
[4096]65            osg::notify(osg::INFO)<<"   Setting StateAttribute parent"<<std::endl;
66
[4094]67            (*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
68        }
69    }
70}
71
[10671]72void StateAttribute::setEventCallback(StateAttributeCallback* ec)
[4094]73{
[4096]74    osg::notify(osg::INFO)<<"StateAttribute::Setting Event callbacks"<<std::endl;
[4094]75
[4258]76    if (_eventCallback==ec) return;
[4094]77   
78    int delta = 0;
[4258]79    if (_eventCallback.valid()) --delta;
[4094]80    if (ec) ++delta;
81
[4258]82    _eventCallback = ec;
[4094]83   
84    if (delta!=0)
85    {
86        for(ParentList::iterator itr=_parents.begin();
87            itr!=_parents.end();
88            ++itr)
89        {
[4258]90            (*itr)->setNumChildrenRequiringEventTraversal((*itr)->getNumChildrenRequiringEventTraversal()+delta);
[4094]91        }
92    }
93}
Note: See TracBrowser for help on using the browser.