]> git.tdb.fi Git - libs/gl.git/commitdiff
Cache texture bindings when the shader program does not change
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 13:23:54 +0000 (15:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Nov 2021 13:24:34 +0000 (15:24 +0200)
source/render/renderer.cpp
source/render/renderer.h

index 8a2833b8b55b5551a5ae992d7cd8a22ef0108299..b935ce14c3e88bf94636135cc5ae0fe084574cbf 100644 (file)
@@ -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)
index 001ec7e1ca11864c172cef70219872de36fdbb6d..107efcb742cdb5ee98015bb19ffaf7b77d0f70d2 100644 (file)
@@ -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;