Skip to content

Commit

Permalink
Use an enum for the buffer type instead of two bools
Browse files Browse the repository at this point in the history
  • Loading branch information
FiniteReality committed Dec 8, 2024
1 parent 631e20b commit 75f5197
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
11 changes: 10 additions & 1 deletion patches/net/minecraft/client/renderer/PostChain.java.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
--- 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));
continue;
- 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);
Expand Down
57 changes: 51 additions & 6 deletions patches/net/minecraft/client/renderer/PostPass.java.patch
Original file line number Diff line number Diff line change
@@ -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<RenderTarget> getHandle(Map<ResourceLocation, ResourceHandle<RenderTarget>> p_364534_) {
ResourceHandle<RenderTarget> resourcehandle = p_364534_.get(this.targetId);
if (resourcehandle == null) {
@@ -142,7 +_,12 @@
@@ -142,7 +_,13 @@
ResourceHandle<RenderTarget> 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());
Expand Down

0 comments on commit 75f5197

Please sign in to comment.