From 7121ff3dbce7bc1ae99c4aa12ce15c3fbb2a8b84 Mon Sep 17 00:00:00 2001 From: Grondag Date: Sun, 1 Nov 2020 21:48:06 -0800 Subject: [PATCH] Stub in draw priority --- .../grondag/canvas/buffer/encoding/CanvasImmediate.java | 8 +++++++- .../canvas/material/state/AbstractRenderStateView.java | 1 - .../grondag/canvas/material/state/RenderMaterialImpl.java | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/grondag/canvas/buffer/encoding/CanvasImmediate.java b/src/main/java/grondag/canvas/buffer/encoding/CanvasImmediate.java index 142c9b835..640eeedc6 100644 --- a/src/main/java/grondag/canvas/buffer/encoding/CanvasImmediate.java +++ b/src/main/java/grondag/canvas/buffer/encoding/CanvasImmediate.java @@ -1,5 +1,6 @@ package grondag.canvas.buffer.encoding; +import java.util.Comparator; import java.util.Map; import java.util.SortedMap; @@ -42,7 +43,11 @@ public VertexConsumer getBuffer(RenderLayer renderLayer) { } } - // WIP: need a way to ensure decal layers go last + private static final Comparator DRAW_SORT = (a, b) -> { + // note reverse argument order - higher priority wins + return Integer.compare(b.materialState.drawPriority, a.materialState.drawPriority); + }; + public void drawCollectors(MaterialTarget target) { final ObjectArrayList drawList = this.drawList; final int limit = collectors.size(); @@ -58,6 +63,7 @@ public void drawCollectors(MaterialTarget target) { } if (!drawList.isEmpty()) { + drawList.sort(DRAW_SORT); VertexCollectorImpl.drawAndClear(drawList); } } diff --git a/src/main/java/grondag/canvas/material/state/AbstractRenderStateView.java b/src/main/java/grondag/canvas/material/state/AbstractRenderStateView.java index 9130f4920..1d673f3d2 100644 --- a/src/main/java/grondag/canvas/material/state/AbstractRenderStateView.java +++ b/src/main/java/grondag/canvas/material/state/AbstractRenderStateView.java @@ -211,7 +211,6 @@ public int shaderFlags() { // Part of render state and collection key for non-sorted, not included in either for sorted static final BitPacker64.IntElement SHADER_ID = PACKER.createIntElement(4096); - public static final long RENDER_STATE_MASK = PACKER.bitMask(); // Can't be part of PTT collector key diff --git a/src/main/java/grondag/canvas/material/state/RenderMaterialImpl.java b/src/main/java/grondag/canvas/material/state/RenderMaterialImpl.java index f716fdde4..f74664f19 100644 --- a/src/main/java/grondag/canvas/material/state/RenderMaterialImpl.java +++ b/src/main/java/grondag/canvas/material/state/RenderMaterialImpl.java @@ -34,12 +34,15 @@ public final class RenderMaterialImpl extends AbstractRenderState implements Ren public final int collectorIndex; public final RenderState renderState; public final int shaderFlags; + public final int drawPriority; RenderMaterialImpl(long bits) { super(nextIndex.getAndIncrement(), bits); collectorIndex = CollectorIndexMap.indexFromKey(collectorKey()); renderState = CollectorIndexMap.renderStateForIndex(collectorIndex); shaderFlags = shaderFlags(); + // WIP: implement + drawPriority = renderState.index; if (Configurator.logMaterials) { CanvasMod.LOG.info("New RenderMaterial" + "\n" + toString() + "\n"); @@ -110,6 +113,7 @@ public String toString() { sb.append("shaderFlags: ").append(Integer.toBinaryString(shaderFlags)).append("\n"); sb.append("blendMode: ").append(blendMode.name()).append("\n"); + sb.append("drawPriority: ").append(drawPriority).append("\n"); return sb.toString(); }