Improve incorrect rendering API error handling

This commit is contained in:
James Seibel
2026-05-16 18:25:48 -05:00
parent ada7668c28
commit 7920415d18
10 changed files with 80 additions and 23 deletions
@@ -13,6 +13,7 @@ import com.seibel.distanthorizons.common.render.blaze.postProcessing.BlazeVanill
import com.seibel.distanthorizons.common.render.blaze.test.BlazeDhTestTriangleRenderer;
import com.seibel.distanthorizons.common.render.blaze.wrappers.buffer.BlazeVertexBufferWrapper;
import com.seibel.distanthorizons.common.render.blaze.wrappers.uniform.BlazeLodUniformBufferWrapper;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
import com.seibel.distanthorizons.core.render.EDhRenderApi;
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
@@ -64,12 +65,8 @@ public class BlazeDhRenderApiDefinition extends AbstractDhRenderApiDefinition
#if MC_VER <= MC_26_1_2
renderApi = EDhRenderApi.OPEN_GL;
#else
String backendName = RenderSystem
.getDevice()
.getDeviceInfo()
.backendName();
boolean isVulkan = backendName.equalsIgnoreCase("Vulkan");
this.renderApi = isVulkan ? EDhRenderApi.VULKAN : EDhRenderApi.OPEN_GL;
// use the same rendering API as Minecraft
this.renderApi = MinecraftRenderWrapper.INSTANCE.getMcRenderingApi();
#endif
this.apiName = "Blaze3D: " + this.getRenderApi();
@@ -29,9 +29,12 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.jar.EPlatform;
import com.seibel.distanthorizons.core.logging.DhLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.render.EDhRenderApi;
import com.seibel.distanthorizons.core.util.objects.GLMessages.*;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
import com.seibel.distanthorizons.coreapi.ModInfo;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
@@ -51,6 +54,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class GLProxy
{
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
public static final DhLogger LOGGER;
static
@@ -126,15 +132,22 @@ public class GLProxy
private GLProxy() throws IllegalStateException
{
// TODO vulkan complain if created when MC is running on vulkan
if (RENDER_API_DEF.getRenderApi() != EDhRenderApi.OPEN_GL)
{
throw new IllegalStateException("[" + GLProxy.class.getSimpleName() + "] was created with the wrong Rendering API ["+RENDER_API_DEF.getRenderApi()+"]!");
}
// this must be created on minecraft's render context to work correctly
if (GLFW.glfwGetCurrentContext() == 0L)
{
throw new IllegalStateException(GLProxy.class.getSimpleName() + " was created outside the render thread!");
String message = "[" + GLProxy.class.getSimpleName() + "] was created outside the render thread!";
IllegalStateException exception = new IllegalStateException(message);
MC_CLIENT.crashMinecraft(message, exception);
throw exception;
}
LOGGER.info("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see there must have been an OpenGL error.");
LOGGER.info("Creating [" + GLProxy.class.getSimpleName() + "]... If this is the last message you see there must have been an OpenGL error.");
LOGGER.info("Lod Render OpenGL version [" + GL32.glGetString(GL32.GL_VERSION) + "].");
@@ -132,7 +132,7 @@ public class GlDhApplyShader extends GlAbstractShaderRenderer
}
private void renderToMcTexture()
{
int targetColorTextureId = MC_RENDER.getColorTextureId();
int targetColorTextureId = MC_RENDER.getGlColorTextureId();
if (targetColorTextureId == -1)
{
return;
@@ -153,7 +153,7 @@ public class GlDhFarFadeShader extends GlAbstractShaderRenderer
GL32.glUniform1i(this.uDhDepthTexture, 0);
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
GLMC.glBindTexture(MC_RENDER.getColorTextureId());
GLMC.glBindTexture(MC_RENDER.getGlColorTextureId());
GL32.glUniform1i(this.uMcColorTexture, 1);
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
@@ -185,7 +185,7 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
GLMC.disableBlend();
GLMC.glActiveTexture(GL32.GL_TEXTURE0);
GLMC.glBindTexture(MC_RENDER.getDepthTextureId());
GLMC.glBindTexture(MC_RENDER.getGlDepthTextureId());
GL32.glUniform1i(this.uMcDepthTexture, 0);
GLMC.glActiveTexture(GL32.GL_TEXTURE1);
@@ -193,7 +193,7 @@ public class GlDhVanillaFadeShader extends GlAbstractShaderRenderer
GL32.glUniform1i(this.uDhDepthTexture, 1);
GLMC.glActiveTexture(GL32.GL_TEXTURE2);
GLMC.glBindTexture(MC_RENDER.getColorTextureId());
GLMC.glBindTexture(MC_RENDER.getGlColorTextureId());
GL32.glUniform1i(this.uCombinedMcDhColorTexture, 2);
GLMC.glActiveTexture(GL32.GL_TEXTURE3);
@@ -108,7 +108,7 @@ public class GlVanillaFadeRenderer implements IDhVanillaFadeRenderer
}
else
{
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getColorTextureId(), 0);
GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, MC_RENDER.getGlColorTextureId(), 0);
}
}
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderObject
import com.seibel.distanthorizons.common.render.blaze.BlazeDhRenderApiDefinition;
import com.seibel.distanthorizons.common.render.openGl.GlDhRenderApiDefinition;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.render.EDhRenderApi;
import com.seibel.distanthorizons.core.render.renderer.GenericRenderObjectFactory;
import com.seibel.distanthorizons.common.wrappers.gui.classicConfig.ClassicConfigGUI;
import com.seibel.distanthorizons.common.wrappers.gui.LangWrapper;
@@ -139,6 +140,15 @@ public class DependencySetup
throw new IllegalStateException(message);
}
// crash if the rendering API set doesn't match Minecraft's
EDhRenderApi mcRenderApi = MinecraftRenderWrapper.INSTANCE.getMcRenderingApi();
if (mcRenderApi != renderDefinition.getRenderApi())
{
String message = "["+renderDefinition.getApiName()+"] cannot be used due to it's API ["+renderDefinition.getRenderApi().name()+"] not matching what Minecraft is currently set to use. Please either change Minecraft's rendering API or Distant Horizons'.";
LOGGER.fatal(message);
throw new IllegalStateException(message);
}
renderDefinition.bindRenderers();
}
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.NativeImage;
#endif
import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.distanthorizons.api.enums.config.EDhApiLodShading;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
@@ -35,6 +36,7 @@ import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.render.EDhRenderApi;
import com.seibel.distanthorizons.coreapi.util.ColorUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
@@ -435,6 +437,30 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
#endif
}
private EDhRenderApi renderApi = null;
@Override
public EDhRenderApi getMcRenderingApi()
{
if (this.renderApi != null)
{
return this.renderApi;
}
#if MC_VER <= MC_26_1_2
this.renderApi = EDhRenderApi.OPEN_GL;
#else
String backendName = RenderSystem
.getDevice()
.getDeviceInfo()
.backendName();
boolean isVulkan = backendName.equalsIgnoreCase("Vulkan");
this.renderApi = isVulkan ? EDhRenderApi.VULKAN : EDhRenderApi.OPEN_GL;
return this.renderApi;
#endif
}
@Override
public int getTargetFramebuffer()
{
@@ -459,7 +485,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
public void clearTargetFrameBuffer() { this.finalLevelFrameBufferId = -1; }
@Override
public int getDepthTextureId()
public int getGlDepthTextureId()
{
#if MC_VER <= MC_1_12_2
//1.12.2 is using renderbuffer instead of framebuffer for depth texture
@@ -491,9 +517,8 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
}
#endif
}
// TODO vulkan deprecate(?) and add method to get color texture
@Override
public int getColorTextureId()
public int getGlColorTextureId()
{
#if MC_VER <= MC_1_12_2
return MC.getFramebuffer().framebufferTexture;
@@ -111,14 +111,26 @@ public class MixinLightTexture
#elif MC_VER <= MC_1_21_10
GlTexture glTexture = (GlTexture) this.texture;
this.renderWrapper.setLightmapId(glTexture.glId(), clientLevel);
#else
// TODO vulkan
//// both options are available since the renderer can be changed to either Blaze3D or OpenGL
//GlTexture glTexture = (GlTexture) this.texture;
//this.renderWrapper.setLightmapId(glTexture.glId(), clientLevel);
#elif MC_VER <= MC_26_1_2
// both options are available since the renderer can be changed to either Blaze3D or OpenGL
GlTexture glTexture = (GlTexture) this.texture;
this.renderWrapper.setLightmapId(glTexture.glId(), clientLevel);
this.renderWrapper.setLightmapGpuTexture(this.texture, clientLevel);
#else
// this will only be used when using native GL rendering
if (this.texture instanceof GlTexture)
{
GlTexture glTexture = (GlTexture) this.texture;
this.renderWrapper.setLightmapId(glTexture.glId(), clientLevel);
}
// this will be used for Blaze3D OpenGL and Vulkan
this.renderWrapper.setLightmapGpuTexture(this.texture, clientLevel);
#endif
}
}