From 5c88ef7a0454739f739217d18a6b1d66c1289cd6 Mon Sep 17 00:00:00 2001 From: QiuYe Date: Tue, 24 Nov 2026 14:49:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=88=E6=88=90=E5=9B=BE?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=9A=84=E7=89=A9=E5=93=81=E5=85=89=E6=95=88?= =?UTF-8?q?=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tree/export/CraftingPlanGraphCapture.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/fish_dan_/data_energistics/client/crafting/tree/export/CraftingPlanGraphCapture.java b/src/main/java/com/fish_dan_/data_energistics/client/crafting/tree/export/CraftingPlanGraphCapture.java index e438cdf63..1fe76fe92 100644 --- a/src/main/java/com/fish_dan_/data_energistics/client/crafting/tree/export/CraftingPlanGraphCapture.java +++ b/src/main/java/com/fish_dan_/data_energistics/client/crafting/tree/export/CraftingPlanGraphCapture.java @@ -3,6 +3,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.util.FastColor.ABGR32; import net.neoforged.neoforge.client.GlStateBackup; @@ -15,6 +16,7 @@ import com.mojang.blaze3d.vertex.VertexSorting; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import org.joml.Matrix4f; import org.jspecify.annotations.Nullable; import org.lwjgl.opengl.GL11; @@ -23,19 +25,27 @@ import org.lwjgl.opengl.GL21; import org.lwjgl.opengl.GL30; +import java.util.List; +import java.util.SequencedMap; + /** Reusable render-thread transparent target, with IO-thread pixel conversion before PNG encoding. */ final class CraftingPlanGraphCapture implements AutoCloseable { private final RenderState previous; private final RenderTarget target = new CaptureTarget(); private final ByteBufferBuilder vertexMemory; + private final SequencedMap glintBuffers = new Object2ObjectLinkedOpenHashMap<>(5); CraftingPlanGraphCapture(int width, int height) { RenderSystem.assertOnRenderThread(); this.previous = new RenderState(); - ByteBufferBuilder allocated = null; + this.vertexMemory = new ByteBufferBuilder(786432); try { - allocated = new ByteBufferBuilder(786432); + // Item rendering keeps both its glint and model consumers open while emitting vertices. + for (RenderType layer : List.of(RenderType.armorEntityGlint(), RenderType.glint(), RenderType.glintTranslucent(), + RenderType.entityGlint(), RenderType.entityGlintDirect())) { + this.glintBuffers.put(layer, new ByteBufferBuilder(layer.bufferSize())); + } RenderSystem.disableScissor(); GL11.glDisable(GL11.GL_STENCIL_TEST); RenderSystem.colorMask(true, true, true, true); @@ -43,13 +53,11 @@ final class CraftingPlanGraphCapture implements AutoCloseable { RenderSystem.glBindBuffer(GL21.GL_PIXEL_UNPACK_BUFFER, 0); this.target.resize(width, height, Minecraft.ON_OSX); this.target.setClearColor(0, 0, 0, 0); - this.vertexMemory = allocated; } catch (Throwable failure) { try { - this.target.destroyBuffers(); - if (allocated != null) allocated.close(); - } finally { - this.previous.restore(); + close(); + } catch (Throwable cleanupFailure) { + failure.addSuppressed(cleanupFailure); } throw failure; } @@ -70,7 +78,7 @@ GuiGraphics begin(Minecraft client, double scale, double x, double y) { RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - GuiGraphics graphics = new GuiGraphics(client, MultiBufferSource.immediate(this.vertexMemory)); + GuiGraphics graphics = new GuiGraphics(client, MultiBufferSource.immediateWithBuffers(this.glintBuffers, this.vertexMemory)); graphics.pose().scale((float) scale, (float) scale, 1); graphics.pose().translate(x, y, 0); return graphics; @@ -136,6 +144,7 @@ private static int unpremultiplyChannel(int channel, int alpha) { public void close() { try { this.vertexMemory.close(); + this.glintBuffers.values().forEach(ByteBufferBuilder::close); } finally { try { this.target.destroyBuffers();