diff --git a/include/osg/Object b/include/osg/Object index 6a739b8f0..32bcc8b8f 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -112,6 +112,14 @@ class OSG_EXPORT Object : public Referenced * Equivalent to dynamic_cast(this).*/ virtual const NodeVisitor* asNodeVisitor() const { return 0; } + /** Convert 'this' into a StateSet pointer if Object is a StateSet, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual StateSet* asStateSet() { return 0; } + + /** convert 'const this' into a const StateSet pointer if Object is a StateSet, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const StateSet* asStateSet() const { return 0; } + /** Convert 'this' into a StateAttribute pointer if Object is a StateAttribute, otherwise return 0. * Equivalent to dynamic_cast(this).*/ virtual StateAttribute* asStateAttribute() { return 0; } @@ -152,7 +160,7 @@ class OSG_EXPORT Object : public Referenced * Equivalent to dynamic_cast(this).*/ virtual const CallbackObject* asCallbackObject() const { return 0; } - + /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/ virtual void setThreadSafeRefUnref(bool threadSafe); diff --git a/include/osg/StateSet b/include/osg/StateSet index 65468328b..3265d528f 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -63,6 +63,14 @@ class OSG_EXPORT StateSet : public Object bool operator == (const StateSet& rhs) const { return compare(rhs)==0; } bool operator != (const StateSet& rhs) const { return compare(rhs)!=0; } + /** Convert 'this' into a StateSet pointer if Object is a StateSet, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual StateSet* asStateSet() { return this; } + + /** convert 'const this' into a const StateSet pointer if Object is a StateSet, otherwise return 0. + * Equivalent to dynamic_cast(this).*/ + virtual const StateSet* asStateSet() const { return this; } + /** A vector of osg::Object pointers which is used to store the parent(s) of this Stateset, the parents could be osg::Node or osg::Drawable.*/ typedef std::vector ParentList; diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 181259298..6650fd777 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -92,8 +92,8 @@ bool osg::isTextureMode(StateAttribute::GLMode mode) // bool StateSet::Callback::run(osg::Object* object, osg::Object* data) { - osg::StateSet* ss = dynamic_cast(object); - osg::NodeVisitor* nv = dynamic_cast(data); + osg::StateSet* ss = object->asStateSet(); + osg::NodeVisitor* nv = data->asNodeVisitor(); if (ss && nv) { operator()(ss, nv); @@ -313,7 +313,7 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const if (_defineList.size()rhs._defineList.size()) return 1; - + // check render bin details if ( _binMode < rhs._binMode ) return -1; @@ -512,7 +512,7 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const } else if (rhs_define_itr == rhs._defineList.end()) return 1; - + return 0; } diff --git a/src/osg/Transform.cpp b/src/osg/Transform.cpp index 26321ff2e..a3c8c8c4a 100644 --- a/src/osg/Transform.cpp +++ b/src/osg/Transform.cpp @@ -66,7 +66,7 @@ class TransformVisitor : public NodeVisitor ritr != nodePath.rend(); ++ritr, --i) { - const osg::Camera* camera = dynamic_cast(*ritr); + const osg::Camera* camera = (*ritr)->asCamera(); if (camera && (camera->getReferenceFrame()!=osg::Transform::RELATIVE_RF || camera->getParents().empty())) {