#include "statesetupdater.hpp" #include #include namespace SceneUtil { void StateSetUpdater::operator()(osg::Node* node, osg::NodeVisitor* nv) { 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 { mStateSets[i] = osg::clone(src, osg::CopyOp::SHALLOW_COPY); setDefaults(mStateSets[i]); } } osg::StateSet* stateset = mStateSets[nv->getTraversalNumber()%2]; node->setStateSet(stateset); apply(stateset, nv); traverse(node, nv); } void StateSetUpdater::reset() { mStateSets[0] = NULL; mStateSets[1] = NULL; } StateSetUpdater::StateSetUpdater() { } StateSetUpdater::StateSetUpdater(const StateSetUpdater ©, const osg::CopyOp ©op) : osg::NodeCallback(copy, copyop) { } // ---------------------------------------------------------------------------------- void CompositeStateSetUpdater::apply(osg::StateSet *stateset, osg::NodeVisitor *nv) { for (unsigned int i=0; iapply(stateset, nv); } void CompositeStateSetUpdater::setDefaults(osg::StateSet *stateset) { for (unsigned int i=0; isetDefaults(stateset); } CompositeStateSetUpdater::CompositeStateSetUpdater() { } CompositeStateSetUpdater::CompositeStateSetUpdater(const CompositeStateSetUpdater ©, const osg::CopyOp ©op) : StateSetUpdater(copy, copyop) { for (unsigned int i=0; i