From 0c89751e539801d4e76c4d2beda7925fbbb27afd Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Mon, 29 Jan 2024 09:42:27 -0800 Subject: [PATCH] Keep a cache of time uniforms instead of querying them every time (#41) --- .../vazkii/botania/client/core/helper/ShaderHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java index 1923a011b..9eca898f5 100644 --- a/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/ShaderHelper.java @@ -14,6 +14,8 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import net.minecraft.client.renderer.OpenGlHelper; import org.apache.logging.log4j.Level; @@ -33,6 +35,8 @@ public final class ShaderHelper { private static final int VERT = ARBVertexShader.GL_VERTEX_SHADER_ARB; private static final int FRAG = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB; + private static final Int2IntMap TIME_UNIFORM_LOCATIONS = new Int2IntOpenHashMap(); + public static int pylonGlow = 0; public static int enchanterRune = 0; public static int manaPool = 0; @@ -67,8 +71,8 @@ public final class ShaderHelper { ARBShaderObjects.glUseProgramObjectARB(shader); if(shader != 0) { - int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time"); - ARBShaderObjects.glUniform1iARB(time, ClientTickHandler.ticksInGame); + int timeUniform = TIME_UNIFORM_LOCATIONS.computeIfAbsent(shader, s -> ARBShaderObjects.glGetUniformLocationARB(shader, "time")); + ARBShaderObjects.glUniform1iARB(timeUniform, ClientTickHandler.ticksInGame); if(callback != null) callback.call(shader);