Skip to content

Commit

Permalink
Remove stencil-only patches in MainTarget
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FiniteReality committed Jan 9, 2025
1 parent 117c7af commit f278e8d
Showing 1 changed file with 11 additions and 57 deletions.
68 changes: 11 additions & 57 deletions patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}

0 comments on commit f278e8d

Please sign in to comment.