From 5afcdfca303220d3e8ae6ad6e81ed4ba64467a5b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 8 Nov 2021 15:23:54 +0200 Subject: [PATCH] Cache texture bindings when the shader program does not change --- source/render/renderer.cpp | 12 +++++++----- source/render/renderer.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 8a2833b8..b935ce14 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -303,11 +303,13 @@ void Renderer::apply_state() flush_textures(); for(const BoundTexture &t: texture_stack) - { - int unit = (t.tag.id ? state->shprog->get_uniform_binding(t.tag) : t.unit); - if(unit>=0) - pipeline_state.set_texture(unit, t.texture, t.sampler); - } + if(t.texture && t.replaced<0) + { + if(t.binding<0 || shprog_changed) + t.binding = state->shprog->get_uniform_binding(t.tag); + if(t.binding>=0) + pipeline_state.set_texture(t.binding, t.texture, t.sampler); + } bool shdata_changed = changed&SHADER_DATA; for(auto i=shdata_stack.begin(); (!shdata_changed && i!=shdata_stack.end()); ++i) diff --git a/source/render/renderer.h b/source/render/renderer.h index 001ec7e1..107efcb7 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -59,7 +59,7 @@ private: struct BoundTexture { Tag tag; - mutable int unit = -1; + mutable int binding = -1; const Texture *texture = 0; const Sampler *sampler = 0; int replaced = -1; -- 2.45.2