Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-06-05 16:26:13 +00:00
parent 35d6cb812f
commit 977ec20751
64 changed files with 590 additions and 471 deletions

View File

@@ -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);
}

View File

@@ -15,7 +15,7 @@
#ifndef OSGUTIL_TRANSFORMCALLBACK
#define OSGUTIL_TRANSFORMCALLBACK 1
#include <osg/Node>
#include <osg/Callback>
#include <osgUtil/Export>
namespace osgUtil

View File

@@ -15,7 +15,6 @@
#define OSGUTIL_UPDATEVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/LOD>
@@ -24,6 +23,7 @@
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgUtil/Export>
@@ -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<osg::Drawable::UpdateCallback*>(callback);
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(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;i<geode.getNumDrawables();++i)
{
osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
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);
}
};
}