diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 83acbe955..beab8e28e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -26,10 +26,9 @@ import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.IFlywheelWorld; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; +import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; import com.jozufozu.flywheel.util.WorldAttached; -import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.foundation.config.AllConfigs; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -131,7 +130,7 @@ public class Backend { /** * Register an instancing material. */ - public static > MaterialSpec register(MaterialSpec spec) { + public static MaterialSpec register(MaterialSpec spec) { ResourceLocation name = spec.name; if (materialRegistry.containsKey(name)) { throw new IllegalStateException("Material spec '" + name + "' already registered."); @@ -275,14 +274,6 @@ public class Backend { return canUseInstancing() && isFlywheelWorld(world); } - /** - * TODO: Remove in favor of separate debug programs specified by the SpecLoader/IMultiProgram - */ - @Deprecated - public static int getDebugMode() { - return KineticDebugger.isActive() ? 1 : 0; - } - public static Collection> allMaterials() { return materialRegistry.values(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/BufferedModel.java b/src/main/java/com/jozufozu/flywheel/backend/BufferedModel.java index 3f2f959a0..934ba2722 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/BufferedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/BufferedModel.java @@ -13,16 +13,45 @@ import net.minecraft.client.renderer.BufferBuilder; public abstract class BufferedModel extends TemplateBuffer { + protected final VertexFormat modelFormat; protected GlBuffer modelVBO; - protected boolean removed; + private boolean initialized; // lazy init + private boolean removed; - protected BufferedModel(BufferBuilder buf) { + protected BufferedModel(VertexFormat modelFormat, BufferBuilder buf) { super(buf); - if (vertexCount > 0) init(); + this.modelFormat = modelFormat; + } + + /** + * Renders this model, checking first if there is anything to render. + */ + public final void render() { + if (vertexCount == 0 || removed) return; + + if (!initialized) { + // Lazily acquire resources in order to get around initialization order, as #getTotalShaderAttributeCount + // might depend on fields in subclasses. + init(); + initialized = true; + } + + doRender(); + } + + /** + * Set up any state and make the draw calls. + */ + protected abstract void doRender(); + + public final void delete() { + removed = true; + if (initialized) { + RenderWork.enqueue(this::deleteInternal); + } } protected void init() { - modelVBO = new GlBuffer(GlBufferType.ARRAY_BUFFER); modelVBO.bind(); @@ -31,7 +60,7 @@ public abstract class BufferedModel extends TemplateBuffer { } protected void initModel() { - int stride = getModelFormat().getStride(); + int stride = modelFormat.getStride(); int invariantSize = vertexCount * stride; // allocate the buffer on the gpu @@ -47,40 +76,17 @@ public abstract class BufferedModel extends TemplateBuffer { protected abstract void copyVertex(MappedBuffer to, int index); - protected abstract VertexFormat getModelFormat(); - protected int getTotalShaderAttributeCount() { - return getModelFormat().getShaderAttributeCount(); + return modelFormat.getShaderAttributeCount(); } - /** - * Renders this model, checking first if there is anything to render. - */ - public final void render() { - if (vertexCount == 0 || removed) return; - - doRender(); - } - - /** - * Set up any state and make the draw calls. - */ - protected abstract void doRender(); - protected void setupAttributes() { int numAttributes = getTotalShaderAttributeCount(); for (int i = 0; i <= numAttributes; i++) { GL20.glEnableVertexAttribArray(i); } - getModelFormat().vertexAttribPointers(0); - } - - public final void delete() { - removed = true; - if (vertexCount > 0) { - RenderWork.enqueue(this::deleteInternal); - } + modelFormat.vertexAttribPointers(0); } protected void deleteInternal() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/materials/OrientedModel.java b/src/main/java/com/jozufozu/flywheel/backend/core/materials/OrientedModel.java deleted file mode 100644 index 6c5ca0544..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/core/materials/OrientedModel.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.jozufozu.flywheel.backend.core.materials; - -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; - -import net.minecraft.client.renderer.BufferBuilder; - -public class OrientedModel extends InstancedModel { - public static final VertexFormat INSTANCE_FORMAT = VertexFormat.builder() - .addAttributes(BasicAttributes.class) - .addAttributes(OrientedAttributes.class) - .build(); - - public OrientedModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected OrientedData newInstance() { - return new OrientedData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return INSTANCE_FORMAT; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/materials/TransformedModel.java b/src/main/java/com/jozufozu/flywheel/backend/core/materials/TransformedModel.java deleted file mode 100644 index 4d848b2e9..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/core/materials/TransformedModel.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.jozufozu.flywheel.backend.core.materials; - -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; - -import net.minecraft.client.renderer.BufferBuilder; - -public class TransformedModel extends InstancedModel { - public static final VertexFormat INSTANCE_FORMAT = VertexFormat.builder() - .addAttributes(BasicAttributes.class) - .addAttributes(TransformAttributes.class) - .build(); - - public TransformedModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected ModelData newInstance() { - return new ModelData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return INSTANCE_FORMAT; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java index eace56477..16de2eb1e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/MappedBuffer.java @@ -20,6 +20,9 @@ public abstract class MappedBuffer implements AutoCloseable { protected abstract void checkAndMap(); + /** + * Make the changes in client memory available to the GPU. + */ public void flush() { if (mapped) { GL15.glUnmapBuffer(owner.type.glEnum); @@ -51,7 +54,6 @@ public abstract class MappedBuffer implements AutoCloseable { /** * Position this buffer relative to the 0-index in GPU memory. * - * @param p * @return This buffer. */ public MappedBuffer position(int p) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceFactory.java new file mode 100644 index 000000000..533b63af9 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceFactory.java @@ -0,0 +1,5 @@ +package com.jozufozu.flywheel.backend.instancing; + +public interface InstanceFactory { + D create(InstancedModel owner); +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedModel.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedModel.java index 57789e637..9409e4edf 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedModel.java @@ -17,11 +17,13 @@ import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import net.minecraft.client.renderer.BufferBuilder; -public abstract class InstancedModel extends BufferedModel { +public class InstancedModel extends BufferedModel { public static final VertexFormat FORMAT = VertexFormat.builder().addAttributes(ModelAttributes.class).build(); public final InstancedTileRenderer renderer; + protected final VertexFormat instanceFormat; + protected final InstanceFactory factory; protected GlVertexArray vao; protected GlBuffer instanceVBO; protected int glBufferSize = -1; @@ -32,11 +34,22 @@ public abstract class InstancedModel extends BufferedMod boolean anyToRemove; boolean anyToUpdate; - public InstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(buf); + public InstancedModel(InstancedTileRenderer renderer, VertexFormat instanceFormat, InstanceFactory factory, BufferBuilder buf) { + super(FORMAT, buf); + this.factory = factory; + this.instanceFormat = instanceFormat; this.renderer = renderer; } + public synchronized D createInstance() { + D instanceData = factory.create(this); + instanceData.dirty = true; + anyToUpdate = true; + data.add(instanceData); + + return instanceData; + } + @Override protected void init() { vao = new GlVertexArray(); @@ -53,14 +66,6 @@ public abstract class InstancedModel extends BufferedMod setupAttributes(); } - public int instanceCount() { - return data.size(); - } - - public boolean isEmpty() { - return instanceCount() == 0; - } - protected void deleteInternal() { super.deleteInternal(); @@ -68,23 +73,13 @@ public abstract class InstancedModel extends BufferedMod vao.delete(); } - public synchronized D createInstance() { - D instanceData = newInstance(); - instanceData.dirty = true; - anyToUpdate = true; - data.add(instanceData); - - return instanceData; - } - - protected abstract D newInstance(); - protected void doRender() { vao.bind(); renderSetup(); if (glInstanceCount > 0) Backend.compat.drawInstanced.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + vao.unbind(); } @@ -115,22 +110,22 @@ public abstract class InstancedModel extends BufferedMod } private void informAttribDivisors() { - int staticAttributes = getModelFormat().getShaderAttributeCount(); - getInstanceFormat().vertexAttribPointers(staticAttributes); + int staticAttributes = modelFormat.getShaderAttributeCount(); + instanceFormat.vertexAttribPointers(staticAttributes); - for (int i = 0; i < getInstanceFormat().getShaderAttributeCount(); i++) { + for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { Backend.compat.instancedArrays.vertexAttribDivisor(i + staticAttributes, 1); } } private void clearBufferTail() { int size = data.size(); - final int offset = size * getInstanceFormat().getStride(); + final int offset = size * instanceFormat.getStride(); final int length = glBufferSize - offset; if (length > 0) { - MappedBuffer buffer = instanceVBO.getBuffer(offset, length); - buffer.putByteArray(new byte[length]); - buffer.flush(); + instanceVBO.getBuffer(offset, length) + .putByteArray(new byte[length]) + .flush(); } } @@ -139,7 +134,7 @@ public abstract class InstancedModel extends BufferedMod if (size <= 0) return; - final int stride = getInstanceFormat().getStride(); + final int stride = instanceFormat.getStride(); final BitSet dirtySet = getDirtyBitSet(); if (dirtySet.isEmpty()) return; @@ -180,7 +175,7 @@ public abstract class InstancedModel extends BufferedMod private boolean realloc() { int size = this.data.size(); - int stride = getInstanceFormat().getStride(); + int stride = instanceFormat.getStride(); int requiredSize = size * stride; if (requiredSize > glBufferSize) { glBufferSize = requiredSize + stride * 16; @@ -199,9 +194,7 @@ public abstract class InstancedModel extends BufferedMod } private void removeDeletedInstances() { - // figure out which elements are to be removed - // any exception thrown from the filter predicate at this stage - // will leave the collection unmodified + // Figure out which elements are to be removed. final int oldSize = this.data.size(); int removeCount = 0; final BitSet removeSet = new BitSet(oldSize); @@ -246,14 +239,7 @@ public abstract class InstancedModel extends BufferedMod constant.putFloat(getV(template, i)); } - @Override - protected VertexFormat getModelFormat() { - return FORMAT; - } - - protected abstract VertexFormat getInstanceFormat(); - protected int getTotalShaderAttributeCount() { - return getInstanceFormat().getShaderAttributeCount() + super.getTotalShaderAttributeCount(); + return instanceFormat.getShaderAttributeCount() + super.getTotalShaderAttributeCount(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java index 61183820e..04a3646fc 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java @@ -46,7 +46,7 @@ public abstract class InstancedTileRenderer

{ materials = new HashMap<>(); for (MaterialSpec spec : Backend.allMaterials()) { - materials.put(spec, spec.create(this)); + materials.put(spec, new RenderMaterial<>(this, spec)); } queuedUpdates = ConcurrentHashMap.newKeySet(64); @@ -137,15 +137,15 @@ public abstract class InstancedTileRenderer

{ } @SuppressWarnings("unchecked") - public > RenderMaterial getMaterial(MaterialSpec materialType) { - return (RenderMaterial) materials.get(materialType); + public RenderMaterial getMaterial(MaterialSpec materialType) { + return (RenderMaterial) materials.get(materialType); } - public RenderMaterial> getTransformMaterial() { + public RenderMaterial getTransformMaterial() { return getMaterial(AllMaterialSpecs.TRANSFORMED); } - public RenderMaterial> getOrientedMaterial() { + public RenderMaterial getOrientedMaterial() { return getMaterial(AllMaterialSpecs.ORIENTED); } 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 8e319f98d..565cf5d41 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java @@ -1,32 +1,35 @@ package com.jozufozu.flywheel.backend.instancing; -import com.jozufozu.flywheel.backend.core.BasicProgram; +import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec; import net.minecraft.util.ResourceLocation; -public class MaterialSpec> { +public class MaterialSpec { public final ResourceLocation name; private final ProgramSpec programSpec; - private final ModelFactory modelFactory; + private final VertexFormat instanceFormat; + private final InstanceFactory instanceFactory; - public MaterialSpec(ResourceLocation name, ProgramSpec programSpec, ModelFactory modelFactory) { + public MaterialSpec(ResourceLocation name, ProgramSpec programSpec, VertexFormat instanceFormat, InstanceFactory instanceFactory) { this.name = name; this.programSpec = programSpec; - this.modelFactory = modelFactory; + this.instanceFormat = instanceFormat; + this.instanceFactory = instanceFactory; } public ProgramSpec getProgramSpec() { return programSpec; } - public ModelFactory getModelFactory() { - return modelFactory; + public VertexFormat getInstanceFormat() { + return instanceFormat; } - public

RenderMaterial create(InstancedTileRenderer

renderer) { - return new RenderMaterial<>(renderer, programSpec, modelFactory); + public InstanceFactory getInstanceFactory() { + return instanceFactory; } + } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/ModelFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/ModelFactory.java deleted file mode 100644 index 74edfc7b4..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/ModelFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.jozufozu.flywheel.backend.instancing; - -import net.minecraft.client.renderer.BufferBuilder; - -@FunctionalInterface -public interface ModelFactory> { - B makeModel(InstancedTileRenderer renderer, BufferBuilder buf); -} 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 f3994d105..7ce543169 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.Arrays; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; -import java.util.function.Predicate; import java.util.function.Supplier; import org.apache.commons.lang3.tuple.Pair; @@ -13,7 +12,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.gl.shader.ProgramSpec; import com.jozufozu.flywheel.backend.gl.shader.ShaderCallback; import com.jozufozu.flywheel.util.RenderUtil; import com.jozufozu.flywheel.util.VirtualEmptyModelData; @@ -32,33 +30,19 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; -public class RenderMaterial

> { +public class RenderMaterial

{ protected final InstancedTileRenderer

renderer; - protected final Cache models; - protected final ModelFactory factory; - protected final ProgramSpec programSpec; - protected final Predicate layerPredicate; + protected final Cache> models; + protected final MaterialSpec spec; - /** - * Creates a material that renders in the default layer (CUTOUT_MIPPED) - */ - public RenderMaterial(InstancedTileRenderer

renderer, ProgramSpec programSpec, ModelFactory factory) { - this(renderer, programSpec, factory, type -> type == RenderType.getCutoutMipped()); - } - - public RenderMaterial(InstancedTileRenderer

renderer, ProgramSpec programSpec, ModelFactory factory, Predicate layerPredicate) { + public RenderMaterial(InstancedTileRenderer

renderer, MaterialSpec spec) { this.renderer = renderer; + this.spec = spec; + this.models = CacheBuilder.newBuilder() .removalListener(notification -> ((InstancedModel) notification.getValue()).delete()) .build(); - this.factory = factory; - this.programSpec = programSpec; - this.layerPredicate = layerPredicate; - } - - public boolean canRenderInLayer(RenderType layer) { - return layerPredicate.test(layer); } public void render(RenderType layer, Matrix4f projection, double camX, double camY, double camZ) { @@ -66,9 +50,9 @@ public class RenderMaterial

setup) { - if (!canRenderInLayer(layer)) return; + if (!(layer == RenderType.getCutoutMipped())) return; - P program = renderer.context.getProgram(programSpec); + P program = renderer.context.getProgram(this.spec.getProgramSpec()); program.bind(); program.uploadViewProjection(viewProjection); program.uploadCameraPos(camX, camY, camZ); @@ -87,30 +71,30 @@ public class RenderMaterial

f) { - for (MODEL model : models.asMap().values()) { + public void runOnAll(Consumer> f) { + for (InstancedModel model : models.asMap().values()) { f.accept(model); } } - public MODEL getModel(PartialModel partial, BlockState referenceState) { + public InstancedModel getModel(PartialModel partial, BlockState referenceState) { return get(partial, () -> buildModel(partial.get(), referenceState)); } - public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir) { + public InstancedModel getModel(PartialModel partial, BlockState referenceState, Direction dir) { return getModel(partial, referenceState, dir, RenderUtil.rotateToFace(dir)); } - public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { + public InstancedModel getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { return get(Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); } - public MODEL getModel(BlockState toRender) { + public InstancedModel getModel(BlockState toRender) { return get(toRender, () -> buildModel(toRender)); } - public MODEL get(Object key, Supplier supplier) { + public InstancedModel get(Object key, Supplier> supplier) { try { return models.get(key, supplier::get); } catch (ExecutionException e) { @@ -119,19 +103,19 @@ public class RenderMaterial

buildModel(BlockState renderedState) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); return buildModel(dispatcher.getModelForState(renderedState), renderedState); } - private MODEL buildModel(IBakedModel model, BlockState renderedState) { + private InstancedModel buildModel(IBakedModel model, BlockState renderedState) { return buildModel(model, renderedState, new MatrixStack()); } - private MODEL buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { + private InstancedModel buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilder builder = getBufferBuilder(model, referenceState, ms); - return factory.makeModel(renderer, builder); + return new InstancedModel<>(renderer, spec.getInstanceFormat(), spec.getInstanceFactory(), builder); } private static final Direction[] dirs; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java index bec358be7..bc7e8f4d2 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java @@ -117,11 +117,11 @@ public abstract class TileEntityInstance implements IInsta models.forEach(model -> model.setBlockLight(block).setSkyLight(sky)); } - protected RenderMaterial> getTransformMaterial() { + protected RenderMaterial getTransformMaterial() { return renderer.getTransformMaterial(); } - protected RenderMaterial> getOrientedMaterial() { + protected RenderMaterial getOrientedMaterial() { return renderer.getOrientedMaterial(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index 5bf761651..3525e9417 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; @@ -85,9 +84,9 @@ public abstract class KineticTileInstance extends T return shaft(getRotationAxis()); } - protected final RenderMaterial> getRotatingMaterial() { + protected final RenderMaterial getRotatingMaterial() { return renderer.getMaterial(AllMaterialSpecs.ROTATING); - } + } public static BlockState shaft(Direction.Axis axis) { return AllBlocks.SHAFT.getDefaultState() diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java index e75eec62c..ef59d938e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java @@ -11,9 +11,9 @@ public class RotatingData extends KineticData { private byte rotationAxisY; private byte rotationAxisZ; - protected RotatingData(InstancedModel owner) { - super(owner); - } + public RotatingData(InstancedModel owner) { + super(owner); + } public RotatingData setRotationAxis(Direction.Axis axis) { Direction orientation = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java deleted file mode 100644 index 5eaadbc5a..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.simibubi.create.content.contraptions.base; - -import com.jozufozu.flywheel.backend.core.materials.BasicAttributes; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; - -import net.minecraft.client.renderer.BufferBuilder; - -public class RotatingModel extends InstancedModel { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(BasicAttributes.class) - .addAttributes(KineticAttributes.class) - .addAttributes(RotatingAttributes.class) - .build(); - - public RotatingModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected RotatingData newInstance() { - return new RotatingData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return FORMAT; - } - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorData.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorData.java index 3d44c51ba..0d993e316 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorData.java @@ -28,9 +28,9 @@ public class ActorData extends InstanceData { private float speed; - protected ActorData(InstancedModel owner) { - super(owner); - } + public ActorData(InstancedModel owner) { + super(owner); + } public ActorData setPosition(BlockPos pos) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorModel.java deleted file mode 100644 index 9010ba9ca..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/ActorModel.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.simibubi.create.content.contraptions.components.actors; - -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; - -import net.minecraft.client.renderer.BufferBuilder; - -public class ActorModel extends InstancedModel { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(ActorVertexAttributes.class) - .build(); - - public ActorModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected VertexFormat getInstanceFormat() { - return FORMAT; - } - - @Override - protected ActorData newInstance() { - return new ActorData(this); - } -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java index 517e4fcdb..e0dd37923 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.components.actors; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; @@ -21,7 +20,7 @@ public class DrillActorInstance extends ActorInstance { public DrillActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> renderMaterial = modelManager.getActorMaterial(); + RenderMaterial renderMaterial = modelManager.getActorMaterial(); BlockState state = context.state; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java index 60dfede9b..e04fa94a8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.actors; import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; import com.jozufozu.flywheel.backend.core.materials.ModelData; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -36,7 +35,7 @@ public class HarvesterActorInstance extends ActorInstance { public HarvesterActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> renderMaterial = modelManager.getTransformMaterial(); + RenderMaterial renderMaterial = modelManager.getTransformMaterial(); BlockState state = context.state; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java index 544fbf41f..94b874fca 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java @@ -5,7 +5,6 @@ import static com.simibubi.create.content.contraptions.base.DirectionalKineticBl import com.jozufozu.flywheel.backend.core.PartialModel; import com.jozufozu.flywheel.backend.core.materials.ModelData; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -45,7 +44,7 @@ public class DeployerActorInstance extends ActorInstance { public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> mat = modelManager.getTransformMaterial(); + RenderMaterial mat = modelManager.getTransformMaterial(); BlockState state = context.state; DeployerTileEntity.Mode mode = NBTHelper.readEnum(context.tileData, "Mode", DeployerTileEntity.Mode.class); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index 96627328b..ef6f69d5b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -63,15 +63,15 @@ public class FlyWheelInstance extends KineticTileInstance im connectorAngleMult = flipAngle ? -1 : 1; - RenderMaterial> mat = getTransformMaterial(); + RenderMaterial mat = getTransformMaterial(); - upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); - lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); - upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, blockState).createInstance(); - lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, blockState).createInstance(); + upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); + lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); + upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, blockState).createInstance(); + lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, blockState).createInstance(); - connectors = Lists.newArrayList(upperRotating, lowerRotating, upperSliding, lowerSliding); - } else { + connectors = Lists.newArrayList(upperRotating, lowerRotating, upperSliding, lowerSliding); + } else { connectors = Collections.emptyList(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java index 821cce83e..a65f178fa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -7,7 +7,6 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.simibubi.create.AllMovementBehaviours; @@ -65,9 +64,9 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer> getActorMaterial() { + public RenderMaterial getActorMaterial() { return getMaterial(AllMaterialSpecs.ACTORS); - } + } public RenderedContraption getContraption() { return contraption.get(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java index 6c4d90485..acdca2f9f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionModel.java @@ -21,7 +21,7 @@ public class ContraptionModel extends BufferedModel { protected GlBuffer ebo; public ContraptionModel(BufferBuilder buf) { - super(buf); + super(FORMAT, buf); } @Override @@ -93,11 +93,6 @@ public class ContraptionModel extends BufferedModel { to.put(sky); } - @Override - protected VertexFormat getModelFormat() { - return FORMAT; - } - @Override protected void deleteInternal() { super.deleteInternal(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java index 1d4025831..29264554a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java @@ -21,9 +21,9 @@ public class BeltData extends KineticData { private float maxV; private byte scrollMult; - protected BeltData(InstancedModel owner) { - super(owner); - } + public BeltData(InstancedModel owner) { + super(owner); + } public BeltData setRotation(Quaternion q) { this.qX = q.getX(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java deleted file mode 100644 index 58dc8e651..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.simibubi.create.content.contraptions.relays.belt; - -import com.jozufozu.flywheel.backend.core.materials.BasicAttributes; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.content.contraptions.base.KineticAttributes; - -import net.minecraft.client.renderer.BufferBuilder; - -public class BeltInstancedModel extends InstancedModel { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(BasicAttributes.class) - .addAttributes(KineticAttributes.class) - .addAttributes(BeltAttributes.class) - .build(); - - public BeltInstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected BeltData newInstance() { - return new BeltData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return FORMAT; - } - -} diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index a2847452d..39596f241 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -26,7 +26,7 @@ public class SplitShaftInstance extends KineticTileInstance> rotatingMaterial = getRotatingMaterial(); + RenderMaterial rotatingMaterial = getRotatingMaterial(); for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index 747c6a9ec..cf85386ac 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -33,7 +33,7 @@ public class GearboxInstance extends KineticTileInstance { int skyLight = world.getLightLevel(LightType.SKY, pos); updateSourceFacing(); - RenderMaterial> rotatingMaterial = getRotatingMaterial(); + RenderMaterial rotatingMaterial = getRotatingMaterial(); for (Direction direction : Iterate.directions) { final Direction.Axis axis = direction.getAxis(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java deleted file mode 100644 index 42aeb46f5..000000000 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapModel.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.simibubi.create.content.logistics.block; - -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; - -import net.minecraft.client.renderer.BufferBuilder; - -public class FlapModel extends InstancedModel { - public static VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(FlapAttributes.class) - .build(); - - public FlapModel(InstancedTileRenderer renderer, BufferBuilder buf) { - super(renderer, buf); - } - - @Override - protected FlapData newInstance() { - return new FlapData(this); - } - - @Override - protected VertexFormat getInstanceFormat() { - return FORMAT; - } -} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 455659db6..42912a6a2 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -47,7 +47,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta public ArmInstance(InstancedTileRenderer modelManager, ArmTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = getTransformMaterial(); + RenderMaterial mat = getTransformMaterial(); base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java index 995952c78..705fde20f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.logistics.block.redstone; import com.jozufozu.flywheel.backend.core.materials.ModelData; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; @@ -27,7 +26,7 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, AnalogLeverTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = getTransformMaterial(); + RenderMaterial mat = getTransformMaterial(); handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance(); indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java index 0a011f316..9568583db 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.schematics.block; import com.jozufozu.flywheel.backend.core.materials.ModelData; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.RenderMaterial; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; @@ -21,7 +20,7 @@ public class SchematicannonInstance extends TileEntityInstance modelManager, SchematicannonTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = getTransformMaterial(); + RenderMaterial mat = getTransformMaterial(); connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance(); pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/foundation/render/AllInstanceFormats.java b/src/main/java/com/simibubi/create/foundation/render/AllInstanceFormats.java new file mode 100644 index 000000000..70c2bf3e6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/AllInstanceFormats.java @@ -0,0 +1,39 @@ +package com.simibubi.create.foundation.render; + +import com.jozufozu.flywheel.backend.core.materials.BasicAttributes; +import com.jozufozu.flywheel.backend.core.materials.OrientedAttributes; +import com.jozufozu.flywheel.backend.core.materials.TransformAttributes; +import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.simibubi.create.content.contraptions.base.KineticAttributes; +import com.simibubi.create.content.contraptions.base.RotatingAttributes; +import com.simibubi.create.content.contraptions.components.actors.ActorVertexAttributes; +import com.simibubi.create.content.contraptions.relays.belt.BeltAttributes; +import com.simibubi.create.content.logistics.block.FlapAttributes; + +public class AllInstanceFormats { + + public static final VertexFormat MODEL = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(TransformAttributes.class) + .build(); + public static final VertexFormat ORIENTED = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(OrientedAttributes.class) + .build(); + public static VertexFormat ROTATING = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(RotatingAttributes.class) + .build(); + public static VertexFormat ACTOR = VertexFormat.builder() + .addAttributes(ActorVertexAttributes.class) + .build(); + public static VertexFormat BELT = VertexFormat.builder() + .addAttributes(BasicAttributes.class) + .addAttributes(KineticAttributes.class) + .addAttributes(BeltAttributes.class) + .build(); + public static VertexFormat FLAP = VertexFormat.builder() + .addAttributes(FlapAttributes.class) + .build(); +} 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 662fb707b..a26402155 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllMaterialSpecs.java @@ -4,19 +4,12 @@ import static com.jozufozu.flywheel.backend.Backend.register; import com.jozufozu.flywheel.backend.core.materials.ModelData; import com.jozufozu.flywheel.backend.core.materials.OrientedData; -import com.jozufozu.flywheel.backend.core.materials.OrientedModel; -import com.jozufozu.flywheel.backend.core.materials.TransformedModel; -import com.jozufozu.flywheel.backend.instancing.InstancedModel; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; import com.simibubi.create.Create; import com.simibubi.create.content.contraptions.base.RotatingData; -import com.simibubi.create.content.contraptions.base.RotatingModel; import com.simibubi.create.content.contraptions.components.actors.ActorData; -import com.simibubi.create.content.contraptions.components.actors.ActorModel; import com.simibubi.create.content.contraptions.relays.belt.BeltData; -import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; import com.simibubi.create.content.logistics.block.FlapData; -import com.simibubi.create.content.logistics.block.FlapModel; import net.minecraft.util.ResourceLocation; @@ -25,14 +18,13 @@ 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 MaterialSpec> TRANSFORMED = register(new MaterialSpec<>(Locations.MODEL, AllProgramSpecs.MODEL, TransformedModel::new)); - public static final MaterialSpec> ORIENTED = register(new MaterialSpec<>(Locations.ORIENTED, AllProgramSpecs.ORIENTED, OrientedModel::new)); - - public static final MaterialSpec> ROTATING = register(new MaterialSpec<>(Locations.ROTATING, AllProgramSpecs.ROTATING, RotatingModel::new)); - public static final MaterialSpec> BELTS = register(new MaterialSpec<>(Locations.BELTS, AllProgramSpecs.BELT, BeltInstancedModel::new)); - public static final MaterialSpec> ACTORS = register(new MaterialSpec<>(Locations.ACTORS, AllProgramSpecs.ACTOR, ActorModel::new)); - public static final MaterialSpec> FLAPS = register(new MaterialSpec<>(Locations.FLAPS, AllProgramSpecs.FLAPS, FlapModel::new)); + 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 class Locations { public static final ResourceLocation MODEL = new ResourceLocation("create", "model"); diff --git a/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java index a2ce90c60..eae45b987 100644 --- a/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsHandler.java @@ -13,7 +13,6 @@ import com.jozufozu.flywheel.backend.gl.GlPrimitiveType; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; -import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.util.RenderUtil; import com.simibubi.create.foundation.render.AllProgramSpecs; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -67,9 +66,9 @@ public class EffectsHandler { private static final int bufferSize = vertices.length * 4; private final Framebuffer framebuffer; - private final GlVertexArray vao = new GlVertexArray(); + private final GlVertexArray vao; - private final GlBuffer vbo = new GlBuffer(GlBufferType.ARRAY_BUFFER); + private final GlBuffer vbo; private final ArrayList spheres; @@ -79,12 +78,14 @@ public class EffectsHandler { Framebuffer render = Minecraft.getInstance().getFramebuffer(); framebuffer = new Framebuffer(render.framebufferWidth, render.framebufferHeight, false, Minecraft.IS_RUNNING_ON_MAC); + vbo = new GlBuffer(GlBufferType.ARRAY_BUFFER); vbo.bind(); vbo.alloc(bufferSize); - MappedBuffer buffer = vbo.getBuffer(0, bufferSize); - buffer.putFloatArray(vertices); - buffer.flush(); + vbo.getBuffer(0, bufferSize) + .putFloatArray(vertices) + .flush(); + vao = new GlVertexArray(); vao.bind(); GL20.glEnableVertexAttribArray(0); diff --git a/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java index c04c61c36..a431579b2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java +++ b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java @@ -81,8 +81,8 @@ public class SphereFilterProgram extends GlProgram { public void uploadFilters(ArrayList filters) { effectsUBO.bind(GlBufferType.ARRAY_BUFFER); - MappedBuffer buffer = effectsUBO.getBuffer(0, BUFFER_SIZE); - buffer.putInt(filters.size()) + MappedBuffer buffer = effectsUBO.getBuffer(0, BUFFER_SIZE) + .putInt(filters.size()) .position(16); filters.forEach(it -> it.write(buffer));