#ifndef OSGANIMATION_UPDATE_UNIFORM #define OSGANIMATION_UPDATE_UNIFORM 1 #include #include #include #include namespace osgAnimation { template class UpdateUniform : public AnimationUpdateCallback { protected: osg::ref_ptr< TemplateTarget > _uniformTarget; public: UpdateUniform(const std::string& aName = "") : AnimationUpdateCallback(aName) { _uniformTarget = new TemplateTarget(); // NOTE: initial value is undefined } UpdateUniform(const UpdateUniform& updateuniform, const osg::CopyOp& copyop) : AnimationUpdateCallback(updateuniform, copyop) { _uniformTarget = new TemplateTarget(*(updateuniform._uniformTarget)); } META_Object(osgAnimation, UpdateUniform); /** Callback method called by the NodeVisitor when visiting a node.*/ 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 { UpdateFloatUniform(const std::string& aName = "") : UpdateUniform(aName) { } UpdateFloatUniform(const UpdateFloatUniform& ufu, const osg::CopyOp& copyop) : osg::Object(ufu, copyop), // copy name UpdateUniform(ufu, copyop) { } META_Object(osgAnimation, UpdateFloatUniform); }; // Vec2f struct UpdateVec2fUniform : public UpdateUniform { UpdateVec2fUniform(const std::string& aName = "") : UpdateUniform(aName) { } UpdateVec2fUniform(const UpdateVec2fUniform& uv2fu, const osg::CopyOp& copyop) : osg::Object(uv2fu, copyop), // copy name UpdateUniform(uv2fu, copyop) { } META_Object(osgAnimation, UpdateVec2fUniform); }; // Vec3f struct UpdateVec3fUniform : public UpdateUniform { UpdateVec3fUniform(const std::string& aName = "") : UpdateUniform(aName) { } UpdateVec3fUniform(const UpdateVec3fUniform& uv3fu, const osg::CopyOp& copyop) : osg::Object(uv3fu, copyop), // copy name UpdateUniform(uv3fu, copyop) { } META_Object(osgAnimation, UpdateVec3fUniform); }; // Vec4f struct UpdateVec4fUniform : public UpdateUniform { UpdateVec4fUniform(const std::string& aName = "") : UpdateUniform(aName) { } UpdateVec4fUniform(const UpdateVec4fUniform& uv4fu, const osg::CopyOp& copyop) : osg::Object(uv4fu, copyop), // copy name UpdateUniform(uv4fu, copyop) { } META_Object(osgAnimation, UpdateVec4fUniform); }; // Matrixf struct UpdateMatrixfUniform : public UpdateUniform { UpdateMatrixfUniform(const std::string& aName = "") : UpdateUniform(aName) { } UpdateMatrixfUniform(const UpdateMatrixfUniform& umfu, const osg::CopyOp& copyop) : osg::Object(umfu, copyop), // copy name UpdateUniform(umfu, copyop) { } META_Object(osgAnimation, UpdateMatrixfUniform); }; } #endif