From ea3aeb45a823cc3e2f5b5695eac0c2cc2ad11971 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Wed, 27 Nov 2024 17:19:44 +0000 Subject: [PATCH 01/18] Separate ClientModLoader begin/finish into two methods, implement MainTarget configuration event --- .../blaze3d/pipeline/MainTarget.java.patch | 15 ++ .../blaze3d/pipeline/RenderTarget.java.patch | 134 ++++++++++++++++++ .../net/minecraft/client/Minecraft.java.patch | 8 +- .../neoforge/client/ClientHooks.java | 7 + .../event/ConfigureMainRenderTargetEvent.java | 72 ++++++++++ .../client/loading/ClientModLoader.java | 5 +- 6 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch create mode 100644 patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch create mode 100644 src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch new file mode 100644 index 00000000000..8071336f342 --- /dev/null +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -0,0 +1,15 @@ +--- a/com/mojang/blaze3d/pipeline/MainTarget.java ++++ b/com/mojang/blaze3d/pipeline/MainTarget.java +@@ -16,7 +_,11 @@ + static final MainTarget.Dimension DEFAULT_DIMENSIONS = new MainTarget.Dimension(854, 480); + + public MainTarget(int p_166137_, int p_166138_) { +- super(true); ++ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(), p_166137_, p_166138_); ++ } ++ ++ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e, int p_166137_, int p_166138_) { ++ super(e.useDepth(), e.useStencil()); + this.createFrameBuffer(p_166137_, p_166138_); + } + diff --git a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch new file mode 100644 index 00000000000..bddf05a9c12 --- /dev/null +++ b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch @@ -0,0 +1,134 @@ +--- a/com/mojang/blaze3d/pipeline/RenderTarget.java ++++ b/com/mojang/blaze3d/pipeline/RenderTarget.java +@@ -25,17 +_,31 @@ + public int viewWidth; + public int viewHeight; + public final boolean useDepth; ++ public final boolean useStencil; + public int frameBufferId; + protected int colorTextureId; + protected int depthBufferId; ++ protected int stencilBufferId; + private final float[] clearChannels = Util.make(() -> new float[]{1.0F, 1.0F, 1.0F, 0.0F}); + public int filterMode; + + public RenderTarget(boolean p_166199_) { +- this.useDepth = p_166199_; ++ this(p_166199_, false); ++ } ++ ++ public RenderTarget(boolean useDepth, boolean useStencil) { ++ this.useDepth = useDepth; ++ this.useStencil = useStencil; + this.frameBufferId = -1; + this.colorTextureId = -1; + this.depthBufferId = -1; ++ ++ if (!useDepth && useStencil) { ++ var capabilities = org.lwjgl.opengl.GL.getCapabilities(); ++ if (!capabilities.GL_ARB_texture_stencil8 && !capabilities.OpenGL44) { ++ throw new UnsupportedOperationException("Stencil-only buffers require GL_ARB_texture_stencil8 OR OpenGL 4.4"); ++ } ++ } + } + + public void resize(int p_83942_, int p_83943_) { +@@ -53,6 +_,11 @@ + RenderSystem.assertOnRenderThreadOrInit(); + this.unbindRead(); + this.unbindWrite(); ++ if (this.stencilBufferId > -1 && this.stencilBufferId != this.depthBufferId) { ++ TextureUtil.releaseTextureId(this.stencilBufferId);; ++ this.stencilBufferId = -1; ++ } ++ + if (this.depthBufferId > -1) { + TextureUtil.releaseTextureId(this.depthBufferId); + this.depthBufferId = -1; +@@ -96,9 +_,50 @@ + GlStateManager._texParameter(3553, 34892, 0); + GlStateManager._texParameter(3553, 10242, 33071); + GlStateManager._texParameter(3553, 10243, 33071); ++ if (!this.useStencil) // If stenciling is enabled, we will fill this later + GlStateManager._texImage2D(3553, 0, 6402, this.width, this.height, 0, 6402, 5126, null); + } + ++ if (this.useStencil) { ++ if (this.useDepth) { ++ // If depth and stencil buffers are both enabled, we must combine them ++ this.stencilBufferId = this.depthBufferId; ++ } else { ++ // Otherwise, we can generate a new texture in its place. ++ this.stencilBufferId = TextureUtil.generateTextureId(); ++ GlStateManager._bindTexture(this.stencilBufferId); ++ GlStateManager._texParameter(3553, 10241, 9728); ++ GlStateManager._texParameter(3553, 10240, 9728); ++ GlStateManager._texParameter(3553, 34892, 0); ++ GlStateManager._texParameter(3553, 10242, 33071); ++ GlStateManager._texParameter(3553, 10243, 33071); ++ } ++ ++ if (this.useDepth) { ++ // Use a combined format for both depth and stencil. ++ GlStateManager._texImage2D( ++ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, ++ 0, ++ org.lwjgl.opengl.GL32.GL_DEPTH24_STENCIL8, ++ this.width, this.height, ++ 0, ++ org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, ++ org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, ++ null); ++ } else { ++ // Otherwise, we can use a separate format. Testing for this was done in the constructor already. ++ GlStateManager._texImage2D( ++ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, ++ 0, ++ org.lwjgl.opengl.GL32.GL_STENCIL_INDEX8, ++ this.width, this.height, ++ 0, ++ org.lwjgl.opengl.GL32.GL_STENCIL_INDEX, ++ org.lwjgl.opengl.GL32.GL_BYTE, ++ null); ++ } ++ } ++ + this.setFilterMode(9728, true); + GlStateManager._bindTexture(this.colorTextureId); + GlStateManager._texParameter(3553, 10242, 33071); +@@ -109,6 +_,14 @@ + if (this.useDepth) { + GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); + } ++ if (this.useStencil) { ++ GlStateManager._glFramebufferTexture2D( ++ org.lwjgl.opengl.GL32.GL_FRAMEBUFFER, ++ org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, ++ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, ++ this.stencilBufferId, ++ 0); ++ } + + this.checkStatus(); + this.clear(); +@@ -218,6 +_,10 @@ + GlStateManager._clearDepth(1.0); + i |= 256; + } ++ if (this.useStencil) { ++ GlStateManager._clearStencil(0); ++ i |= org.lwjgl.opengl.GL32.GL_STENCIL_BUFFER_BIT; ++ } + + GlStateManager._clear(i); + this.unbindWrite(); +@@ -229,5 +_,9 @@ + + public int getDepthTextureId() { + return this.depthBufferId; ++ } ++ ++ public int getStencilBufferId() { ++ return this.stencilBufferId; + } + } diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index 04429bcce30..4b3dc587ed0 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -8,7 +8,7 @@ this.demo = p_91084_.game.demo; this.allowsMultiplayer = !p_91084_.game.disableMultiplayer; this.allowsChat = !p_91084_.game.disableChat; -@@ -483,15 +_,17 @@ +@@ -483,15 +_,18 @@ LOGGER.error("Couldn't set icon", (Throwable)ioexception); } @@ -18,11 +18,12 @@ this.keyboardHandler = new KeyboardHandler(this); - this.keyboardHandler.setup(this.window.getWindow()); RenderSystem.initRenderer(this.options.glDebugVerbosity, false); ++ net.neoforged.neoforge.client.loading.ClientModLoader.begin(this); this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight()); this.mainRenderTarget.setClearColor(0.0F, 0.0F, 0.0F, 0.0F); this.mainRenderTarget.clear(); this.resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES); -+ net.neoforged.neoforge.client.loading.ClientModLoader.begin(this, this.resourcePackRepository, this.resourceManager); ++ net.neoforged.neoforge.client.loading.ClientModLoader.finish(this.resourcePackRepository, this.resourceManager); + //Move client bootstrap to after mod loading so that events can be fired for it. + ClientBootstrap.bootstrap(); this.resourcePackRepository.reload(); @@ -177,7 +178,7 @@ this.deltaTracker.updatePauseState(this.pause); this.deltaTracker.updateFrozenState(!this.isLevelRunningNormally()); long l = Util.getNanos(); -@@ -1351,10 +_,12 @@ +@@ -1351,10 +_,13 @@ this.window.setGuiScale((double)i); if (this.screen != null) { this.screen.resize(this, this.window.getGuiScaledWidth(), this.window.getGuiScaledHeight()); @@ -185,6 +186,7 @@ } RenderTarget rendertarget = this.getMainRenderTarget(); ++ if (rendertarget != null) rendertarget.resize(this.window.getWidth(), this.window.getHeight()); + if (this.gameRenderer != null) this.gameRenderer.resize(this.window.getWidth(), this.window.getHeight()); diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index 7e497ecaf27..bd56d1fe9e8 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -144,6 +144,7 @@ import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.client.event.ComputeFovModifierEvent; +import net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent; import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent; import net.neoforged.neoforge.client.event.EntityRenderersEvent; import net.neoforged.neoforge.client.event.FrameGraphSetupEvent; @@ -1099,4 +1100,10 @@ public static Map gatherMaterialAtlases(Map< public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder, LevelTargetBundle targets, RenderTargetDescriptor renderTargetDescriptor, Frustum frustum, Camera camera, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, DeltaTracker deltaTracker, ProfilerFiller profiler) { return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler)); } + + public static ConfigureMainRenderTargetEvent configureMainRenderTarget() { + var e = new ConfigureMainRenderTargetEvent(); + ModLoader.postEvent(e); + return e; + } } diff --git a/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java new file mode 100644 index 00000000000..c4bc57ad89e --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.neoforge.client.event; + +import com.mojang.blaze3d.pipeline.MainTarget; +import com.mojang.blaze3d.pipeline.RenderTarget; +import net.neoforged.bus.api.Event; +import net.neoforged.bus.api.ICancellableEvent; +import net.neoforged.fml.LogicalSide; +import net.neoforged.fml.event.IModBusEvent; +import org.jetbrains.annotations.ApiStatus; + +/** + * Fired when configuring the main {@linkplain RenderTarget render target}. + *

+ * This event fires during startup when the {@link MainTarget} is constructed. + *

+ * This event is not {@linkplain ICancellableEvent cancellable}. + *

+ * This event is fired on the mod-speciffic event bus, only on the {@linkplain LogicalSide#CLIENT logical client}. + */ +public class ConfigureMainRenderTargetEvent extends Event implements IModBusEvent { + private boolean useDepth; + private boolean useStencil; + + @ApiStatus.Internal + public ConfigureMainRenderTargetEvent() { + this.useDepth = true; + this.useStencil = false; + } + + /** + * Returns whether the depth buffer is enabled. + * + * @return true, if the depth buffer is enabled, or false otherwise. + */ + public boolean useDepth() { + return this.useDepth; + } + + /** + * Returns whether the stencil buffer is enabled. + * + * @return true, if the stencil buffer is enabled, or false otherwise. + */ + public boolean useStencil() { + return this.useStencil; + } + + /** + * Enable the depth buffer for the main render target. + * + * @return this, for method chaining. + */ + public ConfigureMainRenderTargetEvent enableDepth() { + this.useDepth = true; + return this; + } + + /** + * Enable the stencil buffer for the main render target. + * + * @return this, for method chaining. + */ + public ConfigureMainRenderTargetEvent enableStencil() { + this.useStencil = true; + return this; + } +} diff --git a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java index d8c4a35e616..4ee4d48b270 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java @@ -47,7 +47,7 @@ public class ClientModLoader extends CommonModLoader { @Nullable private static ModLoadingException error; - public static void begin(final Minecraft minecraft, final PackRepository defaultResourcePacks, final ReloadableResourceManager mcResourceManager) { + public static void begin(final Minecraft minecraft) { // force log4j to shutdown logging in a shutdown hook. This is because we disable default shutdown hook so the server properly logs it's shutdown Runtime.getRuntime().addShutdownHook(new Thread(LogManager::shutdown)); ImmediateWindowHandler.updateProgress("Loading mods"); @@ -60,6 +60,9 @@ public static void begin(final Minecraft minecraft, final PackRepository default } catch (ModLoadingException e) { error = e; } + } + + public static void finish(final PackRepository defaultResourcePacks, final ReloadableResourceManager mcResourceManager) { if (error == null) { ResourcePackLoader.populatePackRepository(defaultResourcePacks, PackType.CLIENT_RESOURCES, false); DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getPackNames(PackType.SERVER_DATA)); From 5135ec123db09b3f85bea5e840adf16d624ba416 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Sat, 30 Nov 2024 18:38:55 +0000 Subject: [PATCH 02/18] Flow stencil information through post chains --- .../framegraph/FrameGraphBuilder.java.patch | 46 ++++++++++++++++++ .../blaze3d/pipeline/RenderTarget.java.patch | 2 +- .../blaze3d/pipeline/TextureTarget.java.patch | 14 ++++++ .../RenderTargetDescriptor.java.patch | 18 +++++++ .../client/renderer/LevelRenderer.java.patch | 10 ++++ .../client/renderer/PostChain.java.patch | 48 +++++++++++++++++++ .../renderer/PostChainConfig.java.patch | 23 +++++++++ .../client/renderer/PostPass.java.patch | 28 +++++++++++ .../resources/META-INF/accesstransformer.cfg | 4 ++ 9 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch create mode 100644 patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch create mode 100644 patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch create mode 100644 patches/net/minecraft/client/renderer/PostChain.java.patch create mode 100644 patches/net/minecraft/client/renderer/PostChainConfig.java.patch create mode 100644 patches/net/minecraft/client/renderer/PostPass.java.patch diff --git a/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch new file mode 100644 index 00000000000..b03f4d9e054 --- /dev/null +++ b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch @@ -0,0 +1,46 @@ +--- a/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java ++++ b/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java +@@ -173,6 +_,11 @@ + public T get() { + return this.resource; + } ++ ++ @Override ++ public ResourceDescriptor getDescriptor() { ++ return null; ++ } + } + + @OnlyIn(Dist.CLIENT) +@@ -211,6 +_,10 @@ + public String toString() { + return this.createdBy != null ? this.holder + "#" + this.version + " (from " + this.createdBy + ")" : this.holder + "#" + this.version; + } ++ ++ public ResourceDescriptor getDescriptor() { ++ return this.holder.getDescriptor(); ++ } + } + + @OnlyIn(Dist.CLIENT) +@@ -265,6 +_,11 @@ + this.physicalResource = null; + } + } ++ ++ @Override ++ public ResourceDescriptor getDescriptor() { ++ return descriptor; ++ } + } + + @OnlyIn(Dist.CLIENT) +@@ -364,5 +_,8 @@ + public String toString() { + return this.name; + } ++ ++ @Nullable ++ public abstract ResourceDescriptor getDescriptor(); + } + } diff --git a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch index bddf05a9c12..b4990074aef 100644 --- a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch @@ -128,7 +128,7 @@ return this.depthBufferId; + } + -+ public int getStencilBufferId() { ++ public int getStencilTextureId() { + return this.stencilBufferId; } } diff --git a/patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch new file mode 100644 index 00000000000..e0661d83e49 --- /dev/null +++ b/patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch @@ -0,0 +1,14 @@ +--- a/com/mojang/blaze3d/pipeline/TextureTarget.java ++++ b/com/mojang/blaze3d/pipeline/TextureTarget.java +@@ -7,7 +_,10 @@ + @OnlyIn(Dist.CLIENT) + public class TextureTarget extends RenderTarget { + public TextureTarget(int p_166213_, int p_166214_, boolean p_166215_) { +- super(p_166215_); ++ this(p_166213_, p_166214_, p_166215_, false); ++ } ++ public TextureTarget(int p_166213_, int p_166214_, boolean p_166215_, boolean useStencil) { ++ super(p_166215_, useStencil); + RenderSystem.assertOnRenderThreadOrInit(); + this.resize(p_166213_, p_166214_); + } diff --git a/patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch b/patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch new file mode 100644 index 00000000000..060e486b3c7 --- /dev/null +++ b/patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch @@ -0,0 +1,18 @@ +--- a/com/mojang/blaze3d/resource/RenderTargetDescriptor.java ++++ b/com/mojang/blaze3d/resource/RenderTargetDescriptor.java +@@ -6,9 +_,13 @@ + import net.neoforged.api.distmarker.OnlyIn; + + @OnlyIn(Dist.CLIENT) +-public record RenderTargetDescriptor(int width, int height, boolean useDepth) implements ResourceDescriptor { ++public record RenderTargetDescriptor(int width, int height, boolean useDepth, boolean useStencil) implements ResourceDescriptor { ++ public RenderTargetDescriptor(int width, int height, boolean useDepth) { ++ this(width, height, useDepth, false); ++ } ++ + public RenderTarget allocate() { +- return new TextureTarget(this.width, this.height, this.useDepth); ++ return new TextureTarget(this.width, this.height, this.useDepth, this.useStencil); + } + + public void free(RenderTarget p_363223_) { diff --git a/patches/net/minecraft/client/renderer/LevelRenderer.java.patch b/patches/net/minecraft/client/renderer/LevelRenderer.java.patch index 9173efdbf43..094b3d9dfee 100644 --- a/patches/net/minecraft/client/renderer/LevelRenderer.java.patch +++ b/patches/net/minecraft/client/renderer/LevelRenderer.java.patch @@ -1,5 +1,15 @@ --- a/net/minecraft/client/renderer/LevelRenderer.java +++ b/net/minecraft/client/renderer/LevelRenderer.java +@@ -459,7 +_,8 @@ + this.targets.main = framegraphbuilder.importExternal("main", this.minecraft.getMainRenderTarget()); + int i = this.minecraft.getMainRenderTarget().width; + int j = this.minecraft.getMainRenderTarget().height; +- RenderTargetDescriptor rendertargetdescriptor = new RenderTargetDescriptor(i, j, true); ++ boolean useStencil = this.minecraft.getMainRenderTarget().useStencil; ++ RenderTargetDescriptor rendertargetdescriptor = new RenderTargetDescriptor(i, j, true, useStencil); + PostChain postchain = this.getTransparencyChain(); + if (postchain != null) { + this.targets.translucent = framegraphbuilder.createInternal("translucent", rendertargetdescriptor); @@ -473,6 +_,9 @@ this.targets.entityOutline = framegraphbuilder.importExternal("entity_outline", this.entityOutlineTarget); } diff --git a/patches/net/minecraft/client/renderer/PostChain.java.patch b/patches/net/minecraft/client/renderer/PostChain.java.patch new file mode 100644 index 00000000000..0b08462b4f6 --- /dev/null +++ b/patches/net/minecraft/client/renderer/PostChain.java.patch @@ -0,0 +1,48 @@ +--- a/net/minecraft/client/renderer/PostChain.java ++++ b/net/minecraft/client/renderer/PostChain.java +@@ -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)); + continue; + default: + throw new MatchException(null, null); +@@ -95,17 +_,32 @@ + Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float)p_361423_, 0.0F, (float)p_362735_, 0.1F, 1000.0F); + Map> map = new HashMap<>(this.internalTargets.size() + this.externalTargets.size()); + ++ // Enable the depth and stencil buffers based on whether any external targets use them. ++ // This is necessary so any created buffers get the correct parameters for blitting. ++ boolean useDepth = false; ++ boolean useStencil = false; + for (ResourceLocation resourcelocation : this.externalTargets) { + map.put(resourcelocation, p_361871_.getOrThrow(resourcelocation)); ++ ++ var handle = p_361871_.get(resourcelocation); ++ ++ if (handle instanceof FrameGraphBuilder.Handle frameHandle ++ && frameHandle.getDescriptor() instanceof RenderTargetDescriptor renderDescriptor) { ++ useDepth |= renderDescriptor.useDepth(); ++ useStencil |= renderDescriptor.useStencil(); ++ } else { ++ useDepth |= p_361871_.get(resourcelocation).get().useDepth; ++ useStencil |= p_361871_.get(resourcelocation).get().useStencil; ++ } + } + + for (Entry entry : this.internalTargets.entrySet()) { + ResourceLocation resourcelocation1 = entry.getKey(); + RenderTargetDescriptor rendertargetdescriptor = switch (entry.getValue()) { + case PostChainConfig.FixedSizedTarget(int i, int j) -> { +- yield new RenderTargetDescriptor(i, j, true); ++ yield new RenderTargetDescriptor(i, j, useDepth, useStencil); + } +- case PostChainConfig.FullScreenTarget postchainconfig$fullscreentarget -> new RenderTargetDescriptor(p_361423_, p_362735_, true); ++ case PostChainConfig.FullScreenTarget postchainconfig$fullscreentarget -> new RenderTargetDescriptor(p_361423_, p_362735_, useDepth, useStencil); + default -> throw new MatchException(null, null); + }; + map.put(resourcelocation1, p_362523_.createInternal(resourcelocation1.toString(), rendertargetdescriptor)); diff --git a/patches/net/minecraft/client/renderer/PostChainConfig.java.patch b/patches/net/minecraft/client/renderer/PostChainConfig.java.patch new file mode 100644 index 00000000000..e07b4d10af6 --- /dev/null +++ b/patches/net/minecraft/client/renderer/PostChainConfig.java.patch @@ -0,0 +1,23 @@ +--- a/net/minecraft/client/renderer/PostChainConfig.java ++++ b/net/minecraft/client/renderer/PostChainConfig.java +@@ -108,13 +_,18 @@ + } + + @OnlyIn(Dist.CLIENT) +- public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) implements PostChainConfig.Input { ++ public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear, boolean useStencilBuffer) implements PostChainConfig.Input { ++ public TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) { ++ this(samplerName, targetId, useDepthBuffer, bilinear, false); ++ } ++ + public static final Codec CODEC = RecordCodecBuilder.create( + p_363892_ -> p_363892_.group( + Codec.STRING.fieldOf("sampler_name").forGetter(PostChainConfig.TargetInput::samplerName), + ResourceLocation.CODEC.fieldOf("target").forGetter(PostChainConfig.TargetInput::targetId), + Codec.BOOL.optionalFieldOf("use_depth_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useDepthBuffer), +- Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear) ++ Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear), ++ Codec.BOOL.optionalFieldOf("neoforge:use_stencil_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useStencilBuffer) + ) + .apply(p_363892_, PostChainConfig.TargetInput::new) + ); diff --git a/patches/net/minecraft/client/renderer/PostPass.java.patch b/patches/net/minecraft/client/renderer/PostPass.java.patch new file mode 100644 index 00000000000..5ef576cd68a --- /dev/null +++ b/patches/net/minecraft/client/renderer/PostPass.java.patch @@ -0,0 +1,28 @@ +--- a/net/minecraft/client/renderer/PostPass.java ++++ b/net/minecraft/client/renderer/PostPass.java +@@ -122,7 +_,10 @@ + } + + @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 TargetInput(String samplerName, ResourceLocation targetId, boolean depthBuffer, boolean bilinear) { ++ this(samplerName, targetId, depthBuffer, bilinear, false); ++ } + private ResourceHandle getHandle(Map> p_364534_) { + ResourceHandle resourcehandle = p_364534_.get(this.targetId); + if (resourcehandle == null) { +@@ -142,7 +_,12 @@ + 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) ++ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getDepthTextureId()); ++ else if (this.stencilBuffer) ++ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getStencilTextureId()); ++ else ++ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getColorTextureId()); + p_366564_.safeGetUniform(this.samplerName + "Size").set((float)rendertarget.width, (float)rendertarget.height); + } + diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index fc21dedc592..1f4ce258fa3 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,4 +1,8 @@ # Note: This file is for manually added ATs. When AT entries can be programmatically generated based on fixed rules you may define those rules in the build.gradle file +public com.mojang.blaze3d.framegraph.FrameGraphBuilder$Handle +public com.mojang.blaze3d.framegraph.FrameGraphBuilder$Handle holder +public com.mojang.blaze3d.framegraph.FrameGraphBuilder$VirtualResource +public com.mojang.blaze3d.framegraph.FrameGraphBuilder$Pass public net.minecraft.advancements.CriteriaTriggers register(Ljava/lang/String;Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; # register default net.minecraft.client.KeyMapping isDown # isDown public-f net.minecraft.client.Options keyMappings # keyMappings From 613cb46eecb8bd9c8b737106b6a5be31084e09be Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Sun, 8 Dec 2024 14:51:21 +0000 Subject: [PATCH 03/18] Fix copy-paste fail in RenderTarget --- patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch index b4990074aef..bca255906d1 100644 --- a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch @@ -38,7 +38,7 @@ this.unbindRead(); this.unbindWrite(); + if (this.stencilBufferId > -1 && this.stencilBufferId != this.depthBufferId) { -+ TextureUtil.releaseTextureId(this.stencilBufferId);; ++ TextureUtil.releaseTextureId(this.stencilBufferId); + this.stencilBufferId = -1; + } + From f938bfe32ddbd5b0d93a3fb16970b81662c18b09 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Sun, 8 Dec 2024 14:59:49 +0000 Subject: [PATCH 04/18] 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 0b08462b4f6..73b227ac22b 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 5ef576cd68a..efa98f666ba 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()); From b5cd630c834a8df3d9a1fcd16e843d15dd00f701 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Sun, 8 Dec 2024 15:11:53 +0000 Subject: [PATCH 05/18] Fix import whoopsie --- .../minecraft/client/renderer/PostChain.java.patch | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/patches/net/minecraft/client/renderer/PostChain.java.patch b/patches/net/minecraft/client/renderer/PostChain.java.patch index 73b227ac22b..e0c65d1b7ed 100644 --- a/patches/net/minecraft/client/renderer/PostChain.java.patch +++ b/patches/net/minecraft/client/renderer/PostChain.java.patch @@ -1,14 +1,5 @@ --- 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)); @@ -16,7 +7,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, BufferType.from(flag1, useStencilBuffer), flag2)); ++ postpass.addInput(new PostPass.TargetInput(s1, resourcelocation1, net.minecraft.client.renderer.PostPass.TargetInput.BufferType.from(flag1, useStencilBuffer), flag2)); continue; default: throw new MatchException(null, null); From 922fad6940c5c6ce72491be510486dfcb22240c7 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 9 Dec 2024 09:26:28 +0000 Subject: [PATCH 06/18] Fix stenciling on the main target --- .../blaze3d/pipeline/MainTarget.java.patch | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 8071336f342..7e4a944801e 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -13,3 +13,127 @@ this.createFrameBuffer(p_166137_, p_166138_); } +@@ -30,13 +_,24 @@ + GlStateManager._texParameter(3553, 10242, 33071); + GlStateManager._texParameter(3553, 10243, 33071); + GlStateManager._glFramebufferTexture2D(36160, 36064, 3553, this.colorTextureId, 0); +- GlStateManager._bindTexture(this.depthBufferId); +- GlStateManager._texParameter(3553, 34892, 0); +- GlStateManager._texParameter(3553, 10241, 9728); +- GlStateManager._texParameter(3553, 10240, 9728); +- GlStateManager._texParameter(3553, 10242, 33071); +- GlStateManager._texParameter(3553, 10243, 33071); +- GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); ++ if (this.useDepth) { ++ GlStateManager._bindTexture(this.depthBufferId); ++ GlStateManager._texParameter(3553, 34892, 0); ++ GlStateManager._texParameter(3553, 10241, 9728); ++ GlStateManager._texParameter(3553, 10240, 9728); ++ GlStateManager._texParameter(3553, 10242, 33071); ++ GlStateManager._texParameter(3553, 10243, 33071); ++ GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); ++ } ++ if (this.useStencil) { ++ GlStateManager._bindTexture(this.stencilBufferId); ++ GlStateManager._texParameter(3553, 34892, 0); ++ GlStateManager._texParameter(3553, 10241, 9728); ++ GlStateManager._texParameter(3553, 10240, 9728); ++ GlStateManager._texParameter(3553, 10242, 33071); ++ GlStateManager._texParameter(3553, 10243, 33071); ++ GlStateManager._glFramebufferTexture2D(36160, org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, 3553, this.stencilBufferId, 0); ++ } + GlStateManager._bindTexture(0); + this.viewWidth = maintarget$dimension.width; + this.viewHeight = maintarget$dimension.height; +@@ -49,8 +_,14 @@ + private MainTarget.Dimension allocateAttachments(int p_166147_, int p_166148_) { + RenderSystem.assertOnRenderThreadOrInit(); + this.colorTextureId = TextureUtil.generateTextureId(); +- this.depthBufferId = TextureUtil.generateTextureId(); ++ if (this.useDepth) { ++ this.depthBufferId = TextureUtil.generateTextureId(); ++ } ++ if (this.useStencil) { ++ this.stencilBufferId = this.useDepth ? this.depthBufferId : TextureUtil.generateTextureId(); ++ } + MainTarget.AttachmentState maintarget$attachmentstate = MainTarget.AttachmentState.NONE; ++ MainTarget.AttachmentState targetState = MainTarget.AttachmentState.of(true, this.useDepth, this.useStencil); + + for (MainTarget.Dimension maintarget$dimension : MainTarget.Dimension.listWithFallback(p_166147_, p_166148_)) { + maintarget$attachmentstate = MainTarget.AttachmentState.NONE; +@@ -58,11 +_,19 @@ + maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.COLOR); + } + +- if (this.allocateDepthAttachment(maintarget$dimension)) { ++ if (this.useDepth && this.useStencil && this.allocateDepthStencilAttachment(maintarget$dimension)) { ++ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH_STENCIL); ++ } ++ ++ else if (this.useDepth && this.allocateDepthAttachment(maintarget$dimension)) { + maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH); + } + +- if (maintarget$attachmentstate == MainTarget.AttachmentState.COLOR_DEPTH) { ++ else if (this.useStencil && this.allocateStencilAttachment(maintarget$dimension)) { ++ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.STENCIL); ++ } ++ ++ if (maintarget$attachmentstate == targetState) { + return maintarget$dimension; + } + } +@@ -86,17 +_,52 @@ + return GlStateManager._getError() != 1285; + } + ++ private boolean allocateStencilAttachment(MainTarget.Dimension p_166145_) { ++ RenderSystem.assertOnRenderThreadOrInit(); ++ GlStateManager._getError(); ++ GlStateManager._bindTexture(this.stencilBufferId); ++ GlStateManager._texImage2D(3553, 0, org.lwjgl.opengl.GL32.GL_STENCIL_INDEX8, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_STENCIL_INDEX, org.lwjgl.opengl.GL32.GL_BYTE, null); ++ return GlStateManager._getError() != 1285; ++ } ++ ++ private boolean allocateDepthStencilAttachment(MainTarget.Dimension p_166145_) { ++ RenderSystem.assertOnRenderThreadOrInit(); ++ GlStateManager._getError(); ++ GlStateManager._bindTexture(this.depthBufferId); ++ GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, null); ++ return GlStateManager._getError() != 1285; ++ } ++ + @OnlyIn(Dist.CLIENT) + static enum AttachmentState { + NONE, + COLOR, + DEPTH, +- COLOR_DEPTH; ++ COLOR_DEPTH, ++ STENCIL, ++ COLOR_STENCIL, ++ DEPTH_STENCIL, ++ COLOR_DEPTH_STENCIL; + + private static final MainTarget.AttachmentState[] VALUES = values(); + + MainTarget.AttachmentState with(MainTarget.AttachmentState p_166164_) { + return VALUES[this.ordinal() | p_166164_.ordinal()]; ++ } ++ ++ static MainTarget.AttachmentState of(boolean color, boolean depth, boolean stencil) { ++ var result = NONE; ++ if (color) { ++ result = result.with(COLOR); ++ } ++ if (depth) { ++ result = result.with(DEPTH); ++ } ++ if (stencil) { ++ result = result.with(STENCIL); ++ } ++ ++ return result; + } + } + From 721d79d543de84dd3278f1c79f5f785798a05374 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 9 Dec 2024 09:33:56 +0000 Subject: [PATCH 07/18] Remove no-op method for enabling depth, pass desired width/height --- .../blaze3d/pipeline/MainTarget.java.patch | 10 ++++--- .../neoforge/client/ClientHooks.java | 4 +-- .../event/ConfigureMainRenderTargetEvent.java | 30 ++++++++++++++----- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 7e4a944801e..4bc19bd1476 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -1,18 +1,20 @@ --- a/com/mojang/blaze3d/pipeline/MainTarget.java +++ b/com/mojang/blaze3d/pipeline/MainTarget.java -@@ -16,7 +_,11 @@ +@@ -16,8 +_,12 @@ static final MainTarget.Dimension DEFAULT_DIMENSIONS = new MainTarget.Dimension(854, 480); public MainTarget(int p_166137_, int p_166138_) { - super(true); -+ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(), p_166137_, p_166138_); +- this.createFrameBuffer(p_166137_, p_166138_); ++ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(true, p_166137_, p_166138_)); + } + -+ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e, int p_166137_, int p_166138_) { ++ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e) { + super(e.useDepth(), e.useStencil()); - this.createFrameBuffer(p_166137_, p_166138_); ++ this.createFrameBuffer(e.width(), e.height()); } + private void createFrameBuffer(int p_166142_, int p_166143_) { @@ -30,13 +_,24 @@ GlStateManager._texParameter(3553, 10242, 33071); GlStateManager._texParameter(3553, 10243, 33071); diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index bd56d1fe9e8..f22082411fe 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -1101,8 +1101,8 @@ public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler)); } - public static ConfigureMainRenderTargetEvent configureMainRenderTarget() { - var e = new ConfigureMainRenderTargetEvent(); + public static ConfigureMainRenderTargetEvent configureMainRenderTarget(boolean useDepth, int width, int height) { + var e = new ConfigureMainRenderTargetEvent(useDepth, width, height); ModLoader.postEvent(e); return e; } diff --git a/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java index c4bc57ad89e..805092c02e4 100644 --- a/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java +++ b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java @@ -23,13 +23,19 @@ * This event is fired on the mod-speciffic event bus, only on the {@linkplain LogicalSide#CLIENT logical client}. */ public class ConfigureMainRenderTargetEvent extends Event implements IModBusEvent { - private boolean useDepth; + private final boolean useDepth; private boolean useStencil; + private final int width; + private final int height; + @ApiStatus.Internal - public ConfigureMainRenderTargetEvent() { - this.useDepth = true; + public ConfigureMainRenderTargetEvent(boolean useDepth, int width, int height) { + this.useDepth = useDepth; this.useStencil = false; + + this.width = width; + this.height = height; } /** @@ -51,13 +57,21 @@ public boolean useStencil() { } /** - * Enable the depth buffer for the main render target. + * Returns the preferred width of the framebuffer. * - * @return this, for method chaining. + * @return The width, in pixels, to attempt to use for the framebuffer. */ - public ConfigureMainRenderTargetEvent enableDepth() { - this.useDepth = true; - return this; + public int width() { + return this.width; + } + + /** + * Returns the preferred height of the framebuffer. + * + * @return The height, in pixels, to attempt to use for the framebuffer. + */ + public int height() { + return this.height; } /** From ff68a10039645ee171bac65137d34d00c1e3a2e2 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 9 Dec 2024 10:02:16 +0000 Subject: [PATCH 08/18] Minimise patch by removing unnecessary indentation --- .../blaze3d/pipeline/MainTarget.java.patch | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 4bc19bd1476..112e72c6e70 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -15,25 +15,18 @@ } private void createFrameBuffer(int p_166142_, int p_166143_) { -@@ -30,13 +_,24 @@ +@@ -30,6 +_,7 @@ GlStateManager._texParameter(3553, 10242, 33071); GlStateManager._texParameter(3553, 10243, 33071); GlStateManager._glFramebufferTexture2D(36160, 36064, 3553, this.colorTextureId, 0); -- GlStateManager._bindTexture(this.depthBufferId); -- GlStateManager._texParameter(3553, 34892, 0); -- GlStateManager._texParameter(3553, 10241, 9728); -- GlStateManager._texParameter(3553, 10240, 9728); -- GlStateManager._texParameter(3553, 10242, 33071); -- GlStateManager._texParameter(3553, 10243, 33071); -- GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); + if (this.useDepth) { -+ GlStateManager._bindTexture(this.depthBufferId); -+ GlStateManager._texParameter(3553, 34892, 0); -+ GlStateManager._texParameter(3553, 10241, 9728); -+ GlStateManager._texParameter(3553, 10240, 9728); -+ GlStateManager._texParameter(3553, 10242, 33071); -+ GlStateManager._texParameter(3553, 10243, 33071); -+ GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); + GlStateManager._bindTexture(this.depthBufferId); + GlStateManager._texParameter(3553, 34892, 0); + GlStateManager._texParameter(3553, 10241, 9728); +@@ -37,6 +_,16 @@ + GlStateManager._texParameter(3553, 10242, 33071); + GlStateManager._texParameter(3553, 10243, 33071); + GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); + } + if (this.useStencil) { + GlStateManager._bindTexture(this.stencilBufferId); @@ -51,9 +44,8 @@ private MainTarget.Dimension allocateAttachments(int p_166147_, int p_166148_) { RenderSystem.assertOnRenderThreadOrInit(); this.colorTextureId = TextureUtil.generateTextureId(); -- this.depthBufferId = TextureUtil.generateTextureId(); + if (this.useDepth) { -+ this.depthBufferId = TextureUtil.generateTextureId(); + this.depthBufferId = TextureUtil.generateTextureId(); + } + if (this.useStencil) { + this.stencilBufferId = this.useDepth ? this.depthBufferId : TextureUtil.generateTextureId(); From 117c7afddc4722d930dff220d90eb75ac5dcd34f Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 30 Dec 2024 04:55:30 +0000 Subject: [PATCH 09/18] Respond to XFact's feedback --- .../blaze3d/framegraph/FrameGraphBuilder.java.patch | 9 ++++++--- .../net/minecraft/client/renderer/PostChain.java.patch | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch index b03f4d9e054..84d9e314b44 100644 --- a/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch +++ b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch @@ -35,12 +35,15 @@ } @OnlyIn(Dist.CLIENT) -@@ -364,5 +_,8 @@ +@@ -363,6 +_,11 @@ + @Override public String toString() { return this.name; - } ++ } + + @Nullable -+ public abstract ResourceDescriptor getDescriptor(); ++ public ResourceDescriptor getDescriptor() { ++ return null; + } } } diff --git a/patches/net/minecraft/client/renderer/PostChain.java.patch b/patches/net/minecraft/client/renderer/PostChain.java.patch index e0c65d1b7ed..0cabd6b5ec2 100644 --- a/patches/net/minecraft/client/renderer/PostChain.java.patch +++ b/patches/net/minecraft/client/renderer/PostChain.java.patch @@ -11,7 +11,7 @@ continue; default: throw new MatchException(null, null); -@@ -95,17 +_,32 @@ +@@ -95,17 +_,33 @@ Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float)p_361423_, 0.0F, (float)p_362735_, 0.1F, 1000.0F); Map> map = new HashMap<>(this.internalTargets.size() + this.externalTargets.size()); @@ -29,8 +29,9 @@ + useDepth |= renderDescriptor.useDepth(); + useStencil |= renderDescriptor.useStencil(); + } else { -+ useDepth |= p_361871_.get(resourcelocation).get().useDepth; -+ useStencil |= p_361871_.get(resourcelocation).get().useStencil; ++ var target = handle.get(); ++ useDepth |= target.useDepth; ++ useStencil |= target.useStencil; + } } From f278e8dae31efcf26d758fc1d8ce8144702e141b Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Thu, 9 Jan 2025 13:30:48 +0000 Subject: [PATCH 10/18] Remove stencil-only patches in MainTarget Other patches are still necessary as other targets have that as a valid combination in vanilla anyway, and post chains can be configured to render to a target with depth disabled. --- .../blaze3d/pipeline/MainTarget.java.patch | 68 +++---------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 112e72c6e70..eb0f6518725 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -15,80 +15,54 @@ } private void createFrameBuffer(int p_166142_, int p_166143_) { -@@ -30,6 +_,7 @@ - GlStateManager._texParameter(3553, 10242, 33071); - GlStateManager._texParameter(3553, 10243, 33071); - GlStateManager._glFramebufferTexture2D(36160, 36064, 3553, this.colorTextureId, 0); -+ if (this.useDepth) { - GlStateManager._bindTexture(this.depthBufferId); - GlStateManager._texParameter(3553, 34892, 0); - GlStateManager._texParameter(3553, 10241, 9728); -@@ -37,6 +_,16 @@ +@@ -37,6 +_,10 @@ GlStateManager._texParameter(3553, 10242, 33071); GlStateManager._texParameter(3553, 10243, 33071); GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); -+ } + if (this.useStencil) { + GlStateManager._bindTexture(this.stencilBufferId); -+ GlStateManager._texParameter(3553, 34892, 0); -+ GlStateManager._texParameter(3553, 10241, 9728); -+ GlStateManager._texParameter(3553, 10240, 9728); -+ GlStateManager._texParameter(3553, 10242, 33071); -+ GlStateManager._texParameter(3553, 10243, 33071); + GlStateManager._glFramebufferTexture2D(36160, org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, 3553, this.stencilBufferId, 0); + } GlStateManager._bindTexture(0); this.viewWidth = maintarget$dimension.width; this.viewHeight = maintarget$dimension.height; -@@ -49,8 +_,14 @@ - private MainTarget.Dimension allocateAttachments(int p_166147_, int p_166148_) { +@@ -50,7 +_,14 @@ RenderSystem.assertOnRenderThreadOrInit(); this.colorTextureId = TextureUtil.generateTextureId(); -+ if (this.useDepth) { this.depthBufferId = TextureUtil.generateTextureId(); -+ } + if (this.useStencil) { -+ this.stencilBufferId = this.useDepth ? this.depthBufferId : TextureUtil.generateTextureId(); ++ this.stencilBufferId = this.depthBufferId; + } MainTarget.AttachmentState maintarget$attachmentstate = MainTarget.AttachmentState.NONE; -+ MainTarget.AttachmentState targetState = MainTarget.AttachmentState.of(true, this.useDepth, this.useStencil); ++ MainTarget.AttachmentState targetState = MainTarget.AttachmentState.COLOR_DEPTH; ++ if (this.useStencil) { ++ targetState = targetState.with(MainTarget.AttachmentState.STENCIL); ++ } for (MainTarget.Dimension maintarget$dimension : MainTarget.Dimension.listWithFallback(p_166147_, p_166148_)) { maintarget$attachmentstate = MainTarget.AttachmentState.NONE; -@@ -58,11 +_,19 @@ +@@ -58,11 +_,15 @@ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.COLOR); } - if (this.allocateDepthAttachment(maintarget$dimension)) { -+ if (this.useDepth && this.useStencil && this.allocateDepthStencilAttachment(maintarget$dimension)) { ++ if (this.useStencil && this.allocateDepthStencilAttachment(maintarget$dimension)) { + maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH_STENCIL); + } + -+ else if (this.useDepth && this.allocateDepthAttachment(maintarget$dimension)) { ++ else if (this.allocateDepthAttachment(maintarget$dimension)) { maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH); } - if (maintarget$attachmentstate == MainTarget.AttachmentState.COLOR_DEPTH) { -+ else if (this.useStencil && this.allocateStencilAttachment(maintarget$dimension)) { -+ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.STENCIL); -+ } -+ + if (maintarget$attachmentstate == targetState) { return maintarget$dimension; } } -@@ -86,17 +_,52 @@ +@@ -86,12 +_,24 @@ return GlStateManager._getError() != 1285; } -+ private boolean allocateStencilAttachment(MainTarget.Dimension p_166145_) { -+ RenderSystem.assertOnRenderThreadOrInit(); -+ GlStateManager._getError(); -+ GlStateManager._bindTexture(this.stencilBufferId); -+ GlStateManager._texImage2D(3553, 0, org.lwjgl.opengl.GL32.GL_STENCIL_INDEX8, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_STENCIL_INDEX, org.lwjgl.opengl.GL32.GL_BYTE, null); -+ return GlStateManager._getError() != 1285; -+ } -+ + private boolean allocateDepthStencilAttachment(MainTarget.Dimension p_166145_) { + RenderSystem.assertOnRenderThreadOrInit(); + GlStateManager._getError(); @@ -111,23 +85,3 @@ private static final MainTarget.AttachmentState[] VALUES = values(); - MainTarget.AttachmentState with(MainTarget.AttachmentState p_166164_) { - return VALUES[this.ordinal() | p_166164_.ordinal()]; -+ } -+ -+ static MainTarget.AttachmentState of(boolean color, boolean depth, boolean stencil) { -+ var result = NONE; -+ if (color) { -+ result = result.with(COLOR); -+ } -+ if (depth) { -+ result = result.with(DEPTH); -+ } -+ if (stencil) { -+ result = result.with(STENCIL); -+ } -+ -+ return result; - } - } - From 552d6360ff7ce532a7dceb36134f0055ae069917 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:14:08 +0100 Subject: [PATCH 11/18] Stencil requires depth --- .../blaze3d/pipeline/MainTarget.java.patch | 11 +-- .../blaze3d/pipeline/RenderTarget.java.patch | 89 +++++-------------- 2 files changed, 23 insertions(+), 77 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index eb0f6518725..9a87eaa883f 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -15,24 +15,19 @@ } private void createFrameBuffer(int p_166142_, int p_166143_) { -@@ -37,6 +_,10 @@ +@@ -37,6 +_,9 @@ GlStateManager._texParameter(3553, 10242, 33071); GlStateManager._texParameter(3553, 10243, 33071); GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); + if (this.useStencil) { -+ GlStateManager._bindTexture(this.stencilBufferId); -+ GlStateManager._glFramebufferTexture2D(36160, org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, 3553, this.stencilBufferId, 0); ++ GlStateManager._glFramebufferTexture2D(36160, org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, 3553, this.depthBufferId, 0); + } GlStateManager._bindTexture(0); this.viewWidth = maintarget$dimension.width; this.viewHeight = maintarget$dimension.height; -@@ -50,7 +_,14 @@ - RenderSystem.assertOnRenderThreadOrInit(); +@@ -51,6 +_,10 @@ this.colorTextureId = TextureUtil.generateTextureId(); this.depthBufferId = TextureUtil.generateTextureId(); -+ if (this.useStencil) { -+ this.stencilBufferId = this.depthBufferId; -+ } MainTarget.AttachmentState maintarget$attachmentstate = MainTarget.AttachmentState.NONE; + MainTarget.AttachmentState targetState = MainTarget.AttachmentState.COLOR_DEPTH; + if (this.useStencil) { diff --git a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch index bca255906d1..11876e73ad7 100644 --- a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch @@ -1,6 +1,6 @@ --- a/com/mojang/blaze3d/pipeline/RenderTarget.java +++ b/com/mojang/blaze3d/pipeline/RenderTarget.java -@@ -25,17 +_,31 @@ +@@ -25,6 +_,7 @@ public int viewWidth; public int viewHeight; public final boolean useDepth; @@ -8,8 +8,7 @@ public int frameBufferId; protected int colorTextureId; protected int depthBufferId; -+ protected int stencilBufferId; - private final float[] clearChannels = Util.make(() -> new float[]{1.0F, 1.0F, 1.0F, 0.0F}); +@@ -32,7 +_,15 @@ public int filterMode; public RenderTarget(boolean p_166199_) { @@ -18,84 +17,36 @@ + } + + public RenderTarget(boolean useDepth, boolean useStencil) { ++ if (useStencil && !useDepth) { ++ throw new IllegalArgumentException("Stencil can only be enabled if depth is enabled."); ++ } + this.useDepth = useDepth; + this.useStencil = useStencil; this.frameBufferId = -1; this.colorTextureId = -1; this.depthBufferId = -1; -+ -+ if (!useDepth && useStencil) { -+ var capabilities = org.lwjgl.opengl.GL.getCapabilities(); -+ if (!capabilities.GL_ARB_texture_stencil8 && !capabilities.OpenGL44) { -+ throw new UnsupportedOperationException("Stencil-only buffers require GL_ARB_texture_stencil8 OR OpenGL 4.4"); -+ } -+ } - } - - public void resize(int p_83942_, int p_83943_) { -@@ -53,6 +_,11 @@ - RenderSystem.assertOnRenderThreadOrInit(); - this.unbindRead(); - this.unbindWrite(); -+ if (this.stencilBufferId > -1 && this.stencilBufferId != this.depthBufferId) { -+ TextureUtil.releaseTextureId(this.stencilBufferId); -+ this.stencilBufferId = -1; -+ } -+ - if (this.depthBufferId > -1) { - TextureUtil.releaseTextureId(this.depthBufferId); - this.depthBufferId = -1; -@@ -96,9 +_,50 @@ +@@ -96,7 +_,20 @@ GlStateManager._texParameter(3553, 34892, 0); GlStateManager._texParameter(3553, 10242, 33071); GlStateManager._texParameter(3553, 10243, 33071); -+ if (!this.useStencil) // If stenciling is enabled, we will fill this later - GlStateManager._texImage2D(3553, 0, 6402, this.width, this.height, 0, 6402, 5126, null); - } - -+ if (this.useStencil) { -+ if (this.useDepth) { -+ // If depth and stencil buffers are both enabled, we must combine them -+ this.stencilBufferId = this.depthBufferId; +- GlStateManager._texImage2D(3553, 0, 6402, this.width, this.height, 0, 6402, 5126, null); ++ if (!this.useStencil) { ++ GlStateManager._texImage2D(3553, 0, 6402, this.width, this.height, 0, 6402, 5126, null); + } else { -+ // Otherwise, we can generate a new texture in its place. -+ this.stencilBufferId = TextureUtil.generateTextureId(); -+ GlStateManager._bindTexture(this.stencilBufferId); -+ GlStateManager._texParameter(3553, 10241, 9728); -+ GlStateManager._texParameter(3553, 10240, 9728); -+ GlStateManager._texParameter(3553, 34892, 0); -+ GlStateManager._texParameter(3553, 10242, 33071); -+ GlStateManager._texParameter(3553, 10243, 33071); -+ } -+ -+ if (this.useDepth) { + // Use a combined format for both depth and stencil. + GlStateManager._texImage2D( -+ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, -+ 0, -+ org.lwjgl.opengl.GL32.GL_DEPTH24_STENCIL8, -+ this.width, this.height, -+ 0, -+ org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, -+ org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, -+ null); -+ } else { -+ // Otherwise, we can use a separate format. Testing for this was done in the constructor already. -+ GlStateManager._texImage2D( -+ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, -+ 0, -+ org.lwjgl.opengl.GL32.GL_STENCIL_INDEX8, -+ this.width, this.height, -+ 0, -+ org.lwjgl.opengl.GL32.GL_STENCIL_INDEX, -+ org.lwjgl.opengl.GL32.GL_BYTE, -+ null); ++ org.lwjgl.opengl.GL32.GL_TEXTURE_2D, ++ 0, ++ org.lwjgl.opengl.GL32.GL_DEPTH24_STENCIL8, ++ this.width, this.height, ++ 0, ++ org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, ++ org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, ++ null); + } -+ } -+ + } + this.setFilterMode(9728, true); - GlStateManager._bindTexture(this.colorTextureId); - GlStateManager._texParameter(3553, 10242, 33071); @@ -109,6 +_,14 @@ if (this.useDepth) { GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, this.depthBufferId, 0); @@ -105,7 +56,7 @@ + org.lwjgl.opengl.GL32.GL_FRAMEBUFFER, + org.lwjgl.opengl.GL32.GL_STENCIL_ATTACHMENT, + org.lwjgl.opengl.GL32.GL_TEXTURE_2D, -+ this.stencilBufferId, ++ this.depthBufferId, + 0); + } From 2278de18d0488a30fd971a054c21675a944d7e54 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:20:47 +0100 Subject: [PATCH 12/18] Remove unnecessary AttachmentState patch --- .../blaze3d/pipeline/MainTarget.java.patch | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 9a87eaa883f..9df3ce3d3a7 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -25,58 +25,31 @@ GlStateManager._bindTexture(0); this.viewWidth = maintarget$dimension.width; this.viewHeight = maintarget$dimension.height; -@@ -51,6 +_,10 @@ - this.colorTextureId = TextureUtil.generateTextureId(); - this.depthBufferId = TextureUtil.generateTextureId(); - MainTarget.AttachmentState maintarget$attachmentstate = MainTarget.AttachmentState.NONE; -+ MainTarget.AttachmentState targetState = MainTarget.AttachmentState.COLOR_DEPTH; -+ if (this.useStencil) { -+ targetState = targetState.with(MainTarget.AttachmentState.STENCIL); -+ } - - for (MainTarget.Dimension maintarget$dimension : MainTarget.Dimension.listWithFallback(p_166147_, p_166148_)) { - maintarget$attachmentstate = MainTarget.AttachmentState.NONE; -@@ -58,11 +_,15 @@ +@@ -58,7 +_,11 @@ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.COLOR); } - if (this.allocateDepthAttachment(maintarget$dimension)) { + if (this.useStencil && this.allocateDepthStencilAttachment(maintarget$dimension)) { -+ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH_STENCIL); ++ maintarget$attachmentstate = maintarget$attachmentstate.with(AttachmentState.DEPTH); + } + + else if (this.allocateDepthAttachment(maintarget$dimension)) { maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH); } -- if (maintarget$attachmentstate == MainTarget.AttachmentState.COLOR_DEPTH) { -+ if (maintarget$attachmentstate == targetState) { - return maintarget$dimension; - } - } -@@ -86,12 +_,24 @@ - return GlStateManager._getError() != 1285; - } - +@@ -83,6 +_,14 @@ + GlStateManager._getError(); + GlStateManager._bindTexture(this.depthBufferId); + GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, 6402, 5126, null); ++ return GlStateManager._getError() != 1285; ++ } ++ + private boolean allocateDepthStencilAttachment(MainTarget.Dimension p_166145_) { + RenderSystem.assertOnRenderThreadOrInit(); + GlStateManager._getError(); + GlStateManager._bindTexture(this.depthBufferId); + GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, null); -+ return GlStateManager._getError() != 1285; -+ } -+ - @OnlyIn(Dist.CLIENT) - static enum AttachmentState { - NONE, - COLOR, - DEPTH, -- COLOR_DEPTH; -+ COLOR_DEPTH, -+ STENCIL, -+ COLOR_STENCIL, -+ DEPTH_STENCIL, -+ COLOR_DEPTH_STENCIL; - - private static final MainTarget.AttachmentState[] VALUES = values(); + return GlStateManager._getError() != 1285; + } From fa4ebe71660dbb0e8c10738bdc5e7595b6f3d274 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:27:43 +0100 Subject: [PATCH 13/18] Keep simplifying --- .../blaze3d/pipeline/RenderTarget.java.patch | 18 ++++-------------- .../client/renderer/PostPass.java.patch | 10 ++-------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch index 11876e73ad7..4d6619c9184 100644 --- a/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch @@ -62,24 +62,14 @@ this.checkStatus(); this.clear(); -@@ -218,6 +_,10 @@ +@@ -217,6 +_,10 @@ + if (this.useDepth) { GlStateManager._clearDepth(1.0); i |= 256; - } ++ } + if (this.useStencil) { + GlStateManager._clearStencil(0); + i |= org.lwjgl.opengl.GL32.GL_STENCIL_BUFFER_BIT; -+ } + } GlStateManager._clear(i); - this.unbindWrite(); -@@ -229,5 +_,9 @@ - - public int getDepthTextureId() { - return this.depthBufferId; -+ } -+ -+ public int getStencilTextureId() { -+ return this.stencilBufferId; - } - } diff --git a/patches/net/minecraft/client/renderer/PostPass.java.patch b/patches/net/minecraft/client/renderer/PostPass.java.patch index efa98f666ba..b5e564963f0 100644 --- a/patches/net/minecraft/client/renderer/PostPass.java.patch +++ b/patches/net/minecraft/client/renderer/PostPass.java.patch @@ -56,18 +56,12 @@ private ResourceHandle getHandle(Map> p_364534_) { ResourceHandle resourcehandle = p_364534_.get(this.targetId); if (resourcehandle == null) { -@@ -142,7 +_,13 @@ +@@ -142,7 +_,7 @@ 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()) -+ p_366564_.bindSampler(this.samplerName + "Sampler", rendertarget.getDepthTextureId()); -+ // 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()); ++ p_366564_.bindSampler(this.samplerName + "Sampler", this.depthBuffer() ? rendertarget.getDepthTextureId() : rendertarget.getColorTextureId()); p_366564_.safeGetUniform(this.samplerName + "Size").set((float)rendertarget.width, (float)rendertarget.height); } From f3df3e41dc9a44d5275054aaf22fb3bc99907487 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:45:27 +0100 Subject: [PATCH 14/18] Keep simplifying? --- .../client/renderer/PostChain.java.patch | 11 ---- .../renderer/PostChainConfig.java.patch | 23 -------- .../client/renderer/PostPass.java.patch | 56 ------------------- 3 files changed, 90 deletions(-) delete mode 100644 patches/net/minecraft/client/renderer/PostChainConfig.java.patch diff --git a/patches/net/minecraft/client/renderer/PostChain.java.patch b/patches/net/minecraft/client/renderer/PostChain.java.patch index 0cabd6b5ec2..ad7a8d4e9e3 100644 --- a/patches/net/minecraft/client/renderer/PostChain.java.patch +++ b/patches/net/minecraft/client/renderer/PostChain.java.patch @@ -1,16 +1,5 @@ --- a/net/minecraft/client/renderer/PostChain.java +++ b/net/minecraft/client/renderer/PostChain.java -@@ -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, net.minecraft.client.renderer.PostPass.TargetInput.BufferType.from(flag1, useStencilBuffer), flag2)); - continue; - default: - throw new MatchException(null, null); @@ -95,17 +_,33 @@ Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float)p_361423_, 0.0F, (float)p_362735_, 0.1F, 1000.0F); Map> map = new HashMap<>(this.internalTargets.size() + this.externalTargets.size()); diff --git a/patches/net/minecraft/client/renderer/PostChainConfig.java.patch b/patches/net/minecraft/client/renderer/PostChainConfig.java.patch deleted file mode 100644 index e07b4d10af6..00000000000 --- a/patches/net/minecraft/client/renderer/PostChainConfig.java.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- a/net/minecraft/client/renderer/PostChainConfig.java -+++ b/net/minecraft/client/renderer/PostChainConfig.java -@@ -108,13 +_,18 @@ - } - - @OnlyIn(Dist.CLIENT) -- public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) implements PostChainConfig.Input { -+ public static record TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear, boolean useStencilBuffer) implements PostChainConfig.Input { -+ public TargetInput(String samplerName, ResourceLocation targetId, boolean useDepthBuffer, boolean bilinear) { -+ this(samplerName, targetId, useDepthBuffer, bilinear, false); -+ } -+ - public static final Codec CODEC = RecordCodecBuilder.create( - p_363892_ -> p_363892_.group( - Codec.STRING.fieldOf("sampler_name").forGetter(PostChainConfig.TargetInput::samplerName), - ResourceLocation.CODEC.fieldOf("target").forGetter(PostChainConfig.TargetInput::targetId), - Codec.BOOL.optionalFieldOf("use_depth_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useDepthBuffer), -- Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear) -+ Codec.BOOL.optionalFieldOf("bilinear", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::bilinear), -+ Codec.BOOL.optionalFieldOf("neoforge:use_stencil_buffer", Boolean.valueOf(false)).forGetter(PostChainConfig.TargetInput::useStencilBuffer) - ) - .apply(p_363892_, PostChainConfig.TargetInput::new) - ); diff --git a/patches/net/minecraft/client/renderer/PostPass.java.patch b/patches/net/minecraft/client/renderer/PostPass.java.patch index b5e564963f0..38d3c002a9f 100644 --- a/patches/net/minecraft/client/renderer/PostPass.java.patch +++ b/patches/net/minecraft/client/renderer/PostPass.java.patch @@ -1,61 +1,5 @@ --- a/net/minecraft/client/renderer/PostPass.java +++ b/net/minecraft/client/renderer/PostPass.java -@@ -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, 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 ? 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 +_,7 @@ ResourceHandle resourcehandle = this.getHandle(p_361239_); RenderTarget rendertarget = resourcehandle.get(); From 46e68fed2c644a9f6f618282f926d9bc102d44c1 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:50:10 +0100 Subject: [PATCH 15/18] Missed old patch to delete --- .../net/minecraft/client/renderer/PostPass.java.patch | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 patches/net/minecraft/client/renderer/PostPass.java.patch diff --git a/patches/net/minecraft/client/renderer/PostPass.java.patch b/patches/net/minecraft/client/renderer/PostPass.java.patch deleted file mode 100644 index 38d3c002a9f..00000000000 --- a/patches/net/minecraft/client/renderer/PostPass.java.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/client/renderer/PostPass.java -+++ b/net/minecraft/client/renderer/PostPass.java -@@ -142,7 +_,7 @@ - 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()); -+ p_366564_.bindSampler(this.samplerName + "Sampler", this.depthBuffer() ? rendertarget.getDepthTextureId() : rendertarget.getColorTextureId()); - p_366564_.safeGetUniform(this.samplerName + "Size").set((float)rendertarget.width, (float)rendertarget.height); - } - From 02a1ea2fa0115919ad60d053b52d2ff2b8e6e861 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:53:46 +0100 Subject: [PATCH 16/18] getDescriptor simplification --- .../framegraph/FrameGraphBuilder.java.patch | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch index 84d9e314b44..d9d632bd4a1 100644 --- a/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch +++ b/patches/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java.patch @@ -1,22 +1,11 @@ --- a/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java +++ b/com/mojang/blaze3d/framegraph/FrameGraphBuilder.java -@@ -173,6 +_,11 @@ - public T get() { - return this.resource; - } -+ -+ @Override -+ public ResourceDescriptor getDescriptor() { -+ return null; -+ } - } - - @OnlyIn(Dist.CLIENT) -@@ -211,6 +_,10 @@ +@@ -211,6 +_,11 @@ public String toString() { return this.createdBy != null ? this.holder + "#" + this.version + " (from " + this.createdBy + ")" : this.holder + "#" + this.version; } + ++ @Nullable + public ResourceDescriptor getDescriptor() { + return this.holder.getDescriptor(); + } From f62e41755b774e1496d70585d35307fb7ae567dd Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 9 Jan 2025 20:50:11 +0100 Subject: [PATCH 17/18] Simplified event --- .../blaze3d/pipeline/MainTarget.java.patch | 8 +-- .../net/minecraft/client/Minecraft.java.patch | 3 +- .../neoforge/client/ClientHooks.java | 9 ++-- .../event/ConfigureMainRenderTargetEvent.java | 50 ++----------------- 4 files changed, 14 insertions(+), 56 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index 9df3ce3d3a7..f6127abcc72 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -6,12 +6,12 @@ public MainTarget(int p_166137_, int p_166138_) { - super(true); - this.createFrameBuffer(p_166137_, p_166138_); -+ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(true, p_166137_, p_166138_)); ++ this(p_166137_, p_166138_, false); + } + -+ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e) { -+ super(e.useDepth(), e.useStencil()); -+ this.createFrameBuffer(e.width(), e.height()); ++ public MainTarget(int width, int height, boolean useStencil) { ++ super(true, useStencil); ++ this.createFrameBuffer(width, height); } private void createFrameBuffer(int p_166142_, int p_166143_) { diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index 4b3dc587ed0..c59651003d2 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -18,8 +18,9 @@ this.keyboardHandler = new KeyboardHandler(this); - this.keyboardHandler.setup(this.window.getWindow()); RenderSystem.initRenderer(this.options.glDebugVerbosity, false); +- this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight()); + net.neoforged.neoforge.client.loading.ClientModLoader.begin(this); - this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight()); ++ this.mainRenderTarget = net.neoforged.neoforge.client.ClientHooks.createMainRenderTarget(this.window.getWidth(), this.window.getHeight()); this.mainRenderTarget.setClearColor(0.0F, 0.0F, 0.0F, 0.0F); this.mainRenderTarget.clear(); this.resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES); diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index f22082411fe..11d1307d91a 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -9,6 +9,7 @@ import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMap; import com.mojang.blaze3d.framegraph.FrameGraphBuilder; +import com.mojang.blaze3d.pipeline.MainTarget; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.resource.RenderTargetDescriptor; @@ -1101,9 +1102,9 @@ public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler)); } - public static ConfigureMainRenderTargetEvent configureMainRenderTarget(boolean useDepth, int width, int height) { - var e = new ConfigureMainRenderTargetEvent(useDepth, width, height); - ModLoader.postEvent(e); - return e; + @ApiStatus.Internal + public static MainTarget createMainRenderTarget(int width, int height) { + var e = ModLoader.postEventWithReturn(new ConfigureMainRenderTargetEvent()); + return new MainTarget(width, height, e.useStencil()); } } diff --git a/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java index 805092c02e4..92b13184584 100644 --- a/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java +++ b/src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java @@ -6,49 +6,23 @@ package net.neoforged.neoforge.client.event; import com.mojang.blaze3d.pipeline.MainTarget; -import com.mojang.blaze3d.pipeline.RenderTarget; import net.neoforged.bus.api.Event; import net.neoforged.bus.api.ICancellableEvent; import net.neoforged.fml.LogicalSide; import net.neoforged.fml.event.IModBusEvent; -import org.jetbrains.annotations.ApiStatus; /** - * Fired when configuring the main {@linkplain RenderTarget render target}. - *

- * This event fires during startup when the {@link MainTarget} is constructed. + * Fired when configuring the {@linkplain MainTarget main render target} during startup. *

* This event is not {@linkplain ICancellableEvent cancellable}. *

- * This event is fired on the mod-speciffic event bus, only on the {@linkplain LogicalSide#CLIENT logical client}. + * This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}. */ public class ConfigureMainRenderTargetEvent extends Event implements IModBusEvent { - private final boolean useDepth; private boolean useStencil; - private final int width; - private final int height; - - @ApiStatus.Internal - public ConfigureMainRenderTargetEvent(boolean useDepth, int width, int height) { - this.useDepth = useDepth; - this.useStencil = false; - - this.width = width; - this.height = height; - } - - /** - * Returns whether the depth buffer is enabled. - * - * @return true, if the depth buffer is enabled, or false otherwise. - */ - public boolean useDepth() { - return this.useDepth; - } - /** - * Returns whether the stencil buffer is enabled. + * Returns whether enabling the stencil buffer on the main render target was requested. * * @return true, if the stencil buffer is enabled, or false otherwise. */ @@ -56,24 +30,6 @@ public boolean useStencil() { return this.useStencil; } - /** - * Returns the preferred width of the framebuffer. - * - * @return The width, in pixels, to attempt to use for the framebuffer. - */ - public int width() { - return this.width; - } - - /** - * Returns the preferred height of the framebuffer. - * - * @return The height, in pixels, to attempt to use for the framebuffer. - */ - public int height() { - return this.height; - } - /** * Enable the stencil buffer for the main render target. * From 3f5ddc10700f9f022130ef6b96f39f272d6a6749 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:02:43 +0100 Subject: [PATCH 18/18] Simplify allocation (+ missed genPatches) --- .../blaze3d/pipeline/MainTarget.java.patch | 36 +++++++++---------- .../net/minecraft/client/Minecraft.java.patch | 3 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch index f6127abcc72..53624be3982 100644 --- a/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch +++ b/patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch @@ -6,12 +6,12 @@ public MainTarget(int p_166137_, int p_166138_) { - super(true); - this.createFrameBuffer(p_166137_, p_166138_); -+ this(p_166137_, p_166138_, false); ++ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(true, p_166137_, p_166138_)); + } + -+ public MainTarget(int width, int height, boolean useStencil) { -+ super(true, useStencil); -+ this.createFrameBuffer(width, height); ++ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e) { ++ super(e.useDepth(), e.useStencil()); ++ this.createFrameBuffer(e.width(), e.height()); } private void createFrameBuffer(int p_166142_, int p_166143_) { @@ -25,31 +25,27 @@ GlStateManager._bindTexture(0); this.viewWidth = maintarget$dimension.width; this.viewHeight = maintarget$dimension.height; -@@ -58,7 +_,11 @@ +@@ -58,8 +_,8 @@ maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.COLOR); } - if (this.allocateDepthAttachment(maintarget$dimension)) { -+ if (this.useStencil && this.allocateDepthStencilAttachment(maintarget$dimension)) { +- maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH); ++ if (this.useStencil && this.allocateDepthAttachment(maintarget$dimension)) { + maintarget$attachmentstate = maintarget$attachmentstate.with(AttachmentState.DEPTH); -+ } -+ -+ else if (this.allocateDepthAttachment(maintarget$dimension)) { - maintarget$attachmentstate = maintarget$attachmentstate.with(MainTarget.AttachmentState.DEPTH); } -@@ -83,6 +_,14 @@ + if (maintarget$attachmentstate == MainTarget.AttachmentState.COLOR_DEPTH) { +@@ -82,7 +_,11 @@ + RenderSystem.assertOnRenderThreadOrInit(); GlStateManager._getError(); GlStateManager._bindTexture(this.depthBufferId); - GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, 6402, 5126, null); -+ return GlStateManager._getError() != 1285; -+ } -+ -+ private boolean allocateDepthStencilAttachment(MainTarget.Dimension p_166145_) { -+ RenderSystem.assertOnRenderThreadOrInit(); -+ GlStateManager._getError(); -+ GlStateManager._bindTexture(this.depthBufferId); -+ GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, null); +- GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, 6402, 5126, null); ++ if (this.useStencil) { ++ GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, org.lwjgl.opengl.GL32.GL_DEPTH_STENCIL, org.lwjgl.opengl.GL32.GL_UNSIGNED_INT_24_8, null); ++ } else { ++ GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, 6402, 5126, null); ++ } return GlStateManager._getError() != 1285; } diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index c59651003d2..4b3dc587ed0 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -18,9 +18,8 @@ this.keyboardHandler = new KeyboardHandler(this); - this.keyboardHandler.setup(this.window.getWindow()); RenderSystem.initRenderer(this.options.glDebugVerbosity, false); -- this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight()); + net.neoforged.neoforge.client.loading.ClientModLoader.begin(this); -+ this.mainRenderTarget = net.neoforged.neoforge.client.ClientHooks.createMainRenderTarget(this.window.getWidth(), this.window.getHeight()); + this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight()); this.mainRenderTarget.setClearColor(0.0F, 0.0F, 0.0F, 0.0F); this.mainRenderTarget.clear(); this.resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES);