diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java b/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java index 55355ddbc..0e133d1c8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/error/GlError.java @@ -42,9 +42,9 @@ public enum GlError { public static void pollAndThrow(Supplier context) { // TODO: build flag? to enable or disable this function - GlError poll = GlError.poll(); - if (poll != null) { - Flywheel.log.error("{}: {}", poll.name(), context.get()); + GlError err = GlError.poll(); + if (err != null) { + Flywheel.log.error("{}: {}", err.name(), context.get()); } } } diff --git a/src/main/java/com/jozufozu/flywheel/core/model/RecordingVertexConsumer.java b/src/main/java/com/jozufozu/flywheel/core/model/RecordingVertexConsumer.java new file mode 100644 index 000000000..127604939 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/model/RecordingVertexConsumer.java @@ -0,0 +1,70 @@ +package com.jozufozu.flywheel.core.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.VertexConsumer; + +public class RecordingVertexConsumer implements VertexConsumer { + + List> replay = new ArrayList<>(); + + @Override + public VertexConsumer vertex(double x, double y, double z) { + replay.add(v -> v.vertex(x, y, z)); + return this; + } + + @Override + public VertexConsumer color(int r, int g, int b, int a) { + replay.add(v -> v.color(r, g, b, a)); + return this; + } + + @Override + public VertexConsumer uv(float u, float v) { + replay.add(vc -> vc.uv(u, v)); + return this; + } + + @Override + public VertexConsumer overlayCoords(int u, int v) { + replay.add(vc -> vc.overlayCoords(u, v)); + return this; + } + + @Override + public VertexConsumer uv2(int u, int v) { + replay.add(vc -> vc.uv2(u, v)); + return this; + } + + @Override + public VertexConsumer normal(float x, float y, float z) { + replay.add(v -> v.normal(x, y, z)); + return this; + } + + @Override + public void endVertex() { + replay.add(VertexConsumer::endVertex); + } + + @Override + public void defaultColor(int r, int g, int b, int a) { + replay.add(vc -> vc.defaultColor(r, g, b, a)); + } + + @Override + public void unsetDefaultColor() { + replay.add(VertexConsumer::unsetDefaultColor); + } + + public VertexRecording saveRecording() { + VertexRecording out = new VertexRecording(ImmutableList.copyOf(replay)); + replay.clear(); + return out; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/model/VertexRecording.java b/src/main/java/com/jozufozu/flywheel/core/model/VertexRecording.java new file mode 100644 index 000000000..82df180ff --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/model/VertexRecording.java @@ -0,0 +1,15 @@ +package com.jozufozu.flywheel.core.model; + +import java.util.function.Consumer; + +import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.VertexConsumer; + +public record VertexRecording(ImmutableList> recording) { + + public void replay(VertexConsumer vc) { + for (Consumer consumer : recording) { + consumer.accept(vc); + } + } +}