]> git.tdb.fi Git - libs/gl.git/blob - source/animatedobject.cpp
Plug a memory leak
[libs/gl.git] / source / animatedobject.cpp
1 #include <algorithm>
2 #include <msp/strings/format.h>
3 #include "animatedobject.h"
4 #include "object.h"
5 #include "programdata.h"
6 #include "renderer.h"
7 #include "technique.h"
8
9 using namespace std;
10
11 namespace Msp {
12 namespace GL {
13
14 AnimatedObject::AnimatedObject(const Object &o):
15         ObjectInstance(o),
16         shdata(0)
17 {
18         if(const Technique *tech = object.get_technique())
19                 if(tech->has_shaders())
20                         shdata = new ProgramData;
21 }
22
23 AnimatedObject::~AnimatedObject()
24 {
25         delete shdata;
26 }
27
28 void AnimatedObject::set_matrix(const Matrix &m)
29 {
30         matrix = m;
31 }
32
33 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
34 {
35         if(shdata)
36         {
37                 if(link*16>=pose_data.size())
38                         pose_data.resize((link+1)*16);
39                 copy(m.data(), m.data()+16, &pose_data[link*16]);
40                 shdata->uniform_matrix4_array("pose[0]", pose_data.size()/16, &pose_data[0]);
41         }
42 }
43
44 void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const
45 {
46         renderer.matrix_stack() *= matrix;
47         if(shdata)
48                 renderer.add_shader_data(shdata);
49 }
50
51 } // namespace GL
52 } // namespace Msp