Skip to content

Commit

Permalink
Force-rebind lightmap texture when Quartz+Lodestone are active
Browse files Browse the repository at this point in the history
We should not need to do this. Mods should use RenderSystem

Works around:
* BiggerSeries/Quartz#12
* LodestarMC/Lodestone#9
  • Loading branch information
embeddedt committed Sep 1, 2023
1 parent 96b8f69 commit 85784e4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.jellysquid.mods.sodium.client.quirks;

import me.jellysquid.mods.sodium.client.SodiumClientMod;
import net.minecraftforge.fml.ModList;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class QuirkManager {
/**
* Force rebinding of the 2nd texture (lightmap) if Quartz and Lodestone are installed. This fixes
* <a href="https://github.com/LodestarMC/Lodestone/issues/9">LodestarMC/Lodestone#9</a>.
* <p></p>
* Only tested on 18.2.
*/
public static final boolean REBIND_LIGHTMAP_TEXTURE = Stream.of("quartz", "lodestone").allMatch(QuirkManager::isLoaded);

static {
try {
List<String> enabledQuirks = new ArrayList<>();
for(Field f : QuirkManager.class.getDeclaredFields()) {
if(f.getType() == boolean.class && Modifier.isStatic(f.getModifiers())) {
if(f.getBoolean(null))
enabledQuirks.add(f.getName());
}
}
SodiumClientMod.logger().warn("Enabled the following quirks in QuirkManager: [{}]", String.join(", ", enabledQuirks));
} catch(ReflectiveOperationException e) {
e.printStackTrace();
}
}

private static boolean isLoaded(String modId) {
return ModList.get().isLoaded(modId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import me.jellysquid.mods.sodium.client.gl.buffer.GlMutableBuffer;
import me.jellysquid.mods.sodium.client.gl.shader.uniform.*;
import me.jellysquid.mods.sodium.client.model.vertex.type.ChunkVertexType;
import me.jellysquid.mods.sodium.client.quirks.QuirkManager;
import org.lwjgl.opengl.GL13;
import repack.joml.Matrix4f;

import org.lwjgl.opengl.GL32C;
Expand Down Expand Up @@ -44,6 +46,15 @@ public void setup(ChunkVertexType vertexType) {
RenderSystem.activeTexture(GL32C.GL_TEXTURE2);
RenderSystem.bindTexture(RenderSystem.getShaderTexture(2));

if(QuirkManager.REBIND_LIGHTMAP_TEXTURE) {
// Some mods inject their own rendering logic, and do not use the RenderSystem methods, which causes
// the cache to become outdated.
// In this case we unconditionally rebind our texture. We just told the cache about it above, so we
// can never cause the same issue we complain about. ;)
GL13.glActiveTexture(GL32C.GL_TEXTURE2);
GL32C.glBindTexture(GL32C.GL_TEXTURE_2D, RenderSystem.getShaderTexture(2));
}

this.uniformBlockTex.setInt(0);
this.uniformLightTex.setInt(2);

Expand Down

0 comments on commit 85784e4

Please sign in to comment.