mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-27 15:43:02 +00:00
glFrontFace, glHint, and glBlendColor (#1156)
This commit is contained in:
1 parent
87ac03281c
commit
59c270a5b9
19 files changed
+1373
-74
No files matched your search
@@ -18,7 +18,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
name = "Angelica",
|
||||
version = Tags.VERSION,
|
||||
dependencies = """
|
||||
required-after:gtnhlib@[0.8.19,);\
|
||||
required-after:gtnhlib@[0.8.21,);\
|
||||
before:lwjgl3ify@[1.5.3,);\
|
||||
after:hodgepodge@[2.4.4,);\
|
||||
after:CodeChickenCore@[1.2.0,);\
|
||||
|
||||
@@ -30,7 +30,8 @@ public final class CommandBufferBuilder {
|
||||
public static void buildOptimizedFromRawBuffer(
|
||||
CommandBuffer rawBuffer,
|
||||
Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers,
|
||||
CompiledLineBuffer compiledLineBuffer,
|
||||
final CompiledLineBuffer compiledLineBuffer,
|
||||
final Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers,
|
||||
VertexBuffer[] ownedVbos,
|
||||
int glListId,
|
||||
CommandBuffer finalBuffer) {
|
||||
@@ -43,7 +44,7 @@ public final class CommandBufferBuilder {
|
||||
}
|
||||
|
||||
// Collect all merged draw ranges sorted by command index
|
||||
final List<DrawRangeWithBuffer> allRanges = collectDrawRanges(compiledQuadBuffers, compiledLineBuffer);
|
||||
final List<DrawRangeWithBuffer> allRanges = collectDrawRanges(compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers);
|
||||
|
||||
// Buffer optimizer state
|
||||
final BufferTransformOptimizer opt = new BufferTransformOptimizer();
|
||||
@@ -82,9 +83,9 @@ public final class CommandBufferBuilder {
|
||||
*/
|
||||
public static void buildUnoptimizedFromRawBuffer(
|
||||
CommandBuffer rawBuffer,
|
||||
List<AccumulatedDraw> accumulatedDraws,
|
||||
Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers,
|
||||
CompiledLineBuffer compiledLineBuffer,
|
||||
Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers,
|
||||
VertexBuffer[] ownedVbos,
|
||||
CommandBuffer finalBuffer) {
|
||||
|
||||
@@ -96,7 +97,7 @@ public final class CommandBufferBuilder {
|
||||
}
|
||||
|
||||
// Collect all merged draw ranges sorted by command index
|
||||
final List<DrawRangeWithBuffer> allRanges = collectDrawRanges(compiledQuadBuffers, compiledLineBuffer);
|
||||
final List<DrawRangeWithBuffer> allRanges = collectDrawRanges(compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers);
|
||||
|
||||
rawBuffer.resetRead();
|
||||
int cmdIndex = 0;
|
||||
@@ -130,21 +131,53 @@ public final class CommandBufferBuilder {
|
||||
/**
|
||||
* Collect all draw ranges from compiled buffers, sorted by command index.
|
||||
*/
|
||||
private static List<DrawRangeWithBuffer> collectDrawRanges(
|
||||
static List<DrawRangeWithBuffer> collectDrawRanges(
|
||||
Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers,
|
||||
CompiledLineBuffer compiledLineBuffer) {
|
||||
CompiledLineBuffer compiledLineBuffer,
|
||||
Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers) {
|
||||
|
||||
final List<DrawRangeWithBuffer> allRanges = new ArrayList<>();
|
||||
|
||||
for (CompiledFormatBuffer compiledBuffer : compiledQuadBuffers.values()) {
|
||||
for (DrawRange range : compiledBuffer.mergedRanges()) {
|
||||
allRanges.add(new DrawRangeWithBuffer(range, compiledBuffer.vbo(), compiledBuffer.flags().hasBrightness));
|
||||
// Add quad ranges
|
||||
final CompiledFormatBuffer[] quadBufferArray = compiledQuadBuffers.values().toArray(new CompiledFormatBuffer[0]);
|
||||
for (int b = 0; b < quadBufferArray.length; b++) {
|
||||
final CompiledFormatBuffer compiledBuffer = quadBufferArray[b];
|
||||
final DrawRange[] ranges = compiledBuffer.mergedRanges();
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
allRanges.add(new DrawRangeWithBuffer(ranges[i], compiledBuffer.vbo(), compiledBuffer.flags().hasBrightness));
|
||||
}
|
||||
}
|
||||
|
||||
// Add immediate mode line ranges
|
||||
if (compiledLineBuffer != null) {
|
||||
for (DrawRange range : compiledLineBuffer.mergedRanges()) {
|
||||
allRanges.add(new DrawRangeWithBuffer(range, compiledLineBuffer.vbo(), false));
|
||||
final DrawRange[] ranges = compiledLineBuffer.mergedRanges();
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
allRanges.add(new DrawRangeWithBuffer(ranges[i], compiledLineBuffer.vbo(), false));
|
||||
}
|
||||
}
|
||||
|
||||
// Add tessellator primitive ranges (lines and triangles) - grouped by format
|
||||
if (compiledPrimitiveBuffers != null && !compiledPrimitiveBuffers.isEmpty()) {
|
||||
final CompiledPrimitiveBuffers[] primBufferArray = compiledPrimitiveBuffers.values().toArray(new CompiledPrimitiveBuffers[0]);
|
||||
for (int p = 0; p < primBufferArray.length; p++) {
|
||||
final CompiledPrimitiveBuffers primBuffers = primBufferArray[p];
|
||||
final boolean hasBrightness = primBuffers.flags().hasBrightness;
|
||||
// Tessellator lines
|
||||
if (primBuffers.hasLines()) {
|
||||
final DrawRange[] ranges = primBuffers.lineMergedRanges();
|
||||
final VertexBuffer vbo = primBuffers.lineVbo();
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
allRanges.add(new DrawRangeWithBuffer(ranges[i], vbo, hasBrightness));
|
||||
}
|
||||
}
|
||||
// Tessellator triangles
|
||||
if (primBuffers.hasTriangles()) {
|
||||
final DrawRange[] ranges = primBuffers.triangleMergedRanges();
|
||||
final VertexBuffer vbo = primBuffers.triangleVbo();
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
allRanges.add(new DrawRangeWithBuffer(ranges[i], vbo, hasBrightness));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer;
|
||||
* </ul>
|
||||
*/
|
||||
@Desugar
|
||||
record CompiledFormatBuffer(
|
||||
public record CompiledFormatBuffer(
|
||||
VertexBuffer vbo,
|
||||
CapturingTessellator.Flags flags,
|
||||
DrawRange[] mergedRanges,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer;
|
||||
|
||||
/**
|
||||
* Compiled VBOs containing tessellator primitives (lines and triangles) for a single vertex format.
|
||||
* Separate VBOs are used for lines (GL_LINES) and triangles (GL_TRIANGLES) since they have different draw modes.
|
||||
* <p>
|
||||
* Contains range arrays for both optimized (merged) and unoptimized (per-draw) paths.
|
||||
* Similar to CompiledFormatBuffer but handles primitives instead of quads.
|
||||
*/
|
||||
@Desugar
|
||||
record CompiledPrimitiveBuffers(
|
||||
CapturingTessellator.Flags flags,
|
||||
VertexBuffer lineVbo,
|
||||
DrawRange[] lineMergedRanges,
|
||||
DrawRange[] linePerDrawRanges,
|
||||
VertexBuffer triangleVbo,
|
||||
DrawRange[] triangleMergedRanges,
|
||||
DrawRange[] trianglePerDrawRanges
|
||||
) {
|
||||
public boolean hasLines() {
|
||||
return lineVbo != null;
|
||||
}
|
||||
|
||||
public boolean hasTriangles() {
|
||||
return triangleVbo != null;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.gtnewhorizons.angelica.glsm;
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.primitive.ModelPrimitiveView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.ModelQuadViewMutable;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vao.VAOManager;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VBOManager;
|
||||
@@ -11,6 +12,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.DefaultVertexFormat;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.AccumulatedDraw;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.AccumulatedLineDraw;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.AccumulatedPrimitiveDraw;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.CommandBuffer;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.CommandRecorder;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.CompiledDisplayList;
|
||||
@@ -32,7 +34,6 @@ import java.nio.ByteBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -115,7 +116,8 @@ 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<AccumulatedDraw> accumulatedDraws = null; // Accumulates quad draws for batching
|
||||
private static List<AccumulatedLineDraw> accumulatedLineDraws = null; // Accumulates line draws
|
||||
private static List<AccumulatedLineDraw> accumulatedLineDraws = null; // Accumulates immediate mode line draws
|
||||
private static List<AccumulatedPrimitiveDraw> accumulatedPrimitiveDraws = null; // Accumulates tessellator primitive draws (lines, triangles)
|
||||
private static Matrix4fStack relativeTransform = null; // Tracks relative transforms during compilation (with push/pop support)
|
||||
@Getter private static ImmediateModeRecorder immediateModeRecorder = null; // Records glBegin/glEnd/glVertex during compilation
|
||||
|
||||
@@ -136,6 +138,7 @@ public class DisplayListManager {
|
||||
CommandRecorder recorder,
|
||||
List<AccumulatedDraw> draws,
|
||||
List<AccumulatedLineDraw> lineDraws,
|
||||
List<AccumulatedPrimitiveDraw> primitiveDraws,
|
||||
Matrix4fStack transform,
|
||||
boolean wasTessellatorCompiling,
|
||||
ImmediateModeRecorder immediateRecorder
|
||||
@@ -182,10 +185,12 @@ public class DisplayListManager {
|
||||
public static void recordClear(int mask) { if (currentRecorder != null) currentRecorder.recordClear(mask); }
|
||||
public static void recordClearColor(float r, float g, float b, float a) { if (currentRecorder != null) currentRecorder.recordClearColor(r, g, b, a); }
|
||||
public static void recordClearDepth(double depth) { if (currentRecorder != null) currentRecorder.recordClearDepth(depth); }
|
||||
public static void recordBlendColor(float r, float g, float b, float a) { if (currentRecorder != null) currentRecorder.recordBlendColor(r, g, b, a); }
|
||||
public static void recordClearStencil(int s) { if (currentRecorder != null) currentRecorder.recordClearStencil(s); }
|
||||
public static void recordColor(float r, float g, float b, float a) { if (currentRecorder != null) currentRecorder.recordColor(r, g, b, a); }
|
||||
public static void recordColorMask(boolean r, boolean g, boolean b, boolean a) { if (currentRecorder != null) currentRecorder.recordColorMask(r, g, b, a); }
|
||||
public static void recordDepthMask(boolean flag) { if (currentRecorder != null) currentRecorder.recordDepthMask(flag); }
|
||||
public static void recordFrontFace(int mode) { if (currentRecorder != null) currentRecorder.recordFrontFace(mode); }
|
||||
public static void recordDepthFunc(int func) { if (currentRecorder != null) currentRecorder.recordDepthFunc(func); }
|
||||
public static void recordBlendFunc(int srcRgb, int dstRgb, int srcAlpha, int dstAlpha) { if (currentRecorder != null) currentRecorder.recordBlendFunc(srcRgb, dstRgb, srcAlpha, dstAlpha); }
|
||||
public static void recordAlphaFunc(int func, float ref) { if (currentRecorder != null) currentRecorder.recordAlphaFunc(func, ref); }
|
||||
@@ -220,6 +225,7 @@ public class DisplayListManager {
|
||||
public static void recordPopAttrib() { if (currentRecorder != null) currentRecorder.recordPopAttrib(); }
|
||||
public static void recordFogf(int pname, float param) { if (currentRecorder != null) currentRecorder.recordFogf(pname, param); }
|
||||
public static void recordFogi(int pname, int param) { if (currentRecorder != null) currentRecorder.recordFogi(pname, param); }
|
||||
public static void recordHint(int target, int mode) { if (currentRecorder != null) currentRecorder.recordHint(target, mode); }
|
||||
public static void recordFog(int pname, java.nio.FloatBuffer params) { if (currentRecorder != null) currentRecorder.recordFog(pname, params); }
|
||||
public static void recordLightf(int light, int pname, float param) { if (currentRecorder != null) currentRecorder.recordLightf(light, pname, param); }
|
||||
public static void recordLighti(int light, int pname, int param) { if (currentRecorder != null) currentRecorder.recordLighti(light, pname, param); }
|
||||
@@ -413,7 +419,7 @@ public class DisplayListManager {
|
||||
// Save current compilation context and start fresh for nested list
|
||||
final CompilationContext parentContext = new CompilationContext(
|
||||
glListId, glListMode, currentRecorder, accumulatedDraws, accumulatedLineDraws,
|
||||
relativeTransform, tessellatorCompiling, immediateModeRecorder
|
||||
accumulatedPrimitiveDraws, relativeTransform, tessellatorCompiling, immediateModeRecorder
|
||||
);
|
||||
compilationStack.push(parentContext);
|
||||
}
|
||||
@@ -424,23 +430,36 @@ public class DisplayListManager {
|
||||
recordingThread = Thread.currentThread(); // Track which thread is recording
|
||||
currentRecorder = new CommandRecorder(); // Create command recorder
|
||||
accumulatedDraws = new ArrayList<>(64); // Fewer draws than commands typically
|
||||
accumulatedLineDraws = new ArrayList<>(16); // Line draws are less common
|
||||
accumulatedLineDraws = new ArrayList<>(16); // Immediate mode line draws are less common
|
||||
accumulatedPrimitiveDraws = new ArrayList<>(16); // Tessellator primitive draws are less common
|
||||
relativeTransform = new Matrix4fStack(GLStateManager.MAX_MODELVIEW_STACK_DEPTH);
|
||||
relativeTransform.identity(); // Track relative transforms from identity
|
||||
immediateModeRecorder = new ImmediateModeRecorder(); // For glBegin/glEnd/glVertex
|
||||
|
||||
// Start compiling mode with per-draw callback (works for both root and nested lists now)
|
||||
TessellatorManager.setCompiling((quads, flags) -> {
|
||||
if (quads.isEmpty()) {
|
||||
// Callback receives quads (GL_QUADS) and primitives (GL_TRIANGLES, GL_LINES, etc.)
|
||||
TessellatorManager.setCompiling((quads, primitives, flags) -> {
|
||||
final boolean hasQuads = !quads.isEmpty();
|
||||
final boolean hasPrimitives = !primitives.isEmpty();
|
||||
|
||||
// Early exit to avoid allocations when nothing to accumulate
|
||||
if (!hasQuads && !hasPrimitives) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get relative transform (changes since glNewList, not absolute matrix state)
|
||||
final Matrix4f currentTransform = new Matrix4f(relativeTransform);
|
||||
final int cmdIndex = getCommandCount();
|
||||
|
||||
// Accumulate this draw for batching at glEndList()
|
||||
final AccumulatedDraw draw = new AccumulatedDraw(quads, currentTransform, flags, getCommandCount());
|
||||
accumulatedDraws.add(draw);
|
||||
// Accumulate quads for batching at glEndList()
|
||||
if (hasQuads) {
|
||||
accumulatedDraws.add(new AccumulatedDraw(quads, currentTransform, flags, cmdIndex));
|
||||
}
|
||||
|
||||
// Accumulate primitives (lines, triangles) for batching at glEndList()
|
||||
if (hasPrimitives) {
|
||||
accumulatedPrimitiveDraws.add(new AccumulatedPrimitiveDraw(primitives, currentTransform, flags, cmdIndex));
|
||||
}
|
||||
});
|
||||
tessellatorCompiling = true;
|
||||
|
||||
@@ -472,23 +491,27 @@ public class DisplayListManager {
|
||||
final boolean hasCommands = rawCommandBuffer != null && rawCommandBuffer.size() > 0;
|
||||
final boolean hasDraws = accumulatedDraws != null && !accumulatedDraws.isEmpty();
|
||||
final boolean hasLineDraws = accumulatedLineDraws != null && !accumulatedLineDraws.isEmpty();
|
||||
final boolean hasPrimitiveDraws = accumulatedPrimitiveDraws != null && !accumulatedPrimitiveDraws.isEmpty();
|
||||
|
||||
if (hasCommands || hasDraws || hasLineDraws) {
|
||||
if (hasCommands || hasDraws || hasLineDraws || hasPrimitiveDraws) {
|
||||
// Phase 1: Compile format-based VBOs (shared by both optimized and unoptimized paths)
|
||||
final Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers = compileFormatBasedVBOs(accumulatedDraws);
|
||||
|
||||
// Phase 2: Compile line VBO (shared by both paths)
|
||||
// Phase 2: Compile immediate mode line VBO (shared by both paths)
|
||||
final CompiledLineBuffer compiledLineBuffer = compileLineBuffer(accumulatedLineDraws);
|
||||
|
||||
// Collect all owned VBOs (quads + lines)
|
||||
final VertexBuffer[] ownedVbos = extractOwnedVbos(compiledQuadBuffers, compiledLineBuffer);
|
||||
// Phase 3: Compile tessellator primitive VBOs (lines, triangles) - grouped by format
|
||||
final Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers = compilePrimitiveBuffers(accumulatedPrimitiveDraws);
|
||||
|
||||
// Collect all owned VBOs (quads + immediate mode lines + tessellator primitives)
|
||||
final VertexBuffer[] ownedVbos = extractOwnedVbos(compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers);
|
||||
|
||||
// Build to CommandBuffer - optimize raw buffer to final buffer
|
||||
final CommandBuffer finalBuffer = new CommandBuffer();
|
||||
if (DEBUG_DISPLAY_LISTS) {
|
||||
CommandBufferBuilder.buildUnoptimizedFromRawBuffer(rawCommandBuffer, accumulatedDraws, compiledQuadBuffers, compiledLineBuffer, ownedVbos, finalBuffer);
|
||||
CommandBufferBuilder.buildUnoptimizedFromRawBuffer(rawCommandBuffer, compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers, ownedVbos, finalBuffer);
|
||||
} else {
|
||||
CommandBufferBuilder.buildOptimizedFromRawBuffer(rawCommandBuffer, compiledQuadBuffers, compiledLineBuffer, ownedVbos, glListId, finalBuffer);
|
||||
CommandBufferBuilder.buildOptimizedFromRawBuffer(rawCommandBuffer, compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers, ownedVbos, glListId, finalBuffer);
|
||||
}
|
||||
|
||||
// Free the recorder (and its buffer) after optimization
|
||||
@@ -514,6 +537,7 @@ public class DisplayListManager {
|
||||
currentRecorder = parentContext.recorder;
|
||||
accumulatedDraws = parentContext.draws;
|
||||
accumulatedLineDraws = parentContext.lineDraws;
|
||||
accumulatedPrimitiveDraws = parentContext.primitiveDraws;
|
||||
relativeTransform = parentContext.transform;
|
||||
tessellatorCompiling = parentContext.wasTessellatorCompiling;
|
||||
immediateModeRecorder = parentContext.immediateRecorder;
|
||||
@@ -526,6 +550,7 @@ public class DisplayListManager {
|
||||
recordingThread = null;
|
||||
accumulatedDraws = null;
|
||||
accumulatedLineDraws = null;
|
||||
accumulatedPrimitiveDraws = null;
|
||||
relativeTransform = null;
|
||||
immediateModeRecorder = null;
|
||||
glListId = -1;
|
||||
@@ -652,22 +677,74 @@ public class DisplayListManager {
|
||||
*/
|
||||
private static VertexBuffer[] extractOwnedVbos(
|
||||
Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers,
|
||||
CompiledLineBuffer compiledLineBuffer) {
|
||||
CompiledLineBuffer compiledLineBuffer,
|
||||
Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers) {
|
||||
final List<VertexBuffer> vbos = new ArrayList<>();
|
||||
|
||||
// Add quad VBOs
|
||||
for (CompiledFormatBuffer buffer : compiledQuadBuffers.values()) {
|
||||
vbos.add(buffer.vbo());
|
||||
final CompiledFormatBuffer[] quadBufferArray = compiledQuadBuffers.values().toArray(new CompiledFormatBuffer[0]);
|
||||
for (int i = 0; i < quadBufferArray.length; i++) {
|
||||
vbos.add(quadBufferArray[i].vbo());
|
||||
}
|
||||
|
||||
// Add line VBO if present
|
||||
// Add immediate mode line VBO if present
|
||||
if (compiledLineBuffer != null) {
|
||||
vbos.add(compiledLineBuffer.vbo());
|
||||
}
|
||||
|
||||
// Add tessellator primitive VBOs if present (one per format, separate for lines/triangles)
|
||||
if (!compiledPrimitiveBuffers.isEmpty()) {
|
||||
final CompiledPrimitiveBuffers[] primBufferArray = compiledPrimitiveBuffers.values().toArray(new CompiledPrimitiveBuffers[0]);
|
||||
for (int i = 0; i < primBufferArray.length; i++) {
|
||||
final CompiledPrimitiveBuffers primBuffers = primBufferArray[i];
|
||||
if (primBuffers.hasLines()) {
|
||||
vbos.add(primBuffers.lineVbo());
|
||||
}
|
||||
if (primBuffers.hasTriangles()) {
|
||||
vbos.add(primBuffers.triangleVbo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vbos.toArray(new VertexBuffer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile tessellator primitives (lines, triangles) into format-based VBOs.
|
||||
* Groups draws by vertex format for optimal memory usage.
|
||||
*
|
||||
* @param primitiveDraws The accumulated primitive draws from tessellator callback
|
||||
* @return Map of flags to compiled primitive buffers, empty map if no primitives
|
||||
*/
|
||||
private static Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compilePrimitiveBuffers(
|
||||
List<AccumulatedPrimitiveDraw> primitiveDraws) {
|
||||
if (primitiveDraws == null || primitiveDraws.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// Group draws by vertex format
|
||||
final Map<CapturingTessellator.Flags, TessellatorPrimitiveBuffer> formatBuffers = new HashMap<>();
|
||||
final int size = primitiveDraws.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final AccumulatedPrimitiveDraw draw = primitiveDraws.get(i);
|
||||
formatBuffers.computeIfAbsent(draw.flags, TessellatorPrimitiveBuffer::new).addDraw(draw);
|
||||
}
|
||||
|
||||
// Compile each format's geometry into VBOs
|
||||
final Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiled = new HashMap<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map.Entry<CapturingTessellator.Flags, TessellatorPrimitiveBuffer>[] entries =
|
||||
formatBuffers.entrySet().toArray(new Map.Entry[0]);
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
final Map.Entry<CapturingTessellator.Flags, TessellatorPrimitiveBuffer> entry = entries[i];
|
||||
final CompiledPrimitiveBuffers result = entry.getValue().finish();
|
||||
if (result != null) {
|
||||
compiled.put(entry.getKey(), result);
|
||||
}
|
||||
}
|
||||
return compiled;
|
||||
}
|
||||
|
||||
// ==================== Buffer-to-Buffer Optimization ====================
|
||||
/**
|
||||
* Build optimized command list using pre-compiled VBOs.
|
||||
@@ -684,29 +761,15 @@ public class DisplayListManager {
|
||||
List<DisplayListCommand> currentCommands,
|
||||
Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers,
|
||||
CompiledLineBuffer compiledLineBuffer,
|
||||
Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers,
|
||||
int glListId) {
|
||||
|
||||
final List<DisplayListCommand> optimized = new ArrayList<>();
|
||||
final TransformOptimizer transformOpt = new TransformOptimizer(glListId);
|
||||
|
||||
// Collect all merged draw ranges (quads + lines) sorted by command index
|
||||
final List<DrawRangeWithBuffer> allRanges = new ArrayList<>();
|
||||
|
||||
// Add quad ranges
|
||||
for (CompiledFormatBuffer compiledBuffer : compiledQuadBuffers.values()) {
|
||||
for (DrawRange range : compiledBuffer.mergedRanges()) {
|
||||
allRanges.add(new DrawRangeWithBuffer(range, compiledBuffer.vbo(), compiledBuffer.flags().hasBrightness));
|
||||
}
|
||||
}
|
||||
|
||||
// Add line ranges
|
||||
if (compiledLineBuffer != null) {
|
||||
for (DrawRange range : compiledLineBuffer.mergedRanges()) {
|
||||
allRanges.add(new DrawRangeWithBuffer(range, compiledLineBuffer.vbo(), false));
|
||||
}
|
||||
}
|
||||
|
||||
allRanges.sort(Comparator.comparingInt(r -> r.range().commandIndex()));
|
||||
// Collect all merged draw ranges (quads + lines + primitives) sorted by command index
|
||||
final List<DrawRangeWithBuffer> allRanges = CommandBufferBuilder.collectDrawRanges(
|
||||
compiledQuadBuffers, compiledLineBuffer, compiledPrimitiveBuffers);
|
||||
|
||||
// Process command stream with interleaved draws
|
||||
final OptimizationContextImpl ctx = new OptimizationContextImpl(transformOpt, optimized);
|
||||
@@ -755,19 +818,19 @@ public class DisplayListManager {
|
||||
static OptimizedListResult buildOptimizedDisplayList(
|
||||
List<DisplayListCommand> currentCommands,
|
||||
List<AccumulatedDraw> accumulatedDraws,
|
||||
List<AccumulatedLineDraw> accumulatedLineDraws,
|
||||
List<AccumulatedPrimitiveDraw> accumulatedPrimitiveDraws,
|
||||
int glListId) {
|
||||
// Compile quad VBOs
|
||||
final Map<CapturingTessellator.Flags, CompiledFormatBuffer> compiledQuadBuffers = compileFormatBasedVBOs(accumulatedDraws);
|
||||
|
||||
// Compile line VBO
|
||||
final CompiledLineBuffer compiledLineBuffer = compileLineBuffer(accumulatedLineDraws);
|
||||
// Compile tessellator primitive VBOs (lines, triangles) - grouped by format
|
||||
final Map<CapturingTessellator.Flags, CompiledPrimitiveBuffers> compiledPrimitiveBuffers = compilePrimitiveBuffers(accumulatedPrimitiveDraws);
|
||||
|
||||
// Extract owned VBOs
|
||||
final VertexBuffer[] ownedVbos = extractOwnedVbos(compiledQuadBuffers, compiledLineBuffer);
|
||||
// Extract owned VBOs (quads + primitives, no immediate mode lines in test path)
|
||||
final VertexBuffer[] ownedVbos = extractOwnedVbos(compiledQuadBuffers, null, compiledPrimitiveBuffers);
|
||||
|
||||
// Build optimized commands using the new unified path
|
||||
final DisplayListCommand[] optimized = buildOptimizedCommands(currentCommands, compiledQuadBuffers, compiledLineBuffer, glListId);
|
||||
final DisplayListCommand[] optimized = buildOptimizedCommands(currentCommands, compiledQuadBuffers, null, compiledPrimitiveBuffers, glListId);
|
||||
|
||||
return new OptimizedListResult(optimized, ownedVbos);
|
||||
}
|
||||
@@ -817,7 +880,7 @@ public class DisplayListManager {
|
||||
* Selects the optimal VertexFormat from GTNHLib defaults based on actual attribute usage.
|
||||
* This reduces memory usage by excluding unused attributes.
|
||||
*/
|
||||
private static VertexFormat selectOptimalFormat(CapturingTessellator.Flags flags) {
|
||||
static VertexFormat selectOptimalFormat(CapturingTessellator.Flags flags) {
|
||||
final boolean hasColor = flags.hasColor;
|
||||
final boolean hasTexture = flags.hasTexture;
|
||||
final boolean hasBrightness = flags.hasBrightness;
|
||||
|
||||
@@ -881,9 +881,10 @@ public class GLStateManager {
|
||||
|
||||
public static void glBlendColor(float red, float green, float blue, float alpha) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glBlendColor in display lists not yet implemented - if you see this, please report!");
|
||||
DisplayListManager.recordBlendColor(red, green, blue, alpha);
|
||||
} else {
|
||||
GL14.glBlendColor(red, green, blue, alpha);
|
||||
}
|
||||
GL14.glBlendColor(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public static void enableBlend() {
|
||||
@@ -3191,7 +3192,8 @@ public class GLStateManager {
|
||||
|
||||
public static void glFrontFace(int mode) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glFrontFace in display lists not yet implemented - if you see this, please report!");
|
||||
DisplayListManager.recordFrontFace(mode);
|
||||
return;
|
||||
}
|
||||
final boolean caching = isCachingEnabled();
|
||||
if (BYPASS_CACHE || !caching || polygonState.getFrontFace() != mode) {
|
||||
@@ -3203,8 +3205,12 @@ public class GLStateManager {
|
||||
}
|
||||
|
||||
public static void glHint(int target, int mode) {
|
||||
if (DisplayListManager.isRecording()) {
|
||||
throw new UnsupportedOperationException("glHint in display lists not yet implemented - if you see this, please report!");
|
||||
final boolean recording = DisplayListManager.isRecording();
|
||||
if (recording) {
|
||||
DisplayListManager.recordHint(target, mode);
|
||||
if (DisplayListManager.getListMode() == GL11.GL_COMPILE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
GL11.glHint(target, mode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.line.ModelLine;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.primitive.ModelPrimitiveView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.tri.ModelTriangle;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vao.VAOManager;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vbo.VertexBuffer;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.glsm.recording.AccumulatedPrimitiveDraw;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Accumulates tessellator primitives (lines, triangles) for a single vertex format during display list compilation.
|
||||
* Similar to FormatBuffer but handles ModelPrimitiveView instances instead of quads.
|
||||
* <p>
|
||||
* Unlike LineBuffer which handles ImmediateModeRecorder.LineVertex (fixed 16-byte: pos+color),
|
||||
* this handles ModelLine/ModelTriangle from the tessellator with format-optimized vertex size.
|
||||
* <p>
|
||||
* Primitives are separated by draw mode (GL_LINES, GL_TRIANGLES) into separate VBOs.
|
||||
*/
|
||||
class TessellatorPrimitiveBuffer {
|
||||
final CapturingTessellator.Flags flags;
|
||||
|
||||
// Accumulated primitives separated by type
|
||||
final List<ModelLine> allLines = new ArrayList<>();
|
||||
final List<ModelTriangle> allTriangles = new ArrayList<>();
|
||||
|
||||
// Ranges for lines
|
||||
final List<DrawRange> lineMergedRanges = new ArrayList<>();
|
||||
final List<DrawRange> linePerDrawRanges = new ArrayList<>();
|
||||
int currentLineVertexOffset = 0;
|
||||
private int pendingLineStartVertex = -1;
|
||||
private int pendingLineVertexCount = 0;
|
||||
private Matrix4f pendingLineTransform = null;
|
||||
private int pendingLineCommandIndex = -1;
|
||||
|
||||
// Ranges for triangles
|
||||
final List<DrawRange> triangleMergedRanges = new ArrayList<>();
|
||||
final List<DrawRange> trianglePerDrawRanges = new ArrayList<>();
|
||||
int currentTriangleVertexOffset = 0;
|
||||
private int pendingTriangleStartVertex = -1;
|
||||
private int pendingTriangleVertexCount = 0;
|
||||
private Matrix4f pendingTriangleTransform = null;
|
||||
private int pendingTriangleCommandIndex = -1;
|
||||
|
||||
TessellatorPrimitiveBuffer(CapturingTessellator.Flags flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a primitive draw to this buffer.
|
||||
* Separates lines and triangles, tracking ranges for both merged and per-draw paths.
|
||||
*/
|
||||
void addDraw(AccumulatedPrimitiveDraw draw) {
|
||||
final List<ModelPrimitiveView> primitives = draw.primitives;
|
||||
final int size = primitives.size();
|
||||
|
||||
// Single pass: count and collect primitives by type
|
||||
int lineCount = 0;
|
||||
int triangleCount = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
final ModelPrimitiveView prim = primitives.get(i);
|
||||
if (prim instanceof ModelLine ml) {
|
||||
allLines.add(ml);
|
||||
lineCount++;
|
||||
} else if (prim instanceof ModelTriangle mt) {
|
||||
allTriangles.add(mt);
|
||||
triangleCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Process lines
|
||||
if (lineCount > 0) {
|
||||
final int lineVertexCount = lineCount * 2; // 2 vertices per line
|
||||
linePerDrawRanges.add(new DrawRange(currentLineVertexOffset, lineVertexCount, draw.transform, draw.commandIndex));
|
||||
|
||||
// Merge logic for optimized path
|
||||
if (pendingLineTransform != null && pendingLineTransform.equals(draw.transform)) {
|
||||
pendingLineVertexCount += lineVertexCount;
|
||||
} else {
|
||||
flushPendingLineRange();
|
||||
pendingLineStartVertex = currentLineVertexOffset;
|
||||
pendingLineVertexCount = lineVertexCount;
|
||||
pendingLineTransform = new Matrix4f(draw.transform);
|
||||
pendingLineCommandIndex = draw.commandIndex;
|
||||
}
|
||||
currentLineVertexOffset += lineVertexCount;
|
||||
}
|
||||
|
||||
// Process triangles
|
||||
if (triangleCount > 0) {
|
||||
final int triangleVertexCount = triangleCount * 3; // 3 vertices per triangle
|
||||
trianglePerDrawRanges.add(new DrawRange(currentTriangleVertexOffset, triangleVertexCount, draw.transform, draw.commandIndex));
|
||||
|
||||
// Merge logic for optimized path
|
||||
if (pendingTriangleTransform != null && pendingTriangleTransform.equals(draw.transform)) {
|
||||
pendingTriangleVertexCount += triangleVertexCount;
|
||||
} else {
|
||||
flushPendingTriangleRange();
|
||||
pendingTriangleStartVertex = currentTriangleVertexOffset;
|
||||
pendingTriangleVertexCount = triangleVertexCount;
|
||||
pendingTriangleTransform = new Matrix4f(draw.transform);
|
||||
pendingTriangleCommandIndex = draw.commandIndex;
|
||||
}
|
||||
currentTriangleVertexOffset += triangleVertexCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void flushPendingLineRange() {
|
||||
if (pendingLineTransform != null) {
|
||||
lineMergedRanges.add(new DrawRange(pendingLineStartVertex, pendingLineVertexCount, pendingLineTransform, pendingLineCommandIndex));
|
||||
pendingLineTransform = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void flushPendingTriangleRange() {
|
||||
if (pendingTriangleTransform != null) {
|
||||
triangleMergedRanges.add(new DrawRange(pendingTriangleStartVertex, pendingTriangleVertexCount, pendingTriangleTransform, pendingTriangleCommandIndex));
|
||||
pendingTriangleTransform = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile all accumulated primitives into VBOs using optimal vertex format.
|
||||
* @return The compiled buffers with separate VBOs for lines and triangles, or null if empty
|
||||
*/
|
||||
CompiledPrimitiveBuffers finish() {
|
||||
flushPendingLineRange();
|
||||
flushPendingTriangleRange();
|
||||
|
||||
if (allLines.isEmpty() && allTriangles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Use optimal format based on flags (same logic as quads)
|
||||
final VertexFormat format = DisplayListManager.selectOptimalFormat(flags);
|
||||
|
||||
final VertexBuffer lineVbo = allLines.isEmpty() ? null : compileLinesToVBO(format);
|
||||
final VertexBuffer triangleVbo = allTriangles.isEmpty() ? null : compileTrianglesToVBO(format);
|
||||
|
||||
return new CompiledPrimitiveBuffers(
|
||||
flags,
|
||||
lineVbo,
|
||||
lineMergedRanges.toArray(new DrawRange[0]),
|
||||
linePerDrawRanges.toArray(new DrawRange[0]),
|
||||
triangleVbo,
|
||||
triangleMergedRanges.toArray(new DrawRange[0]),
|
||||
trianglePerDrawRanges.toArray(new DrawRange[0])
|
||||
);
|
||||
}
|
||||
|
||||
private VertexBuffer compileLinesToVBO(VertexFormat format) {
|
||||
final int vertexSize = format.getVertexSize();
|
||||
final int size = allLines.size();
|
||||
final ByteBuffer buffer = BufferUtils.createByteBuffer(vertexSize * size * 2);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
writePrimitiveToBuffer(allLines.get(i), buffer);
|
||||
}
|
||||
buffer.flip();
|
||||
|
||||
final VertexBuffer vbo = VAOManager.createVAO(format, GL11.GL_LINES);
|
||||
vbo.upload(buffer);
|
||||
return vbo;
|
||||
}
|
||||
|
||||
private VertexBuffer compileTrianglesToVBO(VertexFormat format) {
|
||||
final int vertexSize = format.getVertexSize();
|
||||
final int size = allTriangles.size();
|
||||
final ByteBuffer buffer = BufferUtils.createByteBuffer(vertexSize * size * 3);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
writePrimitiveToBuffer(allTriangles.get(i), buffer);
|
||||
}
|
||||
buffer.flip();
|
||||
|
||||
final VertexBuffer vbo = VAOManager.createVAO(format, GL11.GL_TRIANGLES);
|
||||
vbo.upload(buffer);
|
||||
return vbo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a primitive's vertices to the buffer using the format specified by flags.
|
||||
* Only writes attributes that are present in the format.
|
||||
*/
|
||||
private void writePrimitiveToBuffer(ModelPrimitiveView prim, ByteBuffer buffer) {
|
||||
final int vertexCount = prim.getVertexCount();
|
||||
final boolean hasTexture = flags.hasTexture;
|
||||
final boolean hasBrightness = flags.hasBrightness;
|
||||
final boolean hasColor = flags.hasColor;
|
||||
final boolean hasNormals = flags.hasNormals;
|
||||
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
// Position (always present) - 12 bytes
|
||||
buffer.putFloat(prim.getX(i));
|
||||
buffer.putFloat(prim.getY(i));
|
||||
buffer.putFloat(prim.getZ(i));
|
||||
|
||||
// Color (4 bytes, ABGR) - if present
|
||||
if (hasColor) {
|
||||
buffer.putInt(prim.getColor(i));
|
||||
}
|
||||
|
||||
// Texture (2 floats = 8 bytes) - if present
|
||||
if (hasTexture) {
|
||||
buffer.putFloat(prim.getTexU(i));
|
||||
buffer.putFloat(prim.getTexV(i));
|
||||
}
|
||||
|
||||
// Light/Brightness (4 bytes, packed) - if present
|
||||
if (hasBrightness) {
|
||||
buffer.putInt(prim.getLight(i));
|
||||
}
|
||||
|
||||
// Normal (4 bytes, packed) - if present
|
||||
if (hasNormals) {
|
||||
buffer.putInt(prim.getForgeNormal(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.gtnewhorizons.angelica.glsm.recording;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.line.ModelLine;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.primitive.ModelPrimitiveView;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.cel.model.tri.ModelTriangle;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an accumulated primitive draw call during display list compilation.
|
||||
* Stores primitives (lines, triangles) from tessellator callback with their transform.
|
||||
* <p>
|
||||
* Unlike AccumulatedLineDraw which stores ImmediateModeRecorder.LineVertex (16-byte: pos+color),
|
||||
* this stores ModelPrimitiveView (32-byte: pos+color+tex+light+normal) from the tessellator.
|
||||
*/
|
||||
public class AccumulatedPrimitiveDraw {
|
||||
public final List<ModelPrimitiveView> primitives;
|
||||
public final Matrix4f transform;
|
||||
public final CapturingTessellator.Flags flags;
|
||||
public final int commandIndex;
|
||||
|
||||
public AccumulatedPrimitiveDraw(List<ModelPrimitiveView> primitives, Matrix4f transform, CapturingTessellator.Flags flags, int commandIndex) {
|
||||
// Deep copy primitives - pooled primitives are reused after callback
|
||||
this.primitives = deepCopyPrimitives(primitives);
|
||||
this.transform = new Matrix4f(transform);
|
||||
this.flags = flags;
|
||||
this.commandIndex = commandIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates deep copies of all primitives in the list.
|
||||
* Required because CapturingTessellator pools and reuses primitive objects.
|
||||
*/
|
||||
private static List<ModelPrimitiveView> deepCopyPrimitives(List<ModelPrimitiveView> source) {
|
||||
final int size = source.size();
|
||||
final List<ModelPrimitiveView> copies = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final ModelPrimitiveView prim = source.get(i);
|
||||
if (prim instanceof ModelLine ml) {
|
||||
copies.add(new ModelLine().copyFrom(ml));
|
||||
} else if (prim instanceof ModelTriangle mt) {
|
||||
copies.add(new ModelTriangle().copyFrom(mt));
|
||||
}
|
||||
}
|
||||
return copies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("AccumulatedPrimitiveDraw[primitives=%d, cmdIdx=%d, mode=%d, flags=C%dT%dL%dN%d]",
|
||||
primitives.size(), commandIndex, flags.drawMode,
|
||||
flags.hasColor ? 1 : 0, flags.hasTexture ? 1 : 0,
|
||||
flags.hasBrightness ? 1 : 0, flags.hasNormals ? 1 : 0);
|
||||
}
|
||||
}
|
||||
@@ -166,6 +166,12 @@ public final class CommandBuffer {
|
||||
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) {
|
||||
@@ -210,6 +216,13 @@ public final class CommandBuffer {
|
||||
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) {
|
||||
@@ -336,6 +349,15 @@ public final class CommandBuffer {
|
||||
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) {
|
||||
|
||||
@@ -123,6 +123,10 @@ public final class CommandBufferExecutor {
|
||||
GLStateManager.glDepthMask(memGetInt(ptr) != 0);
|
||||
ptr += 4;
|
||||
}
|
||||
case GLCommand.FRONT_FACE -> {
|
||||
GLStateManager.glFrontFace(memGetInt(ptr));
|
||||
ptr += 4;
|
||||
}
|
||||
|
||||
// === Two int commands ===
|
||||
case GLCommand.BIND_TEXTURE -> {
|
||||
@@ -161,6 +165,12 @@ public final class CommandBufferExecutor {
|
||||
ptr += 8;
|
||||
GLStateManager.glFogi(pname, param);
|
||||
}
|
||||
case GLCommand.HINT -> {
|
||||
final int target = memGetInt(ptr);
|
||||
final int mode = memGetInt(ptr + 4);
|
||||
ptr += 8;
|
||||
GLStateManager.glHint(target, mode);
|
||||
}
|
||||
|
||||
// === Three int commands ===
|
||||
case GLCommand.STENCIL_FUNC -> {
|
||||
@@ -274,6 +284,14 @@ public final class CommandBufferExecutor {
|
||||
ptr += 8;
|
||||
GLStateManager.glClearDepth(depth);
|
||||
}
|
||||
case GLCommand.BLEND_COLOR -> {
|
||||
final float r = memGetFloat(ptr);
|
||||
final float g = memGetFloat(ptr + 4);
|
||||
final float b = memGetFloat(ptr + 8);
|
||||
final float a = memGetFloat(ptr + 12);
|
||||
ptr += 16;
|
||||
GLStateManager.glBlendColor(r, g, b, a);
|
||||
}
|
||||
|
||||
// === Mixed int+float commands ===
|
||||
case GLCommand.ALPHA_FUNC -> {
|
||||
|
||||
@@ -155,6 +155,7 @@ public final class CommandBufferProcessor {
|
||||
case GLCommand.POP_MATRIX -> out.writePopMatrix(raw.readInt());
|
||||
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());
|
||||
@@ -163,6 +164,7 @@ public final class CommandBufferProcessor {
|
||||
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());
|
||||
@@ -187,6 +189,9 @@ public final class CommandBufferProcessor {
|
||||
// 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());
|
||||
|
||||
@@ -56,6 +56,11 @@ public class CommandRecorder {
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordBlendColor(float r, float g, float b, float a) {
|
||||
buffer.writeBlendColor(r, g, b, a);
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordClearStencil(int s) {
|
||||
buffer.writeClearStencil(s);
|
||||
commandCount++;
|
||||
@@ -76,6 +81,11 @@ public class CommandRecorder {
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordFrontFace(int mode) {
|
||||
buffer.writeFrontFace(mode);
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordDepthFunc(int func) {
|
||||
buffer.writeDepthFunc(func);
|
||||
commandCount++;
|
||||
@@ -246,6 +256,11 @@ public class CommandRecorder {
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordHint(int target, int mode) {
|
||||
buffer.writeHint(target, mode);
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
public void recordFog(int pname, FloatBuffer params) {
|
||||
buffer.writeFog(pname, params);
|
||||
commandCount++;
|
||||
|
||||
@@ -141,13 +141,13 @@ public final class CompiledDisplayList {
|
||||
GLCommand.MATRIX_MODE, GLCommand.ACTIVE_TEXTURE, GLCommand.USE_PROGRAM,
|
||||
GLCommand.PUSH_ATTRIB, GLCommand.POP_ATTRIB, GLCommand.LOAD_IDENTITY,
|
||||
GLCommand.PUSH_MATRIX, GLCommand.POP_MATRIX, GLCommand.STENCIL_MASK,
|
||||
GLCommand.DEPTH_MASK, GLCommand.POINT_SIZE, GLCommand.LINE_WIDTH,
|
||||
GLCommand.DEPTH_MASK, GLCommand.FRONT_FACE, GLCommand.POINT_SIZE, GLCommand.LINE_WIDTH,
|
||||
GLCommand.CALL_LIST, GLCommand.COMPLEX_REF -> 8;
|
||||
|
||||
// Two int commands (12 bytes)
|
||||
case GLCommand.BIND_TEXTURE, GLCommand.POLYGON_MODE, GLCommand.COLOR_MATERIAL,
|
||||
GLCommand.LINE_STIPPLE, GLCommand.STENCIL_MASK_SEPARATE, GLCommand.FOGI,
|
||||
GLCommand.POLYGON_OFFSET, GLCommand.ALPHA_FUNC, GLCommand.FOGF,
|
||||
GLCommand.HINT, GLCommand.POLYGON_OFFSET, GLCommand.ALPHA_FUNC, GLCommand.FOGF,
|
||||
GLCommand.LIGHT_MODELF, GLCommand.LIGHT_MODELI -> 12;
|
||||
|
||||
// Three int commands (16 bytes)
|
||||
@@ -158,13 +158,12 @@ public final class CompiledDisplayList {
|
||||
// Four int commands (20 bytes)
|
||||
case GLCommand.VIEWPORT, GLCommand.BLEND_FUNC, GLCommand.COLOR_MASK,
|
||||
GLCommand.STENCIL_FUNC_SEPARATE, GLCommand.STENCIL_OP_SEPARATE,
|
||||
GLCommand.COLOR, GLCommand.CLEAR_COLOR, GLCommand.DRAW_RANGE -> 20;
|
||||
|
||||
// Single double commands (12 bytes)
|
||||
case GLCommand.CLEAR_DEPTH -> 12;
|
||||
GLCommand.COLOR, GLCommand.CLEAR_COLOR, GLCommand.BLEND_COLOR,
|
||||
GLCommand.DRAW_RANGE -> 20;
|
||||
|
||||
// Double commands
|
||||
case GLCommand.TRANSLATE, GLCommand.SCALE -> 32; // cmd + mode + 3 doubles
|
||||
case GLCommand.CLEAR_DEPTH -> 12; // cmd + 1 double
|
||||
case GLCommand.ROTATE -> 40; // cmd + mode + 4 doubles
|
||||
case GLCommand.ORTHO, GLCommand.FRUSTUM -> 52; // cmd + 6 doubles
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ public final class GLCommand {
|
||||
public static final int POP_MATRIX = 16; // [cmd:4][matrixMode:4]
|
||||
public static final int STENCIL_MASK = 17; // [cmd:4][mask:4]
|
||||
public static final int DEPTH_MASK = 18; // [cmd:4][flag:4] (0 or 1)
|
||||
public static final int FRONT_FACE = 19; // [cmd:4][mode:4]
|
||||
|
||||
// === Two int commands (12 bytes) ===
|
||||
public static final int BIND_TEXTURE = 20; // [cmd:4][target:4][texture:4]
|
||||
@@ -35,6 +36,7 @@ public final class GLCommand {
|
||||
public static final int LINE_STIPPLE = 23; // [cmd:4][factor:4][pattern:4]
|
||||
public static final int STENCIL_MASK_SEPARATE = 24; // [cmd:4][face:4][mask:4]
|
||||
public static final int FOGI = 25; // [cmd:4][pname:4][param:4]
|
||||
public static final int HINT = 26; // [cmd:4][target:4][mode:4]
|
||||
|
||||
// === Three int commands (16 bytes) ===
|
||||
public static final int STENCIL_FUNC = 30; // [cmd:4][func:4][ref:4][mask:4]
|
||||
@@ -55,9 +57,7 @@ public final class GLCommand {
|
||||
public static final int NORMAL = 53; // [cmd:4][x:4f][y:4f][z:4f]
|
||||
public static final int COLOR = 54; // [cmd:4][r:4f][g:4f][b:4f][a:4f]
|
||||
public static final int CLEAR_COLOR = 55; // [cmd:4][r:4f][g:4f][b:4f][a:4f]
|
||||
|
||||
// === Double commands (single value) ===
|
||||
public static final int CLEAR_DEPTH = 56; // [cmd:4][depth:8d] = 12 bytes
|
||||
public static final int BLEND_COLOR = 56; // [cmd:4][r:4f][g:4f][b:4f][a:4f]
|
||||
|
||||
// === Mixed int+float commands ===
|
||||
public static final int ALPHA_FUNC = 60; // [cmd:4][func:4][ref:4f]
|
||||
@@ -75,6 +75,7 @@ public final class GLCommand {
|
||||
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) ===
|
||||
public static final int MULT_MATRIX = 80; // [cmd:4][mode:4][m00-m33:64f] = 72 bytes
|
||||
@@ -116,12 +117,14 @@ public final class GLCommand {
|
||||
case POP_MATRIX -> "POP_MATRIX";
|
||||
case STENCIL_MASK -> "STENCIL_MASK";
|
||||
case DEPTH_MASK -> "DEPTH_MASK";
|
||||
case FRONT_FACE -> "FRONT_FACE";
|
||||
case BIND_TEXTURE -> "BIND_TEXTURE";
|
||||
case POLYGON_MODE -> "POLYGON_MODE";
|
||||
case COLOR_MATERIAL -> "COLOR_MATERIAL";
|
||||
case LINE_STIPPLE -> "LINE_STIPPLE";
|
||||
case STENCIL_MASK_SEPARATE -> "STENCIL_MASK_SEPARATE";
|
||||
case FOGI -> "FOGI";
|
||||
case HINT -> "HINT";
|
||||
case STENCIL_FUNC -> "STENCIL_FUNC";
|
||||
case STENCIL_OP -> "STENCIL_OP";
|
||||
case TEX_PARAMETERI -> "TEX_PARAMETERI";
|
||||
@@ -136,7 +139,7 @@ public final class GLCommand {
|
||||
case NORMAL -> "NORMAL";
|
||||
case COLOR -> "COLOR";
|
||||
case CLEAR_COLOR -> "CLEAR_COLOR";
|
||||
case CLEAR_DEPTH -> "CLEAR_DEPTH";
|
||||
case BLEND_COLOR -> "BLEND_COLOR";
|
||||
case ALPHA_FUNC -> "ALPHA_FUNC";
|
||||
case FOGF -> "FOGF";
|
||||
case LIGHTF -> "LIGHTF";
|
||||
@@ -150,6 +153,7 @@ public final class GLCommand {
|
||||
case SCALE -> "SCALE";
|
||||
case ORTHO -> "ORTHO";
|
||||
case FRUSTUM -> "FRUSTUM";
|
||||
case CLEAR_DEPTH -> "CLEAR_DEPTH";
|
||||
case MULT_MATRIX -> "MULT_MATRIX";
|
||||
case LOAD_MATRIX -> "LOAD_MATRIX";
|
||||
case FOG -> "FOG";
|
||||
|
||||
Reference in new issue
Block a user