From 5374baf24156f3f18bdb7f21b49122128c4ec06b Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Thu, 9 Dec 2021 16:34:32 -0800 Subject: [PATCH] No more material spec, everything is StructType --- .../flywheel/api/FlywheelRendered.java | 4 --- .../jozufozu/flywheel/api/MaterialGroup.java | 4 ++- .../jozufozu/flywheel/api/MaterialSpec.java | 28 ------------------- .../{backend => api}/struct/Batched.java | 2 +- .../struct/BatchingTransformer.java | 2 +- .../struct/Instanced.java} | 10 +++++-- .../{backend => api}/struct/StructType.java | 4 +-- .../{backend => api}/struct/StructWriter.java | 2 +- .../flywheel/api/struct/package-info.java | 6 ++++ .../jozufozu/flywheel/backend/Backend.java | 10 +++---- .../backend/instancing/AbstractInstancer.java | 2 +- .../instancing/batching/BatchedMaterial.java | 6 ++-- .../batching/BatchedMaterialGroup.java | 5 ++-- .../instancing/batching/CPUInstancer.java | 4 +-- .../instancing/instancing/GPUInstancer.java | 8 +++--- .../instancing/InstancedMaterial.java | 6 ++-- .../instancing/InstancedMaterialGroup.java | 10 ++++--- .../flywheel/backend/struct/BufferWriter.java | 2 ++ .../backend/struct/UnsafeBufferWriter.java | 1 + .../com/jozufozu/flywheel/core/Materials.java | 17 +++++------ .../jozufozu/flywheel/core/WorldContext.java | 4 +-- .../materials/model/ModelTransformer.java | 2 +- .../core/materials/model/ModelType.java | 18 ++++++++---- .../core/materials/model/package-info.java | 6 ++++ .../model/writer/UnsafeModelWriter.java | 2 +- .../core/materials/oriented/OrientedType.java | 18 ++++++++---- .../core/materials/oriented/package-info.java | 6 ++++ .../oriented/writer/UnsafeOrientedWriter.java | 2 +- 28 files changed, 101 insertions(+), 90 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/api/MaterialSpec.java rename src/main/java/com/jozufozu/flywheel/{backend => api}/struct/Batched.java (82%) rename src/main/java/com/jozufozu/flywheel/{backend => api}/struct/BatchingTransformer.java (82%) rename src/main/java/com/jozufozu/flywheel/{backend/struct/Writeable.java => api/struct/Instanced.java} (59%) rename src/main/java/com/jozufozu/flywheel/{backend => api}/struct/StructType.java (85%) rename src/main/java/com/jozufozu/flywheel/{backend => api}/struct/StructWriter.java (87%) create mode 100644 src/main/java/com/jozufozu/flywheel/api/struct/package-info.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/materials/model/package-info.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/materials/oriented/package-info.java diff --git a/src/main/java/com/jozufozu/flywheel/api/FlywheelRendered.java b/src/main/java/com/jozufozu/flywheel/api/FlywheelRendered.java index 59d656edf..7ccb6149c 100644 --- a/src/main/java/com/jozufozu/flywheel/api/FlywheelRendered.java +++ b/src/main/java/com/jozufozu/flywheel/api/FlywheelRendered.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.api; -import net.minecraft.world.level.Level; - /** * Something (a BlockEntity or Entity) that can be rendered using the instancing API. */ @@ -13,6 +11,4 @@ public interface FlywheelRendered { default boolean shouldRenderNormally() { return false; } - - Level getWorld(); } diff --git a/src/main/java/com/jozufozu/flywheel/api/MaterialGroup.java b/src/main/java/com/jozufozu/flywheel/api/MaterialGroup.java index 9f9c5ee98..ba48748df 100644 --- a/src/main/java/com/jozufozu/flywheel/api/MaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/api/MaterialGroup.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.api; +import com.jozufozu.flywheel.api.struct.StructType; + public interface MaterialGroup { /** * Get the material as defined by the given {@link MaterialSpec spec}. @@ -8,5 +10,5 @@ public interface MaterialGroup { * @param The type representing the per instance data. * @return A material you can use to render models. */ - Material material(MaterialSpec spec); + Material material(StructType spec); } diff --git a/src/main/java/com/jozufozu/flywheel/api/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/api/MaterialSpec.java deleted file mode 100644 index eb39d03a2..000000000 --- a/src/main/java/com/jozufozu/flywheel/api/MaterialSpec.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.jozufozu.flywheel.api; - -import com.jozufozu.flywheel.backend.struct.StructType; - -import net.minecraft.resources.ResourceLocation; - -public class MaterialSpec { - - public final ResourceLocation name; - - private final ResourceLocation programSpec; - private final StructType instanceType; - - public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, StructType type) { - this.name = name; - this.programSpec = programSpec; - this.instanceType = type; - } - - public ResourceLocation getProgramName() { - return programSpec; - } - - public StructType getInstanceType() { - return instanceType; - } - -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java b/src/main/java/com/jozufozu/flywheel/api/struct/Batched.java similarity index 82% rename from src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java rename to src/main/java/com/jozufozu/flywheel/api/struct/Batched.java index 687dd933e..ddf7e17b8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/Batched.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/Batched.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.struct; +package com.jozufozu.flywheel.api.struct; import com.jozufozu.flywheel.core.model.Model; diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/BatchingTransformer.java b/src/main/java/com/jozufozu/flywheel/api/struct/BatchingTransformer.java similarity index 82% rename from src/main/java/com/jozufozu/flywheel/backend/struct/BatchingTransformer.java rename to src/main/java/com/jozufozu/flywheel/api/struct/BatchingTransformer.java index 75f709761..16280a457 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/BatchingTransformer.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/BatchingTransformer.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.struct; +package com.jozufozu.flywheel.api.struct; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/Writeable.java b/src/main/java/com/jozufozu/flywheel/api/struct/Instanced.java similarity index 59% rename from src/main/java/com/jozufozu/flywheel/backend/struct/Writeable.java rename to src/main/java/com/jozufozu/flywheel/api/struct/Instanced.java index 869e47ed4..f09ca6bff 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/Writeable.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/Instanced.java @@ -1,8 +1,10 @@ -package com.jozufozu.flywheel.backend.struct; +package com.jozufozu.flywheel.api.struct; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -public interface Writeable extends StructType { +import net.minecraft.resources.ResourceLocation; + +public interface Instanced extends StructType { /** * Create a {@link StructWriter} that will consume instances of S and write them to the given buffer. * @@ -10,8 +12,10 @@ public interface Writeable extends StructType { */ StructWriter getWriter(VecBuffer backing); + ResourceLocation getProgramSpec(); + @Override - default Writeable asWriteable() { + default Instanced asInstanced() { return this; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java b/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java similarity index 85% rename from src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java rename to src/main/java/com/jozufozu/flywheel/api/struct/StructType.java index 6591a5faa..999161229 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/StructType.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.struct; +package com.jozufozu.flywheel.api.struct; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; @@ -18,7 +18,7 @@ public interface StructType { */ VertexFormat format(); - Writeable asWriteable(); + Instanced asInstanced(); Batched asBatched(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java b/src/main/java/com/jozufozu/flywheel/api/struct/StructWriter.java similarity index 87% rename from src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java rename to src/main/java/com/jozufozu/flywheel/api/struct/StructWriter.java index 7c22400f6..abebee807 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/StructWriter.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/StructWriter.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.struct; +package com.jozufozu.flywheel.api.struct; /** * StructWriters can quickly consume many instances of S and write them to some backing buffer. diff --git a/src/main/java/com/jozufozu/flywheel/api/struct/package-info.java b/src/main/java/com/jozufozu/flywheel/api/struct/package-info.java new file mode 100644 index 000000000..da8cef289 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/api/struct/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.jozufozu.flywheel.api.struct; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 2d8edb5b7..6485843e3 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -17,6 +17,7 @@ import com.jozufozu.flywheel.api.FlywheelWorld; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.MaterialSpec; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; @@ -43,7 +44,7 @@ public class Backend { private boolean enabled; private final List> contexts = new ArrayList<>(); - private final Map> materialRegistry = new HashMap<>(); + private final Map> materialRegistry = new HashMap<>(); private final Map programSpecRegistry = new HashMap<>(); protected Backend() { @@ -91,14 +92,13 @@ public class Backend { /** * Register an instancing material. */ - public MaterialSpec register(MaterialSpec spec) { - ResourceLocation name = spec.name; + public StructType register(ResourceLocation name, StructType spec) { if (materialRegistry.containsKey(name)) { throw new IllegalStateException("Material spec '" + name + "' already registered."); } materialRegistry.put(name, spec); - log.debug("registered material '" + name + "' with instance size " + spec.getInstanceType().format().getStride()); + log.debug("registered material '" + name + "' with instance size " + spec.format().getStride()); return spec; } @@ -143,7 +143,7 @@ public class Backend { return canUseInstancing() && isFlywheelWorld(world); } - public Collection> allMaterials() { + public Collection> allMaterials() { return materialRegistry.values(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java index aa3574c11..11aec327e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java @@ -5,7 +5,7 @@ import java.util.BitSet; import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.Instancer; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.Model; public abstract class AbstractInstancer implements Instancer { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java index d7b24c696..c9e022800 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterial.java @@ -8,7 +8,7 @@ import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.Instancer; import com.jozufozu.flywheel.api.Material; import com.jozufozu.flywheel.api.MaterialSpec; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.Model; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -18,8 +18,8 @@ public class BatchedMaterial implements Material { protected final Map> models; private final StructType type; - public BatchedMaterial(MaterialSpec spec) { - type = spec.getInstanceType(); + public BatchedMaterial(StructType type) { + this.type = type; this.models = new HashMap<>(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java index 64aaa2a2c..dc35e0f06 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java @@ -6,6 +6,7 @@ import java.util.Map; import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.MaterialGroup; import com.jozufozu.flywheel.api.MaterialSpec; +import com.jozufozu.flywheel.api.struct.StructType; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -16,7 +17,7 @@ public class BatchedMaterialGroup implements MaterialGroup { protected final RenderType state; - private final Map, BatchedMaterial> materials = new HashMap<>(); + private final Map, BatchedMaterial> materials = new HashMap<>(); public BatchedMaterialGroup(RenderType state) { this.state = state; @@ -30,7 +31,7 @@ public class BatchedMaterialGroup implements MaterialGroup { */ @SuppressWarnings("unchecked") @Override - public BatchedMaterial material(MaterialSpec spec) { + public BatchedMaterial material(StructType spec) { return (BatchedMaterial) materials.computeIfAbsent(spec, BatchedMaterial::new); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java index 0e27115bf..270812f92 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java @@ -2,8 +2,8 @@ package com.jozufozu.flywheel.backend.instancing.batching; import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; import com.jozufozu.flywheel.api.InstanceData; -import com.jozufozu.flywheel.backend.struct.BatchingTransformer; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.BatchingTransformer; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.Model; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java index e0e532401..556671492 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java @@ -13,8 +13,8 @@ import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.backend.model.IBufferedModel; import com.jozufozu.flywheel.backend.model.ModelAllocator; -import com.jozufozu.flywheel.backend.struct.StructType; -import com.jozufozu.flywheel.backend.struct.StructWriter; +import com.jozufozu.flywheel.api.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructWriter; import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.util.AttribUtil; @@ -161,7 +161,7 @@ public class GPUInstancer extends AbstractInstancer { if (length > 0) { MappedBuffer mapped = instanceVBO.getBuffer(offset, length); - StructWriter writer = type.asWriteable().getWriter(mapped); + StructWriter writer = type.asInstanced().getWriter(mapped); dirtySet.stream() .forEach(i -> { @@ -181,7 +181,7 @@ public class GPUInstancer extends AbstractInstancer { instanceVBO.alloc(glBufferSize); MappedBuffer buffer = instanceVBO.getBuffer(0, glBufferSize); - StructWriter writer = type.asWriteable().getWriter(buffer); + StructWriter writer = type.asInstanced().getWriter(buffer); for (D datum : data) { writer.write(datum); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java index 855c993b7..675b8fd90 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterial.java @@ -11,7 +11,7 @@ import com.jozufozu.flywheel.api.Instancer; import com.jozufozu.flywheel.api.Material; import com.jozufozu.flywheel.api.MaterialSpec; import com.jozufozu.flywheel.backend.model.ModelPool; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.model.Model; @@ -25,8 +25,8 @@ public class InstancedMaterial implements Material { protected final Cache> models; protected final StructType type; - public InstancedMaterial(MaterialSpec spec) { - this.type = spec.getInstanceType(); + public InstancedMaterial(StructType spec) { + this.type = spec; modelPool = new ModelPool(Formats.UNLIT_MODEL, 64); this.models = CacheBuilder.newBuilder() diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java index 178dfc4c4..cff2ed787 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedMaterialGroup.java @@ -7,6 +7,7 @@ import java.util.Map; import com.jozufozu.flywheel.api.InstanceData; import com.jozufozu.flywheel.api.MaterialGroup; import com.jozufozu.flywheel.api.MaterialSpec; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.util.TextureBinder; import com.mojang.math.Matrix4f; @@ -26,7 +27,7 @@ public class InstancedMaterialGroup

implements MaterialG protected final ArrayList> renderers = new ArrayList<>(); - private final Map, InstancedMaterial> materials = new HashMap<>(); + private final Map, InstancedMaterial> materials = new HashMap<>(); public InstancedMaterialGroup(InstancingEngine

owner, RenderType type) { this.owner = owner; @@ -41,7 +42,7 @@ public class InstancedMaterialGroup

implements MaterialG */ @SuppressWarnings("unchecked") @Override - public InstancedMaterial material(MaterialSpec spec) { + public InstancedMaterial material(StructType spec) { return (InstancedMaterial) materials.computeIfAbsent(spec, this::createInstanceMaterial); } @@ -70,10 +71,11 @@ public class InstancedMaterialGroup

implements MaterialG renderers.clear(); } - private InstancedMaterial createInstanceMaterial(MaterialSpec type) { + private InstancedMaterial createInstanceMaterial(StructType type) { InstancedMaterial material = new InstancedMaterial<>(type); - this.renderers.add(new InstancedMaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup)); + this.renderers.add(new InstancedMaterialRenderer<>(owner.getProgram(type.asInstanced() + .getProgramSpec()), material, this::setup)); return material; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java b/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java index 5d302f5e7..d46cbcaed 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.backend.struct; +import com.jozufozu.flywheel.api.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructWriter; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java index 485d7a6f8..d5e97eeb9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.struct; import org.lwjgl.system.MemoryUtil; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; /** diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index 619c52b86..ccae21eaf 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.core; -import com.jozufozu.flywheel.api.MaterialSpec; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.materials.model.ModelType; import com.jozufozu.flywheel.core.materials.oriented.OrientedData; @@ -14,17 +14,14 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class Materials { - public static final StructType ORIENTED_TYPE = new OrientedType(); - public static final StructType TRANSFORMED_TYPE = new ModelType(); - public static final MaterialSpec ORIENTED = new MaterialSpec<>(Names.ORIENTED, Programs.ORIENTED, ORIENTED_TYPE); - public static final MaterialSpec TRANSFORMED = new MaterialSpec<>(Names.MODEL, Programs.TRANSFORMED, TRANSFORMED_TYPE); + public static final StructType ORIENTED = new OrientedType(); + public static final StructType TRANSFORMED = new ModelType(); public static void flwInit(GatherContextEvent event) { - event.getBackend() - .register(ORIENTED); - event.getBackend() - .register(TRANSFORMED); + Backend backend = event.getBackend(); + backend.register(Names.ORIENTED, ORIENTED); + backend.register(Names.MODEL, TRANSFORMED); } public static class Names { diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java index a9a2ae14e..5271003bd 100644 --- a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java @@ -7,7 +7,6 @@ import java.util.stream.Stream; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.ShaderContext; -import com.jozufozu.flywheel.api.MaterialSpec; import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline; import com.jozufozu.flywheel.core.shader.ContextAwareProgram; import com.jozufozu.flywheel.core.shader.WorldProgram; @@ -88,7 +87,8 @@ public class WorldContext

implements ShaderContext

{ if (specStream == null) { specStream = () -> backend.allMaterials() .stream() - .map(MaterialSpec::getProgramName); + .map(type -> type.asInstanced() + .getProgramSpec()); } return new WorldContext<>(backend, name, specStream, pipeline); } diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java index bfa0a1ac6..0851fbcc4 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelTransformer.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core.materials.model; -import com.jozufozu.flywheel.backend.struct.BatchingTransformer; +import com.jozufozu.flywheel.api.struct.BatchingTransformer; import com.jozufozu.flywheel.core.model.Model; public class ModelTransformer extends BatchingTransformer { diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java index ff99dc97b..6b824890f 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/ModelType.java @@ -2,15 +2,18 @@ package com.jozufozu.flywheel.core.materials.model; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.Batched; -import com.jozufozu.flywheel.backend.struct.BatchingTransformer; -import com.jozufozu.flywheel.backend.struct.StructWriter; -import com.jozufozu.flywheel.backend.struct.Writeable; +import com.jozufozu.flywheel.api.struct.Batched; +import com.jozufozu.flywheel.api.struct.BatchingTransformer; +import com.jozufozu.flywheel.api.struct.StructWriter; +import com.jozufozu.flywheel.api.struct.Instanced; import com.jozufozu.flywheel.core.Formats; +import com.jozufozu.flywheel.core.Programs; import com.jozufozu.flywheel.core.materials.model.writer.UnsafeModelWriter; import com.jozufozu.flywheel.core.model.Model; -public class ModelType implements Writeable, Batched { +import net.minecraft.resources.ResourceLocation; + +public class ModelType implements Instanced, Batched { @Override public ModelData create() { @@ -27,6 +30,11 @@ public class ModelType implements Writeable, Batched { return new UnsafeModelWriter(backing, this); } + @Override + public ResourceLocation getProgramSpec() { + return Programs.TRANSFORMED; + } + @Override public BatchingTransformer getTransformer(Model model) { return null; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/package-info.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/package-info.java new file mode 100644 index 000000000..9f136b741 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.jozufozu.flywheel.core.materials.model; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java b/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java index 090070cc2..f7dba06ad 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/model/writer/UnsafeModelWriter.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core.materials.model.writer; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.util.WriteUnsafe; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java index 5019cd61d..f5203d69c 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/OrientedType.java @@ -2,15 +2,18 @@ package com.jozufozu.flywheel.core.materials.oriented; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.Batched; -import com.jozufozu.flywheel.backend.struct.BatchingTransformer; -import com.jozufozu.flywheel.backend.struct.StructWriter; -import com.jozufozu.flywheel.backend.struct.Writeable; +import com.jozufozu.flywheel.api.struct.Batched; +import com.jozufozu.flywheel.api.struct.BatchingTransformer; +import com.jozufozu.flywheel.api.struct.StructWriter; +import com.jozufozu.flywheel.api.struct.Instanced; import com.jozufozu.flywheel.core.Formats; +import com.jozufozu.flywheel.core.Programs; import com.jozufozu.flywheel.core.materials.oriented.writer.UnsafeOrientedWriter; import com.jozufozu.flywheel.core.model.Model; -public class OrientedType implements Writeable, Batched { +import net.minecraft.resources.ResourceLocation; + +public class OrientedType implements Instanced, Batched { @Override public OrientedData create() { @@ -27,6 +30,11 @@ public class OrientedType implements Writeable, Batched getTransformer(Model model) { return null; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/package-info.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/package-info.java new file mode 100644 index 000000000..185239e40 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.jozufozu.flywheel.core.materials.oriented; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java index b44df9a9d..b33cefa58 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/oriented/writer/UnsafeOrientedWriter.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.core.materials.oriented.writer; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer; -import com.jozufozu.flywheel.backend.struct.StructType; +import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.struct.UnsafeBufferWriter; import com.jozufozu.flywheel.core.materials.oriented.OrientedData;