]> git.tdb.fi Git - libs/gl.git/commitdiff
Automatically add uniforms for texunits
authorMikko Rasa <tdb@tdb.fi>
Tue, 19 May 2020 12:16:35 +0000 (15:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 19 May 2020 12:16:35 +0000 (15:16 +0300)
The uniform statement now uses existing ProgramData if it exists, to
avoid inadvertently erasing the texunit uniforms.

source/renderpass.cpp
source/renderpass.h

index be5bb170280844d88c8b3e8f46fd22cb72e902de..4e3b1f1332bbd0dcda294940821d61be091604f3 100644 (file)
@@ -52,6 +52,17 @@ RenderPass::~RenderPass()
        delete texturing;
 }
 
+void RenderPass::ensure_private_shader_data()
+{
+       if(!shprog)
+               throw invalid_operation("RenderPass::ensure_private_shader_data");
+
+       if(!shdata)
+               shdata = new ProgramData(shprog);
+       else if(shdata.refcount() > 1)
+               shdata = new ProgramData(*shdata);
+}
+
 void RenderPass::set_shader_program(const Program *prog, const ProgramData *data)
 {
        shprog = prog;
@@ -153,12 +164,13 @@ void RenderPass::Loader::texunit_named(unsigned i, const string &n)
 {
        texunit(i);
        obj.tex_names[n] = i;
+       obj.ensure_private_shader_data();
+       obj.shdata->uniform(n, static_cast<int>(i));
 }
 
 void RenderPass::Loader::uniforms()
 {
-       if(!obj.shprog)
-               throw invalid_operation("RenderPass::Loader::uniforms");
+       obj.ensure_private_shader_data();
        RefPtr<ProgramData> shd = new ProgramData(obj.shprog);
        load_sub(*shd);
        obj.shdata = shd.release();
index 76c7472043e188eb09e275df0951fb769bd2f297..66768772f2d545a6e817c612a39873e5a9234b6d 100644 (file)
@@ -71,6 +71,10 @@ public:
        RenderPass &operator=(const RenderPass &);
        ~RenderPass();
 
+private:
+       void ensure_private_shader_data();
+
+public:
        void set_shader_program(const Program *, const ProgramData *);
        const Program *get_shader_program() const { return shprog; }
        const ProgramData *get_shader_data() const { return shdata.get(); }