From ed7ca8892daceebb963950945fed5e75bd96a8a1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 11 Jun 2020 11:09:14 +0300 Subject: [PATCH] Recreate RenderPass shdata if a new program is specified --- source/programdata.cpp | 17 +++++++++++++++++ source/programdata.h | 1 + source/renderpass.cpp | 11 ++++++++++- source/renderpass.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/source/programdata.cpp b/source/programdata.cpp index e279635f..35617197 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -34,6 +34,23 @@ ProgramData::ProgramData(const ProgramData &other): i->value = i->value->clone(); } +ProgramData::ProgramData(const ProgramData &other, const Program *p): + tied_program(p), + last_block(0), + buffer(0), + dirty(0) +{ + if(tied_program) + { + for(vector::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i) + tied_program->get_uniform_info(i->name); + } + + uniforms = other.uniforms; + for(vector::iterator i=uniforms.begin(); i!=uniforms.end(); ++i) + i->value = i->value->clone(); +} + ProgramData &ProgramData::operator=(const ProgramData &other) { tied_program = other.tied_program; diff --git a/source/programdata.h b/source/programdata.h index 605b41b1..bc2289b5 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -155,6 +155,7 @@ private: public: ProgramData(const Program * = 0); ProgramData(const ProgramData &); + ProgramData(const ProgramData &, const Program *); ProgramData &operator=(const ProgramData &); ~ProgramData(); diff --git a/source/renderpass.cpp b/source/renderpass.cpp index 34a311e7..7c7cf2c4 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -135,7 +135,7 @@ RenderPass::Loader::Loader(RenderPass &p, Collection &c): void RenderPass::Loader::init() { - add("shader", &RenderPass::shprog); + add("shader", &Loader::shader); add("material", &Loader::material_inline); add("material", &Loader::material); add("material_slot", &RenderPass::material_slot); @@ -162,6 +162,15 @@ void RenderPass::Loader::material(const string &name) obj.finalize_material(); } +void RenderPass::Loader::shader(const string &n) +{ + obj.shprog = &get_collection().get(n); + if(obj.shdata) + obj.shdata = new ProgramData(*obj.shdata, obj.shprog); + if(obj.material) + obj.finalize_material(); +} + void RenderPass::Loader::texunit(unsigned i) { if(!obj.texturing) diff --git a/source/renderpass.h b/source/renderpass.h index 35701512..26166914 100644 --- a/source/renderpass.h +++ b/source/renderpass.h @@ -34,6 +34,7 @@ public: void material_inline(); void material(const std::string &); + void shader(const std::string &); void texunit(unsigned); void texunit_auto(const std::string &); void texunit_named(unsigned, const std::string &); -- 2.45.2