2015-04-14 15:29:12 +00:00
|
|
|
#include "statesetupdater.hpp"
|
2015-04-14 13:55:56 +00:00
|
|
|
|
|
|
|
#include <osg/Node>
|
2015-06-07 21:51:54 +00:00
|
|
|
#include <osg/NodeVisitor>
|
2015-04-14 13:55:56 +00:00
|
|
|
|
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
void StateSetUpdater::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
2015-04-14 13:55:56 +00:00
|
|
|
{
|
|
|
|
if (!mStateSets[0])
|
|
|
|
{
|
|
|
|
// first time setup
|
|
|
|
osg::StateSet* src = node->getOrCreateStateSet();
|
|
|
|
for (int i=0; i<2; ++i) // Using SHALLOW_COPY for StateAttributes, if users want to modify it is their responsibility to set a non-shared one first
|
|
|
|
// This can be done conveniently in user implementations of the setDefaults() method
|
|
|
|
{
|
2017-02-09 03:50:51 +00:00
|
|
|
mStateSets[i] = new osg::StateSet(*src, osg::CopyOp::SHALLOW_COPY);
|
2015-04-14 13:55:56 +00:00
|
|
|
setDefaults(mStateSets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 22:44:15 +00:00
|
|
|
osg::StateSet* stateset = mStateSets[nv->getTraversalNumber()%2];
|
|
|
|
node->setStateSet(stateset);
|
2015-04-14 13:55:56 +00:00
|
|
|
|
2015-12-03 22:44:15 +00:00
|
|
|
apply(stateset, nv);
|
2015-04-14 13:55:56 +00:00
|
|
|
|
|
|
|
traverse(node, nv);
|
|
|
|
}
|
|
|
|
|
2015-06-01 15:02:44 +00:00
|
|
|
void StateSetUpdater::reset()
|
|
|
|
{
|
|
|
|
mStateSets[0] = NULL;
|
|
|
|
mStateSets[1] = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
StateSetUpdater::StateSetUpdater()
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
StateSetUpdater::StateSetUpdater(const StateSetUpdater ©, const osg::CopyOp ©op)
|
2015-04-14 14:41:06 +00:00
|
|
|
: osg::NodeCallback(copy, copyop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
void CompositeStateSetUpdater::apply(osg::StateSet *stateset, osg::NodeVisitor *nv)
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
|
|
|
mCtrls[i]->apply(stateset, nv);
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
void CompositeStateSetUpdater::setDefaults(osg::StateSet *stateset)
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
|
|
|
mCtrls[i]->setDefaults(stateset);
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
CompositeStateSetUpdater::CompositeStateSetUpdater()
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
CompositeStateSetUpdater::CompositeStateSetUpdater(const CompositeStateSetUpdater ©, const osg::CopyOp ©op)
|
|
|
|
: StateSetUpdater(copy, copyop)
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
2015-04-14 15:29:12 +00:00
|
|
|
for (unsigned int i=0; i<copy.mCtrls.size(); ++i)
|
2016-08-14 14:44:11 +00:00
|
|
|
mCtrls.push_back(osg::clone(copy.mCtrls[i].get(), copyop));
|
2015-04-14 14:41:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
unsigned int CompositeStateSetUpdater::getNumControllers()
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
return mCtrls.size();
|
|
|
|
}
|
|
|
|
|
2015-04-14 15:29:12 +00:00
|
|
|
StateSetUpdater* CompositeStateSetUpdater::getController(int i)
|
|
|
|
{
|
|
|
|
return mCtrls[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositeStateSetUpdater::addController(StateSetUpdater *ctrl)
|
2015-04-14 14:41:06 +00:00
|
|
|
{
|
|
|
|
mCtrls.push_back(ctrl);
|
|
|
|
}
|
|
|
|
|
2015-04-14 13:55:56 +00:00
|
|
|
}
|