From 117ff0cacfcdbc9892de27bb2046d0d544f8fa8d Mon Sep 17 00:00:00 2001 From: Kotmatross <110309314+kotmatross28729@users.noreply.github.com> Date: Sun, 29 Mar 2026 22:53:09 +0300 Subject: [PATCH] Fix other dynamic uniforms not updating properly (#1610) --- .../client/rendering/TextureTracker.java | 34 +++++++----------- .../angelica/iris/IrisGLSMBridge.java | 36 +++++++++++++++++-- .../iris/gl/state/StateUpdateNotifiers.java | 8 ++++- .../iris/uniforms/CommonUniforms.java | 6 ++-- .../coderbot/iris/uniforms/FogUniforms.java | 9 ++--- 5 files changed, 62 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/angelica/client/rendering/TextureTracker.java b/src/main/java/com/gtnewhorizons/angelica/client/rendering/TextureTracker.java index a08b6649e..b99a3e8fb 100644 --- a/src/main/java/com/gtnewhorizons/angelica/client/rendering/TextureTracker.java +++ b/src/main/java/com/gtnewhorizons/angelica/client/rendering/TextureTracker.java @@ -1,10 +1,8 @@ package com.gtnewhorizons.angelica.client.rendering; -import com.gtnewhorizons.angelica.glsm.GLStateManager; -import com.gtnewhorizons.angelica.glsm.RenderSystem; -import com.gtnewhorizons.angelica.glsm.hooks.GLSMHooks; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.coderbot.iris.gl.state.StateUpdateNotifiers; import net.minecraft.client.renderer.texture.AbstractTexture; import org.jetbrains.annotations.Nullable; @@ -15,11 +13,15 @@ public class TextureTracker { */ public static final TextureTracker INSTANCE = new TextureTracker(); - + + private static Runnable bindTextureListener; + + static { + StateUpdateNotifiers.bindTextureNotifier = listener -> bindTextureListener = listener; + } + private final Int2ObjectMap textures = new Int2ObjectOpenHashMap<>(); - private boolean lockBindCallback; - private TextureTracker() { } @@ -31,23 +33,13 @@ public class TextureTracker { public AbstractTexture getTexture(int id) { return textures.get(id); } - - public void onBindTexture(int id) { - if (lockBindCallback) { - return; - } - if (GLStateManager.getActiveTextureUnit() == 0) { - lockBindCallback = true; - if (GLSMHooks.TEXTURE_BIND.hasListeners()) { - GLSMHooks.textureBindEvent.textureId = id; - GLSMHooks.TEXTURE_BIND.post(GLSMHooks.textureBindEvent); - } - // Reset texture state - RenderSystem.bindTextureToUnit(0, id); - lockBindCallback = false; + + public void onBindTexture() { + if (bindTextureListener != null) { + bindTextureListener.run(); } } - + public void onDeleteTexture(int id) { textures.remove(id); } diff --git a/src/main/java/com/gtnewhorizons/angelica/iris/IrisGLSMBridge.java b/src/main/java/com/gtnewhorizons/angelica/iris/IrisGLSMBridge.java index f017a790b..904057b17 100644 --- a/src/main/java/com/gtnewhorizons/angelica/iris/IrisGLSMBridge.java +++ b/src/main/java/com/gtnewhorizons/angelica/iris/IrisGLSMBridge.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.iris; +import com.gtnewhorizons.angelica.client.rendering.TextureTracker; import com.gtnewhorizons.angelica.glsm.hooks.DeferredAlphaHandler; import com.gtnewhorizons.angelica.glsm.hooks.DeferredBlendHandler; import com.gtnewhorizons.angelica.glsm.hooks.DeferredDepthColorHandler; @@ -10,6 +11,7 @@ import net.coderbot.iris.gl.blending.AlphaTestStorage; import net.coderbot.iris.gl.blending.BlendModeStorage; import net.coderbot.iris.gl.blending.DepthColorStorage; import net.coderbot.iris.gl.program.ProgramUniforms; +import net.coderbot.iris.gl.state.StateUpdateNotifiers; import net.coderbot.iris.pipeline.DeferredWorldRenderingPipeline; import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.coderbot.iris.samplers.IrisSamplers; @@ -17,7 +19,21 @@ import net.coderbot.iris.texture.pbr.PBRTextureManager; import net.coderbot.iris.vertices.ImmediateState; public class IrisGLSMBridge { - + + private static Runnable blendFuncListener = null; + private static Runnable fogModeListener = null; + private static Runnable fogStartListener = null; + private static Runnable fogEndListener = null; + private static Runnable fogDensityListener = null; + + static { + StateUpdateNotifiers.blendFuncNotifier = listener -> blendFuncListener = listener; + StateUpdateNotifiers.fogModeNotifier = listener -> fogModeListener = listener; + StateUpdateNotifiers.fogStartNotifier = listener -> fogStartListener = listener; + StateUpdateNotifiers.fogEndNotifier = listener -> fogEndListener = listener; + StateUpdateNotifiers.fogDensityNotifier = listener -> fogDensityListener = listener; + } + public static void register() { IrisSamplers.initRenderer(); GLSMHooks.blendHandler = new DeferredBlendHandler() { @@ -75,9 +91,25 @@ public class IrisGLSMBridge { DepthColorStorage.deferColorMask(r, g, b, a); } }; - + + GLSMHooks.BLEND_FUNC_CHANGE.addListener(event -> { + if (Iris.enabled) { + if (blendFuncListener != null) blendFuncListener.run(); + } + }); + + GLSMHooks.FOG_STATE_CHANGE.addListener(event -> { + if (Iris.enabled) { + if (fogModeListener != null) fogModeListener.run(); + if (fogStartListener != null) fogStartListener.run(); + if (fogEndListener != null) fogEndListener.run(); + if (fogDensityListener != null) fogDensityListener.run(); + } + }); + GLSMHooks.TEXTURE_BIND.addListener(event -> { if (Iris.enabled) { + TextureTracker.INSTANCE.onBindTexture(); final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable(); if (pipeline != null) { pipeline.onBindTexture(event.textureId); diff --git a/src/main/java/net/coderbot/iris/gl/state/StateUpdateNotifiers.java b/src/main/java/net/coderbot/iris/gl/state/StateUpdateNotifiers.java index 29b9d4baf..62ac347fe 100644 --- a/src/main/java/net/coderbot/iris/gl/state/StateUpdateNotifiers.java +++ b/src/main/java/net/coderbot/iris/gl/state/StateUpdateNotifiers.java @@ -1,9 +1,15 @@ package net.coderbot.iris.gl.state; /** - * Holds update notifiers for PBR texture changes. + * Holds some standard update notifiers for various elements of GL state. */ public class StateUpdateNotifiers { + public static ValueUpdateNotifier fogModeNotifier; + public static ValueUpdateNotifier fogStartNotifier; + public static ValueUpdateNotifier fogEndNotifier; + public static ValueUpdateNotifier fogDensityNotifier; + public static ValueUpdateNotifier blendFuncNotifier; + public static ValueUpdateNotifier bindTextureNotifier; public static ValueUpdateNotifier normalTextureChangeNotifier; public static ValueUpdateNotifier specularTextureChangeNotifier; public static ValueUpdateNotifier phaseChangeNotifier; diff --git a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java index b4b36f259..51e604ec3 100644 --- a/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java @@ -83,7 +83,7 @@ public final class CommonUniforms { } return ZERO_VECTOR_2i; - }, ValueUpdateNotifier.NONE); + }, StateUpdateNotifiers.bindTextureNotifier); uniforms.uniform2i("gtextureSize", () -> { final int glId = GLStateManager.getBoundTextureForServerState(0); @@ -91,7 +91,7 @@ public final class CommonUniforms { final TextureInfo info = TextureInfoCache.INSTANCE.getInfo(glId); return new Vector2i(info.getWidth(), info.getHeight()); - }, ValueUpdateNotifier.NONE); + }, StateUpdateNotifiers.bindTextureNotifier); uniforms.uniform4i("blendFunc", () -> { if(GLStateManager.getBlendMode().isEnabled()) { @@ -99,7 +99,7 @@ public final class CommonUniforms { return new Vector4i(blend.getSrcRgb(), blend.getDstRgb(), blend.getSrcAlpha(), blend.getDstAlpha()); } return ZERO_VECTOR_4i; - }, ValueUpdateNotifier.NONE); + }, StateUpdateNotifiers.blendFuncNotifier); uniforms.uniform1i("renderStage", () -> GbufferPrograms.getCurrentPhase().ordinal(), StateUpdateNotifiers.phaseChangeNotifier); diff --git a/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java b/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java index 30ef38d56..8c3271602 100644 --- a/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java +++ b/src/main/java/net/coderbot/iris/uniforms/FogUniforms.java @@ -2,6 +2,7 @@ package net.coderbot.iris.uniforms; import com.gtnewhorizons.angelica.glsm.GLStateManager; import net.coderbot.iris.gl.state.FogMode; +import net.coderbot.iris.gl.state.StateUpdateNotifiers; import net.coderbot.iris.gl.state.ValueUpdateNotifier; import net.coderbot.iris.gl.uniform.DynamicUniformHolder; import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; @@ -19,12 +20,12 @@ public class FogUniforms { uniforms.uniform1i("fogMode", () -> { if (!GLStateManager.getFogMode().isEnabled()) return 0; return GLStateManager.getFogState().getFogMode(); - }, ValueUpdateNotifier.NONE); + }, StateUpdateNotifiers.fogModeNotifier); uniforms.uniform1i("fogShape", () -> 0, ValueUpdateNotifier.NONE); } - uniforms.uniform1f("fogDensity", () -> GLStateManager.getFogState().getDensity(), ValueUpdateNotifier.NONE); - uniforms.uniform1f("fogStart", () -> GLStateManager.getFogState().getStart(), ValueUpdateNotifier.NONE); - uniforms.uniform1f("fogEnd", () -> GLStateManager.getFogState().getEnd(), ValueUpdateNotifier.NONE); + uniforms.uniform1f("fogDensity", () -> GLStateManager.getFogState().getDensity(), StateUpdateNotifiers.fogDensityNotifier); + uniforms.uniform1f("fogStart", () -> GLStateManager.getFogState().getStart(), StateUpdateNotifiers.fogStartNotifier); + uniforms.uniform1f("fogEnd", () -> GLStateManager.getFogState().getEnd(), StateUpdateNotifiers.fogEndNotifier); } }