From: Mikko Rasa Date: Thu, 13 May 2021 11:04:41 +0000 (+0300) Subject: Always assume Technique has shaders X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=edd5491943fe7aba6e6865cf53a02da682071a55;p=libs%2Fgl.git Always assume Technique has shaders --- diff --git a/source/animation/animatedobject.cpp b/source/animation/animatedobject.cpp index 71680623..a551d1a7 100644 --- a/source/animation/animatedobject.cpp +++ b/source/animation/animatedobject.cpp @@ -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); } diff --git a/source/animation/animatedobject.h b/source/animation/animatedobject.h index faa9325c..df920755 100644 --- a/source/animation/animatedobject.h +++ b/source/animation/animatedobject.h @@ -31,15 +31,14 @@ public: private: std::vector 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 &); diff --git a/source/materials/technique.h b/source/materials/technique.h index a7999c0c..bfd979aa 100644 --- a/source/materials/technique.h +++ b/source/materials/technique.h @@ -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 &); };