Skip to content

Commit

Permalink
Upgrade support for Distant Horizons 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 5, 2024
1 parent 7f2f97a commit 84f02e3
Show file tree
Hide file tree
Showing 27 changed files with 757 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dependencies {
forge "net.neoforged:forge:${minecraft_version}-${forge_version}"

modImplementation "org.embeddedt:embeddium-${minecraft_version}:${embeddium_version}"
modCompileOnly(files("DistantHorizons-forge-2.0.4-a-dev-1.20.1.jar"))
modCompileOnly("maven.modrinth:distanthorizonsapi:3.0.0")

forgeRuntimeLibrary(implementation(shadow(project(path: ":glsl-relocated", configuration: "bundledJar")))) {
transitive = false
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.network.NetworkConstants;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -105,6 +106,8 @@ public class Iris {

private static String IRIS_VERSION;
private static boolean fallback;
private static boolean loadPackWhenPossible = false;
private static boolean renderSystemInit = false;

public Iris() {
try {
Expand All @@ -119,6 +122,14 @@ public Iris() {
}
}

public static void loadShaderpackWhenPossible() {
loadPackWhenPossible = true;
}

public static boolean isPackInUseQuick() {
return pipelineManager.getPipelineNullable() instanceof IrisRenderingPipeline;
}

public void onKeyRegister(RegisterKeyMappingsEvent event) {
event.register(reloadKeybind);
event.register(toggleShadersKeybind);
Expand All @@ -141,8 +152,12 @@ public static void onRenderSystemInit() {

PBRTextureManager.INSTANCE.init();

renderSystemInit = true;

// Only load the shader pack when we can access OpenGL
loadShaderpack();
if (LoadingModList.get().getModFileById("distanthorizons") == null) {
loadShaderpack();
}
}

public static void duringRenderSystemInit() {
Expand Down Expand Up @@ -630,6 +645,19 @@ public static PipelineManager getPipelineManager() {
pipelineManager = new PipelineManager(Iris::createPipeline);
}

if (loadPackWhenPossible && renderSystemInit) {
loadPackWhenPossible = false;
try {
reload();
} catch (IOException e) {
logger.error("Error while reloading Shaders for " + MODNAME + "!", e);

if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.displayClientMessage(Component.translatable("iris.shaders.reloaded.failure", Throwables.getRootCause(e).getMessage()).withStyle(ChatFormatting.RED), false);
}
}
}

return pipelineManager;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/irisshaders/iris/compat/dh/DHCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public class DHCompat {
private static boolean dhPresent = true;
private static boolean lastIncompatible;
private static MethodHandle setupEventHandlers;
private static MethodHandle deletePipeline;
private static MethodHandle incompatible;
private static MethodHandle getDepthTex;
Expand Down Expand Up @@ -59,7 +58,7 @@ public static void run() {
try {
if (LoadingModList.get().getModFileById("distanthorizons") != null) {
deletePipeline = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "clear", MethodType.methodType(void.class));
setupEventHandlers = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.LodRendererEvents"), "setupEventHandlers", MethodType.methodType(void.class));
MethodHandle setupEventHandlers = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.LodRendererEvents"), "setupEventHandlers", MethodType.methodType(void.class));
getDepthTex = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "getStoredDepthTex", MethodType.methodType(int.class));
getRenderDistance = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "getRenderDistance", MethodType.methodType(int.class));
incompatible = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "incompatiblePack", MethodType.methodType(boolean.class));
Expand All @@ -79,7 +78,7 @@ public static void run() {
if (e instanceof ExceptionInInitializerError eiie) {
throw new RuntimeException("Failure loading DH compat.", eiie.getCause());
} else {
throw new RuntimeException("DH 2.0 not found, yet Fabric claims it's there. Curious.", e);
throw new RuntimeException("DH found, but one or more API methods are missing. Iris requires DH [2.0.4] or DH API version [1.1.0] or newer. Please make sure you are on the latest version of DH and Iris.", e);
}
} else {
Iris.logger.info("DH not found, and classes not found.");
Expand Down
37 changes: 29 additions & 8 deletions src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiFramebuffer;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
import com.seibel.distanthorizons.coreapi.DependencyInjection.OverrideInjector;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
import net.irisshaders.iris.gl.texture.DepthBufferFormat;
import net.irisshaders.iris.gl.texture.DepthCopyStrategy;
import net.irisshaders.iris.pipeline.IrisRenderingPipeline;
import net.irisshaders.iris.shaderpack.programs.ProgramSource;
import net.irisshaders.iris.shaderpack.properties.CloudSetting;
import net.irisshaders.iris.targets.Blaze3dRenderTargetExt;
import net.irisshaders.iris.targets.DepthTexture;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
Expand All @@ -28,7 +29,9 @@ public class DHCompatInternal {
private final IrisRenderingPipeline pipeline;
public boolean shouldOverrideShadow;
public boolean shouldOverride;
private GlFramebuffer dhGenericFramebuffer;
private IrisLodRenderProgram solidProgram;
private IrisGenericRenderProgram genericShader;
private IrisLodRenderProgram translucentProgram;
private IrisLodRenderProgram shadowProgram;
private GlFramebuffer dhTerrainFramebuffer;
Expand All @@ -54,6 +57,7 @@ public DHCompatInternal(IrisRenderingPipeline pipeline, boolean dhShadowEnabled)
incompatible = true;
return;
}

cachedVersion = ((Blaze3dRenderTargetExt) Minecraft.getInstance().getMainRenderTarget()).iris$getDepthBufferVersion();

createDepthTex(Minecraft.getInstance().getMainRenderTarget().width, Minecraft.getInstance().getMainRenderTarget().height);
Expand All @@ -62,6 +66,10 @@ public DHCompatInternal(IrisRenderingPipeline pipeline, boolean dhShadowEnabled)
ProgramSource terrain = pipeline.getDHTerrainShader().get();
solidProgram = IrisLodRenderProgram.createProgram(terrain.getName(), false, false, terrain, pipeline.getCustomUniforms(), pipeline);

ProgramSource generic = pipeline.getDHGenericShader().get();
genericShader = IrisGenericRenderProgram.createProgram(generic.getName() + "_g", false, false, generic, pipeline.getCustomUniforms(), pipeline);
dhGenericFramebuffer = pipeline.createDHFramebuffer(generic, false);

if (pipeline.getDHWaterShader().isPresent()) {
ProgramSource water = pipeline.getDHWaterShader().get();
translucentProgram = IrisLodRenderProgram.createProgram(water.getName(), false, true, water, pipeline.getCustomUniforms(), pipeline);
Expand Down Expand Up @@ -129,13 +137,10 @@ public static boolean checkFrame() {
guiScale = Minecraft.getInstance().options.guiScale().get();
}

// TODO fix early initialization
if (DhApi.Delayed.configs == null) {
return true;
}
if (DhApi.Delayed.configs == null) return dhEnabled;

if ((dhEnabled != DhApi.Delayed.configs.graphics().renderingEnabled().getValue() || guiScale != Minecraft.getInstance().options.guiScale().get())
&& IrisApi.getInstance().isShaderPackInUse()) {
&& Iris.getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline) {
guiScale = Minecraft.getInstance().options.guiScale().get();
dhEnabled = DhApi.Delayed.configs.graphics().renderingEnabled().getValue();
try {
Expand Down Expand Up @@ -163,6 +168,9 @@ public void reconnectDHTextures(int depthTex) {
if (dhWaterFramebuffer != null) {
dhWaterFramebuffer.addDepthAttachment(depthTex);
}
if (dhGenericFramebuffer != null) {
dhGenericFramebuffer.addDepthAttachment(depthTex);
}
}
}

Expand Down Expand Up @@ -199,12 +207,13 @@ public void clear() {
translucentDepthDirty = true;

OverrideInjector.INSTANCE.unbind(IDhApiFramebuffer.class, dhTerrainFramebufferWrapper);
OverrideInjector.INSTANCE.unbind(IDhApiGenericObjectShaderProgram.class, genericShader);
OverrideInjector.INSTANCE.unbind(IDhApiFramebuffer.class, dhShadowFramebufferWrapper);
dhTerrainFramebufferWrapper = null;
dhShadowFramebufferWrapper = null;
}

public void setModelPos(Vec3f modelPos) {
public void setModelPos(DhApiVec3f modelPos) {
solidProgram.bind();
solidProgram.setModelPos(modelPos);
translucentProgram.bind();
Expand Down Expand Up @@ -262,9 +271,21 @@ public GlFramebuffer getTranslucentFB() {
return dhWaterFramebuffer;
}

public GlFramebuffer getGenericFB() {
return dhGenericFramebuffer;
}

public int getDepthTexNoTranslucent() {
if (depthTexNoTranslucent == null) return 0;

return depthTexNoTranslucent.getTextureId();
}

public IDhApiGenericObjectShaderProgram getGenericShader() {
return genericShader;
}

public boolean avoidRenderingClouds() {
return pipeline != null && (pipeline.getDHCloudSetting() == CloudSetting.OFF || (pipeline.getDHCloudSetting() == CloudSetting.DEFAULT && pipeline.getCloudSetting() == CloudSetting.OFF));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.irisshaders.iris.compat.dh;

import net.minecraftforge.fml.loading.LoadingModList;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class DHMixinConfigPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return "";
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return LoadingModList.get().getModFileById("distanthorizons") != null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return List.of();
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public int getId() {
@Override
public int getStatus() {
this.bind();
int status = GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER);
return status;
return GL32.glCheckFramebufferStatus(GL32.GL_FRAMEBUFFER);
}

@Override
Expand Down
Loading

0 comments on commit 84f02e3

Please sign in to comment.