From 41e2912de7555c08683c83849edacdf24c4dc955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20=C5=A0okala?= Date: Sat, 6 Jun 2026 12:21:50 +0200 Subject: [PATCH] Restore texture and depthFunc in GlDhMetaRenderer instead of in CleanroomRenderMixin --- .../mixins/client/MixinRenderGlobal.java | 29 +++++-------------- .../render/openGl/GlDhMetaRenderer.java | 22 ++++++++++++-- .../minecraft/MinecraftGLWrapper.java | 1 + 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/cleanroom/src/main/java/com/seibel/distanthorizons/cleanroom/mixins/client/MixinRenderGlobal.java b/cleanroom/src/main/java/com/seibel/distanthorizons/cleanroom/mixins/client/MixinRenderGlobal.java index 19bd93e12..f180ca5d4 100644 --- a/cleanroom/src/main/java/com/seibel/distanthorizons/cleanroom/mixins/client/MixinRenderGlobal.java +++ b/cleanroom/src/main/java/com/seibel/distanthorizons/cleanroom/mixins/client/MixinRenderGlobal.java @@ -23,14 +23,10 @@ import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper; import com.seibel.distanthorizons.core.api.internal.ClientApi; import com.seibel.distanthorizons.core.util.math.DhMat4f; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.entity.Entity; import net.minecraft.util.BlockRenderLayer; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL30; +import org.lwjgl.opengl.GL32; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -48,34 +44,25 @@ public class MixinRenderGlobal if (blockLayerIn == BlockRenderLayer.SOLID) { float[] mcProjMatrixRaw = new float[16]; - GL11.glGetFloatv(GL11.GL_PROJECTION_MATRIX, mcProjMatrixRaw); + GL32.glGetFloatv(GL32.GL_PROJECTION_MATRIX, mcProjMatrixRaw); ClientApi.RENDER_STATE.mcProjectionMatrix = new DhMat4f(mcProjMatrixRaw); ClientApi.RENDER_STATE.mcProjectionMatrix.transpose(); float[] mcModelViewRaw = new float[16]; - GL11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, mcModelViewRaw); + GL32.glGetFloatv(GL32.GL_MODELVIEW_MATRIX, mcModelViewRaw); ClientApi.RENDER_STATE.mcModelViewMatrix = new DhMat4f(mcModelViewRaw); ClientApi.RENDER_STATE.mcModelViewMatrix.transpose(); ClientApi.RENDER_STATE.partialTickTime = (float) partialTicks; ClientApi.RENDER_STATE.clientLevelWrapper = ClientLevelWrapper.getWrapperIfDifferent(ClientApi.RENDER_STATE.clientLevelWrapper, this.world); - int blendSrc = GL11.glGetInteger(GL11.GL_BLEND_SRC); - int blendDst = GL11.glGetInteger(GL11.GL_BLEND_DST); - int boundTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); - ClientApi.INSTANCE.renderLods(); - GL30.glBindVertexArray(0); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - GL20.glUseProgram(0); - - //Restore vanilla states - GlStateManager.depthFunc(GL11.GL_LEQUAL); - GlStateManager.bindTexture(boundTexture); - GlStateManager.tryBlendFuncSeparate(blendSrc, blendDst, GL11.GL_ONE, GL11.GL_ZERO); - + //Some 1.12.2 rendering mods breaks if we don't unbind buffers + GL32.glBindVertexArray(0); + GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, 0); + GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, 0); + GL32.glUseProgram(0); } } } \ No newline at end of file diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhMetaRenderer.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhMetaRenderer.java index ebc78b50e..4e0cd9c59 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhMetaRenderer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhMetaRenderer.java @@ -71,6 +71,11 @@ public class GlDhMetaRenderer implements IDhMetaRenderer /** used in case there's an API override */ public IDhApiShaderProgram shaderProgramForThisFrame; + /** Older MC versions assume GL state is unchanged, so we must restore it after DH rendering */ + #if MC_VER <= MC_1_12_2 + private int previousBoundTextureId; + private int previousDepthFunc; + #endif //============// @@ -113,6 +118,11 @@ public class GlDhMetaRenderer implements IDhMetaRenderer DhApiRenderParam renderEventParam, boolean firstPass) { + #if MC_VER <= MC_1_12_2 + this.previousBoundTextureId = GLMC.getActiveTexture(); + this.previousDepthFunc = GLMC.getActiveDepthFunc(); + #endif + //===================// // framebuffer setup // //===================// @@ -357,7 +367,9 @@ public class GlDhMetaRenderer implements IDhMetaRenderer } } - + #if MC_VER <= MC_1_12_2 + GLMC.glDepthFunc(previousDepthFunc); + #endif this.unbindLightmap(); this.shaderProgramForThisFrame.unbind(); } @@ -455,8 +467,12 @@ public class GlDhMetaRenderer implements IDhMetaRenderer public void unbindLightmap() { - // strange that we don't call "glActiveTexture" here but since it's working James isn't going to change it right now (2026-03-10) - GLMC.glBindTexture(0); + // strange that we don't call "glActiveTexture" here but since it's working James isn't going to change it right now (2026-03-10) + #if MC_VER <= MC_1_12_2 + GLMC.glBindTexture(previousBoundTextureId); + #else + GLMC.glBindTexture(0); + #endif } //endregion diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java index d7b83b281..d27a2f328 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java @@ -126,6 +126,7 @@ public class MinecraftGLWrapper GlStateManager._depthFunc(func); #endif } + public int getActiveDepthFunc() { return GL32.glGetInteger(GL32.GL_DEPTH_FUNC); } /** @see GL32#glDepthMask(boolean) */ public void enableDepthMask()