Restore texture and depthFunc in GlDhMetaRenderer instead of in CleanroomRenderMixin

This commit is contained in:
Vojtěch Šokala
2026-06-06 12:21:50 +02:00
parent f64072eeab
commit 41e2912de7
3 changed files with 28 additions and 24 deletions
@@ -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.api.internal.ClientApi;
import com.seibel.distanthorizons.core.util.math.DhMat4f; import com.seibel.distanthorizons.core.util.math.DhMat4f;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL32;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@@ -48,34 +44,25 @@ public class MixinRenderGlobal
if (blockLayerIn == BlockRenderLayer.SOLID) if (blockLayerIn == BlockRenderLayer.SOLID)
{ {
float[] mcProjMatrixRaw = new float[16]; 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 = new DhMat4f(mcProjMatrixRaw);
ClientApi.RENDER_STATE.mcProjectionMatrix.transpose(); ClientApi.RENDER_STATE.mcProjectionMatrix.transpose();
float[] mcModelViewRaw = new float[16]; 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 = new DhMat4f(mcModelViewRaw);
ClientApi.RENDER_STATE.mcModelViewMatrix.transpose(); ClientApi.RENDER_STATE.mcModelViewMatrix.transpose();
ClientApi.RENDER_STATE.partialTickTime = (float) partialTicks; ClientApi.RENDER_STATE.partialTickTime = (float) partialTicks;
ClientApi.RENDER_STATE.clientLevelWrapper = ClientLevelWrapper.getWrapperIfDifferent(ClientApi.RENDER_STATE.clientLevelWrapper, this.world); 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(); ClientApi.INSTANCE.renderLods();
GL30.glBindVertexArray(0); //Some 1.12.2 rendering mods breaks if we don't unbind buffers
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL32.glBindVertexArray(0);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, 0);
GL20.glUseProgram(0); GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, 0);
GL32.glUseProgram(0);
//Restore vanilla states
GlStateManager.depthFunc(GL11.GL_LEQUAL);
GlStateManager.bindTexture(boundTexture);
GlStateManager.tryBlendFuncSeparate(blendSrc, blendDst, GL11.GL_ONE, GL11.GL_ZERO);
} }
} }
} }
@@ -71,6 +71,11 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
/** used in case there's an API override */ /** used in case there's an API override */
public IDhApiShaderProgram shaderProgramForThisFrame; 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, DhApiRenderParam renderEventParam,
boolean firstPass) boolean firstPass)
{ {
#if MC_VER <= MC_1_12_2
this.previousBoundTextureId = GLMC.getActiveTexture();
this.previousDepthFunc = GLMC.getActiveDepthFunc();
#endif
//===================// //===================//
// framebuffer setup // // 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.unbindLightmap();
this.shaderProgramForThisFrame.unbind(); this.shaderProgramForThisFrame.unbind();
} }
@@ -456,7 +468,11 @@ public class GlDhMetaRenderer implements IDhMetaRenderer
public void unbindLightmap() 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) // 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); GLMC.glBindTexture(0);
#endif
} }
//endregion //endregion
@@ -126,6 +126,7 @@ public class MinecraftGLWrapper
GlStateManager._depthFunc(func); GlStateManager._depthFunc(func);
#endif #endif
} }
public int getActiveDepthFunc() { return GL32.glGetInteger(GL32.GL_DEPTH_FUNC); }
/** @see GL32#glDepthMask(boolean) */ /** @see GL32#glDepthMask(boolean) */
public void enableDepthMask() public void enableDepthMask()