mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 07:06:47 +00:00
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#include "statesetcontroller.hpp"
|
|
|
|
#include <osg/Node>
|
|
|
|
namespace SceneUtil
|
|
{
|
|
|
|
void StateSetController::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] = static_cast<osg::StateSet*>(osg::clone(src, osg::CopyOp::SHALLOW_COPY));
|
|
setDefaults(mStateSets[i]);
|
|
}
|
|
}
|
|
|
|
// Swap to make the StateSet in [0] writable, [1] is now the StateSet that was queued by the last frame
|
|
std::swap(mStateSets[0], mStateSets[1]);
|
|
node->setStateSet(mStateSets[0]);
|
|
|
|
apply(mStateSets[0], nv);
|
|
|
|
traverse(node, nv);
|
|
}
|
|
|
|
StateSetController::StateSetController()
|
|
{
|
|
}
|
|
|
|
StateSetController::StateSetController(const StateSetController ©, const osg::CopyOp ©op)
|
|
: osg::NodeCallback(copy, copyop)
|
|
{
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------------
|
|
|
|
void CompositeStateSetController::apply(osg::StateSet *stateset, osg::NodeVisitor *nv)
|
|
{
|
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
|
mCtrls[i]->apply(stateset, nv);
|
|
}
|
|
|
|
void CompositeStateSetController::setDefaults(osg::StateSet *stateset)
|
|
{
|
|
for (unsigned int i=0; i<mCtrls.size(); ++i)
|
|
mCtrls[i]->setDefaults(stateset);
|
|
}
|
|
|
|
CompositeStateSetController::CompositeStateSetController()
|
|
{
|
|
}
|
|
|
|
CompositeStateSetController::CompositeStateSetController(const CompositeStateSetController ©, const osg::CopyOp ©op)
|
|
: StateSetController(copy, copyop)
|
|
, mCtrls(copy.mCtrls)
|
|
{
|
|
}
|
|
|
|
unsigned int CompositeStateSetController::getNumControllers()
|
|
{
|
|
return mCtrls.size();
|
|
}
|
|
|
|
void CompositeStateSetController::addController(StateSetController *ctrl)
|
|
{
|
|
mCtrls.push_back(ctrl);
|
|
}
|
|
|
|
}
|