]> git.tdb.fi Git - libs/gl.git/commitdiff
Share shader data between copied RenderPasses
authorMikko Rasa <tdb@tdb.fi>
Thu, 26 Apr 2018 23:43:51 +0000 (02:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 26 Apr 2018 23:43:51 +0000 (02:43 +0300)
Applications that use the Text class hevily were ending up with multiple
copies of the same ProgramData, each with their own uniform buffers.

An even better solution would be to have Text objects share the technique,
but I don't have any good ideas for implementing that.

source/renderpass.cpp
source/renderpass.h

index 3f63ec47a8c382b058bd3321df01161290e387f2..eb4ae1f93ba145b029ff5a23847b02e557f56c37 100644 (file)
@@ -25,7 +25,7 @@ RenderPass::RenderPass():
 
 RenderPass::RenderPass(const RenderPass &other):
        shprog(other.shprog),
-       shdata(other.shdata ? new ProgramData(*other.shdata) : 0),
+       shdata(other.shdata),
        uniform_slots(other.uniform_slots),
        material(other.material),
        texturing(other.texturing ? new Texturing(*other.texturing) : 0),
@@ -36,7 +36,7 @@ RenderPass::RenderPass(const RenderPass &other):
 RenderPass &RenderPass::operator=(const RenderPass &other)
 {
        shprog = other.shprog;
-       shdata = other.shdata ? new ProgramData(*other.shdata) : 0;
+       shdata = other.shdata;
        uniform_slots = other.uniform_slots;
        material = other.material;
        texturing = other.texturing ? new Texturing(*other.texturing) : 0;
@@ -48,13 +48,11 @@ RenderPass &RenderPass::operator=(const RenderPass &other)
 RenderPass::~RenderPass()
 {
        delete texturing;
-       delete shdata;
 }
 
 void RenderPass::set_shader_program(const Program *prog, const ProgramData *data)
 {
        shprog = prog;
-       delete shdata;
        shdata = new ProgramData(*data);
 }
 
@@ -95,7 +93,7 @@ void RenderPass::apply(Renderer &renderer) const
 {
        renderer.set_texturing(texturing);
        renderer.set_material(material.get());
-       renderer.set_shader_program(shprog, shdata);
+       renderer.set_shader_program(shprog, shdata.get());
        renderer.set_reverse_winding(back_faces);
 }
 
index 34c315b3a2c0cc797031c024d2b1f315906bff7d..3b3b54b8569e12936cf6f8ffb04dbe0d8378ed95 100644 (file)
@@ -58,7 +58,7 @@ private:
        };
 
        const Program *shprog;
-       ProgramData *shdata;
+       RefPtr<ProgramData> shdata;
        std::map<std::string, std::string> uniform_slots;
        RefPtr<const Material> material;
        std::string material_slot;
@@ -74,7 +74,7 @@ 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; }
+       const ProgramData *get_shader_data() const { return shdata.get(); }
        const std::string &get_slotted_uniform_name(const std::string &) const;
        void set_material(const Material *);
        const Material *get_material() const { return material.get(); }