OpenSceneGraph 3.6.5
UpdateUniform
Go to the documentation of this file.
1#ifndef OSGANIMATION_UPDATE_UNIFORM
2#define OSGANIMATION_UPDATE_UNIFORM 1
3
5#include <osgAnimation/Export>
6#include <osg/NodeVisitor>
7#include <osg/Uniform>
8
9namespace osgAnimation
10{
11 template <typename T>
12 class UpdateUniform : public AnimationUpdateCallback<osg::UniformCallback>
13 {
14 protected:
16
17 public:
18 UpdateUniform(const std::string& aName = "")
20 {
21 _uniformTarget = new TemplateTarget<T>(); // NOTE: initial value is undefined
22 }
23
24 UpdateUniform(const UpdateUniform& updateuniform,
25 const osg::CopyOp& copyop) :
26 AnimationUpdateCallback<osg::UniformCallback>(updateuniform, copyop)
27 {
28 _uniformTarget = new TemplateTarget<T>(*(updateuniform._uniformTarget));
29 }
30
32
34 virtual void operator () (osg::Uniform* uniform, osg::NodeVisitor* nv)
35 {
37 update(*uniform);
38
39 traverse(uniform, nv);
40 }
41
42 bool link(Channel* channel)
43 {
44 if (channel->getName().find("uniform") != std::string::npos)
45 return channel->setTarget(_uniformTarget.get());
46 else
47 OSG_WARN << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl;
48
49 return false;
50 }
51
52 void update(osg::Uniform& uniform)
53 {
54 T value = _uniformTarget->getValue();
55 uniform.set(value);
56 }
57
58 };
59
60 // float
61 struct UpdateFloatUniform : public UpdateUniform<float>
62 {
63 UpdateFloatUniform(const std::string& aName = "") : UpdateUniform<float>(aName) { }
65 const osg::CopyOp& copyop) :
66 osg::Object(ufu, copyop), // copy name
67 UpdateUniform<float>(ufu, copyop) { }
68
70 };
71
72 // Vec2f
73 struct UpdateVec2fUniform : public UpdateUniform<osg::Vec2f>
74 {
75 UpdateVec2fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec2f>(aName) { }
77 const osg::CopyOp& copyop) :
78 osg::Object(uv2fu, copyop), // copy name
79 UpdateUniform<osg::Vec2f>(uv2fu, copyop) { }
80
82 };
83
84 // Vec3f
85 struct UpdateVec3fUniform : public UpdateUniform<osg::Vec3f>
86 {
87 UpdateVec3fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec3f>(aName) { }
89 const osg::CopyOp& copyop) :
90 osg::Object(uv3fu, copyop), // copy name
91 UpdateUniform<osg::Vec3f>(uv3fu, copyop) { }
92
94 };
95
96 // Vec4f
97 struct UpdateVec4fUniform : public UpdateUniform<osg::Vec4f>
98 {
99 UpdateVec4fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec4f>(aName) { }
101 const osg::CopyOp& copyop) :
102 osg::Object(uv4fu, copyop), // copy name
103 UpdateUniform<osg::Vec4f>(uv4fu, copyop) { }
104
106 };
107
108 // Matrixf
109 struct UpdateMatrixfUniform : public UpdateUniform<osg::Matrixf>
110 {
111 UpdateMatrixfUniform(const std::string& aName = "") : UpdateUniform<osg::Matrixf>(aName) { }
113 const osg::CopyOp& copyop) :
114 osg::Object(umfu, copyop), // copy name
115 UpdateUniform<osg::Matrixf>(umfu, copyop) { }
116
118 };
119}
120
121#endif
#define OSG_WARN
Definition Notify:85
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
The osgAnimation library provides general purpose utility classes for animation.
Definition Action:34
bool traverse(osg::Object *object, osg::Object *data)
traverse the nested callbacks or call NodeVisitor::traverse() if the object is Node,...
UniformCallback()
Definition Callback:273
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
VisitorType getVisitorType() const
Get the VisitorType.
Definition NodeVisitor:176
@ UPDATE_VISITOR
Definition NodeVisitor:96
Object()
Construct an object.
Definition Object:69
virtual const char * className() const =0
return the name of the object's class type.
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Uniform encapsulates glUniform values.
Definition Uniform:414
bool set(float f)
convenient scalar (non-array) value assignment
AnimationUpdateCallback()
Definition AnimationUpdateCallback:38
Definition Channel:33
const std::string & getName() const
virtual bool setTarget(Target *)=0
Definition Target:50
UpdateUniform(const std::string &aName="")
Definition UpdateUniform:18
osg::ref_ptr< TemplateTarget< T > > _uniformTarget
Definition UpdateUniform:15
bool link(Channel *channel)
Definition UpdateUniform:42
void update(osg::Uniform &uniform)
Definition UpdateUniform:52
UpdateUniform(const UpdateUniform &updateuniform, const osg::CopyOp &copyop)
Definition UpdateUniform:24
virtual void operator()(osg::Uniform *uniform, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.
Definition UpdateUniform:34
META_Object(osgAnimation, UpdateUniform< T >)
UpdateFloatUniform(const std::string &aName="")
Definition UpdateUniform:63
META_Object(osgAnimation, UpdateFloatUniform)
UpdateFloatUniform(const UpdateFloatUniform &ufu, const osg::CopyOp &copyop)
Definition UpdateUniform:64
META_Object(osgAnimation, UpdateVec2fUniform)
UpdateVec2fUniform(const UpdateVec2fUniform &uv2fu, const osg::CopyOp &copyop)
Definition UpdateUniform:76
UpdateVec2fUniform(const std::string &aName="")
Definition UpdateUniform:75
META_Object(osgAnimation, UpdateVec3fUniform)
UpdateVec3fUniform(const UpdateVec3fUniform &uv3fu, const osg::CopyOp &copyop)
Definition UpdateUniform:88
UpdateVec3fUniform(const std::string &aName="")
Definition UpdateUniform:87
META_Object(osgAnimation, UpdateVec4fUniform)
UpdateVec4fUniform(const UpdateVec4fUniform &uv4fu, const osg::CopyOp &copyop)
Definition UpdateUniform:100
UpdateVec4fUniform(const std::string &aName="")
Definition UpdateUniform:99
META_Object(osgAnimation, UpdateMatrixfUniform)
UpdateMatrixfUniform(const std::string &aName="")
Definition UpdateUniform:111
UpdateMatrixfUniform(const UpdateMatrixfUniform &umfu, const osg::CopyOp &copyop)
Definition UpdateUniform:112

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.