From fa91b70528e3c0580b9147bbca16c2f6fff3c68c Mon Sep 17 00:00:00 2001 From: sisyphussy <221229741+sisyphussy@users.noreply.github.com> Date: Mon, 18 May 2026 21:46:48 +0200 Subject: [PATCH] Display list stuff (#1750) --- dependencies.gradle | 20 +- glsm/build.gradle.kts | 1 + glsm/gradle.properties | 2 +- .../angelica/glsm/CommandBufferBuilder.java | 67 -- .../angelica/glsm/DisplayListManager.java | 822 ++++++++++-------- .../angelica/glsm/GLStateManager.java | 135 +-- .../angelica/glsm/ITessellatorData.java | 22 - .../angelica/glsm/TransformOptimizer.java | 132 --- .../angelica/glsm/ffp/VertexKey.java | 3 +- .../glsm/recording/AccumulatedDraw.java | 7 +- .../glsm/recording/CommandBuffer.java | 767 ---------------- .../glsm/recording/CommandBufferExecutor.java | 77 +- .../recording/CommandBufferProcessor.java | 166 ---- .../glsm/recording/CommandRecorder.java | 758 +++++++++++----- .../glsm/recording/CompiledDisplayList.java | 22 +- .../glsm/recording/DisplayListVBO.java | 16 + .../glsm/recording/DisplayListVBOBuilder.java | 2 +- .../angelica/glsm/recording/GLCommand.java | 10 +- .../glsm/recording/ImmediateModeRecorder.java | 4 +- .../streaming/TessellatorStreamingDrawer.java | 30 +- .../glsm/DisplayListCompilationGLSMTest.java | 3 + .../glsm/GLSM_DisplayList_Batching_Test.java | 11 +- ..._DisplayList_TransformCollapsing_Test.java | 22 +- .../glsm/recording/IndexedDrawReplayTest.java | 2 +- .../client/font/BatchingFontRenderer.java | 12 +- .../client/rendering/DeferredDrawBatcher.java | 4 +- .../bettercrashes/BetterCrashesCompat.java | 3 +- .../loading/AngelicaClientTweaker.java | 4 +- .../ffp/MixinTessellator_CoreProfile.java | 45 +- .../umbra/loading/UmbraClientTweaker.java | 4 +- 30 files changed, 1208 insertions(+), 1965 deletions(-) delete mode 100644 glsm/src/main/java/com/gtnewhorizons/angelica/glsm/CommandBufferBuilder.java delete mode 100644 glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ITessellatorData.java delete mode 100644 glsm/src/main/java/com/gtnewhorizons/angelica/glsm/TransformOptimizer.java delete mode 100644 glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBuffer.java delete mode 100644 glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java diff --git a/dependencies.gradle b/dependencies.gradle index 2f1902047..3bfd2ff2f 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -76,7 +76,7 @@ dependencies { // Iris Shaders compileOnly('org.jetbrains:annotations:26.0.2') - api("com.github.GTNewHorizons:GTNHLib:0.9.52:dev") + api("com.github.GTNewHorizons:GTNHLib:0.10.0:dev") shadowImplementation(project(":glsm")) { transitive = false } shadowImplementation(project(":lwjgl3-backend")) { transitive = false } @@ -97,6 +97,24 @@ dependencies { devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.8.35-GTNH:dev') devOnlyNonPublishable('com.github.GTNewHorizons:CodeChickenCore:1.4.7:dev') + // Display List Testing + /* + runtimeOnlyNonPublishable("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-749-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:ae2stuff:0.10.14-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:BuildCraft:7.1.54:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:IguanaTweaksTConstruct:2.7.0:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:OpenBlocks:1.12.4-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:OpenComputers:1.12.12-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:TinkersConstruct:1.14.12-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:ServerUtilities:2.2.13:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:ironchest:6.1.6:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.9.7:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:Botania:1.13.15-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:Mobs-Info:0.5.10-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:Draconic-Evolution:1.5.18-GTNH:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:HoloInventory:2.5.8-GTNH:dev") + */ + //devOnlyNonPublishable('com.github.GTNewHorizons:worldedit-gtnh:v0.0.9') // Notfine Deps diff --git a/glsm/build.gradle.kts b/glsm/build.gradle.kts index 2c012a531..be4a84be5 100644 --- a/glsm/build.gradle.kts +++ b/glsm/build.gradle.kts @@ -66,6 +66,7 @@ repositories { content { includeGroup("xyz.wagyourtail.jvmdowngrader") } } mavenCentral() + mavenLocal() } dependencies { diff --git a/glsm/gradle.properties b/glsm/gradle.properties index 9b285bf50..4591962cc 100644 --- a/glsm/gradle.properties +++ b/glsm/gradle.properties @@ -4,7 +4,7 @@ celeritasVersion = 2.5.3-GTNH lombokVersion = 1.18.42 log4jVersion = 2.0-beta9 guavaVersion = 18.0 -gtnhlibVersion = 0.9.36 +gtnhlibVersion = 0.10.0 glslTransformLibVersion = 0.2.0-26.g5ee7d96-GTNH antlr4RuntimeVersion = 4.13.2 jcppVersion = 1.4.14 diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/CommandBufferBuilder.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/CommandBufferBuilder.java deleted file mode 100644 index d3c86e6c1..000000000 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/CommandBufferBuilder.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.gtnewhorizons.angelica.glsm; - -import com.gtnewhorizons.angelica.glsm.recording.AccumulatedDraw; -import com.gtnewhorizons.angelica.glsm.recording.CommandBuffer; -import com.gtnewhorizons.angelica.glsm.recording.CommandBufferProcessor; - -import java.util.List; - -/** - * Builds final command buffers from raw command buffers and compiled VBO data. - * Bridges the gap between VBO compilation (glsm types) and buffer processing (recording types). - */ -public final class CommandBufferBuilder { - - private CommandBufferBuilder() {} - - /** - * Build commands with transform collapsing optimization. - * Accumulates MODELVIEW transforms and emits MultMatrix at barriers (draws, CallList). - * Uses mergedRanges where consecutive same-transform draws are combined. - */ - public static void buildFromRawBuffer( - CommandBuffer rawBuffer, - List accumulatedDraws, - CommandBuffer finalBuffer) { - - rawBuffer.resetRead(); - int cmdIndex = 0; - int rangeIndex = 0; - - AccumulatedDraw draw; - while (rawBuffer.hasRemaining()) { - // Read and process the command - CommandBufferProcessor.copyCommand(rawBuffer, finalBuffer); - - // Emit draw ranges at this command position - while (rangeIndex < accumulatedDraws.size() && (draw = accumulatedDraws.get(rangeIndex)).commandIndex == cmdIndex) { - emitDrawRangeToBuffer(draw, finalBuffer, rangeIndex); - rangeIndex++; - } - - cmdIndex++; - } - - while (rangeIndex < accumulatedDraws.size()) { - emitDrawRangeToBuffer(accumulatedDraws.get(rangeIndex), finalBuffer, rangeIndex); - rangeIndex++; - } - } - - /** - * Emit a draw range to the output buffer, with transform if needed. - */ - private static void emitDrawRangeToBuffer( - AccumulatedDraw draw, - CommandBuffer out, - int vboIdx) { - - if (draw.restoreData != null) { - out.writeDrawRangeRestore(vboIdx, draw.restoreData); - return; - } - - // Write the draw range command - out.writeDrawRange(vboIdx); - } -} diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java index ad0abccd5..17f2340be 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/DisplayListManager.java @@ -1,29 +1,31 @@ package com.gtnewhorizons.angelica.glsm; import com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities; +import com.gtnewhorizon.gtnhlib.client.model.NormalHelper; +import com.gtnewhorizon.gtnhlib.client.renderer.CallbackTessellator; import com.gtnewhorizon.gtnhlib.client.renderer.DirectTessellator; +import com.gtnewhorizon.gtnhlib.client.renderer.MatrixHelper; import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; +import com.gtnewhorizon.gtnhlib.client.renderer.tessellator.VertexTransformCallback; import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VBOManager; import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer; import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat; import com.gtnewhorizons.angelica.glsm.recording.AccumulatedDraw; -import com.gtnewhorizons.angelica.glsm.recording.ImmediateModeRecorder; -import com.gtnewhorizons.angelica.glsm.recording.CommandBuffer; import com.gtnewhorizons.angelica.glsm.recording.CommandRecorder; import com.gtnewhorizons.angelica.glsm.recording.CompiledDisplayList; import com.gtnewhorizons.angelica.glsm.recording.DisplayListVBO; import com.gtnewhorizons.angelica.glsm.recording.DisplayListVBOBuilder; import com.gtnewhorizons.angelica.glsm.recording.GLCommand; +import com.gtnewhorizons.angelica.glsm.recording.ImmediateModeRecorder; import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; import com.gtnewhorizons.angelica.glsm.recording.commands.IndexedDrawBatch; import com.gtnewhorizons.angelica.glsm.recording.commands.IndexedDrawBatchBuilder; import com.gtnewhorizons.angelica.glsm.recording.commands.IndexedDrawCapture; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import lombok.Getter; import lombok.experimental.UtilityClass; +import org.joml.Matrix3f; import org.joml.Matrix4f; -import org.joml.Matrix4fStack; import org.joml.Vector3f; import org.lwjgl.opengl.GL11; @@ -35,6 +37,7 @@ import java.util.Deque; import java.util.List; import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAddress; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetFloat; import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetInt; /** @@ -46,34 +49,24 @@ import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetInt; * *

Format-Based Batching: Draws with same vertex format share a VBO via {@link DisplayListVBO}. * Consecutive same-transform draws merge. - * Delta transforms handled via {@link TransformOptimizer}. */ @UtilityClass public class DisplayListManager { // -Dangelica.debugDisplayLists: disable transform collapsing and draw merging - private static final boolean DEBUG_DISPLAY_LISTS = Boolean.getBoolean("angelica.debugDisplayLists"); + private static final boolean DEBUG_DISPLAY_LISTS; // -Dangelica.logDisplayListCompilation: log compiled display list commands private static final boolean LOG_DISPLAY_LIST_COMPILATION; static { + DEBUG_DISPLAY_LISTS = Boolean.getBoolean("angelica.debugDisplayLists"); + LOG_DISPLAY_LIST_COMPILATION = Boolean.getBoolean("angelica.logDisplayListCompilation"); if (LOG_DISPLAY_LIST_COMPILATION) { GLStateManager.LOGGER.warn("Display list compilation logging ENABLED (-Dangelica.logDisplayListCompilation=true)"); } } - // Track which display list is currently being rendered - @Getter private static int currentRenderingList = -1; - - private static final Matrix4f IDENTITY = new Matrix4f(); - - public static boolean isIdentity(Matrix4f m) { - return (m.properties() & Matrix4f.PROPERTY_IDENTITY) != 0 || m.equals(IDENTITY, 1e-6f); - } - - /** Transform operation types for relative transform tracking. */ - public enum TransformOp { TRANSLATE, SCALE, ROTATE } /** Recording mode for display list compilation. */ public enum RecordMode { @@ -88,13 +81,14 @@ public class DisplayListManager { private static CommandRecorder currentRecorder = null; // Command recorder (null when not recording) private static volatile Thread recordingThread = null; // Thread that started recording (for thread-safety) private static List accumulatedDraws = null; // Accumulates quad draws for batching - private static Matrix4fStack relativeTransform = null; // Tracks relative transforms during compilation (with push/pop support) - /** - * -- GETTER -- - * Get the current state generation (for draw merging). - */ - @Getter - private static int stateGeneration = 0; // Increments at draw barriers (state commands); used for draw merging + private static AccumulatedDraw pendingDraw = null; + private static DisplayListCallback transformCallback = null; + private static int relativeTransformType; + + private static final int TRANSFORM_SCALE = 0x1; // Can be extracted to a glScale easily + private static final int TRANSFORM_TRANSLATE = 0x2; // Can be extracted to a glTranslate easily + private static final int TRANSFORM_COMPLEX = 0x4; // Cannot easily be extracted, will record a mult matrix call. + private static StackTraceElement[] compilationStackTrace = null; // For logging: captured at glNewList() // Debug logging: track sources of MULT_MATRIX commands and draw origins; only populated when LOG_DISPLAY_LIST_COMPILATION is true @@ -117,7 +111,6 @@ public class DisplayListManager { int listMode, CommandRecorder recorder, List draws, - Matrix4fStack transform, StackTraceElement[] stackTrace, // Debug logging fields (only used when LOG_DISPLAY_LIST_COMPILATION) @@ -152,11 +145,19 @@ public class DisplayListManager { currentRecorder = r; } + + private static final Vector3f transformVector = new Vector3f(); + + static void flushAll() { + drawBarrier(); + flushMatrix(); + } + /** * Emit accumulated transform as MultMatrix if non-identity, then reset. */ - public static void flushMatrix() { - if (relativeTransform == null || isIdentity(relativeTransform)) { + static void flushMatrix() { + if (transformCallback.isIdentity()) { // Clear pending ops even if we don't emit - they were no-ops (identity) if (pendingTransformOps != null) { pendingTransformOps.clear(); @@ -177,18 +178,22 @@ public class DisplayListManager { } // Record the collapsed MultMatrix command (for playback) - if (currentRecorder != null) { - currentRecorder.recordMultMatrix(relativeTransform); - stateGeneration++; + // Always put a draw barrier BEFORE flushing the matrix (the transforms are already baked into the current draw) + drawBarrier(); + if (relativeTransformType == TRANSFORM_SCALE) { + currentRecorder.writeScale(transformCallback.getScale(transformVector)); + } else if (relativeTransformType == TRANSFORM_TRANSLATE) { + currentRecorder.writeTranslate(transformCallback.getTranslation(transformVector)); + } else { + currentRecorder.writeMultMatrix(transformCallback.getReadMatrix()); + } + if (glListMode == GL11.GL_COMPILE_AND_EXECUTE) { + GLStateManager.applyMultMatrix(transformCallback.getReadMatrix()); } + // Reset to identity - we're now synchronized with GL - relativeTransform.identity(); - - } - - public static void matrixBarrier() { - flushMatrix(); + resetRelativeTransform(); } public static int getRecordingListId() { @@ -199,396 +204,367 @@ public class DisplayListManager { return glListMode; } - public static int getCommandCount() { - return currentRecorder != null ? currentRecorder.getCommandCount() : 0; - } - public static void trackDrawRangeSource(String source) { if (drawRangeSources != null) { drawRangeSources.add(source); } } + // Draw barriers: state commands that prevent draw merging static void drawBarrier() { - stateGeneration++; + if (pendingDraw != null) { + emitDrawRangeToBuffer(pendingDraw, currentRecorder, accumulatedDraws.size() - 1); + pendingDraw = null; + } + } + + private static void emitDrawRangeToBuffer( + AccumulatedDraw draw, + CommandRecorder out, + int vboIdx) { + + if (draw.restoreData != null) { + out.writeDrawRangeRestore(vboIdx, draw.restoreData); + return; + } + + // Write the draw range command + out.writeDrawRange(vboIdx); } public static void recordEnable(int cap) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordEnable(cap); + currentRecorder.writeEnable(cap); } public static void recordDisable(int cap) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDisable(cap); + currentRecorder.writeDisable(cap); } // ==================== NON-BARRIER COMMANDS ==================== // Clear commands don't affect subsequent draws, just clear buffers. public static void recordClear(int mask) { - if (currentRecorder == null) return; - currentRecorder.recordClear(mask); + drawBarrier(); // glClear changes the FBO values, needs a draw barrier. + currentRecorder.writeClear(mask); } public static void recordClearColor(float r, float g, float b, float a) { - if (currentRecorder == null) return; - currentRecorder.recordClearColor(r, g, b, a); + currentRecorder.writeClearColor(r, g, b, a); } public static void recordClearDepth(double depth) { - if (currentRecorder == null) return; - currentRecorder.recordClearDepth(depth); + currentRecorder.writeClearDepth(depth); } public static void recordClearStencil(int s) { - if (currentRecorder == null) return; - currentRecorder.recordClearStencil(s); + currentRecorder.writeClearStencil(s); } // ==================== MORE DRAW BARRIER COMMANDS ==================== public static void recordBlendColor(float r, float g, float b, float a) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordBlendColor(r, g, b, a); + currentRecorder.writeBlendColor(r, g, b, a); } public static void recordColor(float r, float g, float b, float a) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordColor(r, g, b, a); + currentRecorder.writeColor(r, g, b, a); if (ImmediateModeRecorder.isDrawing()) { ImmediateModeRecorder.setColor(r, g, b, a); } } public static void recordColorMask(boolean r, boolean g, boolean b, boolean a) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordColorMask(r, g, b, a); + currentRecorder.writeColorMask(r, g, b, a); } public static void recordDepthMask(boolean flag) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDepthMask(flag); + currentRecorder.writeDepthMask(flag); } public static void recordFrontFace(int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordFrontFace(mode); + currentRecorder.writeFrontFace(mode); } public static void recordDepthFunc(int func) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDepthFunc(func); + currentRecorder.writeDepthFunc(func); } public static void recordBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha); + currentRecorder.writeBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha); } public static void recordAlphaFunc(int func, float ref) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordAlphaFunc(func, ref); + currentRecorder.writeAlphaFunc(func, ref); } public static void recordCullFace(int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordCullFace(mode); + currentRecorder.writeCullFace(mode); } public static void recordShadeModel(int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordShadeModel(mode); + currentRecorder.writeShadeModel(mode); } public static void recordBindTexture(int target, int texture) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordBindTexture(target, texture); + currentRecorder.writeBindTexture(target, texture); } public static void recordTexParameteri(int target, int pname, int param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordTexParameteri(target, pname, param); + currentRecorder.writeTexParameteri(target, pname, param); } public static void recordTexParameterf(int target, int pname, float param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordTexParameterf(target, pname, param); + currentRecorder.writeTexParameterf(target, pname, param); } public static void recordMatrixMode(int mode) { - if (currentRecorder == null) return; - matrixBarrier(); // Matrix barrier: flush and reset - currentRecorder.recordMatrixMode(mode); + flushMatrix(); // Matrix barrier: flush and reset + transformCallback.setMatrixMode(mode); + currentRecorder.writeMatrixMode(mode); } public static void recordPushMatrix() { - if (currentRecorder == null) return; // Flush any pending delta, then record push. flushMatrix(); - currentRecorder.recordPushMatrix(); + currentRecorder.writePushMatrix(); } public static void recordPopMatrix() { - if (currentRecorder == null) return; - // Flush any pending delta, then record pop. - flushMatrix(); - currentRecorder.recordPopMatrix(); + // Discard any transformations & flush any pending draw operations + drawBarrier(); + resetRelativeTransform(); + currentRecorder.writePopMatrix(); } public static void recordViewport(int x, int y, int width, int height) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordViewport(x, y, width, height); + currentRecorder.writeViewport(x, y, width, height); } public static void recordScissor(int x, int y, int width, int height) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordScissor(x, y, width, height); + currentRecorder.writeScissor(x, y, width, height); } public static void recordPointSize(float size) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordPointSize(size); + currentRecorder.writePointSize(size); } public static void recordLineWidth(float width) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLineWidth(width); + currentRecorder.writeLineWidth(width); } public static void recordLineStipple(int factor, int pattern) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLineStipple(factor, pattern); + currentRecorder.writeLineStipple(factor, pattern); } public static void recordPolygonOffset(float factor, float units) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordPolygonOffset(factor, units); + currentRecorder.writePolygonOffset(factor, units); } public static void recordPolygonMode(int face, int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordPolygonMode(face, mode); + currentRecorder.writePolygonMode(face, mode); } public static void recordColorMaterial(int face, int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordColorMaterial(face, mode); + currentRecorder.writeColorMaterial(face, mode); } public static void recordLogicOp(int opcode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLogicOp(opcode); + currentRecorder.writeLogicOp(opcode); } public static void recordActiveTexture(int texture) { - if (currentRecorder == null) return; - drawBarrier(); - currentRecorder.recordActiveTexture(texture); + currentRecorder.writeActiveTexture(texture); } public static void recordUseProgram(int program) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordUseProgram(program); + currentRecorder.writeUseProgram(program); } // PushAttrib saves state but doesn't change it - not a draw barrier public static void recordPushAttrib(int mask) { - if (currentRecorder == null) return; - currentRecorder.recordPushAttrib(mask); + currentRecorder.writePushAttrib(mask); } // PopAttrib restores potentially any state - draw barrier public static void recordPopAttrib() { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordPopAttrib(); + currentRecorder.writePopAttrib(); } public static void recordFogf(int pname, float param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordFogf(pname, param); + currentRecorder.writeFogf(pname, param); } public static void recordFogi(int pname, int param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordFogi(pname, param); + currentRecorder.writeFogi(pname, param); } public static void recordHint(int target, int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordHint(target, mode); + currentRecorder.writeHint(target, mode); } public static void recordFog(int pname, java.nio.FloatBuffer params) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordFog(pname, params); + currentRecorder.writeFog(pname, params); } public static void recordLightf(int light, int pname, float param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLightf(light, pname, param); + currentRecorder.writeLightf(light, pname, param); } public static void recordLighti(int light, int pname, int param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLighti(light, pname, param); + currentRecorder.writeLighti(light, pname, param); } public static void recordLight(int light, int pname, java.nio.FloatBuffer params) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLight(light, pname, params); + currentRecorder.writeLight(light, pname, params); } public static void recordLightModelf(int pname, float param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLightModelf(pname, param); + currentRecorder.writeLightModelf(pname, param); } public static void recordLightModeli(int pname, int param) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLightModeli(pname, param); + currentRecorder.writeLightModeli(pname, param); } public static void recordLightModel(int pname, java.nio.FloatBuffer params) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordLightModel(pname, params); + currentRecorder.writeLightModel(pname, params); } public static void recordMaterialf(int face, int pname, float val) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordMaterialf(face, pname, val); + currentRecorder.writeMaterialf(face, pname, val); } public static void recordMaterial(int face, int pname, java.nio.FloatBuffer params) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordMaterial(face, pname, params); + currentRecorder.writeMaterial(face, pname, params); } public static void recordClipPlane(int plane, double a, double b, double c, double d) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordClipPlane(plane, a, b, c, d); + currentRecorder.writeClipPlane(plane, a, b, c, d); } public static void recordStencilFunc(int func, int ref, int mask) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilFunc(func, ref, mask); + currentRecorder.writeStencilFunc(func, ref, mask); } public static void recordStencilFuncSeparate(int face, int func, int ref, int mask) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilFuncSeparate(face, func, ref, mask); + currentRecorder.writeStencilFuncSeparate(face, func, ref, mask); } public static void recordStencilOp(int fail, int zfail, int zpass) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilOp(fail, zfail, zpass); + currentRecorder.writeStencilOp(fail, zfail, zpass); } public static void recordStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilOpSeparate(face, sfail, dpfail, dppass); + currentRecorder.writeStencilOpSeparate(face, sfail, dpfail, dppass); } public static void recordStencilMask(int mask) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilMask(mask); + currentRecorder.writeStencilMask(mask); } public static void recordStencilMaskSeparate(int face, int mask) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordStencilMaskSeparate(face, mask); + currentRecorder.writeStencilMaskSeparate(face, mask); } public static void recordCallList(int listId) { - if (currentRecorder == null) return; - matrixBarrier(); // Matrix barrier: nested list has own transforms - currentRecorder.recordCallList(listId); + // Flush all pending draws & transformations + flushAll(); + currentRecorder.writeCallList(listId); } public static void recordDrawBuffer(int mode) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDrawBuffer(mode); + currentRecorder.writeDrawBuffer(mode); } public static void recordDrawBuffers(int count, int buf) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDrawBuffers(count, buf); + currentRecorder.writeDrawBuffers(count, buf); } public static void recordDrawBuffers(int count, java.nio.IntBuffer bufs) { - if (currentRecorder == null) return; drawBarrier(); - currentRecorder.recordDrawBuffers(count, bufs); + currentRecorder.writeDrawBuffers(count, bufs); } public static void recordComplexCommand(DisplayListCommand cmd) { - if (currentRecorder == null) return; - currentRecorder.recordComplexCommand(cmd); + flushAll(); //TODO + currentRecorder.writeComplexCommand(cmd); } public static void recordIndexedDrawCapture(IndexedDrawCapture capture) { - if (currentRecorder == null) return; - currentRecorder.recordIndexedDrawCapture(capture); + flushAll(); //TODO + currentRecorder.writeIndexedDrawCapture(capture); } public static void recordLoadMatrix(Matrix4f matrix) { - if (currentRecorder != null) currentRecorder.recordLoadMatrix(matrix); + drawBarrier(); + resetRelativeTransform(); + currentRecorder.writeLoadMatrix(matrix); } public static void recordLoadIdentity() { - if (currentRecorder != null) currentRecorder.recordLoadIdentity(); + drawBarrier(); + resetRelativeTransform(); + currentRecorder.writeLoadIdentity(); + } - public static void recordBindVBO(int vbo) { if (currentRecorder != null) currentRecorder.recordBindVBO(vbo); } - public static void recordBindVAO(int vao) { if (currentRecorder != null) currentRecorder.recordBindVAO(vao); } + public static void recordBindVBO(int vbo) { + drawBarrier(); + currentRecorder.writeBindVBO(vbo); + } + + public static void recordBindVAO(int vao) { + drawBarrier(); + currentRecorder.writeBindVAO(vao); + } // recordOrtho/recordFrustum removed - these now accumulate into relativeTransform @@ -611,33 +587,47 @@ public class DisplayListManager { tessellator.reset(); } - private static void applyTransformOp(Matrix4f m, float x, float y, float z, TransformOp op, Vector3f axis) { - switch (op) { - case TRANSLATE -> m.translate(x, y, z); - case SCALE -> m.scale(x, y, z); - case ROTATE -> { if (axis != null) m.rotate((float) Math.toRadians(x), axis); } + public static void applyMatrixTranslation(float x, float y, float z) { + transformCallback.translate(x, y, z); + relativeTransformType |= TRANSFORM_TRANSLATE; + + if (pendingTransformOps != null) { + pendingTransformOps.add(String.format("glTranslatef(%.4f, %.4f, %.4f)", x, y, z)); + } + + if (DEBUG_DISPLAY_LISTS) { + flushMatrix(); } } - public static void updateRelativeTransform(float x, float y, float z, TransformOp op, Vector3f rotationAxis) { - if (relativeTransform == null) return; - - if (DEBUG_DISPLAY_LISTS) { - final Matrix4f singleTransform = new Matrix4f(); - applyTransformOp(singleTransform, x, y, z, op, rotationAxis); - if (currentRecorder != null) currentRecorder.recordMultMatrix(singleTransform); - return; - } - - applyTransformOp(relativeTransform, x, y, z, op, rotationAxis); + public static void applyMatrixScale(float x, float y, float z) { + transformCallback.scale(x, y, z); + relativeTransformType |= TRANSFORM_SCALE; if (pendingTransformOps != null) { - final String log = switch (op) { - case TRANSLATE -> String.format("glTranslatef(%.4f, %.4f, %.4f)", x, y, z); - case SCALE -> String.format("glScalef(%.4f, %.4f, %.4f)", x, y, z); - case ROTATE -> rotationAxis != null ? String.format("glRotatef(%.4f, %.4f, %.4f, %.4f)", x, rotationAxis.x, rotationAxis.y, rotationAxis.z) : null; - }; - if (log != null) pendingTransformOps.add(log); + pendingTransformOps.add(String.format("glScalef(%.4f, %.4f, %.4f)", x, y, z)); + } + + if (DEBUG_DISPLAY_LISTS) { + flushMatrix(); + } + } + + /** + * Records a matrix rotation. + *

+ * Requires the angle to be in radians & the coordinates to be normalized. + */ + public static void applyMatrixRotation(float rad, float x, float y, float z) { + transformCallback.rotate(rad, x, y, z); + relativeTransformType |= TRANSFORM_COMPLEX; + + if (pendingTransformOps != null) { + pendingTransformOps.add(String.format("glRotatef(%.4f, %.4f, %.4f, %.4f)", Math.toDegrees(rad), x, y, z)); + } + + if (DEBUG_DISPLAY_LISTS) { + flushMatrix(); } } @@ -651,65 +641,49 @@ public class DisplayListManager { * @param matrix The matrix to multiply */ public static void updateRelativeTransform(Matrix4f matrix) { - if (relativeTransform == null) { - return; - } - - if (DEBUG_DISPLAY_LISTS) { - if (currentRecorder != null) { - currentRecorder.recordMultMatrix(matrix); - } - return; - } - - relativeTransform.mul(matrix); + transformCallback.multMatrix(matrix); + relativeTransformType |= TRANSFORM_COMPLEX; if (pendingTransformOps != null) { pendingTransformOps.add("glMultMatrixf(...)"); } + + if (DEBUG_DISPLAY_LISTS) { + flushMatrix(); + } } // Reusable matrix for ortho/frustum computation private static final Matrix4f orthoFrustumTemp = new Matrix4f(); - /** Accumulate ortho projection into relativeTransform. */ public static void updateRelativeTransformOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { - if (relativeTransform == null) return; - orthoFrustumTemp.identity().ortho((float) left, (float) right, (float) bottom, (float) top, (float) zNear, (float) zFar); - if (DEBUG_DISPLAY_LISTS) { - if (currentRecorder != null) currentRecorder.recordMultMatrix(orthoFrustumTemp); - if (glListMode == GL11.GL_COMPILE_AND_EXECUTE) { - GLStateManager.getMatrixStack().mul(orthoFrustumTemp); - } - return; - } + transformCallback.multMatrix(orthoFrustumTemp); + relativeTransformType |= TRANSFORM_COMPLEX; - relativeTransform.mul(orthoFrustumTemp); if (pendingTransformOps != null) { pendingTransformOps.add(String.format("glOrtho(%.4f, %.4f, %.4f, %.4f, %.4f, %.4f)", left, right, bottom, top, zNear, zFar)); } - } - - /** Accumulate frustum projection into relativeTransform. */ - public static void updateRelativeTransformFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { - if (relativeTransform == null) return; - - orthoFrustumTemp.identity().frustum((float) left, (float) right, (float) bottom, (float) top, (float) zNear, (float) zFar); if (DEBUG_DISPLAY_LISTS) { - if (currentRecorder != null) currentRecorder.recordMultMatrix(orthoFrustumTemp); - if (glListMode == GL11.GL_COMPILE_AND_EXECUTE) { - GLStateManager.getMatrixStack().mul(orthoFrustumTemp); - } - return; + flushMatrix(); } + } + + public static void updateRelativeTransformFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { + orthoFrustumTemp.identity().frustum((float) left, (float) right, (float) bottom, (float) top, (float) zNear, (float) zFar); + + transformCallback.multMatrix(orthoFrustumTemp); + relativeTransformType |= TRANSFORM_COMPLEX; - relativeTransform.mul(orthoFrustumTemp); if (pendingTransformOps != null) { pendingTransformOps.add(String.format("glFrustum(%.4f, %.4f, %.4f, %.4f, %.4f, %.4f)", left, right, bottom, top, zNear, zFar)); } + + if (DEBUG_DISPLAY_LISTS) { + flushMatrix(); + } } /** @@ -717,11 +691,9 @@ public class DisplayListManager { * Called by GLStateManager.glLoadMatrix() - after loading an absolute matrix, * subsequent transforms are relative to that loaded matrix (i.e., start from identity). */ - public static void resetRelativeTransform() { - if (relativeTransform == null) { - return; - } - relativeTransform.identity(); + static void resetRelativeTransform() { + transformCallback.setIdentity(); + relativeTransformType = 0; } /** @@ -763,10 +735,11 @@ public class DisplayListManager { final boolean isNested = glListMode > 0; if (isNested) { + flushAll(); // Nested display list compilation violates OpenGL spec, but some of our optimizations require it // Save current compilation context and start fresh for nested list final CompilationContext parentContext = new CompilationContext( - glListId, glListMode, currentRecorder, accumulatedDraws, relativeTransform, + glListId, glListMode, currentRecorder, accumulatedDraws, compilationStackTrace, pendingTransformOps, multMatrixSources, drawRangeSources ); compilationStack.push(parentContext); @@ -777,9 +750,8 @@ public class DisplayListManager { glListMode = mode; recordingThread = Thread.currentThread(); // Track which thread is recording currentRecorder = new CommandRecorder(); // Create command recorder - accumulatedDraws = new ArrayList<>(16); // Fewer draws than commands typically - relativeTransform = new Matrix4fStack(GLStateManager.MAX_MODELVIEW_STACK_DEPTH); - stateGeneration = 0; // Reset state generation for fresh list + accumulatedDraws = new ArrayList<>(8); // Fewer draws than commands typically + transformCallback = new DisplayListCallback(); compilationStackTrace = LOG_DISPLAY_LIST_COMPILATION ? Thread.currentThread().getStackTrace() : null; // Initialize debug logging fields (only when logging enabled) @@ -793,12 +765,7 @@ public class DisplayListManager { drawRangeSources = null; } - TessellatorManager.startCapturingDirect((tessellator) -> { - if (!tessellator.isEmpty()) { - addAccumulatedDraw(tessellator, false); - } - return true; - }); + TessellatorManager.startCapturingDirect(transformCallback); } /** @@ -808,25 +775,28 @@ public class DisplayListManager { if (glListMode == 0) { throw new RuntimeException("glEndList called outside of a display list!"); } - flushMatrix(); + final boolean isNested = !compilationStack.isEmpty(); // Stop compiling mode (works for both root and nested lists now) TessellatorManager.stopCapturingDirect(); + flushAll(); + + // Reset back to MODELVIEW (default state) + if (transformCallback.getMatrixMode() != GL11.GL_MODELVIEW) { + recordMatrixMode(GL11.GL_MODELVIEW); + } + final CompiledDisplayList compiled; // Create CompiledDisplayList with both unoptimized and optimized versions - final CommandBuffer rawCommandBuffer = currentRecorder.getBuffer(); - final boolean hasCommands = !rawCommandBuffer.isEmpty(); - final boolean hasDraws = accumulatedDraws != null && !accumulatedDraws.isEmpty(); + final CommandRecorder commandBuffer = currentRecorder; + final boolean hasCommands = !commandBuffer.isEmpty(); - if (hasCommands || hasDraws) { + if (hasCommands) { final DisplayListVBO compiledBuffers = new DisplayListVBOBuilder().addDraws(accumulatedDraws).build(); try { - final CommandBuffer finalBuffer = new CommandBuffer(); - CommandBufferBuilder.buildFromRawBuffer(rawCommandBuffer, accumulatedDraws, finalBuffer); - - final IndexedDrawBatchBuilder indexedBuilder = currentRecorder.getIndexedDraws(); + final IndexedDrawBatchBuilder indexedBuilder = commandBuffer.getIndexedDraws(); final List indexedBatches; if (indexedBuilder.isEmpty()) { indexedBatches = Collections.emptyList(); @@ -845,15 +815,16 @@ public class DisplayListManager { } } - compiled = new CompiledDisplayList(finalBuffer.toBuffer(), finalBuffer.getComplexObjects(), compiledBuffers, indexedBatches); - } finally { - currentRecorder.free(); + compiled = new CompiledDisplayList(commandBuffer.finish(), commandBuffer.getComplexObjects(), compiledBuffers, indexedBatches); + } catch (Exception e) { + GLStateManager.LOGGER.error("Encountered a fatal issue while trying to compile a display list."); + e.printStackTrace(); + commandBuffer.delete(); + return; } } else { // Free the recorder even if empty - if (currentRecorder != null) { - currentRecorder.free(); - } + commandBuffer.delete(); // Empty display list - per OpenGL spec, still valid after glNewList/glEndList compiled = CompiledDisplayList.EMPTY; } @@ -876,7 +847,6 @@ public class DisplayListManager { glListMode = parentContext.listMode; currentRecorder = parentContext.recorder; accumulatedDraws = parentContext.draws; - relativeTransform = parentContext.transform; compilationStackTrace = parentContext.stackTrace; pendingTransformOps = parentContext.pendingOps; multMatrixSources = parentContext.matrixSources; @@ -889,7 +859,7 @@ public class DisplayListManager { currentRecorder = null; recordingThread = null; accumulatedDraws = null; - relativeTransform = null; + pendingDraw = null; compilationStackTrace = null; pendingTransformOps = null; multMatrixSources = null; @@ -900,28 +870,29 @@ public class DisplayListManager { } private static void addAccumulatedDraw(DirectTessellator tessellator, boolean copyLast) { - final int cmdIndex = getCommandCount(); - matrixBarrier(); - - if (accumulatedDraws.isEmpty()) { - accumulatedDraws.add( - new AccumulatedDraw( - tessellator, cmdIndex, stateGeneration, copyLast - ) - ); + if (pendingDraw == null) { + createNewDraw(tessellator, copyLast); return; } - - // Merge the previous draw call if possible - final AccumulatedDraw previous = accumulatedDraws.getLast(); - if (previous.format == tessellator.getVertexFormat() && previous.stateGeneration == stateGeneration) { - previous.mergeDraw(tessellator, copyLast); + if (pendingDraw.drawMode != tessellator.drawMode + || pendingDraw.format != tessellator.getVertexFormat() + || GLStateManager.isContinuousDraw(tessellator.drawMode) + ) { + drawBarrier(); + createNewDraw(tessellator, copyLast); return; } + pendingDraw.mergeDraw(tessellator, copyLast); + } - accumulatedDraws.add( - new AccumulatedDraw(tessellator, cmdIndex, stateGeneration, copyLast) + private static void createNewDraw(DirectTessellator tessellator, boolean copyLast) { + pendingDraw = new AccumulatedDraw( + tessellator, copyLast ); + accumulatedDraws.add(pendingDraw); + if (DEBUG_DISPLAY_LISTS) { + drawBarrier(); + } } /** @@ -949,10 +920,7 @@ public class DisplayListManager { private static void executeDisplayList(int list) { final CompiledDisplayList compiled = displayListCache.get(list); if (compiled != null) { - final int prevList = currentRenderingList; - currentRenderingList = list; - compiled.render(); - currentRenderingList = prevList; + compiled.render(list); return; } @@ -983,7 +951,7 @@ public class DisplayListManager { // ==================== DEBUG LOGGING ==================== public static void logCompiledDisplayList(int listId, CompiledDisplayList compiled, StackTraceElement[] stackTrace) { - GLStateManager.LOGGER.debug(getCompiledDisplayListString(listId, compiled, stackTrace)); + GLStateManager.LOGGER.info(getCompiledDisplayListString(listId, compiled, stackTrace)); } public static String getCompiledDisplayListString(int listId, CompiledDisplayList compiled, StackTraceElement[] stackTrace) { @@ -1002,7 +970,7 @@ public class DisplayListManager { sb.append("Contents: No commands\n"); } else { sb.append("Commands (").append(buffer.limit()).append(" bytes):\n"); - dumpCommandBuffer(buffer, compiled.getComplexObjects(), sb); + dumpCommandBuffer(buffer, compiled, sb); } } @@ -1098,97 +1066,235 @@ public class DisplayListManager { return className; } - private static void dumpCommandBuffer(ByteBuffer buffer, Object[] complexObjects, StringBuilder sb) { + private static void dumpCommandBuffer(ByteBuffer buffer, CompiledDisplayList compiledList, StringBuilder sb) { if (buffer == null) return; + DisplayListCommand[] complexObjects = compiledList.getComplexObjects(); + DisplayListVBO vbos = compiledList.getOwnedVbos(); final long basePtr = memAddress(buffer); long ptr = basePtr; final long end = basePtr + buffer.limit(); int cmdNum = 0; int drawRangeIdx = 0; // Index into drawRangeSources for source tracking - while (ptr < end) { - final int opcode = memGetInt(ptr); - final String cmdName = GLCommand.getName(opcode); - sb.append(" ").append(cmdNum++).append(": ").append(cmdName); + try { + while (ptr < end) { + final int opcode = memGetInt(ptr); + final String cmdName = GLCommand.getName(opcode); + sb.append(" ").append(cmdNum++).append(": ").append(cmdName); - // Add command-specific details - switch (opcode) { - case GLCommand.ENABLE, GLCommand.DISABLE -> { - final int cap = memGetInt(ptr + 4); - sb.append("(").append(GLDebug.getCapabilityName(cap)).append(")"); - } - case GLCommand.BIND_TEXTURE -> { - final int target = memGetInt(ptr + 4); - final int texture = memGetInt(ptr + 8); - sb.append("(target=").append(target).append(", texture=").append(texture).append(")"); - } - case GLCommand.DRAW_RANGE -> { - final int vboIdx = memGetInt(ptr + 4); - sb.append("(vbo=").append(vboIdx).append(")"); - // Show draw source if available - if (drawRangeSources != null && drawRangeIdx < drawRangeSources.size()) { - sb.append(" [from: ").append(drawRangeSources.get(drawRangeIdx)).append("]"); + // Add command-specific details + switch (opcode) { + case GLCommand.ENABLE, GLCommand.DISABLE -> { + final int cap = memGetInt(ptr + 4); + sb.append("(").append(GLDebug.getCapabilityName(cap)).append(")"); } - drawRangeIdx++; - } - case GLCommand.DRAW_RANGE_RESTORE -> { - final int vboIdx = memGetInt(ptr + 4); - final int start = memGetInt(ptr + 8); - final int count = memGetInt(ptr + 12); - final int brightness = memGetInt(ptr + 16); - sb.append("(vbo=").append(vboIdx).append(", start=").append(start) - .append(", count=").append(count).append(", brightness=").append(brightness != 0).append(")"); - // Show draw source if available - if (drawRangeSources != null && drawRangeIdx < drawRangeSources.size()) { - sb.append(" [from: ").append(drawRangeSources.get(drawRangeIdx)).append("]"); + case GLCommand.BIND_TEXTURE -> { + final int target = memGetInt(ptr + 4); + final int texture = memGetInt(ptr + 8); + sb.append("(target=").append(target).append(", texture=").append(texture).append(")"); } - drawRangeIdx++; - } - case GLCommand.MULT_MATRIX, GLCommand.LOAD_MATRIX -> { - sb.append("("); - for (int i = 0; i < 16; i++) { - float value = MemoryUtilities.memGetFloat(ptr + 4 + i * 4); - sb.append(i == 0 ? value : ", " + value); + case GLCommand.DRAW_RANGE -> { + final int vboIdx = memGetInt(ptr + 4); + final DisplayListVBO.SubVBO vbo = vbos.getVBO(vboIdx); + sb.append("(vbo=").append(vboIdx) + .append(", drawMode=").append(vbo.getDrawMode()) + .append(", start=").append(vbo.getStart()) + .append(", count=").append(vbo.getCount()) + .append(", format=").append(vbo.getVAO().getVBO().getVertexFormat()) + .append(")"); + // Show draw source if available + if (drawRangeSources != null && drawRangeIdx < drawRangeSources.size()) { + sb.append(" [from: ").append(drawRangeSources.get(drawRangeIdx)).append("]"); + } + drawRangeIdx++; + } + case GLCommand.DRAW_RANGE_RESTORE -> { + final int vboIdx = memGetInt(ptr + 4); + final int flags = memGetInt(ptr + 8); + final int lastColor = memGetInt(ptr + 12); + final int lastNormal = memGetInt(ptr + 16); + final float lastTexCoordU = memGetFloat(ptr + 20); + final float lastTexCoordV = memGetFloat(ptr + 24); + final DisplayListVBO.SubVBO vbo = vbos.getVBO(vboIdx); + sb.append("(vbo=").append(vboIdx) + .append(", drawMode=").append(vbo.getDrawMode()) + .append(", start=").append(vbo.getStart()) + .append(", count=").append(vbo.getCount()) + .append(", format=").append(vbo.getVAO().getVBO().getVertexFormat()) + .append(", flags=").append(flags) + .append(", lastColor=").append(lastColor) + .append(", lastNormal=").append(lastNormal) + .append(", lastTexCoordU=").append(lastTexCoordU) + .append(", lastTexCoordV=").append(lastTexCoordV) + .append(")"); + // Show draw source if available + if (drawRangeSources != null && drawRangeIdx < drawRangeSources.size()) { + sb.append(" [from: ").append(drawRangeSources.get(drawRangeIdx)).append("]"); + } + drawRangeIdx++; + } + case GLCommand.MULT_MATRIX, GLCommand.LOAD_MATRIX -> { + sb.append("("); + for (int i = 0; i < 16; i++) { + float value = MemoryUtilities.memGetFloat(ptr + 4 + i * 4); + sb.append(i == 0 ? value : ", " + value); + } + sb.append(")"); + } + case GLCommand.SCALE, GLCommand.TRANSLATE -> { + final float x = memGetFloat(ptr + 4); + final float y = memGetFloat(ptr + 8); + final float z = memGetFloat(ptr + 12); + sb.append("(x=").append(x) + .append(", y=").append(y) + .append(", z=").append(z) + .append(")"); + } + case GLCommand.COLOR -> { + final float r = Float.intBitsToFloat(memGetInt(ptr + 4)); + final float g = Float.intBitsToFloat(memGetInt(ptr + 8)); + final float b = Float.intBitsToFloat(memGetInt(ptr + 12)); + final float a = Float.intBitsToFloat(memGetInt(ptr + 16)); + sb.append("(").append(r).append(", ").append(g).append(", ").append(b).append(", ").append(a).append(")"); + } + case GLCommand.DEPTH_MASK -> { + final int flag = memGetInt(ptr + 4); + sb.append("(").append(flag != 0).append(")"); + } + case GLCommand.BLEND_FUNC -> { + final int srcRgb = memGetInt(ptr + 4); + final int dstRgb = memGetInt(ptr + 8); + final int srcAlpha = memGetInt(ptr + 12); + final int dstAlpha = memGetInt(ptr + 16); + sb.append("(srcRgb=").append(srcRgb).append(", dstRgb=").append(dstRgb) + .append(", srcAlpha=").append(srcAlpha).append(", dstAlpha=").append(dstAlpha).append(")"); + } + case GLCommand.CALL_LIST -> { + final int calledList = memGetInt(ptr + 4); + sb.append("(").append(calledList).append(")"); + } + case GLCommand.MATRIX_MODE -> { + final int mode = memGetInt(ptr + 4); + sb.append("(").append(mode == GL11.GL_MODELVIEW ? "MODELVIEW" : mode == GL11.GL_PROJECTION ? "PROJECTION" : mode).append(")"); + } + case GLCommand.COMPLEX_REF -> { + final int idx = memGetInt(ptr + 4); + final Object obj = complexObjects != null && idx < complexObjects.length ? complexObjects[idx] : null; + sb.append("(idx=").append(idx).append(", type=").append(obj != null ? obj.getClass().getSimpleName() : "null").append(")"); } - sb.append(")"); - } - case GLCommand.COLOR -> { - final float r = Float.intBitsToFloat(memGetInt(ptr + 4)); - final float g = Float.intBitsToFloat(memGetInt(ptr + 8)); - final float b = Float.intBitsToFloat(memGetInt(ptr + 12)); - final float a = Float.intBitsToFloat(memGetInt(ptr + 16)); - sb.append("(").append(r).append(", ").append(g).append(", ").append(b).append(", ").append(a).append(")"); - } - case GLCommand.DEPTH_MASK -> { - final int flag = memGetInt(ptr + 4); - sb.append("(").append(flag != 0).append(")"); - } - case GLCommand.BLEND_FUNC -> { - final int srcRgb = memGetInt(ptr + 4); - final int dstRgb = memGetInt(ptr + 8); - final int srcAlpha = memGetInt(ptr + 12); - final int dstAlpha = memGetInt(ptr + 16); - sb.append("(srcRgb=").append(srcRgb).append(", dstRgb=").append(dstRgb) - .append(", srcAlpha=").append(srcAlpha).append(", dstAlpha=").append(dstAlpha).append(")"); - } - case GLCommand.CALL_LIST -> { - final int calledList = memGetInt(ptr + 4); - sb.append("(").append(calledList).append(")"); - } - case GLCommand.MATRIX_MODE -> { - final int mode = memGetInt(ptr + 4); - sb.append("(").append(mode == GL11.GL_MODELVIEW ? "MODELVIEW" : mode == GL11.GL_PROJECTION ? "PROJECTION" : mode).append(")"); - } - case GLCommand.COMPLEX_REF -> { - final int idx = memGetInt(ptr + 4); - final Object obj = complexObjects != null && idx < complexObjects.length ? complexObjects[idx] : null; - sb.append("(idx=").append(idx).append(", type=").append(obj != null ? obj.getClass().getSimpleName() : "null").append(")"); } + ptr += GLCommand.getCommandSize(opcode, ptr); + sb.append("\n"); } - ptr += GLCommand.getCommandSize(opcode, ptr); - sb.append("\n"); + } catch (Exception e) { + sb.append("Unknown commands.\n"); } } + private static final class DisplayListCallback extends VertexTransformCallback { + + + private int matrixMode = GL11.GL_MODELVIEW; + + private final Matrix3f normalMatrix = new Matrix3f(); + + private final Matrix4f transformMatrix = new Matrix4f(); + + public void scale(float x, float y, float z) { + transformMatrix.scale(x, y, z); + markDirty(); + } + + public void translate(float x, float y, float z) { + transformMatrix.translate(x, y, z); + markDirty(); + } + + public void rotate(float rad, float x, float y, float z) { + transformMatrix.rotate(rad, x, y, z); + markDirty(); + } + + public void multMatrix(Matrix4f matrix4f) { + transformMatrix.mul(matrix4f); + markDirty(); + } + + public void setIdentity() { + transformMatrix.identity(); + markDirty(); + } + + public Vector3f getScale(Vector3f dest) { + return transformMatrix.getScale(dest); + } + + public Vector3f getTranslation(Vector3f dest) { + return transformMatrix.getTranslation(dest); + } + + /** + * WARNING: If you apply transformations to this matrix, make sure to call markDirty() afterward! + */ + public Matrix4f getReadMatrix() { + return transformMatrix; + } + + public void markDirty() { + if (matrixMode == GL11.GL_MODELVIEW) { + NormalHelper.getNormalMatrix(transformMatrix, normalMatrix); + } + } + + /** + * @param mode accepts either GL11.GL_MODELVIEW, GL11.GL_PROJECTION, GL11.GL_TEXTURE, GL11.GL_COLOR + */ + public void setMatrixMode(int mode) { + this.matrixMode = mode; + markDirty(); + } + + public int getMatrixMode() { + return this.matrixMode; + } + + public boolean isIdentity() { + return MatrixHelper.isIdentity(transformMatrix); + } + + @Override + public boolean onDraw(CallbackTessellator tessellator) { + if (!tessellator.isEmpty()) { + addAccumulatedDraw(tessellator, false); + } + return true; + } + + @Override + public void onVertex(CallbackTessellator tessellator, double x, double y, double z) { + tessellator.syncVanillaTessellator(); + super.onVertex(tessellator, x, y, z); + } + + @Override + protected Matrix4f getMVPMatrix() { + return matrixMode <= GL11.GL_PROJECTION ? transformMatrix : null; + } + + @Override + protected Matrix4f getTextureMatrix() { + return matrixMode == GL11.GL_TEXTURE ? transformMatrix : null; + } + + @Override + protected Matrix4f getColorMatrix() { + return matrixMode == GL11.GL_COLOR ? transformMatrix : null; + } + + @Override + protected Matrix3f getNormalMatrix() { + return matrixMode == GL11.GL_MODELVIEW ? normalMatrix : null; // GL_PROJECTION doesn't transform normals + } + } } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java index 5deb554a8..e39de6122 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/GLStateManager.java @@ -2099,22 +2099,20 @@ public class GLStateManager { } public static void glEnd() { - if (DisplayListManager.isRecording()) { - final DirectTessellator result = ImmediateModeRecorder.end(); - if (result != null) { + final DirectTessellator result = ImmediateModeRecorder.end(); + if (result != null) { + if (DisplayListManager.isRecording()) { if (DisplayListManager.isCompileAndExecute() && initConfig != null && initConfig.getDirectDrawer() != null) { - DisplayListManager.flushMatrix(); - final var recorder = DisplayListManager.pauseRecording(); + final CommandRecorder recorder = DisplayListManager.pauseRecording(); initConfig.getDirectDrawer().accept(result); DisplayListManager.resumeRecording(recorder); } DisplayListManager.addImmediateModeDraw(result); + return; + } + if (initConfig != null && initConfig.getDirectDrawer() != null) { + initConfig.getDirectDrawer().accept(result); } - return; - } - final DirectTessellator result = ImmediateModeRecorder.end(); - if (result != null && initConfig != null && initConfig.getDirectDrawer() != null) { - initConfig.getDirectDrawer().accept(result); } } @@ -2229,7 +2227,6 @@ public class GLStateManager { if (recordMode != RecordMode.NONE) { // Core profile: a default VAO is generated at init and glBindVertexArray(0) // is redirected to it, so a VAO is always bound here — no fallback branches. - DisplayListManager.flushMatrix(); final IndexedDrawCapture capture = IndexedDrawCapture.create(mode, indices_count, type, indices_buffer_offset, boundEBO); if (capture != null) { DisplayListManager.recordIndexedDrawCapture(capture); @@ -3350,7 +3347,6 @@ public class GLStateManager { final RecordMode recordMode = DisplayListManager.getRecordMode(); if (recordMode != RecordMode.NONE) { DisplayListManager.recordMatrixMode(mode); - DisplayListManager.resetRelativeTransform(); // Mode switch is a barrier - reset delta tracking if (recordMode == RecordMode.COMPILE) { return; } @@ -3364,8 +3360,6 @@ public class GLStateManager { final Matrix4f matrix = new Matrix4f().set(m); m.rewind(); DisplayListManager.recordLoadMatrix(matrix); - // Reset relative transform - subsequent transforms are relative to loaded matrix - DisplayListManager.resetRelativeTransform(); if (mode == RecordMode.COMPILE) { return; } @@ -3385,8 +3379,6 @@ public class GLStateManager { final Matrix4f floatMatrix = new Matrix4f(); floatMatrix.set(conversionMatrix4d); DisplayListManager.recordLoadMatrix(floatMatrix); - // Reset relative transform - subsequent transforms are relative to loaded matrix - DisplayListManager.resetRelativeTransform(); if (mode == RecordMode.COMPILE) { return; } @@ -3426,8 +3418,6 @@ public class GLStateManager { final RecordMode mode = DisplayListManager.getRecordMode(); if (mode != RecordMode.NONE) { DisplayListManager.recordLoadIdentity(); - // Reset relative transform - accumulated transforms are discarded (overwritten by load) - DisplayListManager.resetRelativeTransform(); if (mode == RecordMode.COMPILE) { return; } @@ -3439,10 +3429,9 @@ public class GLStateManager { } public static void glTranslatef(float x, float y, float z) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - DisplayListManager.updateRelativeTransform(x, y, z, DisplayListManager.TransformOp.TRANSLATE, null); - if (mode == RecordMode.COMPILE) return; + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixTranslation(x, y, z); + return; } if (isCachingEnabled()) { getMatrixStack().translate(x, y, z); @@ -3451,10 +3440,9 @@ public class GLStateManager { } public static void glTranslated(double x, double y, double z) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - DisplayListManager.updateRelativeTransform((float) x, (float) y, (float) z, DisplayListManager.TransformOp.TRANSLATE, null); - if (mode == RecordMode.COMPILE) return; + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixTranslation((float) x, (float) y, (float) z); + return; } if (isCachingEnabled()) { getMatrixStack().translate((float) x, (float) y, (float) z); @@ -3463,10 +3451,9 @@ public class GLStateManager { } public static void glScalef(float x, float y, float z) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - DisplayListManager.updateRelativeTransform(x, y, z, DisplayListManager.TransformOp.SCALE, null); - if (mode == RecordMode.COMPILE) return; + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixScale(x, y, z); + return; } if (isCachingEnabled()) { getMatrixStack().scale(x, y, z); @@ -3475,10 +3462,9 @@ public class GLStateManager { } public static void glScaled(double x, double y, double z) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - DisplayListManager.updateRelativeTransform((float) x, (float) y, (float) z, DisplayListManager.TransformOp.SCALE, null); - if (mode == RecordMode.COMPILE) return; + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixScale((float) x, (float) y, (float) z); + return; } if (isCachingEnabled()) { getMatrixStack().scale((float) x, (float) y, (float) z); @@ -3492,10 +3478,9 @@ public class GLStateManager { multMatrix.set(floatBuffer); final int currentMode = matrixMode.getMode(); - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { + if (DisplayListManager.isRecording()) { DisplayListManager.updateRelativeTransform(multMatrix); - if (mode == RecordMode.COMPILE) return; + return; } if (isCachingEnabled()) { getMatrixStack().mul(multMatrix); @@ -3503,6 +3488,13 @@ public class GLStateManager { } } + public static void applyMultMatrix(Matrix4f multMatrix) { + if (isCachingEnabled()) { + getMatrixStack().mul(multMatrix); + bumpMatrixGeneration(); + } + } + public static final Matrix4d conversionMatrix4d = new Matrix4d(); public static final Matrix4f conversionMatrix4f = new Matrix4f(); @@ -3510,10 +3502,9 @@ public class GLStateManager { conversionMatrix4d.set(matrix); conversionMatrix4f.set(conversionMatrix4d); - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { + if (DisplayListManager.isRecording()) { DisplayListManager.updateRelativeTransform(conversionMatrix4f); - if (mode == RecordMode.COMPILE) return; + return; } if (isCachingEnabled()) { getMatrixStack().mul(conversionMatrix4f); @@ -3521,20 +3512,24 @@ public class GLStateManager { } } - private static final Vector3f rotation = new Vector3f(); - public static void glRotatef(float angle, float x, float y, float z) { final float lenSq = x * x + y * y + z * z; if (lenSq == 0.0f) return; - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - rotation.set(x, y, z).normalize(); - DisplayListManager.updateRelativeTransform(angle, 0, 0, DisplayListManager.TransformOp.ROTATE, rotation); - if (mode == RecordMode.COMPILE) return; + + // Fast way to normalize rotation + final float scalar = 1.0f / (float) Math.sqrt(lenSq); + x *= scalar; + y *= scalar; + z *= scalar; + // Convert deg to rad + angle = (float) Math.toRadians(angle); + + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixRotation(angle, x, y, z); + return; } if (isCachingEnabled()) { - rotation.set(x, y, z).normalize(); - getMatrixStack().rotate((float) Math.toRadians(angle), rotation); + getMatrixStack().rotate(angle, x, y, z); bumpMatrixGeneration(); } } @@ -3542,24 +3537,29 @@ public class GLStateManager { public static void glRotated(double angle, double x, double y, double z) { final double lenSq = x * x + y * y + z * z; if (lenSq == 0.0) return; - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { - rotation.set((float) x, (float) y, (float) z).normalize(); - DisplayListManager.updateRelativeTransform((float) angle, 0, 0, DisplayListManager.TransformOp.ROTATE, rotation); - if (mode == RecordMode.COMPILE) return; + + // Fast way to normalize rotation + final double scalar = 1.0 / Math.sqrt(lenSq); + x *= scalar; + y *= scalar; + z *= scalar; + // Convert deg to rad + angle = Math.toRadians(angle); + + if (DisplayListManager.isRecording()) { + DisplayListManager.applyMatrixRotation((float) angle, (float) x, (float) y, (float) z); + return; } if (isCachingEnabled()) { - rotation.set((float) x, (float) y, (float) z).normalize(); - getMatrixStack().rotate((float) Math.toRadians(angle), rotation); + getMatrixStack().rotate((float) angle, (float) x, (float) y, (float) z); bumpMatrixGeneration(); } } public static void glOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { + if (DisplayListManager.isRecording()) { DisplayListManager.updateRelativeTransformOrtho(left, right, bottom, top, zNear, zFar); - if (mode == RecordMode.COMPILE) return; + return; } if (isCachingEnabled()) { getMatrixStack().ortho((float) left, (float) right, (float) bottom, (float) top, (float) zNear, (float) zFar); @@ -3568,10 +3568,9 @@ public class GLStateManager { } public static void glFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { - final RecordMode mode = DisplayListManager.getRecordMode(); - if (mode != RecordMode.NONE) { + if (DisplayListManager.isRecording()) { DisplayListManager.updateRelativeTransformFrustum(left, right, bottom, top, zNear, zFar); - if (mode == RecordMode.COMPILE) return; + return; } if (isCachingEnabled()) { getMatrixStack().frustum((float) left, (float) right, (float) bottom, (float) top, (float) zNear, (float) zFar); @@ -4393,8 +4392,8 @@ public class GLStateManager { } public static int glGetError() { - if (!RENDER_BACKEND.hasContext()) return 0; if (initConfig.noErrorChecks()) return 0; + if (!RENDER_BACKEND.hasContext()) return 0; return RENDER_BACKEND.getError(); } @@ -5917,4 +5916,14 @@ public class GLStateManager { public static void glGetTexImage(int target, int level, int format, int type, long pixels) { GL11.glGetTexImage(target, level, format, type, pixels); } + + /** + * Draw modes that rely on the previous vertex data cannot be merged currently. + * It is possible to merge them using Index Buffers, but currently unimplemented. + */ + public static boolean isContinuousDraw(int drawMode) { + return drawMode == GL11.GL_TRIANGLE_STRIP || drawMode == GL11.GL_TRIANGLE_FAN + || drawMode == GL11.GL_LINE_STRIP || drawMode == GL11.GL_LINE_LOOP + || drawMode == GL11.GL_QUAD_STRIP || drawMode == GL11.GL_POLYGON; + } } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ITessellatorData.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ITessellatorData.java deleted file mode 100644 index b8cdacec6..000000000 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ITessellatorData.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gtnewhorizons.angelica.glsm; - -/** - * Tessellator data needed by {@link com.gtnewhorizons.angelica.glsm.streaming.TessellatorStreamingDrawer}. - */ -public interface ITessellatorData { - - boolean isDrawing(); - void setDrawing(boolean drawing); - int getVertexCount(); - int[] getRawBuffer(); - int getRawBufferIndex(); - int getRawBufferSize(); - void setRawBufferSize(int size); - void setRawBuffer(int[] buffer); - int getDrawMode(); - boolean hasTexture(); - boolean hasColor(); - boolean hasNormals(); - boolean hasBrightness(); - void angelica$reset(); -} diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/TransformOptimizer.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/TransformOptimizer.java deleted file mode 100644 index 49f110778..000000000 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/TransformOptimizer.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.gtnewhorizons.angelica.glsm; - -import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; -import com.gtnewhorizons.angelica.glsm.recording.commands.MultMatrixCmd; -import org.joml.Matrix4f; - -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; - -/** - * Helper class for tracking and collapsing matrix transforms during optimization. - * Implements the transform accumulation and emission strategy: - *

- */ -class TransformOptimizer { - private final Matrix4f accumulated = new Matrix4f(); // Current accumulated transform - private final Matrix4f lastEmitted = new Matrix4f(); // Last emitted transform - private final Deque stack = new ArrayDeque<>(); // For Push/Pop - private final int listId; // For logging - private boolean absoluteMatrixFlag = false; // True after LoadMatrix, cleared by LoadIdentity emit - - TransformOptimizer(int listId) { - this.listId = listId; - accumulated.identity(); - lastEmitted.identity(); - } - - Matrix4f getAccumulated() { - return accumulated; - } - - void loadIdentity() { - accumulated.identity(); - } - - void pushTransform() { - stack.push(new Matrix4f(accumulated)); - } - - void popTransform() { - if (!stack.isEmpty()) { - final Matrix4f popped = stack.pop(); - accumulated.set(popped); - // After Pop, GL state is restored to the pushed value so lastEmitted should also reflect this - lastEmitted.set(accumulated); - } else { - GLStateManager.LOGGER.warn("[TransformOptimizer] list={} Pop with empty stack - resetting to identity", listId); - accumulated.identity(); - lastEmitted.identity(); - } - } - - boolean isIdentity() { - return DisplayListManager.isIdentity(accumulated); - } - - /** - * Check if there's a pending transform that hasn't been emitted yet. - */ - boolean hasPendingTransform() { - return !accumulated.equals(lastEmitted); - } - - /** - * Emit a MultMatrix command if accumulated differs from lastEmitted. - * Updates lastEmitted to match accumulated after emission. - */ - void emitPendingTransform(List output) { - if (!accumulated.equals(lastEmitted)) { - emitTransformTo(output, accumulated); - } - } - - /** - * Emit a MultMatrix command to make GL state match a target transform. - * Used when a draw expects a specific transform that may differ from accumulated. - * Updates lastEmitted to match target after emission. - * - * @param output The command list to emit to - * @param target The target transform to reach - */ - void emitTransformTo(List output, Matrix4f target) { - if (target.equals(lastEmitted)) { - // Already at target - nothing to emit - return; - } - - // Calculate delta: what we need to multiply to go from lastEmitted to target - // delta = inverse(lastEmitted) * target - // But for simplicity, if lastEmitted is identity, just emit target - if (DisplayListManager.isIdentity(lastEmitted)) { - // Simple case: just emit target - output.add(MultMatrixCmd.create(target)); - } else { - // Need to emit delta: inv(lastEmitted) * target - final Matrix4f delta = new Matrix4f(lastEmitted).invert().mul(target); - output.add(MultMatrixCmd.create(delta)); - } - lastEmitted.set(target); - } - - /** - * Check if a draw's expected transform differs from what we've emitted. - */ - boolean needsTransformForDraw(Matrix4f drawTransform) { - return !drawTransform.equals(lastEmitted); - } - - /** - * Mark that the GL matrix is at an absolute value (after LoadMatrix). - * Subsequent LoadIdentity commands must be emitted to actually reset GL to identity. - */ - void markAbsoluteMatrix() { - absoluteMatrixFlag = true; - } - - /** - * Check if the GL matrix is at an absolute value and clear the flag. - * Used to determine if LoadIdentity needs to emit. - * @return true if LoadMatrix was called and not yet reset by LoadIdentity - */ - boolean checkAndClearAbsoluteMatrix() { - boolean was = absoluteMatrixFlag; - absoluteMatrixFlag = false; - return was; - } -} diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ffp/VertexKey.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ffp/VertexKey.java index bfbcc6168..34c1d608c 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ffp/VertexKey.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/ffp/VertexKey.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.glsm.ffp; +import com.gtnewhorizon.gtnhlib.client.renderer.MatrixHelper; import com.gtnewhorizons.angelica.glsm.DisplayListManager; import com.gtnewhorizons.angelica.glsm.GLStateManager; import com.gtnewhorizons.angelica.glsm.states.TexGenState; @@ -182,7 +183,7 @@ public final class VertexKey { // Check if texture matrix unit 0 is non-identity final Matrix4f texMat = GLStateManager.getTextures().getTextureUnitMatrix(0); - if (!DisplayListManager.isIdentity(texMat)) { + if (!MatrixHelper.isIdentity(texMat)) { bits |= (1L << BIT_TEX_MATRIX); } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/AccumulatedDraw.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/AccumulatedDraw.java index ecf2f44a9..da4f9c459 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/AccumulatedDraw.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/AccumulatedDraw.java @@ -16,17 +16,13 @@ public final class AccumulatedDraw { public final VertexFormat format; public final List drawBuffers; public final int drawMode; - public final int commandIndex; // Position in command list for state tracking - public final int stateGeneration; // Position in command list for state tracking public RestoreData restoreData; - public AccumulatedDraw(DirectTessellator tessellator, int commandIndex, int stateGeneration, boolean copyLast) { + public AccumulatedDraw(DirectTessellator tessellator, boolean copyLast) { this.format = tessellator.getVertexFormat(); this.drawMode = tessellator.drawMode; this.drawBuffers = new ArrayList<>(); this.drawBuffers.add(tessellator.allocateBufferCopy()); - this.commandIndex = commandIndex; - this.stateGeneration = stateGeneration; if (copyLast) { this.restoreData = new RestoreData(tessellator); @@ -36,7 +32,6 @@ public final class AccumulatedDraw { public void mergeDraw(DirectTessellator tessellator, boolean copyLast) { this.drawBuffers.add(tessellator.allocateBufferCopy()); - if (copyLast) { this.restoreData = new RestoreData(tessellator); } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBuffer.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBuffer.java deleted file mode 100644 index ea8d14b7e..000000000 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBuffer.java +++ /dev/null @@ -1,767 +0,0 @@ -package com.gtnewhorizons.angelica.glsm.recording; - -import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; -import org.joml.Matrix4f; - -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.util.ArrayList; -import java.util.List; - -import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; - -public final class CommandBuffer { - private static final int DEFAULT_CAPACITY = 4096; // Guess at typical display list size - - private ByteBuffer buffer; - private long basePointer; - private long writePointer; - private final List complexObjects = new ArrayList<>(); - - public CommandBuffer() { - this(DEFAULT_CAPACITY); - } - - public CommandBuffer(int initialCapacity) { - this.buffer = memAlloc(initialCapacity); - this.basePointer = memAddress(buffer); - this.writePointer = basePointer; - } - - // === Low-level write operations === - - private void writeInt(int value) { - memPutInt(writePointer, value); - writePointer += 4; - } - - private void writeLong(long value) { - memPutLong(writePointer, value); - writePointer += 8; - } - - private void writeFloat(float value) { - memPutFloat(writePointer, value); - writePointer += 4; - } - - private void writeDouble(double value) { - memPutDouble(writePointer, value); - writePointer += 8; - } - - private void ensureCapacity(int needed) { - final int size = size(); - final int remaining = buffer.capacity() - size; - if (remaining < needed) { - final int newCapacity = Math.max(buffer.capacity() * 2, buffer.capacity() + needed); - buffer = memRealloc(buffer, newCapacity); - basePointer = memAddress(buffer); - writePointer = basePointer + size; - } - } - - // === Single int commands === - - public void writeEnable(int cap) { - ensureCapacity(8); - writeInt(GLCommand.ENABLE); - writeInt(cap); - } - - public void writeDisable(int cap) { - ensureCapacity(8); - writeInt(GLCommand.DISABLE); - writeInt(cap); - } - - public void writeClear(int mask) { - ensureCapacity(8); - writeInt(GLCommand.CLEAR); - writeInt(mask); - } - - public void writeClearStencil(int s) { - ensureCapacity(8); - writeInt(GLCommand.CLEAR_STENCIL); - writeInt(s); - } - - public void writeCullFace(int mode) { - ensureCapacity(8); - writeInt(GLCommand.CULL_FACE); - writeInt(mode); - } - - public void writeDepthFunc(int func) { - ensureCapacity(8); - writeInt(GLCommand.DEPTH_FUNC); - writeInt(func); - } - - public void writeShadeModel(int mode) { - ensureCapacity(8); - writeInt(GLCommand.SHADE_MODEL); - writeInt(mode); - } - - public void writeLogicOp(int opcode) { - ensureCapacity(8); - writeInt(GLCommand.LOGIC_OP); - writeInt(opcode); - } - - public void writeMatrixMode(int mode) { - ensureCapacity(8); - writeInt(GLCommand.MATRIX_MODE); - writeInt(mode); - } - - public void writeActiveTexture(int texture) { - ensureCapacity(8); - writeInt(GLCommand.ACTIVE_TEXTURE); - writeInt(texture); - } - - public void writeUseProgram(int program) { - ensureCapacity(8); - writeInt(GLCommand.USE_PROGRAM); - writeInt(program); - } - - public void writePushAttrib(int mask) { - ensureCapacity(8); - writeInt(GLCommand.PUSH_ATTRIB); - writeInt(mask); - } - - public void writePopAttrib() { - ensureCapacity(8); - writeInt(GLCommand.POP_ATTRIB); - writeInt(0); // unused padding - } - - public void writeLoadIdentity() { - ensureCapacity(4); - writeInt(GLCommand.LOAD_IDENTITY); - } - - public void writePushMatrix() { - ensureCapacity(4); - writeInt(GLCommand.PUSH_MATRIX); - } - - public void writePopMatrix() { - ensureCapacity(4); - writeInt(GLCommand.POP_MATRIX); - } - - public void writeStencilMask(int mask) { - ensureCapacity(8); - writeInt(GLCommand.STENCIL_MASK); - writeInt(mask); - } - - public void writeDepthMask(boolean flag) { - ensureCapacity(8); - writeInt(GLCommand.DEPTH_MASK); - writeInt(flag ? 1 : 0); - } - - public void writeFrontFace(int mode) { - ensureCapacity(8); - writeInt(GLCommand.FRONT_FACE); - writeInt(mode); - } - - // === Two int commands === - - public void writeBindTexture(int target, int texture) { - ensureCapacity(12); - writeInt(GLCommand.BIND_TEXTURE); - writeInt(target); - writeInt(texture); - } - - public void writePolygonMode(int face, int mode) { - ensureCapacity(12); - writeInt(GLCommand.POLYGON_MODE); - writeInt(face); - writeInt(mode); - } - - public void writeColorMaterial(int face, int mode) { - ensureCapacity(12); - writeInt(GLCommand.COLOR_MATERIAL); - writeInt(face); - writeInt(mode); - } - - public void writeLineStipple(int factor, int pattern) { - ensureCapacity(12); - writeInt(GLCommand.LINE_STIPPLE); - writeInt(factor); - writeInt(pattern); - } - - public void writeStencilMaskSeparate(int face, int mask) { - ensureCapacity(12); - writeInt(GLCommand.STENCIL_MASK_SEPARATE); - writeInt(face); - writeInt(mask); - } - - public void writeFogi(int pname, int param) { - ensureCapacity(12); - writeInt(GLCommand.FOGI); - writeInt(pname); - writeInt(param); - } - - public void writeHint(int target, int mode) { - ensureCapacity(12); - writeInt(GLCommand.HINT); - writeInt(target); - writeInt(mode); - } - - // === Three int commands === - - public void writeStencilFunc(int func, int ref, int mask) { - ensureCapacity(16); - writeInt(GLCommand.STENCIL_FUNC); - writeInt(func); - writeInt(ref); - writeInt(mask); - } - - public void writeStencilOp(int fail, int zfail, int zpass) { - ensureCapacity(16); - writeInt(GLCommand.STENCIL_OP); - writeInt(fail); - writeInt(zfail); - writeInt(zpass); - } - - public void writeTexParameteri(int target, int pname, int param) { - ensureCapacity(16); - writeInt(GLCommand.TEX_PARAMETERI); - writeInt(target); - writeInt(pname); - writeInt(param); - } - - // === Four int commands === - - public void writeViewport(int x, int y, int width, int height) { - ensureCapacity(20); - writeInt(GLCommand.VIEWPORT); - writeInt(x); - writeInt(y); - writeInt(width); - writeInt(height); - } - - public void writeScissor(int x, int y, int width, int height) { - ensureCapacity(20); - writeInt(GLCommand.SCISSOR); - writeInt(x); - writeInt(y); - writeInt(width); - writeInt(height); - } - - public void writeBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) { - ensureCapacity(20); - writeInt(GLCommand.BLEND_FUNC); - writeInt(srcRgb); - writeInt(dstRgb); - writeInt(srcAlpha); - writeInt(dstAlpha); - } - - public void writeColorMask(boolean red, boolean green, boolean blue, boolean alpha) { - ensureCapacity(20); - writeInt(GLCommand.COLOR_MASK); - writeInt(red ? 1 : 0); - writeInt(green ? 1 : 0); - writeInt(blue ? 1 : 0); - writeInt(alpha ? 1 : 0); - } - - public void writeStencilFuncSeparate(int face, int func, int ref, int mask) { - ensureCapacity(20); - writeInt(GLCommand.STENCIL_FUNC_SEPARATE); - writeInt(face); - writeInt(func); - writeInt(ref); - writeInt(mask); - } - - public void writeStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - ensureCapacity(20); - writeInt(GLCommand.STENCIL_OP_SEPARATE); - writeInt(face); - writeInt(sfail); - writeInt(dpfail); - writeInt(dppass); - } - - // === Float commands === - - public void writePointSize(float size) { - ensureCapacity(8); - writeInt(GLCommand.POINT_SIZE); - writeFloat(size); - } - - public void writeLineWidth(float width) { - ensureCapacity(8); - writeInt(GLCommand.LINE_WIDTH); - writeFloat(width); - } - - public void writePolygonOffset(float factor, float units) { - ensureCapacity(12); - writeInt(GLCommand.POLYGON_OFFSET); - writeFloat(factor); - writeFloat(units); - } - - public void writeColor(float r, float g, float b, float a) { - ensureCapacity(20); - writeInt(GLCommand.COLOR); - writeFloat(r); - writeFloat(g); - writeFloat(b); - writeFloat(a); - } - - public void writeClearColor(float r, float g, float b, float a) { - ensureCapacity(20); - writeInt(GLCommand.CLEAR_COLOR); - writeFloat(r); - writeFloat(g); - writeFloat(b); - writeFloat(a); - } - - public void writeClearDepth(double depth) { - ensureCapacity(12); - writeInt(GLCommand.CLEAR_DEPTH); - writeDouble(depth); - } - - public void writeBlendColor(float r, float g, float b, float a) { - ensureCapacity(20); - writeInt(GLCommand.BLEND_COLOR); - writeFloat(r); - writeFloat(g); - writeFloat(b); - writeFloat(a); - } - - // === Mixed int+float commands === - - public void writeAlphaFunc(int func, float ref) { - ensureCapacity(12); - writeInt(GLCommand.ALPHA_FUNC); - writeInt(func); - writeFloat(ref); - } - - public void writeFogf(int pname, float param) { - ensureCapacity(12); - writeInt(GLCommand.FOGF); - writeInt(pname); - writeFloat(param); - } - - public void writeLightf(int light, int pname, float param) { - ensureCapacity(16); - writeInt(GLCommand.LIGHTF); - writeInt(light); - writeInt(pname); - writeFloat(param); - } - - public void writeLightModelf(int pname, float param) { - ensureCapacity(12); - writeInt(GLCommand.LIGHT_MODELF); - writeInt(pname); - writeFloat(param); - } - - public void writeLighti(int light, int pname, int param) { - ensureCapacity(16); - writeInt(GLCommand.LIGHTI); - writeInt(light); - writeInt(pname); - writeInt(param); - } - - public void writeLightModeli(int pname, int param) { - ensureCapacity(12); - writeInt(GLCommand.LIGHT_MODELI); - writeInt(pname); - writeInt(param); - } - - public void writeMaterialf(int face, int pname, float param) { - ensureCapacity(16); - writeInt(GLCommand.MATERIALF); - writeInt(face); - writeInt(pname); - writeFloat(param); - } - - public void writeTexParameterf(int target, int pname, float param) { - ensureCapacity(16); - writeInt(GLCommand.TEX_PARAMETERF); - writeInt(target); - writeInt(pname); - writeFloat(param); - } - - // === Double commands === - - public void writeTranslate(double x, double y, double z) { - ensureCapacity(28); - writeInt(GLCommand.TRANSLATE); - writeDouble(x); - writeDouble(y); - writeDouble(z); - } - - public void writeRotate(double angle, double x, double y, double z) { - ensureCapacity(36); - writeInt(GLCommand.ROTATE); - writeDouble(angle); - writeDouble(x); - writeDouble(y); - writeDouble(z); - } - - public void writeScale(double x, double y, double z) { - ensureCapacity(28); - writeInt(GLCommand.SCALE); - writeDouble(x); - writeDouble(y); - writeDouble(z); - } - - public void writeOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { - ensureCapacity(52); - writeInt(GLCommand.ORTHO); - writeDouble(left); - writeDouble(right); - writeDouble(bottom); - writeDouble(top); - writeDouble(zNear); - writeDouble(zFar); - } - - public void writeFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { - ensureCapacity(52); - writeInt(GLCommand.FRUSTUM); - writeDouble(left); - writeDouble(right); - writeDouble(bottom); - writeDouble(top); - writeDouble(zNear); - writeDouble(zFar); - } - - // === Matrix commands === - - public void writeMultMatrix(Matrix4f matrix) { - ensureCapacity(68); - writeInt(GLCommand.MULT_MATRIX); - writeMatrix4f(matrix); - } - - public void writeLoadMatrix(Matrix4f matrix) { - ensureCapacity(68); - writeInt(GLCommand.LOAD_MATRIX); - writeMatrix4f(matrix); - } - - /** - * Write a Matrix4f to the buffer in column-major order (OpenGL convention). - * Uses accessor methods instead of getToAddress() to avoid JOML MemUtil issues. - */ - private void writeMatrix4f(Matrix4f m) { - // Column 0 - writeFloat(m.m00()); writeFloat(m.m01()); writeFloat(m.m02()); writeFloat(m.m03()); - // Column 1 - writeFloat(m.m10()); writeFloat(m.m11()); writeFloat(m.m12()); writeFloat(m.m13()); - // Column 2 - writeFloat(m.m20()); writeFloat(m.m21()); writeFloat(m.m22()); writeFloat(m.m23()); - // Column 3 - writeFloat(m.m30()); writeFloat(m.m31()); writeFloat(m.m32()); writeFloat(m.m33()); - } - - // === Buffer commands (inline 4 floats) === - - public void writeFog(int pname, FloatBuffer params) { - final int count = Math.min(params.remaining(), 4); - ensureCapacity(12 + count * 4); - writeInt(GLCommand.FOG); - writeInt(pname); - writeInt(count); - final int pos = params.position(); - for (int i = 0; i < count; i++) { - writeFloat(params.get(pos + i)); - } - } - - public void writeLight(int light, int pname, FloatBuffer params) { - final int count = Math.min(params.remaining(), 4); - ensureCapacity(16 + count * 4); - writeInt(GLCommand.LIGHT); - writeInt(light); - writeInt(pname); - writeInt(count); - final int pos = params.position(); - for (int i = 0; i < count; i++) { - writeFloat(params.get(pos + i)); - } - } - - public void writeLightModel(int pname, FloatBuffer params) { - final int count = Math.min(params.remaining(), 4); - ensureCapacity(12 + count * 4); - writeInt(GLCommand.LIGHT_MODEL); - writeInt(pname); - writeInt(count); - final int pos = params.position(); - for (int i = 0; i < count; i++) { - writeFloat(params.get(pos + i)); - } - } - - public void writeMaterial(int face, int pname, FloatBuffer params) { - final int count = Math.min(params.remaining(), 4); - ensureCapacity(16 + count * 4); - writeInt(GLCommand.MATERIAL); - writeInt(face); - writeInt(pname); - writeInt(count); - final int pos = params.position(); - for (int i = 0; i < count; i++) { - writeFloat(params.get(pos + i)); - } - } - - public void writeClipPlane(int plane, double a, double b, double c, double d) { - ensureCapacity(40); - writeInt(GLCommand.CLIP_PLANE); - writeInt(plane); - writeDouble(a); - writeDouble(b); - writeDouble(c); - writeDouble(d); - } - - // === Draw commands === - - public void writeDrawRange(int vboIndex) { - ensureCapacity(8); - writeInt(GLCommand.DRAW_RANGE); - writeInt(vboIndex); - } - - /** - * Write a DRAW_RANGE_RESTORE command that draws a VBO range and restores GL current state after. - * Used for immediate mode VBOs to restore GL_CURRENT_COLOR, GL_CURRENT_NORMAL, GL_CURRENT_TEXTURE_COORDS. - * - * @param vboIndex Index into ownedVbos array - */ - public void writeDrawRangeRestore( - int vboIndex, AccumulatedDraw.RestoreData restoreData - ) { - ensureCapacity(28); - writeInt(GLCommand.DRAW_RANGE_RESTORE); - writeInt(vboIndex); - writeInt(restoreData.flags); - // Last color (4 bytes) - writeInt(restoreData.lastColor); - // Last normal (4 bytes) - writeInt(restoreData.lastNormal); - // Last texcoord (2 floats = 8 bytes) - writeFloat(restoreData.lastTexCoordU); - writeFloat(restoreData.lastTexCoordV); - } - - public void writeCallList(int listId) { - ensureCapacity(8); - writeInt(GLCommand.CALL_LIST); - writeInt(listId); - } - - public void writeBindVBO(int vbo) { - ensureCapacity(8); - writeInt(GLCommand.BIND_VBO); - writeInt(vbo); - } - - public void writeBindVAO(int vao) { - ensureCapacity(8); - writeInt(GLCommand.BIND_VAO); - writeInt(vao); - } - - public void writeDrawBuffer(int mode) { - ensureCapacity(8); - writeInt(GLCommand.DRAW_BUFFER); - writeInt(mode); - } - - private static final int MAX_DRAW_BUFFERS = 8; - // cmd (4) + count (4) + buffers (4 * MAX_DRAW_BUFFERS) - private static final int DRAW_BUFFERS_SIZE = 4 + 4 + 4 * MAX_DRAW_BUFFERS; - - public void writeDrawBuffers(int count, int buffer) { - ensureCapacity(DRAW_BUFFERS_SIZE); - writeInt(GLCommand.DRAW_BUFFERS); - writeInt(count); - writeInt(buffer); - for (int i = 1; i < MAX_DRAW_BUFFERS; i++) { - writeInt(0); - } - } - - public void writeDrawBuffers(int count, IntBuffer bufs) { - ensureCapacity(DRAW_BUFFERS_SIZE); - writeInt(GLCommand.DRAW_BUFFERS); - writeInt(count); - final int pos = bufs.position(); - for (int i = 0; i < count && i < MAX_DRAW_BUFFERS; i++) { - writeInt(bufs.get(pos + i)); - } - for (int i = count; i < MAX_DRAW_BUFFERS; i++) { - writeInt(0); - } - } - - // === Complex object reference === - - public void writeComplexRef(DisplayListCommand cmd) { - ensureCapacity(8); - final int index = complexObjects.size(); - complexObjects.add(cmd); - writeInt(GLCommand.COMPLEX_REF); - writeInt(index); - } - - // === Reading methods for optimization pass === - - private long readPointer = 0; - - /** - * Reset read position to the beginning of the buffer. - */ - public void resetRead() { - readPointer = basePointer; - } - - /** - * Check if there's more data to read. - */ - public boolean hasRemaining() { - return readPointer < writePointer; - } - - /** - * Read an int from the current position. - */ - public int readInt() { - final int value = memGetInt(readPointer); - readPointer += 4; - return value; - } - - public long readLong() { - final long value = memGetLong(readPointer); - readPointer += 8; - return value; - } - - /** - * Read a float from the current position. - */ - public float readFloat() { - final float value = memGetFloat(readPointer); - readPointer += 4; - return value; - } - - /** - * Read a double from the current position. - */ - public double readDouble() { - final double value = memGetDouble(readPointer); - readPointer += 8; - return value; - } - - /** - * Read a Matrix4f from the current position (16 floats in column-major order). - */ - public Matrix4f readMatrix4f(Matrix4f dest) { - dest.m00(readFloat()); dest.m01(readFloat()); dest.m02(readFloat()); dest.m03(readFloat()); - dest.m10(readFloat()); dest.m11(readFloat()); dest.m12(readFloat()); dest.m13(readFloat()); - dest.m20(readFloat()); dest.m21(readFloat()); dest.m22(readFloat()); dest.m23(readFloat()); - dest.m30(readFloat()); dest.m31(readFloat()); dest.m32(readFloat()); dest.m33(readFloat()); - return dest; - } - - // === Lifecycle === - - public int size() { - return (int) (writePointer - basePointer); - } - - public long address() { - return basePointer; - } - - public ByteBuffer toBuffer() { - buffer.limit(size()); - buffer.position(0); - return buffer; - } - - public Object[] getComplexObjects() { - return complexObjects.toArray(); - } - - public Object getComplexObject(int index) { - return complexObjects.get(index); - } - - public boolean isEmpty() { - return size() == 0 && complexObjects.isEmpty(); - } - - /** - * Clear the buffer for reuse. Does NOT free memory. - */ - public void clear() { - writePointer = basePointer; - complexObjects.clear(); - } - - /** - * Free the underlying buffer. Must be called when done. - */ - public void free() { - if (buffer != null) { - memFree(buffer); - buffer = null; - basePointer = 0; - writePointer = 0; - } - } -} diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferExecutor.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferExecutor.java index f9089d196..5be11a786 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferExecutor.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferExecutor.java @@ -1,12 +1,10 @@ package com.gtnewhorizons.angelica.glsm.recording; -import com.gtnewhorizon.gtnhlib.client.opengl.UniversalVAO; import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFlags; import com.gtnewhorizons.angelica.glsm.DisplayListManager; import com.gtnewhorizons.angelica.glsm.GLStateManager; import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import java.nio.ByteBuffer; @@ -14,7 +12,10 @@ import java.nio.DoubleBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; -import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memAddress; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetDouble; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetFloat; +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.memGetInt; /** * Executes commands from a CommandBuffer @@ -39,7 +40,13 @@ public final class CommandBufferExecutor { * @param complexObjects Array of complex objects (TexImage2DCmd, etc.) * @param ownedVbos Array of VBOs owned by the display list (indexed by DrawRange commands) */ - public static void execute(ByteBuffer buffer, Object[] complexObjects, DisplayListVBO ownedVbos) { + public static void execute( + ByteBuffer buffer, + DisplayListCommand[] complexObjects, + DisplayListVBO ownedVbos, + int list, + CompiledDisplayList compiledDisplayList + ) { long ptr = memAddress(buffer); final long end = ptr + buffer.limit(); @@ -343,50 +350,6 @@ public final class CommandBufferExecutor { GLStateManager.glTexParameterf(target, pname, param); } - // === Double commands === - case GLCommand.TRANSLATE -> { - final double x = memGetDouble(ptr); - final double y = memGetDouble(ptr + 8); - final double z = memGetDouble(ptr + 16); - ptr += 24; - GLStateManager.glTranslated(x, y, z); - } - case GLCommand.ROTATE -> { - final double angle = memGetDouble(ptr); - final double x = memGetDouble(ptr + 8); - final double y = memGetDouble(ptr + 16); - final double z = memGetDouble(ptr + 24); - ptr += 32; - GLStateManager.glRotated(angle, x, y, z); - } - case GLCommand.SCALE -> { - final double x = memGetDouble(ptr); - final double y = memGetDouble(ptr + 8); - final double z = memGetDouble(ptr + 16); - ptr += 24; - GLStateManager.glScaled(x, y, z); - } - case GLCommand.ORTHO -> { - final double left = memGetDouble(ptr); - final double right = memGetDouble(ptr + 8); - final double bottom = memGetDouble(ptr + 16); - final double top = memGetDouble(ptr + 24); - final double zNear = memGetDouble(ptr + 32); - final double zFar = memGetDouble(ptr + 40); - ptr += 48; - GLStateManager.glOrtho(left, right, bottom, top, zNear, zFar); - } - case GLCommand.FRUSTUM -> { - final double left = memGetDouble(ptr); - final double right = memGetDouble(ptr + 8); - final double bottom = memGetDouble(ptr + 16); - final double top = memGetDouble(ptr + 24); - final double zNear = memGetDouble(ptr + 32); - final double zFar = memGetDouble(ptr + 40); - ptr += 48; - GLStateManager.glFrustum(left, right, bottom, top, zNear, zFar); - } - // === Matrix commands === case GLCommand.MULT_MATRIX -> { // Mode-agnostic: just multiply current matrix @@ -398,6 +361,20 @@ public final class CommandBufferExecutor { MATRIX_BUFFER.flip(); GLStateManager.glMultMatrix(MATRIX_BUFFER); } + case GLCommand.TRANSLATE -> { + final float x = memGetFloat(ptr); + final float y = memGetFloat(ptr + 4); + final float z = memGetFloat(ptr + 8); + ptr += 12; + GLStateManager.glTranslatef(x, y, z); + } + case GLCommand.SCALE -> { + final float x = memGetFloat(ptr); + final float y = memGetFloat(ptr + 4); + final float z = memGetFloat(ptr + 8); + ptr += 12; + GLStateManager.glScalef(x, y, z); + } case GLCommand.LOAD_MATRIX -> { MATRIX_BUFFER.clear(); for (int i = 0; i < 16; i++) { @@ -543,10 +520,10 @@ public final class CommandBufferExecutor { case GLCommand.COMPLEX_REF -> { final int index = memGetInt(ptr); ptr += 4; - ((DisplayListCommand) complexObjects[index]).execute(); + complexObjects[index].execute(); } - default -> throw new IllegalStateException("Unknown command opcode: " + cmd); + default -> throw new IllegalStateException("Unknown command opcode: " + cmd + " in display list with ID " + list + "\n" + DisplayListManager.getCompiledDisplayListString(list, compiledDisplayList, null)); } } } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java deleted file mode 100644 index 891b27ab8..000000000 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandBufferProcessor.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.gtnewhorizons.angelica.glsm.recording; - -import com.gtnewhorizons.angelica.glsm.GLStateManager; -import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; -import org.joml.Matrix4f; - -import java.nio.FloatBuffer; - -public final class CommandBufferProcessor { - private static final Matrix4f tempMatrix = new Matrix4f(); - - private CommandBufferProcessor() {} - - /** - * Copy a complete command (opcode already read) from raw to final buffer. - */ - public static void copyCommand(CommandBuffer raw, CommandBuffer out) { - final int opcode = raw.readInt(); - copyCommandData(opcode, raw, out); - } - - /** - * Copy command data based on opcode (opcode already consumed from raw). - */ - public static void copyCommandData(int opcode, CommandBuffer raw, CommandBuffer out) { - switch (opcode) { - // Single int commands - case GLCommand.ENABLE -> out.writeEnable(raw.readInt()); - case GLCommand.DISABLE -> out.writeDisable(raw.readInt()); - case GLCommand.CLEAR -> out.writeClear(raw.readInt()); - case GLCommand.CLEAR_STENCIL -> out.writeClearStencil(raw.readInt()); - case GLCommand.CULL_FACE -> out.writeCullFace(raw.readInt()); - case GLCommand.DEPTH_FUNC -> out.writeDepthFunc(raw.readInt()); - case GLCommand.SHADE_MODEL -> out.writeShadeModel(raw.readInt()); - case GLCommand.LOGIC_OP -> out.writeLogicOp(raw.readInt()); - case GLCommand.MATRIX_MODE -> out.writeMatrixMode(raw.readInt()); - case GLCommand.ACTIVE_TEXTURE -> out.writeActiveTexture(raw.readInt()); - case GLCommand.USE_PROGRAM -> out.writeUseProgram(raw.readInt()); - case GLCommand.PUSH_ATTRIB -> out.writePushAttrib(raw.readInt()); - case GLCommand.POP_ATTRIB -> { raw.readInt(); out.writePopAttrib(); } - case GLCommand.LOAD_IDENTITY -> out.writeLoadIdentity(); - case GLCommand.PUSH_MATRIX -> out.writePushMatrix(); - case GLCommand.POP_MATRIX -> out.writePopMatrix(); - case GLCommand.STENCIL_MASK -> out.writeStencilMask(raw.readInt()); - case GLCommand.DEPTH_MASK -> out.writeDepthMask(raw.readInt() != 0); - case GLCommand.FRONT_FACE -> out.writeFrontFace(raw.readInt()); - - // Two int commands - case GLCommand.BIND_TEXTURE -> out.writeBindTexture(raw.readInt(), raw.readInt()); - case GLCommand.POLYGON_MODE -> out.writePolygonMode(raw.readInt(), raw.readInt()); - case GLCommand.COLOR_MATERIAL -> out.writeColorMaterial(raw.readInt(), raw.readInt()); - case GLCommand.LINE_STIPPLE -> out.writeLineStipple(raw.readInt(), raw.readInt()); - case GLCommand.STENCIL_MASK_SEPARATE -> out.writeStencilMaskSeparate(raw.readInt(), raw.readInt()); - case GLCommand.FOGI -> out.writeFogi(raw.readInt(), raw.readInt()); - case GLCommand.HINT -> out.writeHint(raw.readInt(), raw.readInt()); - - // Three int commands - case GLCommand.STENCIL_FUNC -> out.writeStencilFunc(raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.STENCIL_OP -> out.writeStencilOp(raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.TEX_PARAMETERI -> out.writeTexParameteri(raw.readInt(), raw.readInt(), raw.readInt()); - - // Four int commands - case GLCommand.VIEWPORT -> out.writeViewport(raw.readInt(), raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.SCISSOR -> out.writeScissor(raw.readInt(), raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.BLEND_FUNC -> out.writeBlendFunc(raw.readInt(), raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.COLOR_MASK -> out.writeColorMask(raw.readInt() != 0, raw.readInt() != 0, raw.readInt() != 0, raw.readInt() != 0); - case GLCommand.STENCIL_FUNC_SEPARATE -> out.writeStencilFuncSeparate(raw.readInt(), raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.STENCIL_OP_SEPARATE -> out.writeStencilOpSeparate(raw.readInt(), raw.readInt(), raw.readInt(), raw.readInt()); - - // Float commands - case GLCommand.POINT_SIZE -> out.writePointSize(raw.readFloat()); - case GLCommand.LINE_WIDTH -> out.writeLineWidth(raw.readFloat()); - case GLCommand.POLYGON_OFFSET -> out.writePolygonOffset(raw.readFloat(), raw.readFloat()); - 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()); - - // Four float commands - case GLCommand.BLEND_COLOR -> out.writeBlendColor(raw.readFloat(), raw.readFloat(), raw.readFloat(), raw.readFloat()); - - // Mixed int+float commands - case GLCommand.ALPHA_FUNC -> out.writeAlphaFunc(raw.readInt(), raw.readFloat()); - case GLCommand.FOGF -> out.writeFogf(raw.readInt(), raw.readFloat()); - case GLCommand.LIGHTF -> out.writeLightf(raw.readInt(), raw.readInt(), raw.readFloat()); - case GLCommand.LIGHT_MODELF -> out.writeLightModelf(raw.readInt(), raw.readFloat()); - case GLCommand.LIGHTI -> out.writeLighti(raw.readInt(), raw.readInt(), raw.readInt()); - case GLCommand.LIGHT_MODELI -> out.writeLightModeli(raw.readInt(), raw.readInt()); - case GLCommand.MATERIALF -> out.writeMaterialf(raw.readInt(), raw.readInt(), raw.readFloat()); - case GLCommand.TEX_PARAMETERF -> out.writeTexParameterf(raw.readInt(), raw.readInt(), raw.readFloat()); - - // Double commands - case GLCommand.TRANSLATE -> out.writeTranslate(raw.readDouble(), raw.readDouble(), raw.readDouble()); - case GLCommand.ROTATE -> out.writeRotate(raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble()); - case GLCommand.SCALE -> out.writeScale(raw.readDouble(), raw.readDouble(), raw.readDouble()); - case GLCommand.ORTHO -> out.writeOrtho(raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble()); - case GLCommand.FRUSTUM -> out.writeFrustum(raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble(), raw.readDouble()); - - // Matrix commands - case GLCommand.MULT_MATRIX -> { out.writeMultMatrix(raw.readMatrix4f(tempMatrix)); } - case GLCommand.LOAD_MATRIX -> { out.writeLoadMatrix(raw.readMatrix4f(tempMatrix)); } - - // FloatBuffer commands (inline 4 floats max) - case GLCommand.FOG -> { - final int pname = raw.readInt(); - final int count = raw.readInt(); - final FloatBuffer fb = FloatBuffer.allocate(count); - for (int i = 0; i < count; i++) fb.put(raw.readFloat()); - fb.flip(); - out.writeFog(pname, fb); - } - case GLCommand.LIGHT -> { - final int light = raw.readInt(); - final int pname = raw.readInt(); - final int count = raw.readInt(); - final FloatBuffer fb = FloatBuffer.allocate(count); - for (int i = 0; i < count; i++) fb.put(raw.readFloat()); - fb.flip(); - out.writeLight(light, pname, fb); - } - case GLCommand.LIGHT_MODEL -> { - final int pname = raw.readInt(); - final int count = raw.readInt(); - final FloatBuffer fb = FloatBuffer.allocate(count); - for (int i = 0; i < count; i++) fb.put(raw.readFloat()); - fb.flip(); - out.writeLightModel(pname, fb); - } - case GLCommand.MATERIAL -> { - final int face = raw.readInt(); - final int pname = raw.readInt(); - final int count = raw.readInt(); - final FloatBuffer fb = FloatBuffer.allocate(count); - for (int i = 0; i < count; i++) fb.put(raw.readFloat()); - fb.flip(); - out.writeMaterial(face, pname, fb); - } - - // Clip plane command (4 doubles) - case GLCommand.CLIP_PLANE -> { - final int plane = raw.readInt(); - final double a = raw.readDouble(); - final double b = raw.readDouble(); - final double c = raw.readDouble(); - final double d = raw.readDouble(); - out.writeClipPlane(plane, a, b, c, d); - } - - // Draw/call commands - case GLCommand.DRAW_RANGE -> out.writeDrawRange(raw.readInt()); - case GLCommand.CALL_LIST -> out.writeCallList(raw.readInt()); - case GLCommand.BIND_VBO -> out.writeBindVBO(raw.readInt()); - case GLCommand.BIND_VAO -> out.writeBindVAO(raw.readInt()); - - // Complex object reference - transfer the object to output buffer - case GLCommand.COMPLEX_REF -> { - final int index = raw.readInt(); - final Object obj = raw.getComplexObject(index); - out.writeComplexRef((DisplayListCommand) obj); - } - - default -> GLStateManager.LOGGER.warn("[CommandBufferProcessor] Unknown opcode in buffer copy: {}", opcode); - } - } -} diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandRecorder.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandRecorder.java index d3a15b5d1..bb98c2c01 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandRecorder.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CommandRecorder.java @@ -4,376 +4,688 @@ import com.gtnewhorizons.angelica.glsm.recording.commands.DisplayListCommand; import com.gtnewhorizons.angelica.glsm.recording.commands.IndexedDrawBatchBuilder; import com.gtnewhorizons.angelica.glsm.recording.commands.IndexedDrawCapture; import org.joml.Matrix4f; +import org.joml.Vector3f; +import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.util.ArrayList; + +import static com.gtnewhorizon.gtnhlib.bytebuf.MemoryUtilities.*; -/** - * Records GL commands to a CommandBuffer during display list compilation. - */ public final class CommandRecorder { - private final CommandBuffer buffer; + private static final int DEFAULT_CAPACITY = 2048; // Guess at typical display list size + + private ByteBuffer buffer; + private long basePointer; + private long writePointer; + private final ArrayList complexObjects = new ArrayList<>(); private final IndexedDrawBatchBuilder indexedDraws = new IndexedDrawBatchBuilder(); - private int commandCount; public CommandRecorder() { - this.buffer = new CommandBuffer(); - this.commandCount = 0; + this(DEFAULT_CAPACITY); } - public CommandBuffer getBuffer() { - return buffer; + public CommandRecorder(int initialCapacity) { + this.buffer = memAlloc(initialCapacity); + this.basePointer = memAddress0(buffer); + this.writePointer = basePointer; } - public int getCommandCount() { - return commandCount; + // === Low-level write operations === + + private void writeInt(int value) { + memPutInt(writePointer, value); + writePointer += 4; + } + + private void writeLong(long value) { + memPutLong(writePointer, value); + writePointer += 8; + } + + private void writeFloat(float value) { + memPutFloat(writePointer, value); + writePointer += 4; + } + + private void writeDouble(double value) { + memPutDouble(writePointer, value); + writePointer += 8; + } + + private void ensureCapacity(int needed) { + final int size = size(); + final int remaining = buffer.capacity() - size; + if (remaining < needed) { + final int newCapacity = Math.max(buffer.capacity() * 2, buffer.capacity() + needed); + buffer = memRealloc(buffer, newCapacity); + basePointer = memAddress0(buffer); + writePointer = basePointer + size; + } } public IndexedDrawBatchBuilder getIndexedDraws() { return indexedDraws; } - public void recordIndexedDrawCapture(IndexedDrawCapture capture) { + public void writeIndexedDrawCapture(IndexedDrawCapture capture) { indexedDraws.add(capture); - recordComplexCommand(capture.placeholder); + writeComplexCommand(capture.placeholder); } public void free() { for (IndexedDrawCapture c : indexedDraws.getCaptures()) { c.freeBuffers(); } - buffer.free(); } - // ==================== Recording Methods ==================== + // === Single int commands === - public void recordEnable(int cap) { - buffer.writeEnable(cap); - commandCount++; + public void writeEnable(int cap) { + ensureCapacity(8); + writeInt(GLCommand.ENABLE); + writeInt(cap); } - public void recordDisable(int cap) { - buffer.writeDisable(cap); - commandCount++; + public void writeDisable(int cap) { + ensureCapacity(8); + writeInt(GLCommand.DISABLE); + writeInt(cap); } - public void recordClear(int mask) { - buffer.writeClear(mask); - commandCount++; + public void writeClear(int mask) { + ensureCapacity(8); + writeInt(GLCommand.CLEAR); + writeInt(mask); } - public void recordClearColor(float r, float g, float b, float a) { - buffer.writeClearColor(r, g, b, a); - commandCount++; + public void writeClearStencil(int s) { + ensureCapacity(8); + writeInt(GLCommand.CLEAR_STENCIL); + writeInt(s); } - public void recordClearDepth(double depth) { - buffer.writeClearDepth(depth); - commandCount++; + public void writeCullFace(int mode) { + ensureCapacity(8); + writeInt(GLCommand.CULL_FACE); + writeInt(mode); } - public void recordBlendColor(float r, float g, float b, float a) { - buffer.writeBlendColor(r, g, b, a); - commandCount++; + public void writeDepthFunc(int func) { + ensureCapacity(8); + writeInt(GLCommand.DEPTH_FUNC); + writeInt(func); } - public void recordClearStencil(int s) { - buffer.writeClearStencil(s); - commandCount++; + public void writeShadeModel(int mode) { + ensureCapacity(8); + writeInt(GLCommand.SHADE_MODEL); + writeInt(mode); } - public void recordColor(float r, float g, float b, float a) { - buffer.writeColor(r, g, b, a); - commandCount++; + public void writeLogicOp(int opcode) { + ensureCapacity(8); + writeInt(GLCommand.LOGIC_OP); + writeInt(opcode); } - public void recordColorMask(boolean r, boolean g, boolean b, boolean a) { - buffer.writeColorMask(r, g, b, a); - commandCount++; + public void writeMatrixMode(int mode) { + ensureCapacity(8); + writeInt(GLCommand.MATRIX_MODE); + writeInt(mode); } - public void recordDepthMask(boolean flag) { - buffer.writeDepthMask(flag); - commandCount++; + public void writeActiveTexture(int texture) { + ensureCapacity(8); + writeInt(GLCommand.ACTIVE_TEXTURE); + writeInt(texture); } - public void recordFrontFace(int mode) { - buffer.writeFrontFace(mode); - commandCount++; + public void writeUseProgram(int program) { + ensureCapacity(8); + writeInt(GLCommand.USE_PROGRAM); + writeInt(program); } - public void recordDepthFunc(int func) { - buffer.writeDepthFunc(func); - commandCount++; + public void writePushAttrib(int mask) { + ensureCapacity(8); + writeInt(GLCommand.PUSH_ATTRIB); + writeInt(mask); } - public void recordBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) { - buffer.writeBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha); - commandCount++; + public void writePopAttrib() { + ensureCapacity(8); + writeInt(GLCommand.POP_ATTRIB); + writeInt(0); // unused padding } - public void recordAlphaFunc(int func, float ref) { - buffer.writeAlphaFunc(func, ref); - commandCount++; + public void writeLoadIdentity() { + ensureCapacity(4); + writeInt(GLCommand.LOAD_IDENTITY); } - public void recordCullFace(int mode) { - buffer.writeCullFace(mode); - commandCount++; + public void writePushMatrix() { + ensureCapacity(4); + writeInt(GLCommand.PUSH_MATRIX); } - public void recordShadeModel(int mode) { - buffer.writeShadeModel(mode); - commandCount++; + public void writePopMatrix() { + ensureCapacity(4); + writeInt(GLCommand.POP_MATRIX); } - public void recordBindTexture(int target, int texture) { - buffer.writeBindTexture(target, texture); - commandCount++; + public void writeStencilMask(int mask) { + ensureCapacity(8); + writeInt(GLCommand.STENCIL_MASK); + writeInt(mask); } - public void recordTexParameteri(int target, int pname, int param) { - buffer.writeTexParameteri(target, pname, param); - commandCount++; + public void writeDepthMask(boolean flag) { + ensureCapacity(8); + writeInt(GLCommand.DEPTH_MASK); + writeInt(flag ? 1 : 0); } - public void recordTexParameterf(int target, int pname, float param) { - buffer.writeTexParameterf(target, pname, param); - commandCount++; + public void writeFrontFace(int mode) { + ensureCapacity(8); + writeInt(GLCommand.FRONT_FACE); + writeInt(mode); } - public void recordMatrixMode(int mode) { - buffer.writeMatrixMode(mode); - commandCount++; - } + // === Two int commands === - public void recordLoadIdentity() { - buffer.writeLoadIdentity(); - commandCount++; + public void writeBindTexture(int target, int texture) { + ensureCapacity(12); + writeInt(GLCommand.BIND_TEXTURE); + writeInt(target); + writeInt(texture); } - public void recordPushMatrix() { - buffer.writePushMatrix(); - commandCount++; + public void writePolygonMode(int face, int mode) { + ensureCapacity(12); + writeInt(GLCommand.POLYGON_MODE); + writeInt(face); + writeInt(mode); } - public void recordPopMatrix() { - buffer.writePopMatrix(); - commandCount++; + public void writeColorMaterial(int face, int mode) { + ensureCapacity(12); + writeInt(GLCommand.COLOR_MATERIAL); + writeInt(face); + writeInt(mode); } - public void recordMultMatrix(Matrix4f matrix) { - buffer.writeMultMatrix(matrix); - commandCount++; + public void writeLineStipple(int factor, int pattern) { + ensureCapacity(12); + writeInt(GLCommand.LINE_STIPPLE); + writeInt(factor); + writeInt(pattern); } - public void recordLoadMatrix(Matrix4f matrix) { - buffer.writeLoadMatrix(matrix); - commandCount++; + public void writeStencilMaskSeparate(int face, int mask) { + ensureCapacity(12); + writeInt(GLCommand.STENCIL_MASK_SEPARATE); + writeInt(face); + writeInt(mask); } - public void recordOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { - buffer.writeOrtho(left, right, bottom, top, zNear, zFar); - commandCount++; + public void writeFogi(int pname, int param) { + ensureCapacity(12); + writeInt(GLCommand.FOGI); + writeInt(pname); + writeInt(param); } - public void recordFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { - buffer.writeFrustum(left, right, bottom, top, zNear, zFar); - commandCount++; + public void writeHint(int target, int mode) { + ensureCapacity(12); + writeInt(GLCommand.HINT); + writeInt(target); + writeInt(mode); } - public void recordViewport(int x, int y, int width, int height) { - buffer.writeViewport(x, y, width, height); - commandCount++; - } + // === Three int commands === - public void recordScissor(int x, int y, int width, int height) { - buffer.writeScissor(x, y, width, height); - commandCount++; + public void writeStencilFunc(int func, int ref, int mask) { + ensureCapacity(16); + writeInt(GLCommand.STENCIL_FUNC); + writeInt(func); + writeInt(ref); + writeInt(mask); } - public void recordPointSize(float size) { - buffer.writePointSize(size); - commandCount++; + public void writeStencilOp(int fail, int zfail, int zpass) { + ensureCapacity(16); + writeInt(GLCommand.STENCIL_OP); + writeInt(fail); + writeInt(zfail); + writeInt(zpass); } - public void recordLineWidth(float width) { - buffer.writeLineWidth(width); - commandCount++; + public void writeTexParameteri(int target, int pname, int param) { + ensureCapacity(16); + writeInt(GLCommand.TEX_PARAMETERI); + writeInt(target); + writeInt(pname); + writeInt(param); } - public void recordLineStipple(int factor, int pattern) { - buffer.writeLineStipple(factor, pattern); - commandCount++; - } - - public void recordPolygonOffset(float factor, float units) { - buffer.writePolygonOffset(factor, units); - commandCount++; - } + // === Four int commands === - public void recordPolygonMode(int face, int mode) { - buffer.writePolygonMode(face, mode); - commandCount++; + public void writeViewport(int x, int y, int width, int height) { + ensureCapacity(20); + writeInt(GLCommand.VIEWPORT); + writeInt(x); + writeInt(y); + writeInt(width); + writeInt(height); } - public void recordColorMaterial(int face, int mode) { - buffer.writeColorMaterial(face, mode); - commandCount++; + public void writeScissor(int x, int y, int width, int height) { + ensureCapacity(20); + writeInt(GLCommand.SCISSOR); + writeInt(x); + writeInt(y); + writeInt(width); + writeInt(height); } - public void recordLogicOp(int opcode) { - buffer.writeLogicOp(opcode); - commandCount++; + public void writeBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) { + ensureCapacity(20); + writeInt(GLCommand.BLEND_FUNC); + writeInt(srcRgb); + writeInt(dstRgb); + writeInt(srcAlpha); + writeInt(dstAlpha); } - public void recordActiveTexture(int texture) { - buffer.writeActiveTexture(texture); - commandCount++; + public void writeColorMask(boolean red, boolean green, boolean blue, boolean alpha) { + ensureCapacity(20); + writeInt(GLCommand.COLOR_MASK); + writeInt(red ? 1 : 0); + writeInt(green ? 1 : 0); + writeInt(blue ? 1 : 0); + writeInt(alpha ? 1 : 0); } - public void recordUseProgram(int program) { - buffer.writeUseProgram(program); - commandCount++; + public void writeStencilFuncSeparate(int face, int func, int ref, int mask) { + ensureCapacity(20); + writeInt(GLCommand.STENCIL_FUNC_SEPARATE); + writeInt(face); + writeInt(func); + writeInt(ref); + writeInt(mask); } - public void recordPushAttrib(int mask) { - buffer.writePushAttrib(mask); - commandCount++; + public void writeStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { + ensureCapacity(20); + writeInt(GLCommand.STENCIL_OP_SEPARATE); + writeInt(face); + writeInt(sfail); + writeInt(dpfail); + writeInt(dppass); } - public void recordPopAttrib() { - buffer.writePopAttrib(); - commandCount++; - } + // === Float commands === - public void recordFogf(int pname, float param) { - buffer.writeFogf(pname, param); - commandCount++; + public void writePointSize(float size) { + ensureCapacity(8); + writeInt(GLCommand.POINT_SIZE); + writeFloat(size); } - public void recordFogi(int pname, int param) { - buffer.writeFogi(pname, param); - commandCount++; + public void writeLineWidth(float width) { + ensureCapacity(8); + writeInt(GLCommand.LINE_WIDTH); + writeFloat(width); } - public void recordHint(int target, int mode) { - buffer.writeHint(target, mode); - commandCount++; + public void writePolygonOffset(float factor, float units) { + ensureCapacity(12); + writeInt(GLCommand.POLYGON_OFFSET); + writeFloat(factor); + writeFloat(units); } - public void recordFog(int pname, FloatBuffer params) { - buffer.writeFog(pname, params); - commandCount++; + public void writeColor(float r, float g, float b, float a) { + ensureCapacity(20); + writeInt(GLCommand.COLOR); + writeFloat(r); + writeFloat(g); + writeFloat(b); + writeFloat(a); } - public void recordLightf(int light, int pname, float param) { - buffer.writeLightf(light, pname, param); - commandCount++; + public void writeClearColor(float r, float g, float b, float a) { + ensureCapacity(20); + writeInt(GLCommand.CLEAR_COLOR); + writeFloat(r); + writeFloat(g); + writeFloat(b); + writeFloat(a); } - public void recordLighti(int light, int pname, int param) { - buffer.writeLighti(light, pname, param); - commandCount++; + public void writeClearDepth(double depth) { + ensureCapacity(12); + writeInt(GLCommand.CLEAR_DEPTH); + writeDouble(depth); } - public void recordLight(int light, int pname, FloatBuffer params) { - buffer.writeLight(light, pname, params); - commandCount++; + public void writeBlendColor(float r, float g, float b, float a) { + ensureCapacity(20); + writeInt(GLCommand.BLEND_COLOR); + writeFloat(r); + writeFloat(g); + writeFloat(b); + writeFloat(a); } - public void recordLightModelf(int pname, float param) { - buffer.writeLightModelf(pname, param); - commandCount++; - } + // === Mixed int+float commands === - public void recordLightModeli(int pname, int param) { - buffer.writeLightModeli(pname, param); - commandCount++; + public void writeAlphaFunc(int func, float ref) { + ensureCapacity(12); + writeInt(GLCommand.ALPHA_FUNC); + writeInt(func); + writeFloat(ref); } - public void recordLightModel(int pname, FloatBuffer params) { - buffer.writeLightModel(pname, params); - commandCount++; + public void writeFogf(int pname, float param) { + ensureCapacity(12); + writeInt(GLCommand.FOGF); + writeInt(pname); + writeFloat(param); } - public void recordMaterialf(int face, int pname, float val) { - buffer.writeMaterialf(face, pname, val); - commandCount++; + public void writeLightf(int light, int pname, float param) { + ensureCapacity(16); + writeInt(GLCommand.LIGHTF); + writeInt(light); + writeInt(pname); + writeFloat(param); } - public void recordMaterial(int face, int pname, FloatBuffer params) { - buffer.writeMaterial(face, pname, params); - commandCount++; + public void writeLightModelf(int pname, float param) { + ensureCapacity(12); + writeInt(GLCommand.LIGHT_MODELF); + writeInt(pname); + writeFloat(param); } - public void recordClipPlane(int plane, double a, double b, double c, double d) { - buffer.writeClipPlane(plane, a, b, c, d); - commandCount++; + public void writeLighti(int light, int pname, int param) { + ensureCapacity(16); + writeInt(GLCommand.LIGHTI); + writeInt(light); + writeInt(pname); + writeInt(param); } - public void recordStencilFunc(int func, int ref, int mask) { - buffer.writeStencilFunc(func, ref, mask); - commandCount++; + public void writeLightModeli(int pname, int param) { + ensureCapacity(12); + writeInt(GLCommand.LIGHT_MODELI); + writeInt(pname); + writeInt(param); } - public void recordStencilFuncSeparate(int face, int func, int ref, int mask) { - buffer.writeStencilFuncSeparate(face, func, ref, mask); - commandCount++; + public void writeMaterialf(int face, int pname, float param) { + ensureCapacity(16); + writeInt(GLCommand.MATERIALF); + writeInt(face); + writeInt(pname); + writeFloat(param); } - - public void recordStencilOp(int fail, int zfail, int zpass) { - buffer.writeStencilOp(fail, zfail, zpass); - commandCount++; + + public void writeTexParameterf(int target, int pname, float param) { + ensureCapacity(16); + writeInt(GLCommand.TEX_PARAMETERF); + writeInt(target); + writeInt(pname); + writeFloat(param); + } + + // === Transformation commands === + + public void writeTranslate(Vector3f translationVector) { + ensureCapacity(16); + writeInt(GLCommand.TRANSLATE); + writeFloat(translationVector.x); + writeFloat(translationVector.y); + writeFloat(translationVector.z); + } + + public void writeScale(Vector3f scaleVector) { + ensureCapacity(16); + writeInt(GLCommand.SCALE); + writeFloat(scaleVector.x); + writeFloat(scaleVector.y); + writeFloat(scaleVector.z); + } + + // === Matrix commands === + + public void writeMultMatrix(Matrix4f matrix) { + ensureCapacity(68); + writeInt(GLCommand.MULT_MATRIX); + writeMatrix4f(matrix); + } + + public void writeLoadMatrix(Matrix4f matrix) { + ensureCapacity(68); + writeInt(GLCommand.LOAD_MATRIX); + writeMatrix4f(matrix); + } + + /** + * Write a Matrix4f to the buffer in column-major order (OpenGL convention). + * Uses accessor methods instead of getToAddress() to avoid JOML MemUtil issues. + */ + private void writeMatrix4f(Matrix4f m) { + // Column 0 + writeFloat(m.m00()); writeFloat(m.m01()); writeFloat(m.m02()); writeFloat(m.m03()); + // Column 1 + writeFloat(m.m10()); writeFloat(m.m11()); writeFloat(m.m12()); writeFloat(m.m13()); + // Column 2 + writeFloat(m.m20()); writeFloat(m.m21()); writeFloat(m.m22()); writeFloat(m.m23()); + // Column 3 + writeFloat(m.m30()); writeFloat(m.m31()); writeFloat(m.m32()); writeFloat(m.m33()); + } + + // === Buffer commands (inline 4 floats) === + + public void writeFog(int pname, FloatBuffer params) { + final int count = Math.min(params.remaining(), 4); + ensureCapacity(12 + count * 4); + writeInt(GLCommand.FOG); + writeInt(pname); + writeInt(count); + final int pos = params.position(); + for (int i = 0; i < count; i++) { + writeFloat(params.get(pos + i)); + } + } + + public void writeLight(int light, int pname, FloatBuffer params) { + final int count = Math.min(params.remaining(), 4); + ensureCapacity(16 + count * 4); + writeInt(GLCommand.LIGHT); + writeInt(light); + writeInt(pname); + writeInt(count); + final int pos = params.position(); + for (int i = 0; i < count; i++) { + writeFloat(params.get(pos + i)); + } + } + + public void writeLightModel(int pname, FloatBuffer params) { + final int count = Math.min(params.remaining(), 4); + ensureCapacity(12 + count * 4); + writeInt(GLCommand.LIGHT_MODEL); + writeInt(pname); + writeInt(count); + final int pos = params.position(); + for (int i = 0; i < count; i++) { + writeFloat(params.get(pos + i)); + } + } + + public void writeMaterial(int face, int pname, FloatBuffer params) { + final int count = Math.min(params.remaining(), 4); + ensureCapacity(16 + count * 4); + writeInt(GLCommand.MATERIAL); + writeInt(face); + writeInt(pname); + writeInt(count); + final int pos = params.position(); + for (int i = 0; i < count; i++) { + writeFloat(params.get(pos + i)); + } + } + + public void writeClipPlane(int plane, double a, double b, double c, double d) { + ensureCapacity(40); + writeInt(GLCommand.CLIP_PLANE); + writeInt(plane); + writeDouble(a); + writeDouble(b); + writeDouble(c); + writeDouble(d); + } + + // === Draw commands === + + public void writeDrawRange(int vboIndex) { + ensureCapacity(8); + writeInt(GLCommand.DRAW_RANGE); + writeInt(vboIndex); + } + + /** + * Write a DRAW_RANGE_RESTORE command that draws a VBO range and restores GL current state after. + * Used for immediate mode VBOs to restore GL_CURRENT_COLOR, GL_CURRENT_NORMAL, GL_CURRENT_TEXTURE_COORDS. + * + * @param vboIndex Index into ownedVbos array + */ + public void writeDrawRangeRestore( + int vboIndex, AccumulatedDraw.RestoreData restoreData + ) { + ensureCapacity(28); + writeInt(GLCommand.DRAW_RANGE_RESTORE); + writeInt(vboIndex); + writeInt(restoreData.flags); + // Last color (4 bytes) + writeInt(restoreData.lastColor); + // Last normal (4 bytes) + writeInt(restoreData.lastNormal); + // Last texcoord (2 floats = 8 bytes) + writeFloat(restoreData.lastTexCoordU); + writeFloat(restoreData.lastTexCoordV); + } + + + public void writeCallList(int listId) { + ensureCapacity(8); + writeInt(GLCommand.CALL_LIST); + writeInt(listId); + } + + public void writeBindVBO(int vbo) { + ensureCapacity(8); + writeInt(GLCommand.BIND_VBO); + writeInt(vbo); + } + + public void writeBindVAO(int vao) { + ensureCapacity(8); + writeInt(GLCommand.BIND_VAO); + writeInt(vao); + } + + public void writeDrawBuffer(int mode) { + ensureCapacity(8); + writeInt(GLCommand.DRAW_BUFFER); + writeInt(mode); + } + + private static final int MAX_DRAW_BUFFERS = 8; + // cmd (4) + count (4) + buffers (4 * MAX_DRAW_BUFFERS) + private static final int DRAW_BUFFERS_SIZE = 4 + 4 + 4 * MAX_DRAW_BUFFERS; + + public void writeDrawBuffers(int count, int buffer) { + ensureCapacity(DRAW_BUFFERS_SIZE); + writeInt(GLCommand.DRAW_BUFFERS); + writeInt(count); + writeInt(buffer); + for (int i = 1; i < MAX_DRAW_BUFFERS; i++) { + writeInt(0); + } + } + + public void writeDrawBuffers(int count, IntBuffer bufs) { + ensureCapacity(DRAW_BUFFERS_SIZE); + writeInt(GLCommand.DRAW_BUFFERS); + writeInt(count); + final int pos = bufs.position(); + for (int i = 0; i < count && i < MAX_DRAW_BUFFERS; i++) { + writeInt(bufs.get(pos + i)); + } + for (int i = count; i < MAX_DRAW_BUFFERS; i++) { + writeInt(0); + } } - public void recordStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - buffer.writeStencilOpSeparate(face, sfail, dpfail, dppass); - commandCount++; - } + // === Complex object reference === - public void recordStencilMask(int mask) { - buffer.writeStencilMask(mask); - commandCount++; + public void writeComplexCommand(DisplayListCommand cmd) { + ensureCapacity(8); + final int index = complexObjects.size(); + complexObjects.add(cmd); + writeInt(GLCommand.COMPLEX_REF); + writeInt(index); } - public void recordStencilMaskSeparate(int face, int mask) { - buffer.writeStencilMaskSeparate(face, mask); - commandCount++; - } + // === Lifecycle === - public void recordCallList(int listId) { - buffer.writeCallList(listId); - commandCount++; + public int size() { + return (int) (writePointer - basePointer); } - public void recordDrawBuffer(int mode) { - buffer.writeDrawBuffer(mode); - commandCount++; + public void delete() { + for (IndexedDrawCapture c : indexedDraws.getCaptures()) { + c.freeBuffers(); + } + memFree(buffer); } - public void recordDrawBuffers(int count, int buf) { - buffer.writeDrawBuffers(count, buf); - commandCount++; + /** + * Deletes every allocated object & returns a ByteBuffer with the capacity equal to its limit. + * This CommandRecorder object cannot be used after calling this anymore. + */ + public ByteBuffer finish() { + for (IndexedDrawCapture c : indexedDraws.getCaptures()) { + c.freeBuffers(); + } + final int size = size(); + buffer.limit(size); + return memRealloc(buffer, size); } - public void recordDrawBuffers(int count, IntBuffer bufs) { - buffer.writeDrawBuffers(count, bufs); - commandCount++; + public DisplayListCommand[] getComplexObjects() { + return complexObjects.toArray(new DisplayListCommand[complexObjects.size()]); } - public void recordBindVBO(int vbo) { - buffer.writeBindVBO(vbo); - commandCount++; + public DisplayListCommand getComplexObject(int index) { + return complexObjects.get(index); } - public void recordBindVAO(int vao) { - buffer.writeBindVAO(vao); - commandCount++; + public boolean isEmpty() { + return size() == 0; } - public void recordComplexCommand(DisplayListCommand cmd) { - buffer.writeComplexRef(cmd); - commandCount++; + /** + * Clear the buffer for reuse. Does NOT free memory. + */ + public void clear() { + writePointer = basePointer; + complexObjects.clear(); } } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java index 8d77e285a..58b634282 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/CompiledDisplayList.java @@ -32,11 +32,11 @@ public final class CompiledDisplayList { public static final CompiledDisplayList EMPTY = new CompiledDisplayList(null, null, null, Collections.emptyList()); private final ByteBuffer commandBuffer; // Off-heap command storage, must be freed - private final Object[] complexObjects; // Complex commands (TexImage2D, etc.) + private final DisplayListCommand[] complexObjects; // Complex commands (TexImage2D, etc.) private final DisplayListVBO ownedVbos; // GPU resources referenced by index private final List indexedBatches; // Shared VAO/VBO/EBO triples per layout group - public CompiledDisplayList(ByteBuffer commandBuffer, Object[] complexObjects, DisplayListVBO ownedVbos, List indexedBatches) { + public CompiledDisplayList(ByteBuffer commandBuffer, DisplayListCommand[] complexObjects, DisplayListVBO ownedVbos, List indexedBatches) { this.commandBuffer = commandBuffer; this.complexObjects = complexObjects; this.ownedVbos = ownedVbos; @@ -47,8 +47,12 @@ public final class CompiledDisplayList { * Render this display list by executing all commands. */ public void render() { + render(-1); + } + + public void render(int list) { if (commandBuffer != null && commandBuffer.limit() > 0) { - CommandBufferExecutor.execute(commandBuffer, complexObjects, ownedVbos); + CommandBufferExecutor.execute(commandBuffer, complexObjects, ownedVbos, list, this); } } @@ -57,10 +61,8 @@ public final class CompiledDisplayList { */ public void delete() { if (complexObjects != null) { - for (Object obj : complexObjects) { - if (obj instanceof DisplayListCommand cmd) { - cmd.delete(); - } + for (DisplayListCommand cmd : complexObjects) { + cmd.delete(); } } @@ -92,7 +94,7 @@ public final class CompiledDisplayList { /** * Get complex objects for inlining into another display list (nested lists). */ - public Object[] getComplexObjects() { + public DisplayListCommand[] getComplexObjects() { return complexObjects; } @@ -144,6 +146,10 @@ public final class CompiledDisplayList { return opcodes; } + public String getCompiledDisplayListString(int listId, StackTraceElement[] stackTrace) { + return DisplayListManager.getCompiledDisplayListString(listId, this, stackTrace); + } + @Override public String toString() { return DisplayListManager.getCompiledDisplayListString(0, this, null); diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBO.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBO.java index 77f7afcab..a874e187a 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBO.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBO.java @@ -23,6 +23,10 @@ public final class DisplayListVBO { return vbos; } + public SubVBO getVBO(int index) { + return vbos[index]; + } + public void render(int index) { vbos[index].render(); } @@ -41,6 +45,18 @@ public final class DisplayListVBO { this.count = count; } + public int getStart() { + return start; + } + + public int getCount() { + return count; + } + + public int getDrawMode() { + return drawMode; + } + public void delete() { vao.delete(); } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBOBuilder.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBOBuilder.java index 0deead200..1255b87c4 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBOBuilder.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/DisplayListVBOBuilder.java @@ -68,7 +68,7 @@ public final class DisplayListVBOBuilder { allBuffers.addAll(drawBuffers); int size = 0; for (ByteBuffer buffer : drawBuffers) { - size += buffer.remaining(); + size += buffer.limit(); } vertexCount = format.getVertexCount(size); } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/GLCommand.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/GLCommand.java index 0d0ab2240..ccf42953e 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/GLCommand.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/GLCommand.java @@ -74,10 +74,7 @@ public final class GLCommand { // === Double commands === public static final int TRANSLATE = 70; // [cmd:4][mode:4][x:8d][y:8d][z:8d] = 32 bytes - public static final int ROTATE = 71; // [cmd:4][mode:4][angle:8d][x:8d][y:8d][z:8d] = 40 bytes public static final int SCALE = 72; // [cmd:4][mode:4][x:8d][y:8d][z:8d] = 32 bytes - public static final int ORTHO = 73; // [cmd:4][left:8d][right:8d][bottom:8d][top:8d][zNear:8d][zFar:8d] = 52 bytes - public static final int FRUSTUM = 74; // [cmd:4][left:8d][right:8d][bottom:8d][top:8d][zNear:8d][zFar:8d] = 52 bytes public static final int CLEAR_DEPTH = 75; // [cmd:4][depth:8d] = 12 bytes // === Matrix commands (72 bytes) === @@ -167,10 +164,7 @@ public final class GLCommand { case MATERIALF -> "MATERIALF"; case TEX_PARAMETERF -> "TEX_PARAMETERF"; case TRANSLATE -> "TRANSLATE"; - case ROTATE -> "ROTATE"; case SCALE -> "SCALE"; - case ORTHO -> "ORTHO"; - case FRUSTUM -> "FRUSTUM"; case CLEAR_DEPTH -> "CLEAR_DEPTH"; case MULT_MATRIX -> "MULT_MATRIX"; case LOAD_MATRIX -> "LOAD_MATRIX"; @@ -235,10 +229,8 @@ public final class GLCommand { case GLCommand.DRAW_BUFFERS -> 40; // Double commands - case GLCommand.TRANSLATE, GLCommand.SCALE -> 28; // cmd + 3 doubles + case GLCommand.TRANSLATE, GLCommand.SCALE -> 16; // cmd + 3 floats case GLCommand.CLEAR_DEPTH -> 12; // cmd + 1 double - case GLCommand.ROTATE -> 36; // cmd + 4 doubles - case GLCommand.ORTHO, GLCommand.FRUSTUM -> 52; // cmd + 6 doubles // Matrix commands case GLCommand.MULT_MATRIX, GLCommand.LOAD_MATRIX -> 68; // cmd + 16 floats diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/ImmediateModeRecorder.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/ImmediateModeRecorder.java index 842a26a65..1b0e6fbd1 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/ImmediateModeRecorder.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/recording/ImmediateModeRecorder.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.angelica.glsm.recording; +import com.gtnewhorizon.gtnhlib.client.renderer.CallbackTessellator; import com.gtnewhorizon.gtnhlib.client.renderer.DirectTessellator; import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormatElement.Usage; @@ -15,7 +16,7 @@ import java.util.Arrays; * Used both during display list compilation and for live immediate mode emulation in core profile. */ public final class ImmediateModeRecorder { - private static final DirectTessellator tessellator = new DirectTessellator(TessellatorManager.DEFAULT_BUFFER_SIZE); + private static final CallbackTessellator tessellator = new CallbackTessellator(TessellatorManager.DEFAULT_BUFFER_SIZE); /** Separate tessellator for the splash thread. Nulled after splash completes. */ private static DirectTessellator splashTessellator; @@ -29,6 +30,7 @@ public final class ImmediateModeRecorder { } public static void destroySplashTessellator() { + splashTessellator.delete(); splashTessellator = null; } diff --git a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/streaming/TessellatorStreamingDrawer.java b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/streaming/TessellatorStreamingDrawer.java index 32d4a7407..c40b748f4 100644 --- a/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/streaming/TessellatorStreamingDrawer.java +++ b/glsm/src/main/java/com/gtnewhorizons/angelica/glsm/streaming/TessellatorStreamingDrawer.java @@ -5,10 +5,10 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat; import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFlags; import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat; import com.gtnewhorizons.angelica.glsm.GLStateManager; -import com.gtnewhorizons.angelica.glsm.ITessellatorData; import com.gtnewhorizons.angelica.glsm.QuadConverter; import com.gtnewhorizons.angelica.glsm.RenderSystem; import com.gtnewhorizons.angelica.glsm.ffp.ShaderManager; +import net.minecraft.client.renderer.Tessellator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL11; @@ -69,42 +69,42 @@ public class TessellatorStreamingDrawer { /** * Draw the vanilla Tessellator's data using streaming VBO+VAO instead of FFP client arrays. */ - public static int draw(ITessellatorData tess) { - if (!tess.isDrawing()) { + public static int draw(Tessellator tess) { + if (!tess.isDrawing) { throw new IllegalStateException("Not tesselating!"); } - tess.setDrawing(false); + tess.isDrawing = false; - final int vertexCount = tess.getVertexCount(); + final int vertexCount = tess.vertexCount; if (vertexCount == 0) { - final int result = tess.getRawBufferIndex() * 4; - tess.angelica$reset(); + final int result = tess.rawBufferIndex * 4; + tess.reset(); return result; } // Determine the optimal vertex format from the tessellator's flags - final int flags = VertexFlags.convertToFlags(tess.hasTexture(), tess.hasColor(), tess.hasNormals(), tess.hasBrightness()); + final int flags = VertexFlags.convertToFlags(tess.hasTexture, tess.hasColor, tess.hasNormals, tess.hasBrightness); final VertexFormat format = DefaultVertexFormat.ALL_FORMATS[flags]; final int vertexSize = format.getVertexSize(); final int requiredBytes = vertexCount * vertexSize; ensureRepackCapacity(requiredBytes); - final long writePtr = format.writeToBuffer0(repackAddress, tess.getRawBuffer(), tess.getRawBufferIndex()); + final long writePtr = format.writeToBuffer0(repackAddress, tess.rawBuffer, tess.rawBufferIndex); repackBuffer.position(0); repackBuffer.limit((int)(writePtr - repackAddress)); - uploadAndDraw(repackBuffer, flags, format, vertexSize, tess.getDrawMode(), vertexCount); + uploadAndDraw(repackBuffer, flags, format, vertexSize, tess.drawMode, vertexCount); // Shrink rawBuffer if oversized - if (tess.getRawBufferSize() > 0x20000 && tess.getRawBufferIndex() < (tess.getRawBufferSize() << 3)) { - tess.setRawBufferSize(0x10000); - tess.setRawBuffer(new int[tess.getRawBufferSize()]); + if (tess.rawBufferSize > 0x20000 && tess.rawBufferIndex < (tess.rawBufferSize << 3)) { + tess.rawBufferSize = 0x10000; + tess.rawBuffer = new int[tess.rawBufferSize]; } - final int result = tess.getRawBufferIndex() * 4; - tess.angelica$reset(); + final int result = tess.rawBufferIndex * 4; + tess.reset(); return result; } diff --git a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/DisplayListCompilationGLSMTest.java b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/DisplayListCompilationGLSMTest.java index f34b3bd16..05c92f1c1 100644 --- a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/DisplayListCompilationGLSMTest.java +++ b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/DisplayListCompilationGLSMTest.java @@ -107,6 +107,7 @@ class DisplayListCompilationGLSMTest { testList = GL11.glGenLists(1); GLStateManager.glNewList(testList, GL11.GL_COMPILE_AND_EXECUTE); GLStateManager.glTranslatef(10, 0, 0); // Applied immediately + DisplayListManager.flushMatrix(); FloatBuffer afterTranslate = BufferUtils.createFloatBuffer(16); GLStateManager.glGetFloat(GL11.GL_MODELVIEW_MATRIX, afterTranslate); @@ -216,6 +217,7 @@ class DisplayListCompilationGLSMTest { GLStateManager.glTranslatef(10, 0, 0); // Applied immediately GLStateManager.glRotatef(45, 0, 1, 0); // Applied immediately + DisplayListManager.flushMatrix(); FloatBuffer afterTransforms = BufferUtils.createFloatBuffer(16); GLStateManager.glGetFloat(GL11.GL_MODELVIEW_MATRIX, afterTransforms); @@ -241,6 +243,7 @@ class DisplayListCompilationGLSMTest { GLStateManager.glPushMatrix(); GLStateManager.glTranslatef(10, 0, 0); // Applied immediately + DisplayListManager.flushMatrix(); FloatBuffer afterTranslate = BufferUtils.createFloatBuffer(16); GLStateManager.glGetFloat(GL11.GL_MODELVIEW_MATRIX, afterTranslate); diff --git a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java index 8b4a2e135..ae076602c 100644 --- a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java +++ b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_Batching_Test.java @@ -94,9 +94,9 @@ class GLSM_DisplayList_Batching_Test { // Verify: 3 DrawRangeCmds (one per draw, each with different transform) Int2IntMap counts = compiled.getCommandCounts(); int drawCount = counts.getOrDefault(GLCommand.DRAW_RANGE, 0); - int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0); - assertEquals(3, drawCount, "3 draws with different transforms should produce 3 DrawRangeCmds"); - assertEquals(2, multMatrixCount, "Should have MultMatrix commands for each unique transform"); + int multMatrixCount = counts.getOrDefault(GLCommand.TRANSLATE, 0); + assertEquals(1, drawCount, "3 draws with different transforms should produce 1 DrawRangeCmd (transforms get prebaked)"); + assertEquals(1, multMatrixCount, "Should have 1 Translate at the end (the transforms in the draws are prebaked)"); } @Test @@ -140,13 +140,14 @@ class GLSM_DisplayList_Batching_Test { // Verify: 3 DrawRangeCmds (different transforms require separate draw commands) Int2IntMap counts = compiled.getCommandCounts(); int drawCount = counts.getOrDefault(GLCommand.DRAW_RANGE, 0); - assertEquals(3, drawCount, "Draws with different recorded transforms must produce separate DrawRangeCmds"); + assertEquals(1, drawCount, "3 Draws with different transforms should get prebaked + merged"); } @Test void testDrawsWithSameTransformProduceSingleDrawRangeCmd() { CompiledDisplayList compiled = createDisplayList(() -> { GLStateManager.glTranslatef(1.0f, 2.0f, 3.0f); + GLStateManager.glScalef(2, 1, 3); createSimpleDraw(); createSimpleDraw(); createSimpleDraw(); @@ -207,7 +208,7 @@ class GLSM_DisplayList_Batching_Test { int drawRestoreCount = counts.getOrDefault(GLCommand.DRAW_RANGE_RESTORE, 0); // Verify: 2 VBOs (one for format A, one for format B) - assertEquals(2, getVBOCount(compiled), "A A B A A pattern should produce 2 VBOs (one per format)"); + // assertEquals(2, getVBOCount(compiled), "A A B A A pattern should produce 2 VBOs (one per format)"); // Verify: 2 DrawRangeCmds (all A's merged into 1, B is 1) // With format-based batching, all A draws go into the same FormatBuffer diff --git a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java index 5b33c350c..3415a5fcc 100644 --- a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java +++ b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/GLSM_DisplayList_TransformCollapsing_Test.java @@ -61,7 +61,6 @@ class GLSM_DisplayList_TransformCollapsing_Test { Int2IntMap counts = compiled.getCommandCounts(); int multMatrixCount = counts.getOrDefault(GLCommand.MULT_MATRIX, 0); int individualTransformCount = counts.getOrDefault(GLCommand.TRANSLATE, 0) - + counts.getOrDefault(GLCommand.ROTATE, 0) + counts.getOrDefault(GLCommand.SCALE, 0); assertEquals(1, multMatrixCount, @@ -420,7 +419,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { // Count MultMatrix commands before first PushMatrix int multMatrixBeforePushCount = 0; for (int i = 0; i < opcodes.size() && i < pushIndex; i++) { - if (opcodes.get(i) == GLCommand.MULT_MATRIX) { + if (opcodes.get(i) == GLCommand.TRANSLATE) { multMatrixBeforePushCount++; } } @@ -666,13 +665,11 @@ class GLSM_DisplayList_TransformCollapsing_Test { assertNotNull(compiled); IntList opcodes = compiled.getCommandOpcodes(); - int pushIndex = opcodes.indexOf(GLCommand.PUSH_MATRIX); int popIndex = opcodes.indexOf(GLCommand.POP_MATRIX); - int multMatrixIndex = opcodes.indexOf(GLCommand.MULT_MATRIX); + int scaleIndex = opcodes.indexOf(GLCommand.SCALE); int drawRangeIndex = opcodes.indexOf(GLCommand.DRAW_RANGE); - assertTrue(pushIndex < multMatrixIndex, "Push before MultMatrix"); - assertTrue(multMatrixIndex < drawRangeIndex, "MultMatrix before DrawRange"); + assertTrue(scaleIndex == -1, "Scale gets prebaked"); assertTrue(drawRangeIndex < popIndex, "DrawRange before Pop"); } @@ -800,6 +797,7 @@ class GLSM_DisplayList_TransformCollapsing_Test { GLStateManager.glNewList(testList, mode); GLStateManager.glScalef(0.5f, 0.5f, 1.0f); + GLStateManager.glTranslatef(2, 2, 2); // Barrier commands between scale and draw GLStateManager.glDepthMask(true); GLStateManager.disableLighting(); @@ -824,8 +822,8 @@ class GLSM_DisplayList_TransformCollapsing_Test { assertEquals(1, counts.getOrDefault(GLCommand.DRAW_RANGE, 0), "1 DrawRange for mode " + mode); IntList opcodes = compiled.getCommandOpcodes(); - assertTrue(opcodes.indexOf(GLCommand.MULT_MATRIX) < opcodes.indexOf(GLCommand.DRAW_RANGE), - "MultMatrix before DrawRange for mode " + mode); + assertTrue(opcodes.indexOf(GLCommand.MULT_MATRIX) > opcodes.indexOf(GLCommand.DRAW_RANGE), + "MultMatrix after DrawRange for mode " + mode); GLStateManager.glPushMatrix(); GLStateManager.glLoadIdentity(); @@ -874,10 +872,10 @@ class GLSM_DisplayList_TransformCollapsing_Test { Int2IntMap counts = compiled.getCommandCounts(); IntList opcodes = compiled.getCommandOpcodes(); - // Should have exactly 2 MULT_MATRIX (T1 before push, T2 after push) - // Bug would produce 3 (T1, T2, spurious T1^-1) - assertEquals(2, counts.getOrDefault(GLCommand.MULT_MATRIX, 0), - "2 MULT_MATRIX expected (T1 before push, T2 after push)"); + // Should have exactly 1 MULT_MATRIX (T1 before push, T2 after push is already prebaked, will get discarded.) + // No prebaking would produce 2 (last one wouldn't get discarded) + assertEquals(1, counts.getOrDefault(GLCommand.MULT_MATRIX, 0), + "1 MULT_MATRIX expected (T1 before push, T2 after push is already prebaked, will get discarded.)"); // Verify ordering int firstMultMatrix = opcodes.indexOf(GLCommand.MULT_MATRIX); diff --git a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/recording/IndexedDrawReplayTest.java b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/recording/IndexedDrawReplayTest.java index 612df346f..2b8b3e85a 100644 --- a/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/recording/IndexedDrawReplayTest.java +++ b/glsm/src/test/java/com/gtnewhorizons/angelica/glsm/recording/IndexedDrawReplayTest.java @@ -207,7 +207,7 @@ class IndexedDrawReplayTest extends DisplayListTestFixture { new AttribLayoutKey(new int[]{0}, new int[]{2}, new int[]{GL11.GL_FLOAT}, new boolean[]{false}), GL11.GL_TRIANGLES, 4, 6, vtx, idx, new BatchedIndexedDrawCmd()); - rec.recordIndexedDrawCapture(cap); + rec.writeIndexedDrawCapture(cap); assertFalse(cap.isFreed()); rec.free(); diff --git a/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java b/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java index 1f5439d8b..a054974e1 100644 --- a/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java +++ b/src/main/java/com/gtnewhorizons/angelica/client/font/BatchingFontRenderer.java @@ -683,13 +683,11 @@ public class BatchingFontRenderer { } if (FontConfig.enableCustomFont && FontConfig.enableGlyphReplacements) { - String chrReplacement = GlyphReplacements.customGlyphs.get(String.valueOf(chr)); - if (chrReplacement != null) { - char replacement = chrReplacement.charAt(0); - boolean isReplacementCharAvailable = - FontProviderCustom.getPrimary().isGlyphAvailable(replacement) - || FontProviderCustom.getFallback().isGlyphAvailable(replacement); - if (isReplacementCharAvailable) { + final char replacement = GlyphReplacements.getReplacementGlyph(chr); + if (replacement != 0) { + if (FontProviderCustom.getPrimary().isGlyphAvailable(replacement) + || FontProviderCustom.getFallback().isGlyphAvailable(replacement) + ) { chr = replacement; } } diff --git a/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java b/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java index eb8123b40..69a9c7bee 100644 --- a/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java +++ b/src/main/java/com/gtnewhorizons/angelica/client/rendering/DeferredDrawBatcher.java @@ -104,9 +104,7 @@ public class DeferredDrawBatcher { subEnd++; // Don't try to merge strips, fans, loops or polygons - if (drawMode == GL11.GL_TRIANGLE_STRIP || drawMode == GL11.GL_TRIANGLE_FAN || drawMode == GL11.GL_LINE_STRIP || - drawMode == GL11.GL_LINE_LOOP || drawMode == GL11.GL_QUAD_STRIP || drawMode == GL11.GL_POLYGON) - break; + if (GLStateManager.isContinuousDraw(drawMode)) break; } drawPackedBatch(batchTessellator, ranges, i, subEnd, totalBytes, totalVertices, drawMode, flags); diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/bettercrashes/BetterCrashesCompat.java b/src/main/java/com/gtnewhorizons/angelica/compat/bettercrashes/BetterCrashesCompat.java index ae4d166bf..a61d91a0d 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/bettercrashes/BetterCrashesCompat.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/bettercrashes/BetterCrashesCompat.java @@ -2,7 +2,6 @@ package com.gtnewhorizons.angelica.compat.bettercrashes; import com.gtnewhorizons.angelica.AngelicaMod; import com.gtnewhorizons.angelica.glsm.GLStateManager; -import com.gtnewhorizons.angelica.glsm.ITessellatorData; import com.gtnewhorizons.angelica.mixins.interfaces.IRenderGlobalExt; import cpw.mods.fml.common.Optional; import net.minecraft.client.Minecraft; @@ -27,7 +26,7 @@ public class BetterCrashesCompat implements StateManager.IResettable { @Override public void resetState() { - ((ITessellatorData) Tessellator.instance).setDrawing(false); + Tessellator.instance.isDrawing = false; AngelicaMod.LOGGER.info("Reloading SodiumRenderer"); ((IRenderGlobalExt) Minecraft.getMinecraft().renderGlobal).angelica$reload(); AngelicaMod.LOGGER.info("Resetting GLStateManager"); diff --git a/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaClientTweaker.java b/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaClientTweaker.java index ead4d2f0a..67db72746 100644 --- a/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaClientTweaker.java +++ b/src/main/java/com/gtnewhorizons/angelica/loading/AngelicaClientTweaker.java @@ -106,8 +106,8 @@ public final class AngelicaClientTweaker implements IFMLLoadingPlugin, IEarlyMix "/it/unimi/dsi/fastutil/ints/Int2ObjectMap.class", "Missing dependency: Angelica requires GTNHLib! Download: https://modrinth.com/mod/gtnhlib"), new DependencyVerifier.Check( - "/xyz/wagyourtail/jvmdg/exc/MissingStubError.class", - "GTNHLib is outdated: Angelica requires GTNHLib 0.9.0 or newer! Download: https://modrinth.com/mod/gtnhlib") + "/com/gtnewhorizon/gtnhlib/client/renderer/VertexCallbackManager.class", + "GTNHLib is outdated: Angelica requires GTNHLib 0.10.0 or newer! Download: https://modrinth.com/mod/gtnhlib") )); } diff --git a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/ffp/MixinTessellator_CoreProfile.java b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/ffp/MixinTessellator_CoreProfile.java index 699d20145..641bf76d6 100644 --- a/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/ffp/MixinTessellator_CoreProfile.java +++ b/src/mixin/java/com/gtnewhorizons/angelica/mixins/early/angelica/ffp/MixinTessellator_CoreProfile.java @@ -1,12 +1,9 @@ package com.gtnewhorizons.angelica.mixins.early.angelica.ffp; -import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager; -import com.gtnewhorizons.angelica.glsm.ITessellatorData; import com.gtnewhorizons.angelica.glsm.streaming.TessellatorStreamingDrawer; import net.minecraft.client.renderer.Tessellator; -import org.spongepowered.asm.mixin.Intrinsic; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -16,43 +13,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; * except when GTNHLib needs to intercept (display list compilation, DirectTessellator capture). */ @Mixin(Tessellator.class) -public class MixinTessellator_CoreProfile implements ITessellatorData { +public class MixinTessellator_CoreProfile { - @Shadow public boolean isDrawing; - @Shadow public int vertexCount; - @Shadow public int[] rawBuffer; - @Shadow public int rawBufferIndex; - @Shadow public int rawBufferSize; - @Shadow public int drawMode; - @Shadow public boolean hasTexture; - @Shadow public boolean hasColor; - @Shadow public boolean hasNormals; - @Shadow public boolean hasBrightness; - - @Shadow public void reset() {} - - public void angelica$reset() { - reset(); - } - - @Inject(method = "draw", at = @At("HEAD"), cancellable = true) + @Inject(method = "draw", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/Tessellator;isDrawing:Z", opcode = Opcodes.GETFIELD), cancellable = true) private void angelica$coreProfileDraw(CallbackInfoReturnable cir) { - // Let GTNHLib handle display list compilation and DirectTessellator capture - if (TessellatorManager.shouldInterceptDraw((Tessellator)(Object)this)) return; - cir.setReturnValue(TessellatorStreamingDrawer.draw((ITessellatorData) this)); + // Injecting after HEAD because GTNHLib's shouldInterceptDraw() takes priority + cir.setReturnValue(TessellatorStreamingDrawer.draw((Tessellator) (Object) this)); } - - @Override public boolean isDrawing() { return isDrawing; } - @Override public void setDrawing(boolean drawing) { isDrawing = drawing; } - @Override public int getVertexCount() { return vertexCount; } - @Override public int[] getRawBuffer() { return rawBuffer; } - @Override public int getRawBufferIndex() { return rawBufferIndex; } - @Override public int getRawBufferSize() { return rawBufferSize; } - @Override public void setRawBufferSize(int size) { rawBufferSize = size; } - @Override public void setRawBuffer(int[] buffer) { rawBuffer = buffer; } - @Override public int getDrawMode() { return drawMode; } - @Override public boolean hasTexture() { return hasTexture; } - @Override public boolean hasColor() { return hasColor; } - @Override public boolean hasNormals() { return hasNormals; } - @Override public boolean hasBrightness() { return hasBrightness; } } diff --git a/umbra/src/main/java/com/gtnewhorizons/umbra/loading/UmbraClientTweaker.java b/umbra/src/main/java/com/gtnewhorizons/umbra/loading/UmbraClientTweaker.java index 16c6c5ed4..887e68b3e 100644 --- a/umbra/src/main/java/com/gtnewhorizons/umbra/loading/UmbraClientTweaker.java +++ b/umbra/src/main/java/com/gtnewhorizons/umbra/loading/UmbraClientTweaker.java @@ -73,8 +73,8 @@ public class UmbraClientTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader "/it/unimi/dsi/fastutil/ints/Int2ObjectMap.class", "Missing dependency: Umbra requires GTNHLib! Download: https://modrinth.com/mod/gtnhlib"), new DependencyVerifier.Check( - "/xyz/wagyourtail/jvmdg/exc/MissingStubError.class", - "GTNHLib is outdated: Umbra requires GTNHLib 0.9.0+! Download: https://modrinth.com/mod/gtnhlib") + "/com/gtnewhorizon/gtnhlib/client/renderer/VertexCallbackManager.class", + "GTNHLib is outdated: Angelica requires GTNHLib 0.10.0 or newer! Download: https://modrinth.com/mod/gtnhlib") )); }