namespace GL {
AnimatedObject::AnimatedObject(const Object &o):
- ObjectInstance(o),
- shdata(0)
-{
- if(const Technique *tech = object.get_technique())
- if(tech->has_shaders())
- shdata = new ProgramData;
-}
-
-AnimatedObject::~AnimatedObject()
-{
- delete shdata;
-}
+ ObjectInstance(o)
+{ }
void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
{
- if(shdata)
- {
- if(link*16>=pose_data.size())
- pose_data.resize((link+1)*16);
- copy(m.data(), m.data()+16, &pose_data[link*16]);
- shdata->uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
- }
-}
-
-ProgramData &AnimatedObject::get_shader_data()
-{
- if(!shdata)
- throw invalid_operation("AnimatedObject::get_shader_data");
- return *shdata;
-}
-
-const ProgramData &AnimatedObject::get_shader_data() const
-{
- if(!shdata)
- throw invalid_operation("AnimatedObject::get_shader_data");
- return *shdata;
+ if(link*16>=pose_data.size())
+ pose_data.resize((link+1)*16);
+ copy(m.data(), m.data()+16, &pose_data[link*16]);
+ shdata.uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
}
void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
{
- if(!shdata)
- throw invalid_operation("AnimatedObject::set_uniform");
-
if(uni.size==1)
- shdata->uniform(name, uni.values[0]);
+ shdata.uniform(name, uni.values[0]);
else if(uni.size==2)
- shdata->uniform2(name, uni.values);
+ shdata.uniform2(name, uni.values);
else if(uni.size==3)
- shdata->uniform3(name, uni.values);
+ shdata.uniform3(name, uni.values);
else if(uni.size==4)
- shdata->uniform4(name, uni.values);
+ shdata.uniform4(name, uni.values);
else
throw invalid_argument("AnimatedObject::set_uniform");
}
void AnimatedObject::setup_render(Renderer &renderer, Tag) const
{
renderer.transform(matrix);
- if(shdata)
- renderer.add_shader_data(*shdata);
+ renderer.add_shader_data(shdata);
}
private:
std::vector<float> pose_data;
- ProgramData *shdata;
+ ProgramData shdata;
public:
AnimatedObject(const Object &);
- ~AnimatedObject();
void set_pose_matrix(unsigned, const Matrix &);
- ProgramData &get_shader_data();
- const ProgramData &get_shader_data() const;
+ ProgramData &get_shader_data() { return shdata; }
+ const ProgramData &get_shader_data() const { return shdata; }
DEPRECATED void set_uniform(const std::string &, const KeyFrame::AnimatedUniform &);