Compare commits

...
Author SHA1 Message Date
Jason Mitchell 87ac03281c Add clear depth in display lists 2025-12-04 09:21:22 -08:00
Jason Mitchell 36b82fa2ce Update README.MD 2025-12-03 16:01:26 -08:00
Jason Mitchell 2fc2e2e38d Fix some small things
* Bump nhlib dep due to crash when Iris is disabled
* Use jabel for tests
* use joml isIdentity
* remove Integer usage
2025-12-03 10:54:20 -08:00
16 changed files with 109 additions and 43 deletions

No files matched your search

+2 -2
View File
@@ -14,8 +14,8 @@
# Required Dependencies
* [UniMixins](https://github.com/LegacyModdingMC/UniMixins/releases) >= 0.1.19
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.8.6
* [UniMixins](https://github.com/LegacyModdingMC/UniMixins/releases) >= 0.1.23
* [GTNHLib](https://github.com/GTNewHorizons/GTNHLib/releases) >= 0.8.19
* NOTE: Some mods are not required, but a specific version is required if present - see: `Permanent Incompatibilities` below.
# Known (temporary) Incompatibilities
+5
View File
@@ -5,6 +5,11 @@ plugins {
minecraft {
extraRunJvmArguments.add("-Dangelica.enableTestBlocks=true")
extraRunJvmArguments.add("-Dangelica.dumpClass=true")
/* extraRunJvmArguments.addAll(
"-Dlegacy.debugClassLoading=true",
"-Dlegacy.debugClassLoadingFiner=true",
"-Dlegacy.debugClassLoadingSave=true")*/
//extraRunJvmArguments.add("-Dangelica.redirectorLogspam=true")
}
+2 -1
View File
@@ -58,7 +58,7 @@ dependencies {
// Iris Shaders
compileOnly('org.jetbrains:annotations:26.0.2')
api("com.github.GTNewHorizons:GTNHLib:0.8.18:dev")
api("com.github.GTNewHorizons:GTNHLib:0.8.19:dev")
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-4.g6b42bca") {
exclude module: "antlr4" // we only want to shadow the runtime module
@@ -114,6 +114,7 @@ dependencies {
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("org.mockito:mockito-core:3.+")
testImplementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209")
testAnnotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:1.0.1")
compileOnly("mega:fluidlogged-mc1.7.10:0.1.2")
}
@@ -18,7 +18,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
name = "Angelica",
version = Tags.VERSION,
dependencies = """
required-after:gtnhlib@[0.8.18,);\
required-after:gtnhlib@[0.8.19,);\
before:lwjgl3ify@[1.5.3,);\
after:hodgepodge@[2.4.4,);\
after:CodeChickenCore@[1.2.0,);\
@@ -101,7 +101,7 @@ public class DisplayListManager {
return currentRenderingList != -1;
}
static boolean isIdentity(Matrix4f m) {
public static boolean isIdentity(Matrix4f m) {
return (m.properties() & Matrix4f.PROPERTY_IDENTITY) != 0;
}
@@ -181,6 +181,7 @@ public class DisplayListManager {
public static void recordDisable(int cap) { if (currentRecorder != null) currentRecorder.recordDisable(cap); }
public static void recordClear(int mask) { if (currentRecorder != null) currentRecorder.recordClear(mask); }
public static void recordClearColor(float r, float g, float b, float a) { if (currentRecorder != null) currentRecorder.recordClearColor(r, g, b, a); }
public static void recordClearDepth(double depth) { if (currentRecorder != null) currentRecorder.recordClearDepth(depth); }
public static void recordClearStencil(int s) { if (currentRecorder != null) currentRecorder.recordClearStencil(s); }
public static void recordColor(float r, float g, float b, float a) { if (currentRecorder != null) currentRecorder.recordColor(r, g, b, a); }
public static void recordColorMask(boolean r, boolean g, boolean b, boolean a) { if (currentRecorder != null) currentRecorder.recordColorMask(r, g, b, a); }
@@ -1245,9 +1245,10 @@ public class GLStateManager {
public static void glClearDepth(double depth) {
if (DisplayListManager.isRecording()) {
throw new UnsupportedOperationException("glClearDepth in display lists not yet implemented - if you see this, please report!");
DisplayListManager.recordClearDepth(depth);
} else {
GL11.glClearDepth(depth);
}
GL11.glClearDepth(depth);
}
// ALPHA
@@ -330,6 +330,12 @@ public final class CommandBuffer {
writeFloat(a);
}
public void writeClearDepth(double depth) {
ensureCapacity(12);
writeInt(GLCommand.CLEAR_DEPTH);
writeDouble(depth);
}
// === Mixed int+float commands ===
public void writeAlphaFunc(int func, float ref) {
@@ -269,6 +269,11 @@ public final class CommandBufferExecutor {
ptr += 16;
GLStateManager.glClearColor(r, g, b, a);
}
case GLCommand.CLEAR_DEPTH -> {
final double depth = memGetDouble(ptr);
ptr += 8;
GLStateManager.glClearDepth(depth);
}
// === Mixed int+float commands ===
case GLCommand.ALPHA_FUNC -> {
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.glsm.recording;
import com.gtnewhorizons.angelica.glsm.DisplayListManager;
import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -183,6 +184,9 @@ public final class CommandBufferProcessor {
case GLCommand.COLOR -> out.writeColor(raw.readFloat(), raw.readFloat(), raw.readFloat(), raw.readFloat());
case GLCommand.CLEAR_COLOR -> out.writeClearColor(raw.readFloat(), raw.readFloat(), raw.readFloat(), raw.readFloat());
// Single double commands
case GLCommand.CLEAR_DEPTH -> out.writeClearDepth(raw.readDouble());
// Mixed int+float commands
case GLCommand.ALPHA_FUNC -> out.writeAlphaFunc(raw.readInt(), raw.readFloat());
case GLCommand.FOGF -> out.writeFogf(raw.readInt(), raw.readFloat());
@@ -255,17 +259,6 @@ public final class CommandBufferProcessor {
}
}
/**
* Check if a matrix is identity (within epsilon).
*/
public static boolean isIdentity(Matrix4f m) {
final float eps = 1e-6f;
return Math.abs(m.m00() - 1) < eps && Math.abs(m.m01()) < eps && Math.abs(m.m02()) < eps && Math.abs(m.m03()) < eps
&& Math.abs(m.m10()) < eps && Math.abs(m.m11() - 1) < eps && Math.abs(m.m12()) < eps && Math.abs(m.m13()) < eps
&& Math.abs(m.m20()) < eps && Math.abs(m.m21()) < eps && Math.abs(m.m22() - 1) < eps && Math.abs(m.m23()) < eps
&& Math.abs(m.m30()) < eps && Math.abs(m.m31()) < eps && Math.abs(m.m32()) < eps && Math.abs(m.m33() - 1) < eps;
}
/**
* Lightweight transform optimizer for buffer-to-buffer processing.
* Tracks accumulated MODELVIEW transform and emits MultMatrix commands when needed.
@@ -316,7 +309,7 @@ public final class CommandBufferProcessor {
}
public boolean isIdentity() {
return CommandBufferProcessor.isIdentity(accumulated);
return DisplayListManager.isIdentity(accumulated);
}
public void markAbsoluteMatrix() {
@@ -340,7 +333,7 @@ public final class CommandBufferProcessor {
return;
}
if (CommandBufferProcessor.isIdentity(lastEmitted)) {
if (DisplayListManager.isIdentity(lastEmitted)) {
out.writeMultMatrix(GL11.GL_MODELVIEW, target);
} else {
final Matrix4f delta = new Matrix4f(lastEmitted).invert().mul(target);
@@ -51,6 +51,11 @@ public class CommandRecorder {
commandCount++;
}
public void recordClearDepth(double depth) {
buffer.writeClearDepth(depth);
commandCount++;
}
public void recordClearStencil(int s) {
buffer.writeClearStencil(s);
commandCount++;
@@ -2,12 +2,12 @@ package com.gtnewhorizons.angelica.glsm.recording;
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer;
import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAddress;
import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memFree;
@@ -96,8 +96,8 @@ public final class CompiledDisplayList {
* Get counts of each command type in the buffer.
* Used for testing to verify optimization results.
*/
public Map<Integer, Integer> getCommandCounts() {
Map<Integer, Integer> counts = new HashMap<>();
public Int2IntMap getCommandCounts() {
Int2IntMap counts = new Int2IntOpenHashMap();
if (commandBuffer == null || commandBuffer.limit() == 0) {
return counts;
}
@@ -105,7 +105,7 @@ public final class CompiledDisplayList {
long end = ptr + commandBuffer.limit();
while (ptr < end) {
int cmd = memGetInt(ptr);
counts.merge(cmd, 1, Integer::sum);
counts.mergeInt(cmd, 1, Integer::sum);
ptr += getCommandSize(cmd, ptr);
}
return counts;
@@ -115,8 +115,8 @@ public final class CompiledDisplayList {
* Get the sequence of command opcodes in order.
* Used for testing to verify command ordering.
*/
public List<Integer> getCommandOpcodes() {
List<Integer> opcodes = new ArrayList<>();
public IntList getCommandOpcodes() {
IntList opcodes = new IntArrayList();
if (commandBuffer == null || commandBuffer.limit() == 0) {
return opcodes;
}
@@ -160,6 +160,9 @@ public final class CompiledDisplayList {
GLCommand.STENCIL_FUNC_SEPARATE, GLCommand.STENCIL_OP_SEPARATE,
GLCommand.COLOR, GLCommand.CLEAR_COLOR, GLCommand.DRAW_RANGE -> 20;
// Single double commands (12 bytes)
case GLCommand.CLEAR_DEPTH -> 12;
// Double commands
case GLCommand.TRANSLATE, GLCommand.SCALE -> 32; // cmd + mode + 3 doubles
case GLCommand.ROTATE -> 40; // cmd + mode + 4 doubles
@@ -56,6 +56,9 @@ public final class GLCommand {
public static final int COLOR = 54; // [cmd:4][r:4f][g:4f][b:4f][a:4f]
public static final int CLEAR_COLOR = 55; // [cmd:4][r:4f][g:4f][b:4f][a:4f]
// === Double commands (single value) ===
public static final int CLEAR_DEPTH = 56; // [cmd:4][depth:8d] = 12 bytes
// === Mixed int+float commands ===
public static final int ALPHA_FUNC = 60; // [cmd:4][func:4][ref:4f]
public static final int FOGF = 61; // [cmd:4][pname:4][param:4f]
@@ -133,6 +136,7 @@ public final class GLCommand {
case NORMAL -> "NORMAL";
case COLOR -> "COLOR";
case CLEAR_COLOR -> "CLEAR_COLOR";
case CLEAR_DEPTH -> "CLEAR_DEPTH";
case ALPHA_FUNC -> "ALPHA_FUNC";
case FOGF -> "FOGF";
case LIGHTF -> "LIGHTF";
@@ -58,8 +58,8 @@ class GLSM_DisplayList_Batching_Test {
private Set<VertexBuffer> getUniqueVBOs(DisplayListCommand[] commands) {
Set<VertexBuffer> vbos = new HashSet<>();
for (DisplayListCommand cmd : commands) {
if (cmd instanceof DrawRangeCmd) {
vbos.add(((DrawRangeCmd) cmd).sharedVbo());
if (cmd instanceof DrawRangeCmd rangeCmd) {
vbos.add(rangeCmd.sharedVbo());
}
}
return vbos;
@@ -3,6 +3,8 @@ package com.gtnewhorizons.angelica.glsm;
import com.gtnewhorizons.angelica.AngelicaExtension;
import com.gtnewhorizons.angelica.glsm.recording.CompiledDisplayList;
import com.gtnewhorizons.angelica.glsm.recording.GLCommand;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.IntList;
import org.joml.Matrix4f;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@@ -11,8 +13,6 @@ import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import java.nio.FloatBuffer;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
@@ -68,7 +68,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
assertNotNull(compiled, "Display list should be compiled");
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0);
int individualTransformCount = counts.getOrDefault(GLCommand.TRANSLATE, 0)
+ counts.getOrDefault(GLCommand.ROTATE, 0)
@@ -122,7 +122,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
// Verify optimization: should have Push, Pop, and collapsed MultMatrix commands
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
int pushCount = counts.getOrDefault(GLCommand.PUSH_MATRIX, 0);
int popCount = counts.getOrDefault(GLCommand.POP_MATRIX, 0);
@@ -217,7 +217,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
// Verify optimization: MultMatrix should be emitted before CallList
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
List<Integer> opcodes = compiled.getCommandOpcodes();
IntList opcodes = compiled.getCommandOpcodes();
// Find positions of MultMatrix and CallList
int multMatrixIndex = opcodes.indexOf(GLCommand.MULT_MATRIX);
@@ -268,7 +268,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
GLStateManager.glEndList();
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0);
@@ -356,7 +356,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
// Verify optimization: should collapse to 1 MultMatrix
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0);
@@ -416,7 +416,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
assertNotNull(compiled, "Display list should be compiled");
List<Integer> opcodes = compiled.getCommandOpcodes();
IntList opcodes = compiled.getCommandOpcodes();
// Find indices of key commands
int pushIndex = opcodes.indexOf(GLCommand.PUSH_MATRIX);
@@ -467,7 +467,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
GLStateManager.glEndList();
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
List<Integer> opcodes = compiled.getCommandOpcodes();
IntList opcodes = compiled.getCommandOpcodes();
int pushIndex = opcodes.indexOf(GLCommand.PUSH_MATRIX);
int popIndex = opcodes.indexOf(GLCommand.POP_MATRIX);
@@ -507,7 +507,7 @@ class GLSM_DisplayList_TransformCollapsing_Test {
CompiledDisplayList compiled = DisplayListManager.getDisplayList(testList);
assertNotNull(compiled, "Display list should be compiled");
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
int loadMatrixCount = counts.getOrDefault(GLCommand.LOAD_MATRIX, 0);
assertEquals(1, loadMatrixCount,
@@ -155,4 +155,45 @@ class GLSM_DisplayList_UnitTest {
GLStateManager.glDisable(GL11.GL_LIGHTING);
GLStateManager.glDeleteLists(list, 1);
}
// ==================== ClearDepth Tests ====================
@Test
void testClearDepthInDisplayList() {
// Get initial clear depth
double initialDepth = GL11.glGetDouble(GL11.GL_DEPTH_CLEAR_VALUE);
int list = GL11.glGenLists(1);
GLStateManager.glNewList(list, GL11.GL_COMPILE);
GLStateManager.glClearDepth(0.5);
GLStateManager.glEndList();
// After compile, depth should be unchanged
assertEquals(initialDepth, GL11.glGetDouble(GL11.GL_DEPTH_CLEAR_VALUE), 0.0001, "ClearDepth should be unchanged after GL_COMPILE");
// Call the display list
GLStateManager.glCallList(list);
// Now depth should be 0.5
assertEquals(0.5, GL11.glGetDouble(GL11.GL_DEPTH_CLEAR_VALUE), 0.0001, "ClearDepth should be 0.5 after calling display list");
// Cleanup
GLStateManager.glClearDepth(1.0); // Reset to default
GLStateManager.glDeleteLists(list, 1);
}
@Test
void testClearDepthCompileAndExecute() {
int list = GL11.glGenLists(1);
GLStateManager.glNewList(list, GL11.GL_COMPILE_AND_EXECUTE);
GLStateManager.glClearDepth(0.25);
GLStateManager.glEndList();
// After compile and execute, depth should be changed
assertEquals(0.25, GL11.glGetDouble(GL11.GL_DEPTH_CLEAR_VALUE), 0.0001, "ClearDepth should be 0.25 after GL_COMPILE_AND_EXECUTE");
// Cleanup
GLStateManager.glClearDepth(1.0);
GLStateManager.glDeleteLists(list, 1);
}
}
@@ -9,10 +9,11 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lwjgl.opengl.GL11;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
@@ -72,7 +73,7 @@ class RecordingDataStructuresTest {
assertNotNull(compiled.getCommandBuffer(), "Command buffer should not be null");
// Get command counts to verify structure
Map<Integer, Integer> counts = compiled.getCommandCounts();
Int2IntMap counts = compiled.getCommandCounts();
// Should have PushMatrix and PopMatrix
assertEquals(1, counts.getOrDefault(GLCommand.PUSH_MATRIX, 0), "Should have 1 PushMatrix");