From 87aa853f814c17a97cc9f4ea5252d47a43ffd98c Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Tue, 16 Jun 2026 22:16:26 -0700 Subject: [PATCH] Attempt to fix deferred particle batching (#1871) --- .../angelica/client/rendering/DeferredDrawBatcher.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java b/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java index 69a9c7bee..74c812960 100644 --- a/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java +++ b/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java @@ -25,6 +25,7 @@ public class DeferredDrawBatcher { @Getter private static boolean active = false; private static DeferredBatchTessellator batchTessellator; + private static long entryStateKey; private DeferredDrawBatcher() {} @@ -41,13 +42,14 @@ public class DeferredDrawBatcher { batchTessellator.clearRanges(); batchTessellator.setParentTessellator(Tessellator.instance); batchTessellator.snapshotDefaultModelview(); + entryStateKey = captureStateKey(); TessellatorManager.startCapturingDirect(batchTessellator); } /** * Exit deferred mode and flush all captured batches. Groups entries by state key - * and vertex format, issues one draw per unique group. Restores the GL state that - * was active for the last group so vanilla sees consistent state. + * and vertex format, issues one draw per unique group. Restores the bracket's entry + * state so the trailing vanilla Tessellator.draw() renders with the layer atlas. */ public static void exitAndFlush() { active = false; @@ -56,6 +58,7 @@ public class DeferredDrawBatcher { if (!ranges.isEmpty()) { ranges.sort(Comparator.comparingLong(DeferredBatchTessellator.DrawRange::stateKey)); flushSorted(ranges); + applyStateKey(entryStateKey); } TessellatorManager.stopCapturingDirect(); @@ -147,7 +150,8 @@ public class DeferredDrawBatcher { * - fog state (mode, color, start/end — constant for the frame) */ static long captureStateKey() { - final int textureId = GLStateManager.getTextures().getTextureUnitBindings(0).getBinding(); + final int activeUnit = GLStateManager.getActiveTextureUnit(); + final int textureId = GLStateManager.getTextures().getTextureUnitBindings(activeUnit).getBinding(); final int srcRgb = GLStateManager.getBlendState().getSrcRgb(); final int dstRgb = GLStateManager.getBlendState().getDstRgb(); final boolean blendEnabled = GLStateManager.getBlendMode().isEnabled();