From 75f5197577c72a347e88c36be8c11ad416f338ac Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Sun, 8 Dec 2024 14:59:49 +0000 Subject: [PATCH] Use an enum for the buffer type instead of two bools --- .../client/renderer/PostChain.java.patch | 11 +++- .../client/renderer/PostPass.java.patch | 57 +++++++++++++++++-- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/patches/net/minecraft/client/renderer/PostChain.java.patch b/patches/net/minecraft/client/renderer/PostChain.java.patch index 0b08462b4f..73b227ac22 100644 --- a/patches/net/minecraft/client/renderer/PostChain.java.patch +++ b/patches/net/minecraft/client/renderer/PostChain.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/client/renderer/PostChain.java +++ b/net/minecraft/client/renderer/PostChain.java +@@ -17,6 +_,8 @@ + import java.util.stream.Collectors; + import java.util.stream.Stream; + import javax.annotation.Nullable; ++ ++import net.minecraft.client.renderer.PostPass.TargetInput.BufferType; + import net.minecraft.client.renderer.texture.AbstractTexture; + import net.minecraft.client.renderer.texture.TextureManager; + import net.minecraft.resources.ResourceLocation; @@ -79,8 +_,8 @@ abstracttexture.setFilter(flag, false); postpass.addInput(new PostPass.TextureInput(s3, abstracttexture, i, j)); @@ -7,7 +16,7 @@ - case PostChainConfig.TargetInput(String s1, ResourceLocation resourcelocation1, boolean flag1, boolean flag2): - postpass.addInput(new PostPass.TargetInput(s1, resourcelocation1, flag1, flag2)); + case PostChainConfig.TargetInput(String s1, ResourceLocation resourcelocation1, boolean flag1, boolean flag2, boolean useStencilBuffer): -+ postpass.addInput(new PostPass.TargetInput(s1, resourcelocation1, flag1, flag2, useStencilBuffer)); ++ postpass.addInput(new PostPass.TargetInput(s1, resourcelocation1, BufferType.from(flag1, useStencilBuffer), flag2)); continue; default: throw new MatchException(null, null); diff --git a/patches/net/minecraft/client/renderer/PostPass.java.patch b/patches/net/minecraft/client/renderer/PostPass.java.patch index 5ef576cd68..efa98f666b 100644 --- a/patches/net/minecraft/client/renderer/PostPass.java.patch +++ b/patches/net/minecraft/client/renderer/PostPass.java.patch @@ -1,25 +1,70 @@ --- a/net/minecraft/client/renderer/PostPass.java +++ b/net/minecraft/client/renderer/PostPass.java -@@ -122,7 +_,10 @@ +@@ -122,7 +_,54 @@ } @OnlyIn(Dist.CLIENT) - public static record TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear) implements PostPass.Input { -+ public static record TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear, boolean stencilBuffer) implements PostPass.Input { ++ public static record TargetInput(String samplerName, ResourceLocation targetId, BufferType bufferType, boolean bilinear) implements PostPass.Input { ++ public enum BufferType { ++ NONE(false, false), ++ DEPTH_ONLY(true, false), ++ STENCIL_ONLY(false, true), ++ DEPTH_STENCIL(true, true); ++ ++ private final boolean depth; ++ private final boolean stencil; ++ ++ BufferType(boolean depth, boolean stencil) { ++ this.depth = depth; ++ this.stencil = stencil; ++ } ++ ++ public boolean hasDepth() { ++ return this.depth; ++ } ++ ++ public boolean hasStencil() { ++ return this.stencil; ++ } ++ ++ public static BufferType from(boolean useDepth, boolean useStencil) { ++ if (useDepth && useStencil) { ++ return DEPTH_STENCIL; ++ } else if (useDepth) { ++ return DEPTH_ONLY; ++ } else if (useStencil) { ++ return STENCIL_ONLY; ++ } else { ++ return NONE; ++ } ++ } ++ } ++ + public TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear) { -+ this(samplerName, targetId, depthBuffer, bilinear, false); ++ this(samplerName, targetId, depthBuffer ? BufferType.DEPTH_ONLY : BufferType.NONE, bilinear); ++ } ++ ++ public boolean depthBuffer() { ++ return bufferType.hasDepth(); ++ } ++ ++ public boolean stencilBuffer() { ++ return bufferType.hasStencil(); + } ++ private ResourceHandle getHandle(Map> p_364534_) { ResourceHandle resourcehandle = p_364534_.get(this.targetId); if (resourcehandle == null) { -@@ -142,7 +_,12 @@ +@@ -142,7 +_,13 @@ ResourceHandle resourcehandle = this.getHandle(p_361239_); RenderTarget rendertarget = resourcehandle.get(); rendertarget.setFilterMode(this.bilinear ? 9729 : 9728); - p_366564_.bindSampler(this.samplerName + "Sampler", this.depthBuffer ? rendertarget.getDepthTextureId() : rendertarget.getColorTextureId()); -+ if (this.depthBuffer) ++ if (this.depthBuffer()) + p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getDepthTextureId()); -+ else if (this.stencilBuffer) ++ // If stencil is specified ++ else if (this.stencilBuffer()) + p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getStencilTextureId()); + else + p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getColorTextureId());