UpdateUniform
Go to the documentation of this file.
#ifndef OSGANIMATION_UPDATE_UNIFORM
#define OSGANIMATION_UPDATE_UNIFORM 1
#include <osgAnimation/AnimationUpdateCallback>
#include <osgAnimation/Export>
#include <osg/NodeVisitor>
#include <osg/Uniform>
namespace osgAnimation
{
template <typename T>
class UpdateUniform : public AnimationUpdateCallback<osg::UniformCallback>
{
protected:
osg::ref_ptr< TemplateTarget<T> > _uniformTarget;
public:
UpdateUniform(const std::string& aName = "")
: AnimationUpdateCallback<osg::UniformCallback>(aName)
{
_uniformTarget = new TemplateTarget<T>(); // NOTE: initial value is undefined
}
UpdateUniform(const UpdateUniform& updateuniform,
const osg::CopyOp& copyop) :
AnimationUpdateCallback<osg::UniformCallback>(updateuniform, copyop)
{
_uniformTarget = new TemplateTarget<T>(*(updateuniform._uniformTarget));
}
META_Object(osgAnimation, UpdateUniform<T>);
virtual void operator () (osg::Uniform* uniform, osg::NodeVisitor* nv)
{
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
update(*uniform);
traverse(uniform, nv);
}
bool link(Channel* channel)
{
if (channel->getName().find("uniform") != std::string::npos)
return channel->setTarget(_uniformTarget.get());
else
OSG_WARN << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl;
return false;
}
void update(osg::Uniform& uniform)
{
T value = _uniformTarget->getValue();
uniform.set(value);
}
};
// float
struct UpdateFloatUniform : public UpdateUniform<float>
{
UpdateFloatUniform(const std::string& aName = "") : UpdateUniform<float>(aName) { }
UpdateFloatUniform(const UpdateFloatUniform& ufu,
const osg::CopyOp& copyop) :
osg::Object(ufu, copyop), // copy name
UpdateUniform<float>(ufu, copyop) { }
META_Object(osgAnimation, UpdateFloatUniform);
};
// Vec2f
struct UpdateVec2fUniform : public UpdateUniform<osg::Vec2f>
{
UpdateVec2fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec2f>(aName) { }
UpdateVec2fUniform(const UpdateVec2fUniform& uv2fu,
const osg::CopyOp& copyop) :
osg::Object(uv2fu, copyop), // copy name
UpdateUniform<osg::Vec2f>(uv2fu, copyop) { }
META_Object(osgAnimation, UpdateVec2fUniform);
};
// Vec3f
struct UpdateVec3fUniform : public UpdateUniform<osg::Vec3f>
{
UpdateVec3fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec3f>(aName) { }
UpdateVec3fUniform(const UpdateVec3fUniform& uv3fu,
const osg::CopyOp& copyop) :
osg::Object(uv3fu, copyop), // copy name
UpdateUniform<osg::Vec3f>(uv3fu, copyop) { }
META_Object(osgAnimation, UpdateVec3fUniform);
};
// Vec4f
struct UpdateVec4fUniform : public UpdateUniform<osg::Vec4f>
{
UpdateVec4fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec4f>(aName) { }
UpdateVec4fUniform(const UpdateVec4fUniform& uv4fu,
const osg::CopyOp& copyop) :
osg::Object(uv4fu, copyop), // copy name
UpdateUniform<osg::Vec4f>(uv4fu, copyop) { }
META_Object(osgAnimation, UpdateVec4fUniform);
};
// Matrixf
struct UpdateMatrixfUniform : public UpdateUniform<osg::Matrixf>
{
UpdateMatrixfUniform(const std::string& aName = "") : UpdateUniform<osg::Matrixf>(aName) { }
UpdateMatrixfUniform(const UpdateMatrixfUniform& umfu,
const osg::CopyOp& copyop) :
osg::Object(umfu, copyop), // copy name
UpdateUniform<osg::Matrixf>(umfu, copyop) { }
META_Object(osgAnimation, UpdateMatrixfUniform);
};
}
#endif
AnimationUpdateCallback
NodeVisitor
OSG_WARN
#define OSG_WARN
Definition Notify:85
Uniform
osgAnimation::AnimationUpdateCallback< osg::UniformCallback >::AnimationUpdateCallback
AnimationUpdateCallback()
Definition AnimationUpdateCallback:38
osgAnimation::Channel
Definition Channel:33
osgAnimation::Channel::getName
const std::string & getName() const
osgAnimation::Channel::setTarget
virtual bool setTarget(Target *)=0
osgAnimation::TemplateTarget
Definition Target:50
osgAnimation::UpdateUniform::UpdateUniform
UpdateUniform(const std::string &aName="")
Definition UpdateUniform:18
osgAnimation::UpdateUniform::_uniformTarget
osg::ref_ptr< TemplateTarget< T > > _uniformTarget
Definition UpdateUniform:15
osgAnimation::UpdateUniform::link
bool link(Channel *channel)
Definition UpdateUniform:42
osgAnimation::UpdateUniform::update
void update(osg::Uniform &uniform)
Definition UpdateUniform:52
osgAnimation::UpdateUniform::UpdateUniform
UpdateUniform(const UpdateUniform &updateuniform, const osg::CopyOp &copyop)
Definition UpdateUniform:24
osgAnimation::UpdateUniform::operator()
virtual void operator()(osg::Uniform *uniform, osg::NodeVisitor *nv)
Definition UpdateUniform:34
osgAnimation::UpdateUniform::META_Object
META_Object(osgAnimation, UpdateUniform< T >)
osg::Callback::traverse
bool traverse(osg::Object *object, osg::Object *data)
osg::CopyOp
Definition CopyOp:41
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::getVisitorType
VisitorType getVisitorType() const
Definition NodeVisitor:176
osg::NodeVisitor::UPDATE_VISITOR
@ UPDATE_VISITOR
Definition NodeVisitor:96
osg::Object::Object
Object()
Definition Object:69
osg::Object::className
virtual const char * className() const =0
osg::UniformCallback::UniformCallback
UniformCallback()
Definition Callback:273
osg::Uniform
Definition Uniform:414
osg::Uniform::set
bool set(float f)
osg::ref_ptr
Definition ref_ptr:32
osgAnimation
Definition Action:34
osg
Definition AlphaFunc:19
Export
osgAnimation::UpdateFloatUniform::UpdateFloatUniform
UpdateFloatUniform(const std::string &aName="")
Definition UpdateUniform:63
osgAnimation::UpdateFloatUniform::META_Object
META_Object(osgAnimation, UpdateFloatUniform)
osgAnimation::UpdateFloatUniform::UpdateFloatUniform
UpdateFloatUniform(const UpdateFloatUniform &ufu, const osg::CopyOp &copyop)
Definition UpdateUniform:64
osgAnimation::UpdateMatrixfUniform::META_Object
META_Object(osgAnimation, UpdateMatrixfUniform)
osgAnimation::UpdateMatrixfUniform::UpdateMatrixfUniform
UpdateMatrixfUniform(const std::string &aName="")
Definition UpdateUniform:111
osgAnimation::UpdateMatrixfUniform::UpdateMatrixfUniform
UpdateMatrixfUniform(const UpdateMatrixfUniform &umfu, const osg::CopyOp &copyop)
Definition UpdateUniform:112
osgAnimation::UpdateVec2fUniform::META_Object
META_Object(osgAnimation, UpdateVec2fUniform)
osgAnimation::UpdateVec2fUniform::UpdateVec2fUniform
UpdateVec2fUniform(const UpdateVec2fUniform &uv2fu, const osg::CopyOp &copyop)
Definition UpdateUniform:76
osgAnimation::UpdateVec2fUniform::UpdateVec2fUniform
UpdateVec2fUniform(const std::string &aName="")
Definition UpdateUniform:75
osgAnimation::UpdateVec3fUniform::META_Object
META_Object(osgAnimation, UpdateVec3fUniform)
osgAnimation::UpdateVec3fUniform::UpdateVec3fUniform
UpdateVec3fUniform(const UpdateVec3fUniform &uv3fu, const osg::CopyOp &copyop)
Definition UpdateUniform:88
osgAnimation::UpdateVec3fUniform::UpdateVec3fUniform
UpdateVec3fUniform(const std::string &aName="")
Definition UpdateUniform:87
osgAnimation::UpdateVec4fUniform::META_Object
META_Object(osgAnimation, UpdateVec4fUniform)
osgAnimation::UpdateVec4fUniform::UpdateVec4fUniform
UpdateVec4fUniform(const UpdateVec4fUniform &uv4fu, const osg::CopyOp &copyop)
Definition UpdateUniform:100
osgAnimation::UpdateVec4fUniform::UpdateVec4fUniform
UpdateVec4fUniform(const std::string &aName="")
Definition UpdateUniform:99