]> git.tdb.fi Git - libs/gl.git/commitdiff
Always assume Technique has shaders
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 May 2021 11:04:41 +0000 (14:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 May 2021 11:04:41 +0000 (14:04 +0300)
source/animation/animatedobject.cpp
source/animation/animatedobject.h
source/materials/technique.h

index 7168062320138599a81db306e983563020fffa6e..a551d1a759544c4b1fe33fb655a533e78435209a 100644 (file)
@@ -13,57 +13,27 @@ namespace Msp {
 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");
 }
@@ -71,8 +41,7 @@ void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUni
 void AnimatedObject::setup_render(Renderer &renderer, Tag) const
 {
        renderer.transform(matrix);
-       if(shdata)
-               renderer.add_shader_data(*shdata);
+       renderer.add_shader_data(shdata);
 }
 
 
index faa9325cb74912a4439788616c5dac4475dc7cc3..df920755729e05e17da5a617a546d8460f63704c 100644 (file)
@@ -31,15 +31,14 @@ public:
 
 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 &);
 
index a7999c0cf67652a140a219c24258e2a3e210ee39..bfd979aae573c26f5a29330ff2a5a1c86981d1d0 100644 (file)
@@ -64,7 +64,7 @@ public:
        bool replace_texture(const std::string &, const Texture &);
        bool replace_material(const std::string &, const Material &);
        bool replace_uniforms(const ProgramData &);
-       bool has_shaders() const;
+       DEPRECATED bool has_shaders() const;
 
        void set_debug_name(const std::string &);
 };