From f278e8dae31efcf26d758fc1d8ce8144702e141b Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Thu, 9 Jan 2025 13:30:48 +0000 Subject: [PATCH] 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 112e72c6e7..eb0f651872 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; - } - } -