]> git.tdb.fi Git - libs/gl.git/commitdiff
Recreate RenderPass shdata if a new program is specified
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 08:09:14 +0000 (11:09 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 15:38:43 +0000 (18:38 +0300)
source/programdata.cpp
source/programdata.h
source/renderpass.cpp
source/renderpass.h

index e279635f876116d1e40fce3064423e05c1e597c3..3561719725501a4ca7663ad4ae6c3e825e6bd10b 100644 (file)
@@ -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<NamedUniform>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
+                       tied_program->get_uniform_info(i->name);
+       }
+
+       uniforms = other.uniforms;
+       for(vector<NamedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+               i->value = i->value->clone();
+}
+
 ProgramData &ProgramData::operator=(const ProgramData &other)
 {
        tied_program = other.tied_program;
index 605b41b1359c0da3146b05d2b78e9cf7dfb96e9f..bc2289b52965a4e29262c1754139bec7efdbd33c 100644 (file)
@@ -155,6 +155,7 @@ private:
 public:
        ProgramData(const Program * = 0);
        ProgramData(const ProgramData &);
+       ProgramData(const ProgramData &, const Program *);
        ProgramData &operator=(const ProgramData &);
        ~ProgramData();
 
index 34a311e79ece2f7e4df91d382010dca39137be1f..7c7cf2c4a2022cbb1da62c84c385914d543c2edf 100644 (file)
@@ -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<Program>(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)
index 3570151258beb225f84ecd6ef43dd269f8579c7b..261669148de31838cb7dfc980f0bc70c2cd08bb7 100644 (file)
@@ -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 &);