]> git.tdb.fi Git - libs/gl.git/blob - source/animatedobject.cpp
Support for armature-based animation
[libs/gl.git] / source / animatedobject.cpp
1 #include <msp/strings/format.h>
2 #include "animatedobject.h"
3 #include "object.h"
4 #include "programdata.h"
5 #include "renderer.h"
6 #include "technique.h"
7
8 namespace Msp {
9 namespace GL {
10
11 AnimatedObject::AnimatedObject(const Object &o):
12         ObjectInstance(o),
13         shdata(0)
14 {
15         if(const Technique *tech = object.get_technique())
16         {
17                 // XXX Should create separate ProgramData for each pass
18                 const RenderPass &pass = tech->get_pass(Tag());
19                 if(const Program *shprog = pass.get_shader_program())
20                         shdata = new ProgramData(*shprog);
21         }
22 }
23
24 void AnimatedObject::set_matrix(const Matrix &m)
25 {
26         matrix = m;
27 }
28
29 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
30 {
31         if(shdata)
32                 shdata->uniform_matrix4(format("pose[%d]", link), m);
33 }
34
35 void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const
36 {
37         renderer.matrix_stack() *= matrix;
38         if(shdata)
39                 renderer.add_shader_data(shdata);
40 }
41
42 } // namespace GL
43 } // namespace Msp