diff --git a/examples/osgfpdepth/osgfpdepth.cpp b/examples/osgfpdepth/osgfpdepth.cpp index c71634ad8..40c1a2e3d 100644 --- a/examples/osgfpdepth/osgfpdepth.cpp +++ b/examples/osgfpdepth/osgfpdepth.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/osgposter/PosterPrinter.h b/examples/osgposter/PosterPrinter.h index 952d36b7a..eaa369d0a 100644 --- a/examples/osgposter/PosterPrinter.h +++ b/examples/osgposter/PosterPrinter.h @@ -10,40 +10,41 @@ class PosterVisitor : public osg::NodeVisitor { public: typedef std::set PagedNodeNameSet; - + PosterVisitor(); META_NodeVisitor( osgPoster, PosterVisitor ); - + void insertName( const std::string& name ) { if ( _pagedNodeNames.insert(name).second ) _needToApplyCount++; } - + void eraseName( const std::string& name ) { if ( _pagedNodeNames.erase(name)>0 ) _needToApplyCount--; } - + void clearNames() { _pagedNodeNames.clear(); _needToApplyCount = 0; _appliedCount = 0; } unsigned int getNumNames() const { return _pagedNodeNames.size(); } - + PagedNodeNameSet& getPagedNodeNames() { return _pagedNodeNames; } const PagedNodeNameSet& getPagedNodeNames() const { return _pagedNodeNames; } - + unsigned int getNeedToApplyCount() const { return _needToApplyCount; } unsigned int getAppliedCount() const { return _appliedCount; } unsigned int inQueue() const { return _needToApplyCount>_appliedCount ? _needToApplyCount-_appliedCount : 0; } - + void setAddingCallbacks( bool b ) { _addingCallbacks = b; } bool getAddingCallbacks() const { return _addingCallbacks; } - + virtual void apply( osg::LOD& node ); virtual void apply( osg::PagedLOD& node ); - + protected: - bool hasCullCallback( osg::NodeCallback* nc, osg::NodeCallback* target ) + + bool hasCullCallback( osg::Callback* nc, osg::Callback* target ) { if ( nc==target ) return true; else if ( !nc ) return false; return hasCullCallback( nc->getNestedCallback(), target ); } - + PagedNodeNameSet _pagedNodeNames; unsigned int _appliedCount; unsigned int _needToApplyCount; @@ -55,24 +56,24 @@ class PosterIntersector : public osgUtil::Intersector { public: typedef std::set PagedNodeNameSet; - + PosterIntersector( const osg::Polytope& polytope ); PosterIntersector( double xMin, double yMin, double xMax, double yMax ); - + void setPosterVisitor( PosterVisitor* pcv ) { _visitor = pcv; } PosterVisitor* getPosterVisitor() { return _visitor.get(); } const PosterVisitor* getPosterVisitor() const { return _visitor.get(); } - + virtual Intersector* clone( osgUtil::IntersectionVisitor& iv ); - + virtual bool containsIntersections() { return _visitor.valid()&&_visitor->getNumNames()>0; } - + virtual bool enter( const osg::Node& node ); virtual void leave() {} virtual void reset(); virtual void intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable ); - + protected: osgUtil::IntersectionVisitor* _intersectionVisitor; osg::ref_ptr _visitor; @@ -86,60 +87,60 @@ class PosterPrinter : public osg::Referenced public: typedef std::pair TilePosition; typedef std::map< TilePosition, osg::ref_ptr > TileImages; - + PosterPrinter(); - + /** Set to output each sub-image-tile to disk */ void setOutputTiles( bool b ) { _outputTiles = b; } bool getOutputTiles() const { return _outputTiles; } - + /** Set the output sub-image-tile extension, e.g. bmp */ void setOutputTileExtension( const std::string& ext ) { _outputTileExt = ext; } const std::string& getOutputTileExtension() const { return _outputTileExt; } - + /** Set the output poster name, e.g. output.bmp */ void setOutputPosterName( const std::string& name ) { _outputPosterName = name; } const std::string& getOutputPosterName() const { return _outputPosterName; } - + /** Set the size of each sub-image-tile, e.g. 640x480 */ void setTileSize( int w, int h ) { _tileSize.set(w, h); } const osg::Vec2& getTileSize() const { return _tileSize; } - + /** Set the final size of the high-res poster, e.g. 6400x4800 */ void setPosterSize( int w, int h ) { _posterSize.set(w, h); } const osg::Vec2& getPosterSize() const { return _posterSize; } - + /** Set the capturing camera */ void setCamera( osg::Camera* camera ) { _camera = camera; } const osg::Camera* getCamera() const { return _camera.get(); } - + /** Set the final poster image, should be already allocated */ void setFinalPoster( osg::Image* image ) { _finalPoster = image; } const osg::Image* getFinalPoster() const { return _finalPoster.get(); } - + PosterVisitor* getPosterVisitor() { return _visitor.get(); } const PosterVisitor* getPosterVisitor() const { return _visitor.get(); } - + bool done() const { return !_isRunning && !_isFinishing; } - + void init( const osg::Camera* camera ); void init( const osg::Matrixd& view, const osg::Matrixd& proj ); void frame( const osg::FrameStamp* fs, osg::Node* node ); - + protected: virtual ~PosterPrinter() {} - + bool addCullCallbacks( const osg::FrameStamp* fs, osg::Node* node ); void removeCullCallbacks( osg::Node* node ); void bindCameraToImage( osg::Camera* camera, int row, int col ); void recordImages(); - + bool _outputTiles; std::string _outputTileExt; std::string _outputPosterName; osg::Vec2 _tileSize; osg::Vec2 _posterSize; - + bool _isRunning; bool _isFinishing; unsigned int _lastBindingFrame; @@ -149,7 +150,7 @@ protected: int _currentColumn; osg::ref_ptr _intersector; osg::ref_ptr _visitor; - + osg::Matrixd _currentViewMatrix; osg::Matrixd _currentProjectionMatrix; osg::ref_ptr _camera; diff --git a/examples/osgvertexprogram/osgvertexprogram.cpp b/examples/osgvertexprogram/osgvertexprogram.cpp index 18c3e17c3..a8d211e96 100644 --- a/examples/osgvertexprogram/osgvertexprogram.cpp +++ b/examples/osgvertexprogram/osgvertexprogram.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -220,7 +219,7 @@ class MoveEarthySkyWithEyePointTransform : public osg::Transform { public: /** Get the transformation matrix which moves from local coords to world coords.*/ - virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const + virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const { osgUtil::CullVisitor* cv = dynamic_cast(nv); if (cv) @@ -270,7 +269,7 @@ osg::Node* createSkyBox() // clear the depth to the far plane. osg::Depth* depth = new osg::Depth; depth->setFunction(osg::Depth::ALWAYS); - depth->setRange(1.0,1.0); + depth->setRange(1.0,1.0); stateset->setAttributeAndModes(depth, osg::StateAttribute::ON ); stateset->setRenderBinDetails(-1,"RenderBin"); @@ -305,7 +304,7 @@ osg::Node* addRefractStateSet(osg::Node* node) osg::TextureCubeMap* reflectmap = readCubeMap(); stateset->setTextureAttributeAndModes( 0, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); stateset->setTextureAttributeAndModes( 1, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); - + osg::TexMat* texMat = new osg::TexMat; stateset->setTextureAttribute(0, texMat); @@ -329,14 +328,14 @@ osg::Node* addRefractStateSet(osg::Node* node) // REPLACE function: Arg0 // = T0 - osg::TexEnvCombine *te0 = new osg::TexEnvCombine; + osg::TexEnvCombine *te0 = new osg::TexEnvCombine; te0->setCombine_RGB(osg::TexEnvCombine::REPLACE); te0->setSource0_RGB(osg::TexEnvCombine::TEXTURE0); te0->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR); - + // INTERPOLATE function: Arg0 * (Arg2) + Arg1 * (1-Arg2) // = T1 * C0.a + Cp * (1-C0.a) - osg::TexEnvCombine *te1 = new osg::TexEnvCombine; + osg::TexEnvCombine *te1 = new osg::TexEnvCombine; // rgb = Cp + Ct te1->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE); @@ -354,7 +353,7 @@ osg::Node* addRefractStateSet(osg::Node* node) group->addChild(node); group->setCullCallback(new TexMatCallback(*texMat)); group->setStateSet( stateset ); - + return group; } @@ -385,7 +384,7 @@ int main(int argc, char *argv[]) osgUtil::Optimizer optimzer; optimzer.optimize(model); - // create normals. + // create normals. osgUtil::SmoothingVisitor smoother; model->accept(smoother); @@ -393,7 +392,7 @@ int main(int argc, char *argv[]) // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(rootnode); - + // create the windows and run the threads. viewer.realize(); diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index f96e53028..15df5f685 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -21,7 +21,7 @@ #include #include #include -#include +#include namespace osg { diff --git a/include/osg/Callback b/include/osg/Callback new file mode 100644 index 000000000..ff4c2dca2 --- /dev/null +++ b/include/osg/Callback @@ -0,0 +1,202 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_CALLBACK +#define OSG_CALLBACK 1 + +#include +#include + +namespace osg { + + +class Callback : public virtual Object { + + public : + + Callback(){} + + Callback(const Callback& cb,const CopyOp&): + _nestedCallback(cb._nestedCallback) {} + + META_Object(osg, Callback); + + /** Invoke the callback, first parameter is the Object that the callback is attached to, + * the second parameter, the data, is typically the NodeVisitor that is invoking the callback. + * The run(..) method may be overriden by users directly, or if the user is using one of the old + * style callbacks such as NodeCallback or Drawable::UpdateCallback then you can just override + * the appropriate callback method on those callback subclasses. + * If you are implementing your own callback then one should call traverse() to make sure nested callbacks + * and visitor traversal() is completed. */ + virtual bool run(osg::Object* object, osg::Object* data) + { + return traverse(object, data); + } + + /** traverse the nested callbacks or call NodeVisitor::traverse() if the object is Node, and data is NodeVisitor.*/ + bool traverse(osg::Object* object, osg::Object* data); + + void setNestedCallback(osg::Callback* cb) { _nestedCallback = cb; } + osg::Callback* getNestedCallback() { return _nestedCallback.get(); } + const osg::Callback* getNestedCallback() const { return _nestedCallback.get(); } + + inline void addNestedCallback(osg::Callback* nc) + { + if (nc) + { + if (_nestedCallback.valid()) + { + _nestedCallback->addNestedCallback(nc); + } + else + { + _nestedCallback = nc; + } + } + } + + inline void removeNestedCallback(osg::Callback* nc) + { + if (nc) + { + if (_nestedCallback==nc) + { + ref_ptr new_nested_callback = _nestedCallback->getNestedCallback(); + _nestedCallback->setNestedCallback(0); + _nestedCallback = new_nested_callback; + } + else if (_nestedCallback.valid()) + { + _nestedCallback->removeNestedCallback(nc); + } + } + } + + protected: + + virtual ~Callback() {} + ref_ptr _nestedCallback; +}; + +typedef std::vector< osg::ref_ptr > Parameters; + +/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/ +class OSG_EXPORT CallbackObject : public virtual osg::Callback +{ +public: + CallbackObject() {} + CallbackObject(const std::string& name) { setName(name); } + CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Callback(rhs,copyop) {} + META_Object(osg, CallbackObject); + + virtual CallbackObject* asCallbackObject() { return this; } + virtual const CallbackObject* asCallbackObject() const { return this; } + + /** override Callback::run() entry point to adapt to CallbackObject::run(..) method.*/ + bool run(osg::Object* object, osg::Object* data); + + inline bool run(osg::Object* object) const + { + osg::Parameters inputParameters; + osg::Parameters outputParameters; + return run(object, inputParameters, outputParameters); + } + + virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const; + +}; + +/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/ +inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name) +{ + osg::UserDataContainer* udc = object->getUserDataContainer(); + return udc ? dynamic_cast(udc->getUserObject(name)) : 0; +} + +/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/ +inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters) +{ + bool result = false; + osg::UserDataContainer* udc = object->getUserDataContainer(); + if (udc) + { + for(unsigned int i = 0; igetNumUserObjects(); ++i) + { + osg::Object* obj = udc->getUserObject(i); + if (obj && obj->getName()==name) + { + osg::CallbackObject* co = dynamic_cast(obj); + if (co) result = co->run(object, inputParameters, outputParameters) | result; + } + } + } + + return result; +} + + + +// forward declare +class Node; +class NodeVisitor; + + +/** Deprecated. */ +class OSG_EXPORT NodeCallback : public virtual Callback { + + public : + + + NodeCallback(){} + + NodeCallback(const NodeCallback& nc,const CopyOp& copyop): + Callback(nc,copyop) {} + + META_Object(osg,NodeCallback); + + /** NodeCallback overrides the Callback::run() method to adapt it the old style NodeCallback::operator()(Node* node, NodeVisitor* nv) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + + /** Callback method called by the NodeVisitor when visiting a node.*/ + virtual void operator()(Node* node, NodeVisitor* nv); + + protected: + + virtual ~NodeCallback() {} +}; + +// forward declare +class StateAttribute; + +/** Deprecated. */ +class OSG_EXPORT StateAttributeCallback : public virtual osg::Callback +{ + public: + StateAttributeCallback() {} + + StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {} + + META_Object(osg,StateAttributeCallback); + + /** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + + /** do customized update code.*/ + virtual void operator () (StateAttribute*, NodeVisitor*) {} +}; + + +} // namespace + +#endif + diff --git a/include/osg/ClusterCullingCallback b/include/osg/ClusterCullingCallback index 339fcdc31..34976798e 100644 --- a/include/osg/ClusterCullingCallback +++ b/include/osg/ClusterCullingCallback @@ -15,7 +15,7 @@ #define OSG_CLUSTERCULLINGCALLBACK 1 #include -#include +#include namespace osg { diff --git a/include/osg/CopyOp b/include/osg/CopyOp index 096e0c526..fae50bd09 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -31,7 +31,7 @@ class Drawable; class Array; class PrimitiveSet; class Shape; -class NodeCallback; +class Callback; /** Copy Op(erator) used to control whether shallow or deep copy is used @@ -80,7 +80,7 @@ class OSG_EXPORT CopyOp virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const; virtual Shape* operator() (const Shape* shape) const; virtual Uniform* operator() (const Uniform* shape) const; - virtual NodeCallback* operator() (const NodeCallback* nodecallback) const; + virtual Callback* operator() (const Callback* nodecallback) const; virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const; protected: diff --git a/include/osg/Drawable b/include/osg/Drawable index d1afefef0..3cd0623a9 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -268,7 +268,7 @@ class OSG_EXPORT Drawable : public Node * for all graphics contexts. */ virtual void releaseGLObjects(State* state=0) const; - struct UpdateCallback : public virtual osg::Object + struct OSG_EXPORT UpdateCallback : public virtual Callback { UpdateCallback() {} @@ -276,24 +276,15 @@ class OSG_EXPORT Drawable : public Node META_Object(osg,UpdateCallback); + /** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + /** do customized update code.*/ virtual void update(osg::NodeVisitor*, osg::Drawable*) {} }; - /** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal. */ - virtual void setUpdateCallback(UpdateCallback* ac); - /** Get the non const UpdateCallback.*/ - UpdateCallback* getUpdateCallback() { return _drawableUpdateCallback.get(); } - - /** Get the const UpdateCallback.*/ - const UpdateCallback* getUpdateCallback() const { return _drawableUpdateCallback.get(); } - - /** Return whether this Drawable has update callbacks associated with it, and therefore must be traversed.*/ - bool requiresUpdateTraversal() const { return _drawableUpdateCallback.valid() || (_stateset.valid() && _stateset->requiresUpdateTraversal()); } - - - struct EventCallback : public virtual osg::Object + struct OSG_EXPORT EventCallback : public virtual Callback { EventCallback() {} @@ -301,24 +292,14 @@ class OSG_EXPORT Drawable : public Node META_Object(osg,EventCallback); + /** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + /** do customized Event code. */ virtual void event(osg::NodeVisitor*, osg::Drawable*) {} }; - /** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/ - virtual void setEventCallback(EventCallback* ac); - - /** Get the non const EventCallback.*/ - EventCallback* getEventCallback() { return _drawableEventCallback.get(); } - - /** Get the const EventCallback.*/ - const EventCallback* getEventCallback() const { return _drawableEventCallback.get(); } - - /** Return whether this Drawable has event callbacks associated with it, and therefore must be traversed.*/ - bool requiresEventTraversal() const { return _drawableEventCallback.valid() || (_stateset.valid() && _stateset->requiresEventTraversal()); } - - - struct CullCallback : public virtual osg::Object + struct CullCallback : public virtual Callback { CullCallback() {} @@ -333,17 +314,6 @@ class OSG_EXPORT Drawable : public Node virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const { return cull(nv, drawable, renderInfo? renderInfo->getState():0); } }; - /** Set the CullCallback which allows users to customize the culling of Drawable during the cull traversal.*/ - virtual void setCullCallback(CullCallback* cc) { _drawableCullCallback=cc; } - - /** Get the non const CullCallback.*/ - CullCallback* getCullCallback() { return _drawableCullCallback.get(); } - - /** Get the const CullCallback.*/ - const CullCallback* getCullCallback() const { return _drawableCullCallback.get(); } - - - /** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object. * The draw callback is implement as a replacement to the Drawable's own drawImplementation() method, if the diff --git a/include/osg/Node b/include/osg/Node index dcd9d508d..ec7ef4878 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -202,16 +202,16 @@ class OSG_EXPORT Node : public Object /** Set update node callback, called during update traversal. */ - void setUpdateCallback(NodeCallback* nc); + void setUpdateCallback(Callback* nc); /** Get update node callback, called during update traversal. */ - inline NodeCallback* getUpdateCallback() { return _updateCallback.get(); } + inline Callback* getUpdateCallback() { return _updateCallback.get(); } /** Get const update node callback, called during update traversal. */ - inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); } + inline const Callback* getUpdateCallback() const { return _updateCallback.get(); } /** Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the existing one. */ - inline void addUpdateCallback(NodeCallback* nc) { + inline void addUpdateCallback(Callback* nc) { if (nc != NULL) { if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc); else setUpdateCallback(nc); @@ -219,7 +219,7 @@ class OSG_EXPORT Node : public Object } /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ - inline void removeUpdateCallback(NodeCallback* nc) { + inline void removeUpdateCallback(Callback* nc) { if (nc != NULL && _updateCallback.valid()) { if (_updateCallback == nc) { @@ -236,16 +236,16 @@ class OSG_EXPORT Node : public Object /** Set event node callback, called during event traversal. */ - void setEventCallback(NodeCallback* nc); + void setEventCallback(Callback* nc); /** Get event node callback, called during event traversal. */ - inline NodeCallback* getEventCallback() { return _eventCallback.get(); } + inline Callback* getEventCallback() { return _eventCallback.get(); } /** Get const event node callback, called during event traversal. */ - inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); } + inline const Callback* getEventCallback() const { return _eventCallback.get(); } /** Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the existing one. */ - inline void addEventCallback(NodeCallback* nc) { + inline void addEventCallback(Callback* nc) { if (nc != NULL) { if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc); else setEventCallback(nc); @@ -253,7 +253,7 @@ class OSG_EXPORT Node : public Object } /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ - inline void removeEventCallback(NodeCallback* nc) { + inline void removeEventCallback(Callback* nc) { if (nc != NULL && _eventCallback.valid()) { if (_eventCallback == nc) { @@ -270,16 +270,16 @@ class OSG_EXPORT Node : public Object /** Set cull node callback, called during cull traversal. */ - void setCullCallback(NodeCallback* nc) { _cullCallback = nc; } + void setCullCallback(Callback* nc) { _cullCallback = nc; } /** Get cull node callback, called during cull traversal. */ - inline NodeCallback* getCullCallback() { return _cullCallback.get(); } + inline Callback* getCullCallback() { return _cullCallback.get(); } /** Get const cull node callback, called during cull traversal. */ - inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); } + inline const Callback* getCullCallback() const { return _cullCallback.get(); } /** Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the existing one. */ - inline void addCullCallback(NodeCallback* nc) { + inline void addCullCallback(Callback* nc) { if (nc != NULL) { if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc); else setCullCallback(nc); @@ -287,7 +287,7 @@ class OSG_EXPORT Node : public Object } /** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */ - inline void removeCullCallback(NodeCallback* nc) { + inline void removeCullCallback(Callback* nc) { if (nc != NULL && _cullCallback.valid()) { if (_cullCallback == nc) { @@ -477,15 +477,15 @@ class OSG_EXPORT Node : public Object friend class osg::Drawable; friend class osg::StateSet; - ref_ptr _updateCallback; + ref_ptr _updateCallback; unsigned int _numChildrenRequiringUpdateTraversal; void setNumChildrenRequiringUpdateTraversal(unsigned int num); - ref_ptr _eventCallback; + ref_ptr _eventCallback; unsigned int _numChildrenRequiringEventTraversal; void setNumChildrenRequiringEventTraversal(unsigned int num); - ref_ptr _cullCallback; + ref_ptr _cullCallback; bool _cullingActive; unsigned int _numChildrenWithCullingDisabled; diff --git a/include/osg/NodeCallback b/include/osg/NodeCallback index 4676746ae..0c0b9cbd1 100644 --- a/include/osg/NodeCallback +++ b/include/osg/NodeCallback @@ -14,86 +14,7 @@ #ifndef OSG_NODECALLBACK #define OSG_NODECALLBACK 1 -#include -#include - -namespace osg { - -class Node; -class NodeVisitor; - -class OSG_EXPORT NodeCallback : public virtual Object { - - public : - - - NodeCallback(){} - - NodeCallback(const NodeCallback& nc,const CopyOp&): - _nestedCallback(nc._nestedCallback) {} - - - META_Object(osg,NodeCallback); - - - /** Callback method called by the NodeVisitor when visiting a node.*/ - virtual void operator()(Node* node, NodeVisitor* nv) - { - // note, callback is responsible for scenegraph traversal so - // they must call traverse(node,nv) to ensure that the - // scene graph subtree (and associated callbacks) are traversed. - traverse(node,nv); - } - - /** Call any nested callbacks and then traverse the scene graph. */ - void traverse(Node* node,NodeVisitor* nv); - - void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; } - NodeCallback* getNestedCallback() { return _nestedCallback.get(); } - const NodeCallback* getNestedCallback() const { return _nestedCallback.get(); } - - inline void addNestedCallback(NodeCallback* nc) - { - if (nc) - { - if (_nestedCallback.valid()) - { - _nestedCallback->addNestedCallback(nc); - } - else - { - _nestedCallback = nc; - } - } - } - - inline void removeNestedCallback(NodeCallback* nc) - { - if (nc) - { - if (_nestedCallback==nc) - { - ref_ptr new_nested_callback = _nestedCallback->getNestedCallback(); - _nestedCallback->setNestedCallback(0); - _nestedCallback = new_nested_callback; - } - else if (_nestedCallback.valid()) - { - _nestedCallback->removeNestedCallback(nc); - } - } - } - - public: - - ref_ptr _nestedCallback; - - protected: - - virtual ~NodeCallback() {} -}; - -} // namespace +#include #endif diff --git a/include/osg/NodeTrackerCallback b/include/osg/NodeTrackerCallback index ed35229f9..ec81cdb81 100644 --- a/include/osg/NodeTrackerCallback +++ b/include/osg/NodeTrackerCallback @@ -17,7 +17,6 @@ #include #include -#include #include namespace osg diff --git a/include/osg/ScriptEngine b/include/osg/ScriptEngine index 3fa81a954..c382fcd8f 100644 --- a/include/osg/ScriptEngine +++ b/include/osg/ScriptEngine @@ -15,20 +15,16 @@ #define OSG_SCRIPTENGINE 1 #include -#include +#include #include #include namespace osg { -typedef std::vector< osg::ref_ptr > Parameters; - - // forward declare class ScriptEngine; - /* Script class for wrapping a script and the language used in the script.*/ class Script : public osg::Object { @@ -57,53 +53,6 @@ class Script : public osg::Object unsigned int _modifiedCount; }; -/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/ -class OSG_EXPORT CallbackObject : public osg::Object -{ -public: - CallbackObject() {} - CallbackObject(const std::string& name) { setName(name); } - CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Object(rhs,copyop) {} - META_Object(osg, CallbackObject); - - inline bool run(osg::Object* object) const - { - osg::Parameters inputParameters; - osg::Parameters outputParameters; - return run(object, inputParameters, outputParameters); - } - - virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const; - -}; - -/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/ -inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name) -{ - osg::UserDataContainer* udc = object->getUserDataContainer(); - return udc ? dynamic_cast(udc->getUserObject(name)) : 0; -} - -/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/ -inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters) -{ - bool result = false; - osg::UserDataContainer* udc = object->getUserDataContainer(); - if (udc) - { - for(unsigned int i = 0; igetNumUserObjects(); ++i) - { - osg::Object* obj = udc->getUserObject(i); - if (obj && obj->getName()==name) - { - osg::CallbackObject* co = dynamic_cast(obj); - if (co) result = co->run(object, inputParameters, outputParameters) | result; - } - } - } - - return result; -} /** NodeCallback for attaching a script to a NodeCallback so that it can be called as an update or event callback.*/ class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index bf202197b..9b370c971 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include diff --git a/include/osg/StateAttributeCallback b/include/osg/StateAttributeCallback index 09e38ceb4..5458d4b90 100644 --- a/include/osg/StateAttributeCallback +++ b/include/osg/StateAttributeCallback @@ -13,27 +13,6 @@ #ifndef OSG_STATEATTRIBUTECALLBACK #define OSG_STATEATTRIBUTECALLBACK 1 -#include -#include - -namespace osg { - -class StateAttribute; -class NodeVisitor; - -class OSG_EXPORT StateAttributeCallback : public virtual osg::Object -{ - public: - StateAttributeCallback() {} - - StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {} - - META_Object(osg,StateAttributeCallback); - - /** do customized update code.*/ - virtual void operator () (StateAttribute*, NodeVisitor*) {} -}; - -} +#include #endif diff --git a/include/osg/StateSet b/include/osg/StateSet index e14398f80..f9b076c17 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -378,7 +378,7 @@ class OSG_EXPORT StateSet : public Object inline bool getNestRenderBins() const { return _nestRenderBins; } - struct Callback : public virtual osg::Object + struct Callback : public virtual osg::Callback { Callback() {} @@ -386,6 +386,9 @@ class OSG_EXPORT StateSet : public Object META_Object(osg,Callback); + /** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/ + virtual bool run(osg::Object* object, osg::Object* data); + /** do customized callback code.*/ virtual void operator() (StateSet*, NodeVisitor*) {} }; diff --git a/include/osgAnimation/Skeleton b/include/osgAnimation/Skeleton index c2444da05..6c37e95a8 100644 --- a/include/osgAnimation/Skeleton +++ b/include/osgAnimation/Skeleton @@ -17,6 +17,7 @@ #include #include +#include namespace osgAnimation { diff --git a/include/osgAnimation/UpdateMatrixTransform b/include/osgAnimation/UpdateMatrixTransform index b39c80680..e268d54dc 100644 --- a/include/osgAnimation/UpdateMatrixTransform +++ b/include/osgAnimation/UpdateMatrixTransform @@ -16,10 +16,10 @@ #ifndef OSGANIMATION_UPDATE_MATRIX_TRANSFORM #define OSGANIMATION_UPDATE_MATRIX_TRANSFORM 1 +#include #include #include #include -#include namespace osgAnimation { diff --git a/include/osgGA/EventHandler b/include/osgGA/EventHandler index 606b6e386..95b38d04e 100644 --- a/include/osgGA/EventHandler +++ b/include/osgGA/EventHandler @@ -16,7 +16,6 @@ #include -#include #include #include @@ -37,12 +36,20 @@ public: EventHandler() {} EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - osg::Object(eh,copyop), + osg::Callback(eh,copyop), osg::NodeCallback(eh, copyop), osg::Drawable::EventCallback(eh, copyop) {} META_Object(osgGA, EventHandler); + virtual bool run(osg::Object* object, osg::Object* data) + { + osg::Node* node = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + operator()(node, nv); + return true; + } + /** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); diff --git a/include/osgGA/EventVisitor b/include/osgGA/EventVisitor index e83008b2a..77712555a 100644 --- a/include/osgGA/EventVisitor +++ b/include/osgGA/EventVisitor @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -68,8 +69,27 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor /** During traversal each type of node calls its callbacks and its children traversed. */ virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); } - virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); } - virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); } + + virtual void apply(osg::Drawable& drawable) + { + osg::Callback* callback = drawable.getEventCallback(); + if (callback) + { + osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast(callback); + osg::NodeCallback* node_callback = dynamic_cast(callback); + osg::CallbackObject* callback_object = dynamic_cast(callback); + + if (drawable_callback) drawable_callback->update(this,&drawable); + if (node_callback) (*node_callback)(&drawable, this); + + if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this); + } + + handle_callbacks(drawable.getStateSet()); + } + + virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); } + virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); } @@ -98,34 +118,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor { handle_callbacks(node.getStateSet()); - osg::NodeCallback* callback = node.getEventCallback(); - if (callback) (*callback)(&node,this); - else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node); + osg::Callback* callback = node.getEventCallback(); + if (callback) callback->run(&node,this); + else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node); } - inline void handle_geode_callbacks(osg::Geode& node) - { - handle_callbacks(node.getStateSet()); - - osg::NodeCallback* callback = node.getEventCallback(); - if (callback) (*callback)(&node,this); - /*else if (node.getNumChildrenRequiringEventTraversal()>0)*/ - traverseGeode(node); - } - - inline void traverseGeode(osg::Geode& geode) - { - traverse((osg::Node&)geode); - - // Call the app callbacks on the drawables. - for(unsigned int i=0;igetEventCallback(); - if (callback) callback->event(this,geode.getDrawable(i)); - - handle_callbacks(geode.getDrawable(i)->getStateSet()); - } - } osgGA::GUIActionAdapter* _actionAdapter; diff --git a/include/osgGA/GUIEventHandler b/include/osgGA/GUIEventHandler index 547cd3625..1c9fd2e8a 100644 --- a/include/osgGA/GUIEventHandler +++ b/include/osgGA/GUIEventHandler @@ -16,7 +16,6 @@ #include -#include #include #include @@ -54,7 +53,7 @@ public: #if 1 GUIEventHandler() {} GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - osg::Object(eh, copyop), EventHandler(eh, copyop) {} + osg::Callback(eh, copyop), EventHandler(eh, copyop) {} #else GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {} GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): @@ -123,7 +122,7 @@ protected: unsigned int _ignoreHandledEventsMask; #endif -protected: +protected: virtual ~GUIEventHandler(); }; diff --git a/include/osgPresentation/deprecated/AnimationMaterial b/include/osgPresentation/deprecated/AnimationMaterial index dbf0a72d8..c1b15da92 100644 --- a/include/osgPresentation/deprecated/AnimationMaterial +++ b/include/osgPresentation/deprecated/AnimationMaterial @@ -14,7 +14,7 @@ #define OSG_ANIMATIONMATERIAL 1 #include -#include +#include #include diff --git a/include/osgPresentation/deprecated/PropertyManager b/include/osgPresentation/deprecated/PropertyManager index a0154fa3c..91641c091 100644 --- a/include/osgPresentation/deprecated/PropertyManager +++ b/include/osgPresentation/deprecated/PropertyManager @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -29,13 +28,13 @@ namespace osgPresentation class PropertyManager : protected osg::Object { public: - + PropertyManager() {} PropertyManager(const PropertyManager& pm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): osg::Object(pm,copyop) {} META_Object(osgPresentation, PropertyManager) - + /** Convinience method that casts the named UserObject to osg::TemplateValueObject and gets the value. * To use this template method you need to include the osg/ValueObject header.*/ template @@ -57,7 +56,7 @@ public: int ref() const { return osg::Referenced::ref(); } int unref() const { return osg::Referenced::unref(); } - + protected: mutable OpenThreads::Mutex _mutex; @@ -125,7 +124,7 @@ struct PropertyReader bool _errorGenerated; osg::NodePath _nodePath; - std::istringstream _sstream; + std::istringstream _sstream; }; @@ -176,7 +175,7 @@ protected: double _latestTime; bool _pause; double _pauseTime; - + }; diff --git a/include/osgShadow/MinimalDrawBoundsShadowMap b/include/osgShadow/MinimalDrawBoundsShadowMap index 2c85b3498..65e66622c 100644 --- a/include/osgShadow/MinimalDrawBoundsShadowMap +++ b/include/osgShadow/MinimalDrawBoundsShadowMap @@ -98,28 +98,30 @@ class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap osg::observer_ptr< ViewData > _vd; }; - struct CameraCullCallback: public osg::NodeCallback { + struct CameraCullCallback: public osg::Callback { - CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc) + CameraCullCallback(ViewData * vd, osg::Callback * nc): _vd(vd), _nc(nc) { } - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + virtual bool run(osg::Object* object, osg::Object* data) { - osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv ); + osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( data ); if( _nc.valid() ) - _nc->operator()(node,nv); + _nc->run(object, data); else - traverse(node,nv); + traverse(object, data); if( cv ) _vd->recordShadowMapParams( ); + + return true; } protected: osg::observer_ptr< ViewData > _vd; - osg::ref_ptr< osg::NodeCallback > _nc; + osg::ref_ptr< osg::Callback > _nc; }; }; diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 93fd8a28f..b824c1e4c 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -309,15 +309,15 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac inline void handle_cull_callbacks_and_traverse(osg::Node& node) { - osg::NodeCallback* callback = node.getCullCallback(); - if (callback) (*callback)(&node,this); + osg::Callback* callback = node.getCullCallback(); + if (callback) callback->run(&node,this); else traverse(node); } inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode) { - osg::NodeCallback* callback = node.getCullCallback(); - if (callback) (*callback)(&node,this); + osg::Callback* callback = node.getCullCallback(); + if (callback) callback->run(&node,this); else acceptNode->accept(*this); } diff --git a/include/osgUtil/TransformCallback b/include/osgUtil/TransformCallback index 9ae5616be..6acd4ded0 100644 --- a/include/osgUtil/TransformCallback +++ b/include/osgUtil/TransformCallback @@ -15,7 +15,7 @@ #ifndef OSGUTIL_TRANSFORMCALLBACK #define OSGUTIL_TRANSFORMCALLBACK 1 -#include +#include #include namespace osgUtil diff --git a/include/osgUtil/UpdateVisitor b/include/osgUtil/UpdateVisitor index 799df2524..ed4a62703 100644 --- a/include/osgUtil/UpdateVisitor +++ b/include/osgUtil/UpdateVisitor @@ -15,7 +15,6 @@ #define OSGUTIL_UPDATEVISITOR 1 #include -#include #include #include #include @@ -24,6 +23,7 @@ #include #include #include +#include #include @@ -50,17 +50,24 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor virtual void apply(osg::Drawable& drawable) { - osg::Drawable::UpdateCallback* callback = drawable.getUpdateCallback(); - if (callback) callback->update(this,&drawable); + osg::Callback* callback = drawable.getUpdateCallback(); + if (callback) + { + osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast(callback); + osg::NodeCallback* node_callback = dynamic_cast(callback); + osg::CallbackObject* callback_object = dynamic_cast(callback); - osg::NodeCallback* node_callback = drawable.osg::Node::getUpdateCallback(); - if (node_callback) (*node_callback)(&drawable, this); + if (drawable_callback) drawable_callback->update(this,&drawable); + if (node_callback) (*node_callback)(&drawable, this); + + if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this); + } handle_callbacks(drawable.getStateSet()); } - virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); } - virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); } + virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); } + virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); } @@ -92,31 +99,10 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor { handle_callbacks(node.getStateSet()); - osg::NodeCallback* callback = node.getUpdateCallback(); - if (callback) (*callback)(&node,this); + osg::Callback* callback = node.getUpdateCallback(); + if (callback) callback->run(&node,this); else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node); } - - inline void handle_geode_callbacks(osg::Geode& geode) - { - handle_callbacks(geode.getStateSet()); - - osg::NodeCallback* callback = geode.getUpdateCallback(); - if (callback) (*callback)(&geode,this); - - // Call the app callbacks on the drawables. - for(unsigned int i=0;igetUpdateCallback(); - if (callback) callback->update(this,geode.getDrawable(i)); - - handle_callbacks(geode.getDrawable(i)->getStateSet()); - } - - // should we traverse just in case a subclass of Geode adds children?? Won't for now as - // Geode's arn't designed to have children. - // traverse(geode); - } }; } diff --git a/include/osgViewer/ViewerEventHandlers b/include/osgViewer/ViewerEventHandlers index c2458a85f..5701a4c12 100644 --- a/include/osgViewer/ViewerEventHandlers +++ b/include/osgViewer/ViewerEventHandlers @@ -525,7 +525,7 @@ protected: InteractiveImageHandler() {} InteractiveImageHandler(const InteractiveImageHandler&,const osg::CopyOp& = osg::CopyOp::SHALLOW_COPY): - osg::Object(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {} + osg::Callback(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {} bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const; diff --git a/include/osgVolume/Property b/include/osgVolume/Property index 0af6dd8d2..9a6743b2a 100644 --- a/include/osgVolume/Property +++ b/include/osgVolume/Property @@ -447,7 +447,9 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle PropertyAdjustmentCallback(const PropertyAdjustmentCallback&,const osg::CopyOp&); - META_Object(osgVolume,PropertyAdjustmentCallback); + META_Object(osgVolume, PropertyAdjustmentCallback); + + virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); } void setKeyEventCycleForward(int key) { _cyleForwardKey = key; } int getKeyEventCycleForward() const { return _cyleForwardKey; } diff --git a/src/osg/CMakeLists.txt b/src/osg/CMakeLists.txt index b82869d5f..a7e93dfcd 100644 --- a/src/osg/CMakeLists.txt +++ b/src/osg/CMakeLists.txt @@ -37,6 +37,7 @@ SET(TARGET_H ${HEADER_PATH}/buffered_value ${HEADER_PATH}/BufferIndexBinding ${HEADER_PATH}/BufferObject + ${HEADER_PATH}/Callback ${HEADER_PATH}/Camera ${HEADER_PATH}/CameraView ${HEADER_PATH}/ClampColor @@ -230,6 +231,7 @@ SET(TARGET_SRC BlendFunc.cpp BufferIndexBinding.cpp BufferObject.cpp + Callback.cpp Camera.cpp CameraView.cpp ClampColor.cpp @@ -296,7 +298,6 @@ SET(TARGET_SRC # Matrix_implementation.cpp MatrixTransform.cpp Multisample.cpp - NodeCallback.cpp Node.cpp NodeTrackerCallback.cpp NodeVisitor.cpp diff --git a/src/osg/Callback.cpp b/src/osg/Callback.cpp new file mode 100644 index 000000000..e6711cca0 --- /dev/null +++ b/src/osg/Callback.cpp @@ -0,0 +1,109 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ +#include +#include +#include + +using namespace osg; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Callback +// +bool Callback::traverse(Object* object, Object* data) +{ + if (_nestedCallback.valid()) return run(object, data); + else + { +#if 1 + osg::Node* node = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); +#else + osg::Node* node = object ? data->asNode() : 0; + osg::NodeVisitor* nv = data ? data->asNodeVisitor() : 0; +#endif + if (node && nv) + { + nv->traverse(*node); + return true; + } + else return false; + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// CallbackObject +// +bool CallbackObject::run(osg::Object* object, osg::Object* data) +{ + osg::Parameters inputParameters, outputParameters; + + if (data && data->referenceCount()>=1) + { + inputParameters.push_back(data); + } + + return run(object,inputParameters, outputParameters); +} + +bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const +{ + OSG_NOTICE<<"CallbackObject::run(object="<(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (node && nv) + { + operator()(node, nv); + return true; + } + else + { + return traverse(object, data); + } +} +void NodeCallback::operator()(Node* node, NodeVisitor* nv) +{ + // note, callback is responsible for scenegraph traversal so + // they must call traverse(node,nv) to ensure that the + // scene graph subtree (and associated callbacks) are traversed. + traverse(node,nv); +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// StateAttributeCallback +// +bool StateAttributeCallback::run(osg::Object* object, osg::Object* data) +{ + osg::StateAttribute* sa = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (sa && nv) + { + operator()(sa, nv); + return true; + } + else + { + return traverse(object, data); + } +} diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index 6a5a360b5..50e801d57 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace osg; @@ -66,19 +67,19 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const return const_cast(attr); } -NodeCallback* CopyOp::operator() (const NodeCallback* nc) const +Callback* CopyOp::operator() (const Callback* nc) const { if (nc && _flags&DEEP_COPY_CALLBACKS) { // deep copy the full chain of callback - osg::NodeCallback* first = osg::clone(nc, *this); + Callback* first = osg::clone(nc, *this); if (!first) return 0; first->setNestedCallback(0); nc = nc->getNestedCallback(); while (nc) { - osg::NodeCallback* ucb = osg::clone(nc, *this); + Callback* ucb = osg::clone(nc, *this); if (ucb) { ucb->setNestedCallback(0); @@ -89,5 +90,5 @@ NodeCallback* CopyOp::operator() (const NodeCallback* nc) const return first; } else - return const_cast(nc); + return const_cast(nc); } diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index c32a2edc3..765bb2d64 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -216,6 +216,36 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID, double& availabl #endif } +bool Drawable::UpdateCallback::run(osg::Object* object, osg::Object* data) +{ + osg::Drawable* drawable = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (drawable && nv) + { + update(nv, drawable); + return true; + } + else + { + return traverse(object, data); + } +} + +bool Drawable::EventCallback::run(osg::Object* object, osg::Object* data) +{ + osg::Drawable* drawable = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (drawable && nv) + { + event(nv, drawable); + return true; + } + else + { + return traverse(object, data); + } +} + Drawable::Drawable() { _boundingBoxComputed = false; @@ -468,48 +498,6 @@ void Drawable::dirtyDisplayList() } -void Drawable::setUpdateCallback(UpdateCallback* ac) -{ - if (_drawableUpdateCallback==ac) return; - - int delta = 0; - if (_drawableUpdateCallback.valid()) --delta; - if (ac) ++delta; - - _drawableUpdateCallback = ac; - - if (delta!=0 && !(_stateset.valid() && _stateset->requiresUpdateTraversal())) - { - for(ParentList::iterator itr=_parents.begin(); - itr!=_parents.end(); - ++itr) - { - (*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta); - } - } -} - -void Drawable::setEventCallback(EventCallback* ac) -{ - if (_drawableEventCallback==ac) return; - - int delta = 0; - if (_drawableEventCallback.valid()) --delta; - if (ac) ++delta; - - _drawableEventCallback = ac; - - if (delta!=0 && !(_stateset.valid() && _stateset->requiresEventTraversal())) - { - for(ParentList::iterator itr=_parents.begin(); - itr!=_parents.end(); - ++itr) - { - (*itr)->setNumChildrenRequiringEventTraversal( (*itr)->getNumChildrenRequiringEventTraversal()+delta ); - } - } -} - struct ComputeBound : public PrimitiveFunctor { ComputeBound() diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index e1783ad91..e7ac56f48 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -203,7 +203,7 @@ MatrixList Node::getWorldMatrices(const osg::Node* haltTraversalAtNode) const return matrices; } -void Node::setUpdateCallback(NodeCallback* nc) +void Node::setUpdateCallback(Callback* nc) { // if no changes just return. if (_updateCallback==nc) return; @@ -281,7 +281,7 @@ void Node::setNumChildrenRequiringUpdateTraversal(unsigned int num) } -void Node::setEventCallback(NodeCallback* nc) +void Node::setEventCallback(Callback* nc) { // if no changes just return. if (_eventCallback==nc) return; diff --git a/src/osg/NodeCallback.cpp b/src/osg/NodeCallback.cpp deleted file mode 100644 index 8c59416a3..000000000 --- a/src/osg/NodeCallback.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ -#include -#include -#include - -using namespace osg; - -void NodeCallback::traverse(Node* node,NodeVisitor* nv) -{ - if (_nestedCallback.valid()) (*_nestedCallback)(node,nv); - else nv->traverse(*node); -} diff --git a/src/osg/ScriptEngine.cpp b/src/osg/ScriptEngine.cpp index 8e6db5c24..183b3711f 100644 --- a/src/osg/ScriptEngine.cpp +++ b/src/osg/ScriptEngine.cpp @@ -16,13 +16,6 @@ using namespace osg; - -bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const -{ - OSG_NOTICE<<"CallbackObject::run(object="< #include #include +#include #include #include diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index fbd4d7145..7f01c7654 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -84,6 +84,26 @@ bool osg::isTextureMode(StateAttribute::GLMode mode) return getTextureGLModeSet().isTextureMode(mode); } + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// StateAttributeCallback +// +bool StateSet::Callback::run(osg::Object* object, osg::Object* data) +{ + osg::StateSet* ss = dynamic_cast(object); + osg::NodeVisitor* nv = dynamic_cast(data); + if (ss && nv) + { + operator()(ss, nv); + return true; + } + else + { + return traverse(object, data); + } +} + StateSet::StateSet(): Object(true), _nestRenderBins(true) diff --git a/src/osgAnimation/AnimationManagerBase.cpp b/src/osgAnimation/AnimationManagerBase.cpp index 06ce5756f..03e9b2abb 100644 --- a/src/osgAnimation/AnimationManagerBase.cpp +++ b/src/osgAnimation/AnimationManagerBase.cpp @@ -62,7 +62,7 @@ void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv) } -AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Object(b, copyop), osg::NodeCallback(b,copyop) // TODO check this +AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Callback(b, copyop), osg::NodeCallback(b,copyop) // TODO check this { const AnimationList& animationList = b.getAnimationList(); for (AnimationList::const_iterator it = animationList.begin(); diff --git a/src/osgAnimation/LinkVisitor.cpp b/src/osgAnimation/LinkVisitor.cpp index 1dc4f67c1..45efc6e78 100644 --- a/src/osgAnimation/LinkVisitor.cpp +++ b/src/osgAnimation/LinkVisitor.cpp @@ -64,7 +64,7 @@ void LinkVisitor::apply(osg::Node& node) if (st) handle_stateset(st); - osg::NodeCallback* cb = node.getUpdateCallback(); + osg::Callback* cb = node.getUpdateCallback(); while (cb) { osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast(cb); diff --git a/src/osgAnimation/StatsHandler.cpp b/src/osgAnimation/StatsHandler.cpp index e282c4cda..4508e9d55 100644 --- a/src/osgAnimation/StatsHandler.cpp +++ b/src/osgAnimation/StatsHandler.cpp @@ -466,7 +466,7 @@ struct FindTimelineStats : public osg::NodeVisitor FindTimelineStats() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} void apply(osg::Node& node) { - osg::NodeCallback* cb = node.getUpdateCallback(); + osg::Callback* cb = node.getUpdateCallback(); while (cb) { osgAnimation::TimelineAnimationManager* tam = dynamic_cast(cb); if (tam) diff --git a/src/osgGA/CameraManipulator.cpp b/src/osgGA/CameraManipulator.cpp index 9646f2149..549b631f6 100644 --- a/src/osgGA/CameraManipulator.cpp +++ b/src/osgGA/CameraManipulator.cpp @@ -21,7 +21,7 @@ CameraManipulator::CameraManipulator() CameraManipulator::CameraManipulator(const CameraManipulator& mm, const CopyOp& copyOp) - : osg::Object(mm, copyOp), + : osg::Callback(mm, copyOp), inherited(mm, copyOp), _intersectTraversalMask(mm._intersectTraversalMask), _autoComputeHomePosition(mm._autoComputeHomePosition), diff --git a/src/osgGA/FirstPersonManipulator.cpp b/src/osgGA/FirstPersonManipulator.cpp index 39801b597..1596928c1 100644 --- a/src/osgGA/FirstPersonManipulator.cpp +++ b/src/osgGA/FirstPersonManipulator.cpp @@ -44,7 +44,7 @@ FirstPersonManipulator::FirstPersonManipulator( int flags ) /// Constructor. FirstPersonManipulator::FirstPersonManipulator( const FirstPersonManipulator& fpm, const CopyOp& copyOp ) - : osg::Object(fpm, copyOp), + : osg::Callback(fpm, copyOp), inherited( fpm, copyOp ), _eye( fpm._eye ), _rotation( fpm._rotation ), diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index 2c31a045a..1d5e81ba9 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -28,7 +28,7 @@ FlightManipulator::FlightManipulator( int flags ) /// Constructor. FlightManipulator::FlightManipulator( const FlightManipulator& fm, const CopyOp& copyOp ) - : osg::Object(fm, copyOp), + : osg::Callback(fm, copyOp), inherited( fm, copyOp ), _yawMode( fm._yawMode ) { diff --git a/src/osgGA/MultiTouchTrackballManipulator.cpp b/src/osgGA/MultiTouchTrackballManipulator.cpp index 14e808536..fa2c0ee5e 100644 --- a/src/osgGA/MultiTouchTrackballManipulator.cpp +++ b/src/osgGA/MultiTouchTrackballManipulator.cpp @@ -30,7 +30,7 @@ MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( int flags ) /// Constructor. MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( const MultiTouchTrackballManipulator& tm, const CopyOp& copyOp ) - : osg::Object(tm, copyOp), inherited( tm, copyOp ) + : osg::Callback(tm, copyOp), inherited( tm, copyOp ) { } diff --git a/src/osgGA/NodeTrackerManipulator.cpp b/src/osgGA/NodeTrackerManipulator.cpp index 0155813af..da829799d 100644 --- a/src/osgGA/NodeTrackerManipulator.cpp +++ b/src/osgGA/NodeTrackerManipulator.cpp @@ -30,7 +30,7 @@ NodeTrackerManipulator::NodeTrackerManipulator( int flags ) NodeTrackerManipulator::NodeTrackerManipulator( const NodeTrackerManipulator& m, const CopyOp& copyOp ) - : osg::Object(m, copyOp), + : osg::Callback(m, copyOp), inherited( m, copyOp ), _trackNodePath( m._trackNodePath ), _trackerMode( m._trackerMode ) diff --git a/src/osgGA/OrbitManipulator.cpp b/src/osgGA/OrbitManipulator.cpp index 1ee5af221..59a5a9039 100644 --- a/src/osgGA/OrbitManipulator.cpp +++ b/src/osgGA/OrbitManipulator.cpp @@ -43,7 +43,7 @@ OrbitManipulator::OrbitManipulator( int flags ) /// Constructor. OrbitManipulator::OrbitManipulator( const OrbitManipulator& om, const CopyOp& copyOp ) - : osg::Object(om, copyOp), + : osg::Callback(om, copyOp), inherited( om, copyOp ), _center( om._center ), _rotation( om._rotation ), diff --git a/src/osgGA/StandardManipulator.cpp b/src/osgGA/StandardManipulator.cpp index b7dfc0516..dcbc5dcfb 100644 --- a/src/osgGA/StandardManipulator.cpp +++ b/src/osgGA/StandardManipulator.cpp @@ -48,7 +48,7 @@ StandardManipulator::StandardManipulator( int flags ) /// Constructor. StandardManipulator::StandardManipulator( const StandardManipulator& uim, const CopyOp& copyOp ) - : osg::Object(uim, copyOp), + : osg::Callback(uim, copyOp), inherited( uim, copyOp ), _thrown( uim._thrown ), _allowThrow( uim._allowThrow ), diff --git a/src/osgGA/TerrainManipulator.cpp b/src/osgGA/TerrainManipulator.cpp index 928dc5118..4c38e9605 100644 --- a/src/osgGA/TerrainManipulator.cpp +++ b/src/osgGA/TerrainManipulator.cpp @@ -29,7 +29,7 @@ TerrainManipulator::TerrainManipulator( int flags ) /// Constructor. TerrainManipulator::TerrainManipulator( const TerrainManipulator& tm, const CopyOp& copyOp ) - : osg::Object(tm, copyOp), + : osg::Callback(tm, copyOp), inherited( tm, copyOp ), _previousUp( tm._previousUp ) { diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 8448a9cac..408eaea33 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -28,7 +28,7 @@ TrackballManipulator::TrackballManipulator( int flags ) /// Constructor. TrackballManipulator::TrackballManipulator( const TrackballManipulator& tm, const CopyOp& copyOp ) - : osg::Object(tm, copyOp), + : osg::Callback(tm, copyOp), inherited( tm, copyOp ) { } diff --git a/src/osgPlugins/bvh/ReaderWriterBVH.cpp b/src/osgPlugins/bvh/ReaderWriterBVH.cpp index 88e21e1bb..4a425fce2 100644 --- a/src/osgPlugins/bvh/ReaderWriterBVH.cpp +++ b/src/osgPlugins/bvh/ReaderWriterBVH.cpp @@ -46,7 +46,7 @@ public: parent->setMatrixInSkeletonSpace( osg::Matrix::translate(offset) * parent->getMatrixInSkeletonSpace() ); osgAnimation::UpdateBone* updateBone = - static_cast( parent->getUpdateCallback() ); + dynamic_cast( parent->getUpdateCallback() ); if ( updateBone ) { osgAnimation::StackedTransform& stack = updateBone->getStackedTransforms(); diff --git a/src/osgPlugins/dae/daeRAnimations.cpp b/src/osgPlugins/dae/daeRAnimations.cpp index 8dfbd8a25..63ef93382 100644 --- a/src/osgPlugins/dae/daeRAnimations.cpp +++ b/src/osgPlugins/dae/daeRAnimations.cpp @@ -758,7 +758,7 @@ daeReader::ChannelPart* daeReader::processSampler(domChannel* pDomChannel, Sourc return NULL; } -osgAnimation::Target* findChannelTarget(osg::NodeCallback* nc, const std::string& targetName, bool& rotation) +osgAnimation::Target* findChannelTarget(osg::Callback* nc, const std::string& targetName, bool& rotation) { if (osgAnimation::UpdateMatrixTransform* umt = dynamic_cast(nc)) { @@ -827,7 +827,7 @@ void daeReader::processChannel(domChannel* pDomChannel, SourceMap& sources, Targ domChannelOsgAnimationUpdateCallbackMap::iterator iter = _domChannelOsgAnimationUpdateCallbackMap.find(pDomChannel); if (iter != _domChannelOsgAnimationUpdateCallbackMap.end()) { - osg::NodeCallback* nc = iter->second.get(); + osg::Callback* nc = iter->second.get(); std::string channelName, targetName, componentName; extractTargetName(pDomChannel->getTarget(), channelName, targetName, componentName); diff --git a/src/osgPlugins/dae/daeRTransforms.cpp b/src/osgPlugins/dae/daeRTransforms.cpp index a656c50dc..3c69cae96 100644 --- a/src/osgPlugins/dae/daeRTransforms.cpp +++ b/src/osgPlugins/dae/daeRTransforms.cpp @@ -44,7 +44,7 @@ osg::Transform* daeReader::processOsgMatrixTransform(domNode *node, bool isBone) resultNode = new osg::MatrixTransform; } - osg::NodeCallback* pNodeCallback = resultNode->getUpdateCallback(); + osg::Callback* pNodeCallback = resultNode->getUpdateCallback(); std::vector > transformElements; osg::ref_ptr pLastStaticTransformElement; diff --git a/src/osgPlugins/dae/daeReader.h b/src/osgPlugins/dae/daeReader.h index 7b28d14d7..5c051cf65 100644 --- a/src/osgPlugins/dae/daeReader.h +++ b/src/osgPlugins/dae/daeReader.h @@ -241,7 +241,7 @@ public: typedef std::map > domMaterialStateSetMap; typedef std::map > MaterialStateSetMap; typedef std::multimap< daeElement*, domChannel*> daeElementDomChannelMap; - typedef std::map > domChannelOsgAnimationUpdateCallbackMap; + typedef std::map > domChannelOsgAnimationUpdateCallbackMap; typedef std::map > domNodeOsgBoneMap; typedef std::map > domNodeOsgSkeletonMap; typedef std::map > TextureParametersMap; diff --git a/src/osgPlugins/dae/daeWAnimations.cpp b/src/osgPlugins/dae/daeWAnimations.cpp index 2f9540a85..ef1777e3a 100644 --- a/src/osgPlugins/dae/daeWAnimations.cpp +++ b/src/osgPlugins/dae/daeWAnimations.cpp @@ -37,7 +37,7 @@ using namespace osgDAE; void daeWriter::writeAnimations( osg::Node &node ) { const std::string nodeNameUTF( _pluginOptions.namesUseCodepage ? osgDB::convertStringFromCurrentCodePageToUTF8(node.getName()) : node.getName() ); - osg::NodeCallback* ncb = node.getUpdateCallback(); + osg::Callback* ncb = node.getUpdateCallback(); if (ncb) { osgAnimation::AnimationManagerBase* am = dynamic_cast(ncb); diff --git a/src/osgPlugins/dae/daeWTransforms.cpp b/src/osgPlugins/dae/daeWTransforms.cpp index 9c4b4d25e..9e70ca4e6 100644 --- a/src/osgPlugins/dae/daeWTransforms.cpp +++ b/src/osgPlugins/dae/daeWTransforms.cpp @@ -67,7 +67,7 @@ void daeWriter::apply( osg::MatrixTransform &node ) std::string nodeName = getNodeName(node,"matrixTransform"); currentNode->setId(nodeName.c_str()); - osg::NodeCallback* ncb = node.getUpdateCallback(); + osg::Callback* ncb = node.getUpdateCallback(); bool handled = false; if (ncb) { @@ -124,7 +124,7 @@ void daeWriter::apply( osg::PositionAttitudeTransform &node ) const osg::Quat &q = node.getAttitude(); const osg::Vec3 &s = node.getScale(); - osg::NodeCallback* ncb = node.getUpdateCallback(); + osg::Callback* ncb = node.getUpdateCallback(); bool handled = false; if (ncb) { @@ -287,7 +287,7 @@ void daeWriter::apply( osg::Transform &node ) osg::Matrix matrix; node.computeLocalToWorldMatrix(matrix, NULL); - osg::NodeCallback* ncb = node.getUpdateCallback(); + osg::Callback* ncb = node.getUpdateCallback(); bool handled = false; if (ncb) { @@ -309,7 +309,7 @@ void daeWriter::apply( osg::Transform &node ) domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) ); nodeName += "_matrix"; mat->setSid(nodeName.c_str()); - + const osg::Matrix::value_type *mat_vals = matrix.ptr(); for ( int i = 0; i < 4; i++ ) { diff --git a/src/osgPlugins/dae/daeWriter.h b/src/osgPlugins/dae/daeWriter.h index c6cf19d18..e8e557826 100644 --- a/src/osgPlugins/dae/daeWriter.h +++ b/src/osgPlugins/dae/daeWriter.h @@ -93,7 +93,7 @@ public: virtual void apply(osg::Node& node) { - osg::NodeCallback* ncb = node.getUpdateCallback(); + osg::Callback* ncb = node.getUpdateCallback(); if (ncb) { osgAnimation::AnimationUpdateCallback* ut = dynamic_cast*>(ncb); diff --git a/src/osgPlugins/txp/TXPNode.h b/src/osgPlugins/txp/TXPNode.h index d3f60a04e..43149e428 100644 --- a/src/osgPlugins/txp/TXPNode.h +++ b/src/osgPlugins/txp/TXPNode.h @@ -37,7 +37,6 @@ #include #include -#include #include #include "TXPArchive.h" diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 764509340..9afe65f4b 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -985,8 +985,11 @@ void CullVisitor::apply(osg::Drawable& drawable) if( drawable.getCullCallback() ) { - if( drawable.getCullCallback()->cull( this, &drawable, &_renderInfo ) == true ) - return; + osg::Drawable::CullCallback* dcb = dynamic_cast(drawable.getCullCallback()); + if (dcb) + { + if( dcb->cull( this, &drawable, &_renderInfo ) == true ) return; + } } if (!getNodePath().empty() && getNodePath().back()->isCullingActive() && isCulled(bb)) return; @@ -1073,7 +1076,8 @@ void CullVisitor::apply(Billboard& node) if( drawable->getCullCallback() ) { - if( drawable->getCullCallback()->cull( this, drawable, &_renderInfo ) == true ) + osg::Drawable::CullCallback* dcb = dynamic_cast(drawable->getCullCallback()); + if (dcb && dcb->cull( this, drawable, &_renderInfo ) == true ) continue; } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index c6f7688cf..06e5e9331 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -903,8 +903,8 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod // If the camera has a cullCallback execute the callback which has the // requirement that it must traverse the camera's children. { - osg::NodeCallback* callback = _camera->getCullCallback(); - if (callback) (*callback)(_camera.get(), cullVisitor); + osg::Callback* callback = _camera->getCullCallback(); + if (callback) callback->run(_camera.get(), cullVisitor); else cullVisitor->traverse(*_camera); } diff --git a/src/osgWrappers/deprecated-dotosg/osg/NodeCallback.cpp b/src/osgWrappers/deprecated-dotosg/osg/NodeCallback.cpp index e49dbb589..5644db54e 100644 --- a/src/osgWrappers/deprecated-dotosg/osg/NodeCallback.cpp +++ b/src/osgWrappers/deprecated-dotosg/osg/NodeCallback.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include diff --git a/src/osgWrappers/serializers/osg/Callback.cpp b/src/osgWrappers/serializers/osg/Callback.cpp new file mode 100644 index 000000000..5c7f71583 --- /dev/null +++ b/src/osgWrappers/serializers/osg/Callback.cpp @@ -0,0 +1,18 @@ +#undef OBJECT_CAST +#define OBJECT_CAST dynamic_cast + +#include +#include +#include +#include + +REGISTER_OBJECT_WRAPPER( Callback, + new osg::Callback, + osg::Callback, + "osg::Object osg::Callback" ) +{ + ADD_OBJECT_SERIALIZER( NestedCallback, osg::Callback, NULL ); // _nestedCallback +} + +#undef OBJECT_CAST +#define OBJECT_CAST static_cast diff --git a/src/osgWrappers/serializers/osg/Drawable.cpp b/src/osgWrappers/serializers/osg/Drawable.cpp index d131a9f21..e144313f5 100644 --- a/src/osgWrappers/serializers/osg/Drawable.cpp +++ b/src/osgWrappers/serializers/osg/Drawable.cpp @@ -43,8 +43,8 @@ REGISTER_OBJECT_WRAPPER( Drawable, ADD_BOOL_SERIALIZER( SupportsDisplayList, true ); // _supportsDisplayList ADD_BOOL_SERIALIZER( UseDisplayList, true ); // _useDisplayList ADD_BOOL_SERIALIZER( UseVertexBufferObjects, false ); // _useVertexBufferObjects - ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Drawable::UpdateCallback, NULL ); // _updateCallback - ADD_OBJECT_SERIALIZER( EventCallback, osg::Drawable::EventCallback, NULL ); // _eventCallback - ADD_OBJECT_SERIALIZER( CullCallback, osg::Drawable::CullCallback, NULL ); // _cullCallback + ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback + ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback + ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback ADD_OBJECT_SERIALIZER( DrawCallback, osg::Drawable::DrawCallback, NULL ); // _drawCallback } diff --git a/src/osgWrappers/serializers/osg/Node.cpp b/src/osgWrappers/serializers/osg/Node.cpp index 4fa744061..9fe5e3ff8 100644 --- a/src/osgWrappers/serializers/osg/Node.cpp +++ b/src/osgWrappers/serializers/osg/Node.cpp @@ -72,9 +72,9 @@ REGISTER_OBJECT_WRAPPER( Node, ADD_USER_SERIALIZER( InitialBound ); // _initialBound ADD_OBJECT_SERIALIZER( ComputeBoundingSphereCallback, osg::Node::ComputeBoundingSphereCallback, NULL ); // _computeBoundCallback - ADD_OBJECT_SERIALIZER( UpdateCallback, osg::NodeCallback, NULL ); // _updateCallback - ADD_OBJECT_SERIALIZER( EventCallback, osg::NodeCallback, NULL ); // _eventCallback - ADD_OBJECT_SERIALIZER( CullCallback, osg::NodeCallback, NULL ); // _cullCallback + ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback + ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback + ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback ADD_BOOL_SERIALIZER( CullingActive, true ); // _cullingActive ADD_HEXINT_SERIALIZER( NodeMask, 0xffffffff ); // _nodeMask diff --git a/src/osgWrappers/serializers/osg/NodeCallback.cpp b/src/osgWrappers/serializers/osg/NodeCallback.cpp index 0b7806a9d..5590cb800 100644 --- a/src/osgWrappers/serializers/osg/NodeCallback.cpp +++ b/src/osgWrappers/serializers/osg/NodeCallback.cpp @@ -1,6 +1,3 @@ -#undef OBJECT_CAST -#define OBJECT_CAST dynamic_cast - #include #include #include @@ -9,10 +6,6 @@ REGISTER_OBJECT_WRAPPER( NodeCallback, new osg::NodeCallback, osg::NodeCallback, - "osg::Object osg::NodeCallback" ) + "osg::Object osg::Callback osg::NodeCallback" ) { - ADD_OBJECT_SERIALIZER( NestedCallback, osg::NodeCallback, NULL ); // _nestedCallback } - -#undef OBJECT_CAST -#define OBJECT_CAST static_cast