forked from neoforged/NeoForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore ability to enable stenciling (neoforged#1830)
Co-authored-by: FiniteReality <[email protected]> Co-authored-by: Sebastian Hartte <[email protected]>
- Loading branch information
Showing
12 changed files
with
306 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- a/com/mojang/blaze3d/pipeline/MainTarget.java | ||
+++ b/com/mojang/blaze3d/pipeline/MainTarget.java | ||
@@ -16,7 +_,10 @@ | ||
static final MainTarget.Dimension DEFAULT_DIMENSIONS = new MainTarget.Dimension(854, 480); | ||
|
||
public MainTarget(int p_166137_, int p_166138_) { | ||
- super(true); | ||
+ this(p_166137_, p_166138_, false); | ||
+ } | ||
+ public MainTarget(int p_166137_, int p_166138_, boolean enableStencil) { | ||
+ super(true, enableStencil); | ||
this.createFrameBuffer(p_166137_, p_166138_); | ||
} | ||
|
||
@@ -37,6 +_,14 @@ | ||
GlStateManager._texParameter(3553, 10242, 33071); | ||
GlStateManager._texParameter(3553, 10243, 33071); | ||
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.depthBufferId, | ||
+ 0); | ||
+ } | ||
GlStateManager._bindTexture(0); | ||
this.viewWidth = maintarget$dimension.width; | ||
this.viewHeight = maintarget$dimension.height; | ||
@@ -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); | ||
+ if (!this.useStencil) { | ||
+ GlStateManager._texImage2D(3553, 0, 6402, p_166145_.width, p_166145_.height, 0, 6402, 5126, null); | ||
+ } else { | ||
+ net.neoforged.neoforge.client.ClientHooks.texImageDepthStencil(p_166145_.width, p_166145_.height); | ||
+ } | ||
return GlStateManager._getError() != 1285; | ||
} | ||
|
66 changes: 66 additions & 0 deletions
66
patches/com/mojang/blaze3d/pipeline/RenderTarget.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- a/com/mojang/blaze3d/pipeline/RenderTarget.java | ||
+++ b/com/mojang/blaze3d/pipeline/RenderTarget.java | ||
@@ -25,6 +_,7 @@ | ||
public int viewWidth; | ||
public int viewHeight; | ||
public final boolean useDepth; | ||
+ public final boolean useStencil; | ||
public int frameBufferId; | ||
protected int colorTextureId; | ||
protected int depthBufferId; | ||
@@ -32,7 +_,15 @@ | ||
public int filterMode; | ||
|
||
public RenderTarget(boolean p_166199_) { | ||
- this.useDepth = p_166199_; | ||
+ this(p_166199_, false); | ||
+ } | ||
+ | ||
+ 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; | ||
@@ -96,7 +_,11 @@ | ||
GlStateManager._texParameter(3553, 34892, 0); | ||
GlStateManager._texParameter(3553, 10242, 33071); | ||
GlStateManager._texParameter(3553, 10243, 33071); | ||
- 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 { | ||
+ net.neoforged.neoforge.client.ClientHooks.texImageDepthStencil(this.width, this.height); | ||
+ } | ||
} | ||
|
||
this.setFilterMode(9728, true); | ||
@@ -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.depthBufferId, | ||
+ 0); | ||
+ } | ||
|
||
this.checkStatus(); | ||
this.clear(); | ||
@@ -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); |
14 changes: 14 additions & 0 deletions
14
patches/com/mojang/blaze3d/pipeline/TextureTarget.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_); | ||
} |
18 changes: 18 additions & 0 deletions
18
patches/com/mojang/blaze3d/resource/RenderTargetDescriptor.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RenderTarget> { | ||
+public record RenderTargetDescriptor(int width, int height, boolean useDepth, boolean useStencil) implements ResourceDescriptor<RenderTarget> { | ||
+ 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_) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
patches/net/minecraft/client/renderer/LevelRenderer.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/net/neoforged/neoforge/client/event/ConfigureMainRenderTargetEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 net.neoforged.bus.api.Event; | ||
import net.neoforged.bus.api.ICancellableEvent; | ||
import net.neoforged.fml.LogicalSide; | ||
import net.neoforged.fml.event.IModBusEvent; | ||
|
||
/** | ||
* Fired when configuring the {@linkplain MainTarget main render target} during startup. | ||
* <p> | ||
* This event is not {@linkplain ICancellableEvent cancellable}. | ||
* <p> | ||
* 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 boolean enableStencil; | ||
|
||
/** | ||
* Returns whether enabling the stencil buffer on the main render target was requested. | ||
* | ||
* @return <code>true</code>, if the stencil buffer is enabled, or <code>false</code> otherwise. | ||
*/ | ||
public boolean isStencilEnabled() { | ||
return this.enableStencil; | ||
} | ||
|
||
/** | ||
* Enables the stencil buffer for the main render target. | ||
*/ | ||
public void enableStencil() { | ||
this.enableStencil = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.