From ec7d9d417987d69aadb7926eb07be9a6d3b6da8b Mon Sep 17 00:00:00 2001 From: Funwayguy Date: Mon, 2 Mar 2020 08:45:03 +0100 Subject: [PATCH] Re-added patch to enable stencil buffer in net.minecraft.client.shader.Framebuffer Add test for the stencil buffer feature. Only tests that it doesn't crash when enabling, for now. - giga --- .../client/shader/Framebuffer.java.patch | 46 +++++++++++++++++++ .../client/rendering/StencilEnableTest.java | 18 ++++++++ src/test/resources/META-INF/mods.toml | 2 + 3 files changed, 66 insertions(+) create mode 100644 patches/minecraft/net/minecraft/client/shader/Framebuffer.java.patch create mode 100644 src/test/java/net/minecraftforge/debug/client/rendering/StencilEnableTest.java diff --git a/patches/minecraft/net/minecraft/client/shader/Framebuffer.java.patch b/patches/minecraft/net/minecraft/client/shader/Framebuffer.java.patch new file mode 100644 index 000000000..6369428f5 --- /dev/null +++ b/patches/minecraft/net/minecraft/client/shader/Framebuffer.java.patch @@ -0,0 +1,46 @@ +--- a/net/minecraft/client/shader/Framebuffer.java ++++ b/net/minecraft/client/shader/Framebuffer.java +@@ -100,8 +100,14 @@ + GlStateManager.func_227645_a_(FramebufferConstants.field_227592_a_, FramebufferConstants.field_227594_c_, 3553, this.field_147617_g, 0); + if (this.field_147619_e) { + GlStateManager.func_227730_i_(FramebufferConstants.field_227593_b_, this.field_147624_h); ++ if (!stencilEnabled) { + GlStateManager.func_227678_b_(FramebufferConstants.field_227593_b_, 33190, this.field_147622_a, this.field_147620_b); + GlStateManager.func_227693_c_(FramebufferConstants.field_227592_a_, FramebufferConstants.field_227595_d_, FramebufferConstants.field_227593_b_, this.field_147624_h); ++ } else { ++ GlStateManager.func_227678_b_(FramebufferConstants.field_227593_b_, org.lwjgl.opengl.EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, this.field_147622_a, this.field_147620_b); ++ GlStateManager.func_227693_c_(FramebufferConstants.field_227592_a_, org.lwjgl.opengl.EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, FramebufferConstants.field_227593_b_, this.field_147624_h); ++ GlStateManager.func_227693_c_(FramebufferConstants.field_227592_a_, org.lwjgl.opengl.EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, FramebufferConstants.field_227593_b_, this.field_147624_h); ++ } + } + + this.func_147611_b(); +@@ -254,4 +260,28 @@ + GlStateManager.func_227658_a_(i, p_216493_1_); + this.func_147609_e(); + } ++ ++ /*================================ FORGE START ================================================*/ ++ private boolean stencilEnabled = false; ++ /** ++ * Attempts to enabled 8 bits of stencil buffer on this FrameBuffer. ++ * Modders must call this directly to set things up. ++ * This is to prevent the default cause where graphics cards do not support stencil bits. ++ */ ++ public void enableStencil() ++ { ++ if(stencilEnabled) return; ++ stencilEnabled = true; ++ this.func_216491_a(field_147621_c, field_147618_d, net.minecraft.client.Minecraft.field_142025_a); ++ } ++ ++ /** ++ * Returns wither or not this FBO has been successfully initialized with stencil bits. ++ * If not, and a modder wishes it to be, they must call enableStencil. ++ */ ++ public boolean isStencilEnabled() ++ { ++ return this.stencilEnabled; ++ } ++ /*================================ FORGE END ================================================*/ + } diff --git a/src/test/java/net/minecraftforge/debug/client/rendering/StencilEnableTest.java b/src/test/java/net/minecraftforge/debug/client/rendering/StencilEnableTest.java new file mode 100644 index 000000000..0ca0993b4 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/client/rendering/StencilEnableTest.java @@ -0,0 +1,18 @@ +package net.minecraftforge.debug.client.rendering; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + +@Mod("stencil_enable_test") +public class StencilEnableTest { + public StencilEnableTest() { + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); + } + + private void clientSetup(FMLClientSetupEvent event) { + Minecraft.getInstance().getFramebuffer().enableStencil(); + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index 6a7aa666d..0115bbec8 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -69,6 +69,8 @@ loaderVersion="[28,)" modId="composite_model_test" [[mods]] modId="music_disc_test" +[[mods]] + modId="stencil_enable_test" [[dependencies.global_loot_test]] modId="forge" mandatory=true