From 695fe98d289d5e6033f539ff565f1f4a1a61d9bb Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sun, 16 May 2021 20:37:26 -0700 Subject: [PATCH] MaterialSpecs choose their model formats --- .../backend/instancing/MaterialSpec.java | 8 +++++++- .../backend/instancing/RenderMaterial.java | 4 +--- .../foundation/render/AllMaterialSpecs.java | 16 ++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java index 565cf5d41..2cfcfa435 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java @@ -10,12 +10,14 @@ public class MaterialSpec { public final ResourceLocation name; private final ProgramSpec programSpec; + private final VertexFormat modelFormat; private final VertexFormat instanceFormat; private final InstanceFactory instanceFactory; - public MaterialSpec(ResourceLocation name, ProgramSpec programSpec, VertexFormat instanceFormat, InstanceFactory instanceFactory) { + public MaterialSpec(ResourceLocation name, ProgramSpec programSpec, VertexFormat modelFormat, VertexFormat instanceFormat, InstanceFactory instanceFactory) { this.name = name; this.programSpec = programSpec; + this.modelFormat = modelFormat; this.instanceFormat = instanceFormat; this.instanceFactory = instanceFactory; } @@ -24,6 +26,10 @@ public class MaterialSpec { return programSpec; } + public VertexFormat getModelFormat() { + return modelFormat; + } + public VertexFormat getInstanceFormat() { return instanceFormat; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java index 19f0c8fcb..c5a1b4e11 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java @@ -14,7 +14,6 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.jozufozu.flywheel.backend.core.BasicProgram; import com.jozufozu.flywheel.backend.core.PartialModel; -import com.jozufozu.flywheel.backend.core.materials.ModelAttributes; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.shader.ShaderCallback; import com.jozufozu.flywheel.util.BufferBuilderReader; @@ -36,7 +35,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; public class RenderMaterial

{ - public static final VertexFormat MODEL_FORMAT = VertexFormat.builder().addAttributes(ModelAttributes.class).build(); protected final InstancedTileRenderer

renderer; protected final Cache> models; @@ -121,7 +119,7 @@ public class RenderMaterial

{ private InstancedModel buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilderReader reader = new BufferBuilderReader(getBufferBuilder(model, referenceState, ms)); - VertexFormat format = MODEL_FORMAT; + VertexFormat format = spec.getModelFormat(); int vertexCount = reader.getVertexCount(); ByteBuffer to = ByteBuffer.allocate(vertexCount * format.getStride()); diff --git a/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java index a26402155..374bcb368 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java @@ -2,8 +2,10 @@ package com.simibubi.create.foundation.render; import static com.jozufozu.flywheel.backend.Backend.register; +import com.jozufozu.flywheel.backend.core.materials.ModelAttributes; import com.jozufozu.flywheel.backend.core.materials.ModelData; import com.jozufozu.flywheel.backend.core.materials.OrientedData; +import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -18,13 +20,15 @@ public class AllMaterialSpecs { // noop, make sure the static field are loaded. } - public static final MaterialSpec TRANSFORMED = register(new MaterialSpec<>(Locations.MODEL, AllProgramSpecs.MODEL, AllInstanceFormats.MODEL, ModelData::new)); - public static final MaterialSpec ORIENTED = register(new MaterialSpec<>(Locations.ORIENTED, AllProgramSpecs.ORIENTED, AllInstanceFormats.ORIENTED, OrientedData::new)); + public static final VertexFormat UNLIT_MODEL = VertexFormat.builder().addAttributes(ModelAttributes.class).build(); - public static final MaterialSpec ROTATING = register(new MaterialSpec<>(Locations.ROTATING, AllProgramSpecs.ROTATING, AllInstanceFormats.ROTATING, RotatingData::new)); - public static final MaterialSpec BELTS = register(new MaterialSpec<>(Locations.BELTS, AllProgramSpecs.BELT, AllInstanceFormats.BELT, BeltData::new)); - public static final MaterialSpec ACTORS = register(new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, AllInstanceFormats.ACTOR, ActorData::new)); - public static final MaterialSpec FLAPS = register(new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, AllInstanceFormats.FLAP, FlapData::new)); + public static final MaterialSpec TRANSFORMED = register(new MaterialSpec<>(Locations.MODEL, AllProgramSpecs.MODEL, UNLIT_MODEL, AllInstanceFormats.MODEL, ModelData::new)); + public static final MaterialSpec ORIENTED = register(new MaterialSpec<>(Locations.ORIENTED, AllProgramSpecs.ORIENTED, UNLIT_MODEL, AllInstanceFormats.ORIENTED, OrientedData::new)); + + public static final MaterialSpec ROTATING = register(new MaterialSpec<>(Locations.ROTATING, AllProgramSpecs.ROTATING, UNLIT_MODEL, AllInstanceFormats.ROTATING, RotatingData::new)); + public static final MaterialSpec BELTS = register(new MaterialSpec<>(Locations.BELTS, AllProgramSpecs.BELT, UNLIT_MODEL, AllInstanceFormats.BELT, BeltData::new)); + public static final MaterialSpec ACTORS = register(new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, UNLIT_MODEL, AllInstanceFormats.ACTOR, ActorData::new)); + public static final MaterialSpec FLAPS = register(new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, UNLIT_MODEL, AllInstanceFormats.FLAP, FlapData::new)); public static class Locations { public static final ResourceLocation MODEL = new ResourceLocation("create", "model");