From: Mikko Rasa Date: Sun, 22 Apr 2018 08:35:46 +0000 (+0300) Subject: Allow direct access to AnimatedObject's ProgramData X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d093b45975eb03b07680711ce982ad634a50fba3;p=libs%2Fgl.git Allow direct access to AnimatedObject's ProgramData 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. --- diff --git a/source/animatedobject.cpp b/source/animatedobject.cpp index d2157fd1..99466f20 100644 --- a/source/animatedobject.cpp +++ b/source/animatedobject.cpp @@ -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) diff --git a/source/animatedobject.h b/source/animatedobject.h index 23333ee5..3ec336fd 100644 --- a/source/animatedobject.h +++ b/source/animatedobject.h @@ -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; } diff --git a/source/animationplayer.cpp b/source/animationplayer.cpp index 59c6f595..0c001052 100644 --- a/source/animationplayer.cpp +++ b/source/animationplayer.cpp @@ -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; ianimation.get_n_uniforms(); for(unsigned j=0; janimation.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), diff --git a/source/animationplayer.h b/source/animationplayer.h index 34a282d6..f4eb0c76 100644 --- a/source/animationplayer.h +++ b/source/animationplayer.h @@ -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