From 94d127ccc32b3a7704595c371abfe4727e5b3dc0 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sun, 14 Jun 2020 08:16:38 +0100 Subject: [PATCH] GLES2 Batching - Fix try_join_item logic for lights The old logic was incorrect, the first item with lights would prevent joining the next item in case it didn't have lights. Now the check is deferred so that items without lights check to see if the previous item had lights, and if so they prevent a join. --- drivers/gles2/rasterizer_canvas_gles2.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index edf47f6f4d1..e840636b61e 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -2426,14 +2426,18 @@ bool RasterizerCanvasGLES2::try_join_item(Item *p_ci, RenderItemState &r_ris, bo if (!light_allow_join) { // can't join join = false; - // we also dont want to allow joining this item with the next item, because the next item could have no lights! - r_batch_break = true; } } else { - // can't join the next item if it has any lights as it will be by definition affected by different set of lights - r_ris.light_region.light_bitfield = 0; - r_ris.light_region.shadow_bitfield = 0; + // if the last item had lights, we should not join it to this one (which has no lights) + if (r_ris.light_region.light_bitfield || r_ris.light_region.shadow_bitfield) { + join = false; + + // setting these to zero ensures that any following item with lights will, by definition, + // be affected by a different set of lights, and thus prevent a join + r_ris.light_region.light_bitfield = 0; + r_ris.light_region.shadow_bitfield = 0; + } } if (reclip) {