From: Mikko Rasa Date: Thu, 26 Apr 2018 23:43:51 +0000 (+0300) Subject: Share shader data between copied RenderPasses X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d713e5391dc5d85759c7aab36f6df7a85c3d8eff;p=libs%2Fgl.git Share shader data between copied RenderPasses 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. --- diff --git a/source/renderpass.cpp b/source/renderpass.cpp index 3f63ec47..eb4ae1f9 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -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); } diff --git a/source/renderpass.h b/source/renderpass.h index 34c315b3..3b3b54b8 100644 --- a/source/renderpass.h +++ b/source/renderpass.h @@ -58,7 +58,7 @@ private: }; const Program *shprog; - ProgramData *shdata; + RefPtr shdata; std::map uniform_slots; RefPtr 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(); }