diff --git a/include/osg/Callback b/include/osg/Callback index 5f67cd18d..9dae40985 100644 --- a/include/osg/Callback +++ b/include/osg/Callback @@ -207,6 +207,26 @@ class OSG_EXPORT StateAttributeCallback : public virtual osg::Callback virtual void operator () (StateAttribute*, NodeVisitor*) {} }; +// forward declare +class Uniform; + +/** Deprecated. */ +class OSG_EXPORT UniformCallback : public virtual osg::Callback +{ +public: + UniformCallback() {} + + UniformCallback(const UniformCallback&, const CopyOp&) {} + + META_Object(osg, UniformCallback); + + /** override Callback::run() entry point to adapt to UniformCallback::run(..) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + + /** do customized update code.*/ + virtual void operator () (Uniform*, NodeVisitor*) {} +}; + } // namespace diff --git a/include/osg/CopyOp b/include/osg/CopyOp index fae50bd09..6dea3de5e 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -26,6 +26,7 @@ class StateSet; class StateAttribute; class StateAttributeCallback; class Uniform; +class UniformCallback; class Node; class Drawable; class Array; @@ -82,6 +83,7 @@ class OSG_EXPORT CopyOp virtual Uniform* operator() (const Uniform* shape) const; virtual Callback* operator() (const Callback* nodecallback) const; virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const; + virtual UniformCallback* operator() (const UniformCallback* uniformcallback) const; protected: diff --git a/include/osg/Uniform b/include/osg/Uniform index b5130f911..4609132c0 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -823,38 +824,28 @@ class OSG_EXPORT Uniform : public Object bool getElement( unsigned int index, bool& b0, bool& b1 ) const; bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2 ) const; bool getElement( unsigned int index, bool& b0, bool& b1, bool& b2, bool& b3 ) const; - - - struct Callback : public virtual osg::Object - { - Callback() {} - - Callback(const Callback&,const CopyOp&) {} - - META_Object(osg,Callback); - - /** do customized update code.*/ - virtual void operator () (Uniform*, NodeVisitor*) {} - }; + + + typedef UniformCallback 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(UniformCallback* uc); /** Get the non const UpdateCallback.*/ - Callback* getUpdateCallback() { return _updateCallback.get(); } + UniformCallback* getUpdateCallback() { return _updateCallback.get(); } /** Get the const UpdateCallback.*/ - const Callback* getUpdateCallback() const { return _updateCallback.get(); } - + const UniformCallback* 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(UniformCallback* ec); /** Get the non const EventCallback.*/ - Callback* getEventCallback() { return _eventCallback.get(); } + UniformCallback* getEventCallback() { return _eventCallback.get(); } /** Get the const EventCallback.*/ - const Callback* getEventCallback() const { return _eventCallback.get(); } + const UniformCallback* getEventCallback() const { return _eventCallback.get(); } /** Increment the modified count on the Uniform so Programs watching it know it update themselves. * NOTE: automatically called during osg::Uniform::set*(); @@ -923,8 +914,8 @@ class OSG_EXPORT Uniform : public Object ref_ptr _intArray; ref_ptr _uintArray; - ref_ptr _updateCallback; - ref_ptr _eventCallback; + ref_ptr _updateCallback; + ref_ptr _eventCallback; unsigned int _modifiedCount; }; diff --git a/src/osg/Callback.cpp b/src/osg/Callback.cpp index fa9a8db66..13e8aa7f2 100644 --- a/src/osg/Callback.cpp +++ b/src/osg/Callback.cpp @@ -107,3 +107,22 @@ bool StateAttributeCallback::run(osg::Object* object, osg::Object* data) return traverse(object, data); } } + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// UniformCallback +// +bool UniformCallback::run(osg::Object* object, osg::Object* data) +{ + osg::Uniform* uniform = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (uniform && nv) + { + operator()(uniform, nv); + return true; + } + else + { + return traverse(object, data); + } +} diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index 9c28c0f29..b6075e332 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -36,6 +36,7 @@ COPY_OP( Object, DEEP_COPY_OBJECTS ) COPY_OP( StateSet, DEEP_COPY_STATESETS ) COPY_OP( Image, DEEP_COPY_IMAGES ) COPY_OP( Uniform, DEEP_COPY_UNIFORMS ) +COPY_OP( UniformCallback, DEEP_COPY_CALLBACKS ) COPY_OP( StateAttributeCallback, DEEP_COPY_CALLBACKS ) COPY_OP( Drawable, DEEP_COPY_DRAWABLES ) COPY_OP( Texture, DEEP_COPY_TEXTURES ) diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 85418102d..7853945ec 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -1780,7 +1780,7 @@ void StateSet::runUpdateCallbacks(osg::NodeVisitor* nv) uitr != _uniformList.end(); ++uitr) { - Uniform::Callback* callback = uitr->second.first->getUpdateCallback(); + UniformCallback* callback = uitr->second.first->getUpdateCallback(); if (callback) (*callback)(uitr->second.first.get(),nv); } } @@ -1843,7 +1843,7 @@ void StateSet::runEventCallbacks(osg::NodeVisitor* nv) uitr != _uniformList.end(); ++uitr) { - Uniform::Callback* callback = uitr->second.first->getEventCallback(); + UniformCallback* callback = uitr->second.first->getEventCallback(); if (callback) (*callback)(uitr->second.first.get(),nv); } } diff --git a/src/osg/Uniform.cpp b/src/osg/Uniform.cpp index 2093c1d97..7136a83f6 100644 --- a/src/osg/Uniform.cpp +++ b/src/osg/Uniform.cpp @@ -45,10 +45,13 @@ Uniform::Uniform( Type type, const std::string& name, int numElements ) : allocateDataArray(); } -Uniform::Uniform( const Uniform& rhs, const CopyOp& copyop ) : - Object(rhs,copyop), _type(rhs._type) +Uniform::Uniform(const Uniform& uniform, const CopyOp& copyop) : + Object(uniform, copyop), + _type(uniform._type), + _updateCallback(copyop(uniform._updateCallback.get())), + _eventCallback(copyop(uniform._eventCallback.get())) { - copyData( rhs ); + copyData(uniform); } Uniform::~Uniform() @@ -1298,7 +1301,7 @@ Uniform::Uniform( const char* name, bool b0, bool b1, bool b2, bool b3 ) : /////////////////////////////////////////////////////////////////////////// // Value assignment for single-element (ie: non-array) uniforms. -// (For backwards compatibility, if not already configured, set the +// (For backwards compatability, if not already configured, set the // Uniform's _numElements=1) bool Uniform::set( float f ) @@ -2607,7 +2610,7 @@ void Uniform::apply(const GLExtensions* ext, GLint location) const } } -void Uniform::setUpdateCallback(Callback* uc) +void Uniform::setUpdateCallback(UniformCallback* uc) { OSG_INFO<<"Uniform::Setting Update callbacks"<(); + UniformCallback* callback = fr.readObjectOfType(); if (callback) { uniform.setUpdateCallback(callback); } @@ -225,7 +225,7 @@ bool Uniform_readLocalData(Object& obj, Input& fr) { //int entry = fr[0].getNoNestedBrackets(); fr += 2; - Uniform::Callback* callback = fr.readObjectOfType(); + UniformCallback* callback = fr.readObjectOfType(); if (callback) { uniform.setEventCallback(callback); } diff --git a/src/osgWrappers/serializers/osg/LibraryWrapper.cpp b/src/osgWrappers/serializers/osg/LibraryWrapper.cpp index 1cd56deda..8d0993807 100644 --- a/src/osgWrappers/serializers/osg/LibraryWrapper.cpp +++ b/src/osgWrappers/serializers/osg/LibraryWrapper.cpp @@ -108,6 +108,7 @@ USE_SERIALIZER_WRAPPER(TransferFunction1D) USE_SERIALIZER_WRAPPER(Transform) USE_SERIALIZER_WRAPPER(TriangleMesh) USE_SERIALIZER_WRAPPER(Uniform) +USE_SERIALIZER_WRAPPER(UniformCallback) USE_SERIALIZER_WRAPPER(UpdateCallback) USE_SERIALIZER_WRAPPER(UserDataContainer) USE_SERIALIZER_WRAPPER(VertexProgram)