]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow direct access to AnimatedObject's ProgramData
authorMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:35:46 +0000 (11:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:35:46 +0000 (11:35 +0300)
The animation-related set_uniform interface was already public so there
isn't any good reason to not allow full access.  This also makes trivial
customization easier as subclassing is not needed.

source/animatedobject.cpp
source/animatedobject.h
source/animationplayer.cpp
source/animationplayer.h

index d2157fd1bc128ebc6dd676ef0cc10c54b9204e5c..99466f2098dd1d6a526354c86ce62bcf3043853c 100644 (file)
@@ -37,6 +37,13 @@ void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
        }
 }
 
+ProgramData &AnimatedObject::get_shader_data()
+{
+       if(!shdata)
+               throw invalid_operation("AnimatedObject::get_shader_data");
+       return *shdata;
+}
+
 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
 {
        if(!shdata)
index 23333ee53dfb4e5e347c97ed97d7c05b033e737a..3ec336fd353e1349bec2d0811f579512c5819233 100644 (file)
@@ -37,6 +37,9 @@ public:
        ~AnimatedObject();
 
        void set_pose_matrix(unsigned, const Matrix &);
+       ProgramData &get_shader_data();
+
+       // Deprecated
        void set_uniform(const std::string &, const KeyFrame::AnimatedUniform &);
 
        virtual const Matrix *get_matrix() const { return &matrix; }
index 59c6f595a0b45cb889b1e7b447084205a26cb22d..0c00105276309f711569a0ae65a29347c0879b2a 100644 (file)
@@ -1,6 +1,7 @@
 #include "animatedobject.h"
 #include "animationplayer.h"
 #include "armature.h"
+#include "programdata.h"
 
 using namespace std;
 
@@ -91,7 +92,7 @@ bool AnimationPlayer::tick_single(ObjectSlot &slot, const Time::TimeDelta &dt)
 
        unsigned n_uniforms = anim.animation.get_n_uniforms();
        for(unsigned i=0; i<n_uniforms; ++i)
-               obj.set_uniform(anim.animation.get_uniform_name(i), anim.iterator.get_uniform(i));
+               set_object_uniform(obj, anim.animation.get_uniform_name(i), anim.iterator.get_uniform(i));
 
        if(slot.armature)
        {
@@ -113,7 +114,7 @@ bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt)
 
                unsigned n_uniforms = i->animation.get_n_uniforms();
                for(unsigned j=0; j<n_uniforms; ++j)
-                       slot.object.set_uniform(i->animation.get_uniform_name(j), i->iterator.get_uniform(j));
+                       set_object_uniform(slot.object, i->animation.get_uniform_name(j), i->iterator.get_uniform(j));
        }
        slot.object.set_matrix(matrix);
 
@@ -143,6 +144,20 @@ bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt)
        return !slot.animations.empty();
 }
 
+void AnimationPlayer::set_object_uniform(AnimatedObject &obj, const string &name, const KeyFrame::AnimatedUniform &uni)
+{
+       ProgramData &shdata = obj.get_shader_data();
+
+       if(uni.size==1)
+               shdata.uniform(name, uni.values[0]);
+       else if(uni.size==2)
+               shdata.uniform2(name, uni.values);
+       else if(uni.size==2)
+               shdata.uniform3(name, uni.values);
+       else if(uni.size==4)
+               shdata.uniform4(name, uni.values);
+}
+
 
 AnimationPlayer::ObjectSlot::ObjectSlot(AnimatedObject &o):
        object(o),
index 34a282d6b5bba2f36dce446a243c84b841176714..f4eb0c767c8c660296e35c204588c40f6d7da42e 100644 (file)
@@ -69,6 +69,7 @@ public:
 private:
        bool tick_single(ObjectSlot &, const Time::TimeDelta &);
        bool tick_stacked(ObjectSlot &, const Time::TimeDelta &);
+       static void set_object_uniform(AnimatedObject &, const std::string &, const KeyFrame::AnimatedUniform &);
 };
 
 } // namespace GL