diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/BlazeDhRenderApiDefinition.java b/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/BlazeDhRenderApiDefinition.java index fb70f9d97..2f2bfd934 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/BlazeDhRenderApiDefinition.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/blaze/BlazeDhRenderApiDefinition.java @@ -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(); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/glObject/GLProxy.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/glObject/GLProxy.java index aad3e218f..9b5ca060f 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/glObject/GLProxy.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/glObject/GLProxy.java @@ -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) + "]."); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/apply/GlDhApplyShader.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/apply/GlDhApplyShader.java index 1d65a5e9a..78ebc3991 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/apply/GlDhApplyShader.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/apply/GlDhApplyShader.java @@ -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; diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhFarFadeShader.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhFarFadeShader.java index d2cbda827..e8e33f30b 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhFarFadeShader.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhFarFadeShader.java @@ -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); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhVanillaFadeShader.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhVanillaFadeShader.java index 9ad70522b..ac921503d 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhVanillaFadeShader.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlDhVanillaFadeShader.java @@ -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); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlVanillaFadeRenderer.java b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlVanillaFadeRenderer.java index 0592caa34..950fc0a4d 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlVanillaFadeRenderer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/render/openGl/postProcessing/fade/GlVanillaFadeRenderer.java @@ -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); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java index 0f8ffb7cd..9bcd0590f 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/DependencySetup.java @@ -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(); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java index e369a4901..f0a39f21f 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -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; diff --git a/coreSubProjects b/coreSubProjects index 2f9504b16..ec6f8255b 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 2f9504b16768283cb9c1bb261a6409d3e19d71ef +Subproject commit ec6f8255b5cc823ad2fa9ddd7fd9ca1894adea09 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java index e37a026c5..f2b860e2c 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java @@ -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 } + + }