Skip to content

Commit

Permalink
Stub in draw priority
Browse files Browse the repository at this point in the history
  • Loading branch information
grondag committed Nov 2, 2020
1 parent ee98c02 commit 7121ff3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package grondag.canvas.buffer.encoding;

import java.util.Comparator;
import java.util.Map;
import java.util.SortedMap;

Expand Down Expand Up @@ -42,7 +43,11 @@ public VertexConsumer getBuffer(RenderLayer renderLayer) {
}
}

// WIP: need a way to ensure decal layers go last
private static final Comparator<VertexCollectorImpl> 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<VertexCollectorImpl> drawList = this.drawList;
final int limit = collectors.size();
Expand All @@ -58,6 +63,7 @@ public void drawCollectors(MaterialTarget target) {
}

if (!drawList.isEmpty()) {
drawList.sort(DRAW_SORT);
VertexCollectorImpl.drawAndClear(drawList);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 7121ff3

Please sign in to comment.