From d713e5391dc5d85759c7aab36f6df7a85c3d8eff Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 27 Apr 2018 02:43:51 +0300 Subject: [PATCH] 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. --- source/renderpass.cpp | 8 +++----- source/renderpass.h | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) 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(); } -- 2.45.2