From 0ffefaa8c19bd033a8af5fc81100df15e8c8e6b0 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 13 Mar 2026 07:42:41 -0500 Subject: [PATCH] Fix a few Legacy GL issues --- .../openGl/GlDhRenderApiDefinition.java | 10 +++++ .../openGl/GlDhTerrainShaderProgram.java | 42 +++++++++---------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhRenderApiDefinition.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhRenderApiDefinition.java index 7c6f0afdc..26f604c10 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhRenderApiDefinition.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhRenderApiDefinition.java @@ -2,6 +2,7 @@ package com.seibel.distanthorizons.common.render.openGl; import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectRenderer; import com.seibel.distanthorizons.common.render.openGl.generic.GlGenericObjectVertexContainer; +import com.seibel.distanthorizons.common.render.openGl.glObject.GLState; import com.seibel.distanthorizons.common.render.openGl.glObject.GlDummyUniformData; import com.seibel.distanthorizons.common.render.openGl.glObject.buffer.GLVertexBuffer; import com.seibel.distanthorizons.common.render.openGl.postProcessing.fade.GlDhFarFadeRenderer; @@ -44,6 +45,15 @@ public class GlDhRenderApiDefinition extends AbstractDhRenderApiDefinition @Override public IDhVanillaFadeRenderer getVanillaFadeRenderer() { return GlVanillaFadeRenderer.INSTANCE; } @Override public IDhTestTriangleRenderer getTestTriangleRenderer() { return GlTestTriangleRenderer.INSTANCE; } + @Override + public void bindRenderers() + { + try (GLState state = new GLState()) + { + super.bindRenderers(); + } + } + //endregion diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhTerrainShaderProgram.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhTerrainShaderProgram.java index 2d051735a..48bade6c8 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhTerrainShaderProgram.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/GlDhTerrainShaderProgram.java @@ -1,22 +1,3 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - package com.seibel.distanthorizons.common.render.openGl; import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShaderProgram; @@ -55,7 +36,7 @@ import org.lwjgl.opengl.GL32; /** * Handles rendering the normal LOD terrain. - * @see LodQuadBuilder + * @see LodQuadBuilder */ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiShaderProgram, IDhTerrainRenderer { @@ -69,9 +50,10 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class); + private boolean init = false; public GlQuadElementBuffer quadIBO = null; - public final GlAbstractVertexAttribute vao; + public GlAbstractVertexAttribute vao; // uniforms // //region @@ -113,6 +95,15 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS "assets/distanthorizons/shaders/shared/gl/flat_shaded.frag", new String[]{"vPosition", "color"} ); + } + + public void init() + { + if (this.init) + { + return; + } + this.uCombinedMatrix = this.getUniformLocation("uCombinedMatrix"); this.uModelOffset = this.getUniformLocation("uModelOffset"); @@ -165,6 +156,10 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS throw e; } + // unbinding here is necessary to fix an issue when running on Legacy GL + this.vao.unbind(); + + this.init = true; } //endregion @@ -179,6 +174,7 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS @Override public void bind() { + this.init(); super.bind(); this.vao.bind(); } @@ -206,7 +202,7 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS combinedMatrix.multiply(renderParameters.dhModelViewMatrix); super.bind(); - + // uniforms this.setUniform(this.uCombinedMatrix, combinedMatrix); this.setUniform(this.uMircoOffset, 0.01f); // 0.01 block offset @@ -384,4 +380,4 @@ public class GlDhTerrainShaderProgram extends GlShaderProgram implements IDhApiS -} +} \ No newline at end of file