diff --git a/include/osg/CopyOp b/include/osg/CopyOp index d96445404..eff881fee 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -24,6 +24,7 @@ class Image; class Texture; class StateSet; class StateAttribute; +class StateAttributeCallback; class Uniform; class Node; class Drawable; @@ -32,6 +33,7 @@ class PrimitiveSet; class Shape; class NodeCallback; + /** Copy Op(erator) used to control whether shallow or deep copy is used * during copy construction and clone operation.*/ class OSG_EXPORT CopyOp @@ -53,7 +55,7 @@ class OSG_EXPORT CopyOp DEEP_COPY_PRIMITIVES = 1<<8, DEEP_COPY_SHAPES = 1<<9, DEEP_COPY_UNIFORMS = 1<<10, - DEEP_COPY_NODECALLBACKS = 1<<11, + DEEP_COPY_CALLBACKS = 1<<11, DEEP_COPY_ALL = 0x7FFFFFFF }; @@ -75,6 +77,7 @@ class OSG_EXPORT CopyOp virtual Shape* operator() (const Shape* shape) const; virtual Uniform* operator() (const Uniform* shape) const; virtual NodeCallback* operator() (const NodeCallback* nodecallback) const; + virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const; protected: diff --git a/include/osg/ImageSequence b/include/osg/ImageSequence index a8f15dcb3..822bd2156 100644 --- a/include/osg/ImageSequence +++ b/include/osg/ImageSequence @@ -105,7 +105,7 @@ class OSG_EXPORT ImageSequence : public ImageStream virtual void update(NodeVisitor* nv); - struct OSG_EXPORT UpdateCallback : public osg::StateAttribute::Callback + struct OSG_EXPORT UpdateCallback : public osg::StateAttributeCallback { virtual void operator () (osg::StateAttribute* attr, osg::NodeVisitor* nv); }; diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index d4c75b241..42f617616 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -190,7 +191,9 @@ class OSG_EXPORT StateAttribute : public Object StateAttribute(); StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Object(sa,copyop) {} + Object(sa,copyop), + _updateCallback(copyop(sa._updateCallback.get())) + {} /** Clone the type of an attribute, with Object* return type. @@ -281,37 +284,28 @@ class OSG_EXPORT StateAttribute : public Object // default to no black listed GLMode's associated with use of the StateAttribute. return true; } - - struct Callback : public virtual osg::Object - { - Callback() {} - Callback(const Callback&,const CopyOp&) {} - - META_Object(osg,Callback); - - /** do customized update code.*/ - virtual void operator () (StateAttribute*, NodeVisitor*) {} - }; + // provide callback for backwards compatibility. + typedef osg::StateAttributeCallback Callback; /** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal.*/ - void setUpdateCallback(Callback* uc); + void setUpdateCallback(StateAttributeCallback* uc); /** Get the non const UpdateCallback.*/ - Callback* getUpdateCallback() { return _updateCallback.get(); } + StateAttributeCallback* getUpdateCallback() { return _updateCallback.get(); } /** Get the const UpdateCallback.*/ - const Callback* getUpdateCallback() const { return _updateCallback.get(); } + const StateAttributeCallback* getUpdateCallback() const { return _updateCallback.get(); } /** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/ - void setEventCallback(Callback* ec); + void setEventCallback(StateAttributeCallback* ec); /** Get the non const EventCallback.*/ - Callback* getEventCallback() { return _eventCallback.get(); } + StateAttributeCallback* getEventCallback() { return _eventCallback.get(); } /** Get the const EventCallback.*/ - const Callback* getEventCallback() const { return _eventCallback.get(); } + const StateAttributeCallback* getEventCallback() const { return _eventCallback.get(); } /** apply the OpenGL state attributes. @@ -343,8 +337,8 @@ class OSG_EXPORT StateAttribute : public Object ParentList _parents; friend class osg::StateSet; - ref_ptr _updateCallback; - ref_ptr _eventCallback; + ref_ptr _updateCallback; + ref_ptr _eventCallback; }; } diff --git a/include/osgAnimation/UpdateCallback b/include/osgAnimation/UpdateCallback index 45c06e7dd..75296cdf0 100644 --- a/include/osgAnimation/UpdateCallback +++ b/include/osgAnimation/UpdateCallback @@ -36,8 +36,6 @@ namespace osgAnimation virtual int link(osgAnimation::Animation* animation) = 0; virtual void updateLink() = 0; virtual const std::string& getName() const = 0; - - virtual ~AnimationUpdateCallbackBase() {} }; template @@ -130,7 +128,7 @@ namespace osgAnimation - class OSGANIMATION_EXPORT UpdateMaterial : public AnimationUpdateCallback + class OSGANIMATION_EXPORT UpdateMaterial : public AnimationUpdateCallback { protected: osg::ref_ptr _diffuse; @@ -147,6 +145,7 @@ namespace osgAnimation void update(osg::Material& material); bool needLink() const; bool link(osgAnimation::Channel* channel); + osgAnimation::Vec4Target* getDiffuse(); }; } diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index 91f4e2a1f..02dde57f4 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -140,6 +140,7 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/ShapeDrawable ${HEADER_PATH}/State ${HEADER_PATH}/StateAttribute + ${HEADER_PATH}/StateAttributeCallback ${HEADER_PATH}/StateSet ${HEADER_PATH}/Stats ${HEADER_PATH}/Stencil diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index b71dcd9f4..36469a331 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace osg; @@ -67,7 +68,7 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const NodeCallback* CopyOp::operator() (const NodeCallback* nc) const { - if (nc && _flags&DEEP_COPY_NODECALLBACKS) + if (nc && _flags&DEEP_COPY_CALLBACKS) { // deep copy the full chain of callback osg::NodeCallback* first = dynamic_cast(nc->clone(*this)); @@ -85,3 +86,17 @@ NodeCallback* CopyOp::operator() (const NodeCallback* nc) const else return const_cast(nc); } + + +StateAttributeCallback* CopyOp::operator() (const StateAttributeCallback* sc) const +{ + if (sc && _flags&DEEP_COPY_CALLBACKS) + { + // deep copy the full chain of callback + StateAttributeCallback* cb = dynamic_cast(sc->clone(*this)); + return cb; + } + else + return const_cast(sc); +} + diff --git a/src/osg/StateAttribute.cpp b/src/osg/StateAttribute.cpp index 0501c17c3..06746975e 100644 --- a/src/osg/StateAttribute.cpp +++ b/src/osg/StateAttribute.cpp @@ -42,7 +42,7 @@ void StateAttribute::removeParent(osg::StateSet* object) } -void StateAttribute::setUpdateCallback(Callback* uc) +void StateAttribute::setUpdateCallback(StateAttributeCallback* uc) { osg::notify(osg::INFO)<<"StateAttribute::Setting Update callbacks"<second.first->getUpdateCallback(); + StateAttributeCallback* callback = itr->second.first->getUpdateCallback(); if (callback) (*callback)(itr->second.first.get(),nv); } @@ -1686,7 +1686,7 @@ void StateSet::runUpdateCallbacks(osg::NodeVisitor* nv) itr!=attributeList.end(); ++itr) { - StateAttribute::Callback* callback = itr->second.first->getUpdateCallback(); + StateAttributeCallback* callback = itr->second.first->getUpdateCallback(); if (callback) (*callback)(itr->second.first.get(),nv); } } @@ -1747,7 +1747,7 @@ void StateSet::runEventCallbacks(osg::NodeVisitor* nv) itr!=_attributeList.end(); ++itr) { - StateAttribute::Callback* callback = itr->second.first->getEventCallback(); + StateAttributeCallback* callback = itr->second.first->getEventCallback(); if (callback) (*callback)(itr->second.first.get(),nv); } @@ -1760,7 +1760,7 @@ void StateSet::runEventCallbacks(osg::NodeVisitor* nv) itr!=attributeList.end(); ++itr) { - StateAttribute::Callback* callback = itr->second.first->getEventCallback(); + StateAttributeCallback* callback = itr->second.first->getEventCallback(); if (callback) (*callback)(itr->second.first.get(),nv); } } diff --git a/src/osgAnimation/UpdateCallback.cpp b/src/osgAnimation/UpdateCallback.cpp index 94098a6cc..8b66fd2f3 100644 --- a/src/osgAnimation/UpdateCallback.cpp +++ b/src/osgAnimation/UpdateCallback.cpp @@ -122,13 +122,13 @@ bool UpdateTransform::link(osgAnimation::Channel* channel) UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop) : osg::Object(apc, copyop), - AnimationUpdateCallback(apc, copyop) + AnimationUpdateCallback(apc, copyop) { _diffuse = new osgAnimation::Vec4Target(apc._diffuse->getValue()); } UpdateMaterial::UpdateMaterial(const std::string& name): - AnimationUpdateCallback(name) + AnimationUpdateCallback(name) { _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1)); } @@ -144,6 +144,8 @@ void UpdateMaterial::operator()(osg::StateAttribute* sa, osg::NodeVisitor* nv) } } + +osgAnimation::Vec4Target* UpdateMaterial::getDiffuse() { return _diffuse.get(); } void UpdateMaterial::update(osg::Material& material) { osg::Vec4 diffuse = _diffuse->getValue(); diff --git a/src/osgPlugins/osg/StateAttribute.cpp b/src/osgPlugins/osg/StateAttribute.cpp index 69293a834..57d7845a4 100644 --- a/src/osgPlugins/osg/StateAttribute.cpp +++ b/src/osgPlugins/osg/StateAttribute.cpp @@ -29,12 +29,12 @@ bool StateAttribute_readLocalData(Object& obj, Input& fr) bool iteratorAdvanced = false; StateAttribute& stateAttribute = static_cast(obj); - static ref_ptr s_callback = new osg::StateAttribute::Callback; + static ref_ptr s_callback = new osg::StateAttributeCallback; while (fr.matchSequence("UpdateCallback {")) { //int entry = fr[0].getNoNestedBrackets(); fr += 2; - StateAttribute::Callback* callback = dynamic_cast(fr.readObjectOfType(*s_callback)); + StateAttributeCallback* callback = dynamic_cast(fr.readObjectOfType(*s_callback)); if (callback) { stateAttribute.setUpdateCallback(callback); } @@ -45,7 +45,7 @@ bool StateAttribute_readLocalData(Object& obj, Input& fr) { //int entry = fr[0].getNoNestedBrackets(); fr += 2; - StateAttribute::Callback* callback = dynamic_cast(fr.readObjectOfType(*s_callback)); + StateAttributeCallback* callback = dynamic_cast(fr.readObjectOfType(*s_callback)); if (callback) { stateAttribute.setEventCallback(callback); }