From Cedric Pinson, "Here a patch to be able to clone stateattribute, in order to do that i
moved the StateAttribute::Callback structure to a file StateAttributeCallback with the same behavior as NodeCallback. "
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <osg/Array>
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osg/Shape>
|
||||
#include <osg/StateAttribute>
|
||||
|
||||
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<osg::NodeCallback*>(nc->clone(*this));
|
||||
@@ -85,3 +86,17 @@ NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
|
||||
else
|
||||
return const_cast<NodeCallback*>(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<StateAttributeCallback*>(sc->clone(*this));
|
||||
return cb;
|
||||
}
|
||||
else
|
||||
return const_cast<StateAttributeCallback*>(sc);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"<<std::endl;
|
||||
|
||||
@@ -69,7 +69,7 @@ void StateAttribute::setUpdateCallback(Callback* uc)
|
||||
}
|
||||
}
|
||||
|
||||
void StateAttribute::setEventCallback(Callback* ec)
|
||||
void StateAttribute::setEventCallback(StateAttributeCallback* ec)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"StateAttribute::Setting Event callbacks"<<std::endl;
|
||||
|
||||
|
||||
@@ -1673,7 +1673,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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ bool UpdateTransform::link(osgAnimation::Channel* channel)
|
||||
|
||||
UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop)
|
||||
: osg::Object(apc, copyop),
|
||||
AnimationUpdateCallback<osg::StateAttribute::Callback>(apc, copyop)
|
||||
AnimationUpdateCallback<osg::StateAttributeCallback>(apc, copyop)
|
||||
{
|
||||
_diffuse = new osgAnimation::Vec4Target(apc._diffuse->getValue());
|
||||
}
|
||||
|
||||
UpdateMaterial::UpdateMaterial(const std::string& name):
|
||||
AnimationUpdateCallback<osg::StateAttribute::Callback>(name)
|
||||
AnimationUpdateCallback<osg::StateAttributeCallback>(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();
|
||||
|
||||
@@ -29,12 +29,12 @@ bool StateAttribute_readLocalData(Object& obj, Input& fr)
|
||||
bool iteratorAdvanced = false;
|
||||
StateAttribute& stateAttribute = static_cast<StateAttribute&>(obj);
|
||||
|
||||
static ref_ptr<StateAttribute::Callback> s_callback = new osg::StateAttribute::Callback;
|
||||
static ref_ptr<StateAttributeCallback> s_callback = new osg::StateAttributeCallback;
|
||||
while (fr.matchSequence("UpdateCallback {"))
|
||||
{
|
||||
//int entry = fr[0].getNoNestedBrackets();
|
||||
fr += 2;
|
||||
StateAttribute::Callback* callback = dynamic_cast<StateAttribute::Callback*>(fr.readObjectOfType(*s_callback));
|
||||
StateAttributeCallback* callback = dynamic_cast<StateAttributeCallback*>(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<StateAttribute::Callback*>(fr.readObjectOfType(*s_callback));
|
||||
StateAttributeCallback* callback = dynamic_cast<StateAttributeCallback*>(fr.readObjectOfType(*s_callback));
|
||||
if (callback) {
|
||||
stateAttribute.setEventCallback(callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user