From 418676a0f0c53a28138a82496c2fe6938ceee21d Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 21 Jul 2021 20:28:20 -0700 Subject: [PATCH] MaterialGroups and massive refactors - Move material stuff to its own package - The various render functions in the material tree now bind to specific render layers - Instancers can choose which layer to use - The layers are SOLID, CUTOUT, and TRANSPARENT - More layers are likely unnecessary, but we'll see - Deprecate functions in MaterialManager in favor of more builderesque ones using MaterialGroups --- .../jozufozu/flywheel/backend/Backend.java | 2 +- .../backend/instancing/InstanceManager.java | 1 + .../instancing/InstancedRenderDispatcher.java | 8 +- .../instancing/InstancedRenderRegistry.java | 1 + .../backend/instancing/Instancer.java | 10 +- .../backend/instancing/MaterialManager.java | 161 -------------- .../instancing/entity/EntityInstance.java | 11 +- .../entity/EntityInstanceManager.java | 2 +- .../entity/IEntityInstanceFactory.java | 2 +- .../backend/instancing/package-info.java | 6 + .../instancing/tile/ITileInstanceFactory.java | 2 +- .../instancing/tile/TileEntityInstance.java | 11 +- .../instancing/tile/TileInstanceManager.java | 2 +- .../InstanceMaterial.java | 12 +- .../backend/material/MaterialGroup.java | 59 +++++ .../backend/material/MaterialManager.java | 203 ++++++++++++++++++ .../MaterialRenderer.java | 17 +- .../MaterialSpec.java | 4 +- .../flywheel/backend/state/IRenderState.java | 3 + .../flywheel/backend/state/RenderLayer.java | 25 +++ .../com/jozufozu/flywheel/core/Materials.java | 2 +- .../jozufozu/flywheel/core/WorldContext.java | 2 +- .../core/crumbling/CrumblingGroup.java | 42 ++++ .../crumbling/CrumblingInstanceManager.java | 2 +- .../crumbling/CrumblingMaterialManager.java | 66 ------ .../core/crumbling/CrumblingRenderer.java | 12 +- .../core/shader/IProgramCallback.java | 2 + .../util/transform/MatrixTransformStack.java | 14 +- .../flywheel/vanilla/BellInstance.java | 7 +- .../flywheel/vanilla/ChestInstance.java | 13 +- .../flywheel/vanilla/RenderStates.java | 1 + .../flywheel/vanilla/ShulkerBoxInstance.java | 12 +- 32 files changed, 432 insertions(+), 285 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java create mode 100644 src/main/java/com/jozufozu/flywheel/backend/instancing/package-info.java rename src/main/java/com/jozufozu/flywheel/backend/{instancing => material}/InstanceMaterial.java (92%) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java create mode 100644 src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java rename src/main/java/com/jozufozu/flywheel/backend/{instancing => material}/MaterialRenderer.java (62%) rename src/main/java/com/jozufozu/flywheel/backend/{instancing => material}/MaterialSpec.java (89%) create mode 100644 src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java delete mode 100644 src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 239aedf01..0cfb51552 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -15,7 +15,7 @@ import org.lwjgl.opengl.GLCapabilities; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index cbf29a09d..304bac4f0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.material.MaterialManager; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.client.renderer.ActiveRenderInfo; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 27bcbfacc..ce368a913 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -5,6 +5,8 @@ import javax.annotation.Nonnull; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.event.BeginFrameEvent; @@ -84,10 +86,14 @@ public class InstancedRenderDispatcher { if (!Backend.getInstance() .canUseInstancing(world)) return; + RenderLayer renderLayer = RenderLayer.fromRenderType(event.type); + + if (renderLayer == null) return; + event.type.setupRenderState(); materialManagers.get(world) - .render(event.type, event.viewProjection, event.camX, event.camY, event.camZ); + .render(renderLayer, event.viewProjection, event.camX, event.camY, event.camZ); event.type.clearRenderState(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java index 76a883bad..23d2821e9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -9,6 +9,7 @@ import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.backend.instancing.entity.IEntityInstanceFactory; import com.jozufozu.flywheel.backend.instancing.tile.ITileInstanceFactory; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; +import com.jozufozu.flywheel.backend.material.MaterialManager; import it.unimi.dsi.fastutil.objects.Object2BooleanLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java index 31f1103d8..b98d78828 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java @@ -5,12 +5,15 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.function.Supplier; +import javax.annotation.Nonnull; + import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; 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.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.util.AttribUtil; @@ -20,7 +23,7 @@ public class Instancer { public final Supplier originCoordinate; - protected Supplier gen; + protected final Supplier gen; protected BufferedModel model; protected final VertexFormat instanceFormat; @@ -30,6 +33,7 @@ public class Instancer { protected int glBufferSize = -1; protected int glInstanceCount = 0; private boolean deleted; + private boolean initialized; protected final ArrayList data = new ArrayList<>(); @@ -69,7 +73,7 @@ public class Instancer { private void init() { model = gen.get(); - gen = null; + initialized = true; if (model.getVertexCount() <= 0) throw new IllegalArgumentException("Refusing to instance a model with no vertices."); @@ -90,7 +94,7 @@ public class Instancer { } public boolean isInitialized() { - return gen != null; + return initialized; } public boolean isEmpty() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java deleted file mode 100644 index 7b6f2690b..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.jozufozu.flywheel.backend.instancing; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import com.jozufozu.flywheel.backend.state.IRenderState; -import com.jozufozu.flywheel.backend.state.TextureRenderState; -import com.jozufozu.flywheel.core.Materials; -import com.jozufozu.flywheel.core.WorldContext; -import com.jozufozu.flywheel.core.materials.ModelData; -import com.jozufozu.flywheel.core.materials.OrientedData; -import com.jozufozu.flywheel.core.shader.IProgramCallback; -import com.jozufozu.flywheel.core.shader.WorldProgram; -import com.jozufozu.flywheel.util.WeakHashSet; - -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.inventory.container.PlayerContainer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Matrix4f; -import net.minecraft.util.math.vector.Vector3i; - -// TODO: 0.2 block atlas should not be a special case -public class MaterialManager

{ - - public static int MAX_ORIGIN_DISTANCE = 100; - - protected final WorldContext

context; - - protected final Map>> renderers; - protected final Map, InstanceMaterial>> materials; - - protected BlockPos originCoordinate = BlockPos.ZERO; - - private final WeakHashSet listeners; - - public MaterialManager(WorldContext

context) { - this.context = context; - - this.materials = new HashMap<>(); - this.renderers = new HashMap<>(); - - this.listeners = new WeakHashSet<>(); - } - - /** - * Render every model for every material. - * - * @param layer Which vanilla {@link RenderType} is being drawn? - * @param viewProjection How do we get from camera space to clip space? - */ - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { - render(layer, viewProjection, camX, camY, camZ, null); - } - - /** - * Render every model for every material. - * - * @param layer Which vanilla {@link RenderType} is being drawn? - * @param viewProjection How do we get from camera space to clip space? - * @param callback Provide additional uniforms or state here. - */ - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { - camX -= originCoordinate.getX(); - camY -= originCoordinate.getY(); - camZ -= originCoordinate.getZ(); - - Matrix4f translate = Matrix4f.createTranslateMatrix((float) -camX, (float) -camY, (float) -camZ); - - translate.multiplyBackward(viewProjection); - - for (Map.Entry>> entry : renderers.entrySet()) { - entry.getKey().bind(); - - for (MaterialRenderer

materialRenderer : entry.getValue()) { - materialRenderer.render(layer, translate, camX, camY, camZ, callback); - } - - entry.getKey().unbind(); - } - } - - public void delete() { - materials.values() - .stream() - .flatMap(m -> m.values() - .stream()) - .forEach(InstanceMaterial::delete); - - materials.clear(); - renderers.clear(); - } - - public InstanceMaterial getMaterial(MaterialSpec materialType) { - return getMaterial(materialType, PlayerContainer.BLOCK_ATLAS); - } - - public InstanceMaterial getMaterial(MaterialSpec materialType, ResourceLocation texture) { - return getMaterial(materialType, TextureRenderState.get(texture)); - } - - @SuppressWarnings("unchecked") - public InstanceMaterial getMaterial(MaterialSpec materialType, IRenderState state) { - return (InstanceMaterial) materials.computeIfAbsent(state, $ -> new HashMap<>()) - .computeIfAbsent(materialType, type -> { - InstanceMaterial material = new InstanceMaterial<>(this::getOriginCoordinate, type); - - this.renderers.computeIfAbsent(state, $ -> new ArrayList<>()) - .add(new MaterialRenderer<>(context.getProgramSupplier(type.getProgramName()), material)); - - return material; - }); - } - - public InstanceMaterial getTransformMaterial() { - return getMaterial(Materials.TRANSFORMED); - } - - public InstanceMaterial getOrientedMaterial() { - return getMaterial(Materials.ORIENTED); - } - - public Vector3i getOriginCoordinate() { - return originCoordinate; - } - - public void addListener(OriginShiftListener listener) { - listeners.add(listener); - } - - public void checkAndShiftOrigin(ActiveRenderInfo info) { - int cX = MathHelper.floor(info.getPosition().x); - int cY = MathHelper.floor(info.getPosition().y); - int cZ = MathHelper.floor(info.getPosition().z); - - int dX = cX - originCoordinate.getX(); - int dY = cY - originCoordinate.getY(); - int dZ = cZ - originCoordinate.getZ(); - - if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) { - - originCoordinate = new BlockPos(cX, cY, cZ); - - materials.values() - .stream() - .flatMap(m -> m.values() - .stream()) - .forEach(InstanceMaterial::clear); - - listeners.forEach(OriginShiftListener::onOriginShift); - } - } - - @FunctionalInterface - public interface OriginShiftListener { - void onOriginShift(); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java index ae4050bac..d06dcb125 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java @@ -6,9 +6,10 @@ import java.util.stream.Stream; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.IInstance; import com.jozufozu.flywheel.backend.instancing.ITickableInstance; -import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.InstanceMaterial; +import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; +import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.IFlatLight; import com.jozufozu.flywheel.core.materials.ModelData; import com.jozufozu.flywheel.core.materials.OrientedData; @@ -120,11 +121,11 @@ public abstract class EntityInstance implements IInstance { } protected InstanceMaterial getTransformMaterial() { - return materialManager.getTransformMaterial(); - } + return materialManager.defaultSolid().material(Materials.TRANSFORMED); + } protected InstanceMaterial getOrientedMaterial() { - return materialManager.getOrientedMaterial(); + return materialManager.defaultSolid().material(Materials.ORIENTED); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java index 98429f8d5..7d2da71aa 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstanceManager.java @@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.IInstance; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java index 7915947e4..d199fb2a8 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.entity; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import net.minecraft.entity.Entity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/package-info.java new file mode 100644 index 000000000..2210f8d14 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/package-info.java @@ -0,0 +1,6 @@ +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package com.jozufozu.flywheel.backend.instancing; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java index b46187ab6..11de652ca 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/ITileInstanceFactory.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.tile; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java index 038d571ff..6c7f5bb77 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileEntityInstance.java @@ -6,8 +6,9 @@ import java.util.stream.Stream; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.IInstance; import com.jozufozu.flywheel.backend.instancing.ITickableInstance; -import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.InstanceMaterial; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.IFlatLight; import com.jozufozu.flywheel.core.materials.ModelData; import com.jozufozu.flywheel.core.materials.OrientedData; @@ -122,10 +123,10 @@ public abstract class TileEntityInstance implements IInsta } protected InstanceMaterial getTransformMaterial() { - return materialManager.getTransformMaterial(); - } + return materialManager.defaultCutout().material(Materials.TRANSFORMED); + } protected InstanceMaterial getOrientedMaterial() { - return materialManager.getOrientedMaterial(); + return materialManager.defaultCutout().material(Materials.ORIENTED); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java index c9dc7dd5f..b8878e019 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/tile/TileInstanceManager.java @@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.IInstance; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java similarity index 92% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java rename to src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java index 4a2823432..119b7ea9f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.material; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -15,6 +15,8 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.jozufozu.flywheel.backend.RenderWork; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.backend.model.IndexedModel; import com.jozufozu.flywheel.core.PartialModel; @@ -83,7 +85,7 @@ public class InstanceMaterial { } public Instancer getModel(PartialModel partial, BlockState referenceState) { - return get(partial, () -> buildModel(partial.get(), referenceState)); + return model(partial, () -> buildModel(partial.get(), referenceState)); } public Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir) { @@ -91,14 +93,14 @@ public class InstanceMaterial { } public Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { - return get(Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); + return model(Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); } public Instancer getModel(BlockState toRender) { - return get(toRender, () -> buildModel(toRender)); + return model(toRender, () -> buildModel(toRender)); } - public Instancer get(Object key, Supplier supplier) { + public Instancer model(Object key, Supplier supplier) { try { return models.get(key, () -> new Instancer<>(supplier, originCoordinate, spec)); } catch (ExecutionException e) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java new file mode 100644 index 000000000..bbcace0e0 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java @@ -0,0 +1,59 @@ +package com.jozufozu.flywheel.backend.material; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.state.IRenderState; +import com.jozufozu.flywheel.core.shader.IProgramCallback; +import com.jozufozu.flywheel.core.shader.WorldProgram; + +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.math.vector.Matrix4f; + +public class MaterialGroup

{ + + protected final MaterialManager

owner; + protected final IRenderState state; + + private final ArrayList> renderers = new ArrayList<>(); + + private final Map, InstanceMaterial> materials = new HashMap<>(); + + public MaterialGroup(MaterialManager

owner, IRenderState state) { + this.owner = owner; + this.state = state; + } + + public void render(Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { + for (MaterialRenderer

renderer : renderers) { + renderer.render(viewProjection, camX, camY, camZ, callback); + } + } + + @SuppressWarnings("unchecked") + public InstanceMaterial material(MaterialSpec spec) { + return (InstanceMaterial) materials.computeIfAbsent(spec, this::createInstanceMaterial); + } + + private InstanceMaterial createInstanceMaterial(MaterialSpec type) { + InstanceMaterial material = new InstanceMaterial<>(owner::getOriginCoordinate, type); + + this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material)); + + return material; + } + + public void clear() { + materials.values().forEach(InstanceMaterial::clear); + } + + public void delete() { + materials.values() + .forEach(InstanceMaterial::delete); + + materials.clear(); + renderers.clear(); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java new file mode 100644 index 000000000..f7c76d711 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java @@ -0,0 +1,203 @@ +package com.jozufozu.flywheel.backend.material; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.state.IRenderState; +import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.backend.state.TextureRenderState; +import com.jozufozu.flywheel.core.Materials; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.materials.ModelData; +import com.jozufozu.flywheel.core.materials.OrientedData; +import com.jozufozu.flywheel.core.shader.IProgramCallback; +import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.util.WeakHashSet; + +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.inventory.container.PlayerContainer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3i; + +public class MaterialManager

{ + + public static int MAX_ORIGIN_DISTANCE = 100; + + protected final WorldContext

context; + protected GroupFactory

groupFactory; + protected boolean ignoreOriginCoordinate; + + protected final Map>> layers; + + protected BlockPos originCoordinate = BlockPos.ZERO; + + private final WeakHashSet listeners; + + public MaterialManager(WorldContext

context) { + this.context = context; + + this.layers = new HashMap<>(); + this.listeners = new WeakHashSet<>(); + this.groupFactory = MaterialGroup::new; + + for (RenderLayer value : RenderLayer.values()) { + layers.put(value, new HashMap<>()); + } + } + + /** + * Render every model for every material. + * @param layer Which vanilla {@link RenderType} is being drawn? + * @param viewProjection How do we get from camera space to clip space? + */ + public void render(RenderLayer layer, Matrix4f viewProjection, double camX, double camY, double camZ) { + render(layer, viewProjection, camX, camY, camZ, null); + } + + /** + * Render every model for every material. + * @param layer Which vanilla {@link RenderType} is being drawn? + * @param viewProjection How do we get from camera space to clip space? + * @param callback Provide additional uniforms or state here. + */ + public void render(RenderLayer layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { + if (!ignoreOriginCoordinate) { + camX -= originCoordinate.getX(); + camY -= originCoordinate.getY(); + camZ -= originCoordinate.getZ(); + + Matrix4f translate = Matrix4f.createTranslateMatrix((float) -camX, (float) -camY, (float) -camZ); + + translate.multiplyBackward(viewProjection); + + viewProjection = translate; + } + + for (Map.Entry> entry : layers.get(layer).entrySet()) { + IRenderState state = entry.getKey(); + MaterialGroup

group = entry.getValue(); + + state.bind(); + group.render(viewProjection, camX, camY, camZ, callback); + state.unbind(); + } + } + + public void delete() { + for (Map> groups : layers.values()) { + + groups.values().forEach(MaterialGroup::delete); + } + } + + public MaterialGroup

state(RenderLayer layer, IRenderState state) { + return layers.get(layer).computeIfAbsent(state, this::createGroup); + } + + public MaterialGroup

solid(IRenderState state) { + return layers.get(RenderLayer.SOLID).computeIfAbsent(state, this::createGroup); + } + + public MaterialGroup

cutout(IRenderState state) { + return layers.get(RenderLayer.CUTOUT).computeIfAbsent(state, this::createGroup); + } + + public MaterialGroup

transparent(IRenderState state) { + return layers.get(RenderLayer.TRANSPARENT).computeIfAbsent(state, this::createGroup); + } + + public MaterialGroup

defaultSolid() { + return solid(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS)); + } + + public MaterialGroup

defaultCutout() { + return cutout(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS)); + } + + public MaterialGroup

defaultTransparent() { + return transparent(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS)); + } + + @Deprecated + public InstanceMaterial getMaterial(MaterialSpec materialType) { + return defaultCutout().material(materialType); + } + + @Deprecated + public InstanceMaterial getMaterial(MaterialSpec materialType, ResourceLocation texture) { + return cutout(TextureRenderState.get(texture)).material(materialType); + } + + @Deprecated + public InstanceMaterial getTransformMaterial() { + return defaultCutout().material(Materials.TRANSFORMED); + } + + @Deprecated + public InstanceMaterial getOrientedMaterial() { + return defaultCutout().material(Materials.ORIENTED); + } + + public Supplier

getProgram(ResourceLocation name) { + return context.getProgramSupplier(name); + } + + public MaterialManager

setIgnoreOriginCoordinate(boolean ignoreOriginCoordinate) { + this.ignoreOriginCoordinate = ignoreOriginCoordinate; + return this; + } + + public MaterialManager

setGroupFactory(GroupFactory

factory) { + this.groupFactory = factory; + return this; + } + + public Vector3i getOriginCoordinate() { + return originCoordinate; + } + + public void addListener(OriginShiftListener listener) { + listeners.add(listener); + } + + public void checkAndShiftOrigin(ActiveRenderInfo info) { + int cX = MathHelper.floor(info.getPosition().x); + int cY = MathHelper.floor(info.getPosition().y); + int cZ = MathHelper.floor(info.getPosition().z); + + int dX = cX - originCoordinate.getX(); + int dY = cY - originCoordinate.getY(); + int dZ = cZ - originCoordinate.getZ(); + + if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) { + + originCoordinate = new BlockPos(cX, cY, cZ); + + for (Map> groups : layers.values()) { + groups.values().forEach(MaterialGroup::clear); + } + + listeners.forEach(OriginShiftListener::onOriginShift); + } + } + + private MaterialGroup

createGroup(IRenderState state) { + return groupFactory.create(this, state); + } + + @FunctionalInterface + public interface OriginShiftListener { + void onOriginShift(); + } + + @FunctionalInterface + public interface GroupFactory

{ + MaterialGroup

create(MaterialManager

materialManager, IRenderState state); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java similarity index 62% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java rename to src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java index ee04fb373..ff52f00e5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java @@ -1,26 +1,24 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.material; import java.util.function.Supplier; +import com.jozufozu.flywheel.backend.instancing.Instancer; import com.jozufozu.flywheel.core.shader.IProgramCallback; import com.jozufozu.flywheel.core.shader.WorldProgram; -import net.minecraft.client.renderer.RenderType; import net.minecraft.util.math.vector.Matrix4f; public class MaterialRenderer

{ - private final Supplier

program; - private final InstanceMaterial material; + protected final Supplier

program; + protected final InstanceMaterial material; public MaterialRenderer(Supplier

programSupplier, InstanceMaterial material) { this.program = programSupplier; this.material = material; } - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

setup) { - if (!(layer == RenderType.cutoutMipped())) return; - + public void render(Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

setup) { if (material.nothingToRender()) return; P program = this.program.get(); @@ -31,10 +29,7 @@ public class MaterialRenderer

{ if (setup != null) setup.call(program); - makeRenderCalls(); - } - - protected void makeRenderCalls() { material.forEachInstancer(Instancer::render); } + } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java similarity index 89% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java rename to src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java index f22f911db..8946fcbff 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java @@ -1,6 +1,8 @@ -package com.jozufozu.flywheel.backend.instancing; +package com.jozufozu.flywheel.backend.material; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; +import com.jozufozu.flywheel.backend.instancing.IInstanceFactory; +import com.jozufozu.flywheel.backend.instancing.InstanceData; import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/IRenderState.java b/src/main/java/com/jozufozu/flywheel/backend/state/IRenderState.java index f312ab881..4d0fd024e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/state/IRenderState.java +++ b/src/main/java/com/jozufozu/flywheel/backend/state/IRenderState.java @@ -3,6 +3,9 @@ package com.jozufozu.flywheel.backend.state; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialGroup; +import com.jozufozu.flywheel.core.shader.WorldProgram; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java b/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java new file mode 100644 index 000000000..231e5cead --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java @@ -0,0 +1,25 @@ +package com.jozufozu.flywheel.backend.state; + +import javax.annotation.Nullable; + +import net.minecraft.client.renderer.RenderType; + +public enum RenderLayer { + SOLID, + CUTOUT, + TRANSPARENT, + ; + + @Nullable + public static RenderLayer fromRenderType(RenderType type) { + if (type == RenderType.solid()) { + return SOLID; + } else if (type == RenderType.cutoutMipped()) { + return CUTOUT; + } else if (type == RenderType.translucent()) { + return TRANSPARENT; + } + + return null; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index 4ef644926..473d9204d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core; -import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.core.materials.ModelData; import com.jozufozu.flywheel.core.materials.OrientedData; import com.jozufozu.flywheel.event.GatherContextEvent; diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java index 44d125f1f..f0b63ed64 100644 --- a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java @@ -12,7 +12,7 @@ import com.jozufozu.flywheel.backend.ResourceUtil; import com.jozufozu.flywheel.backend.ShaderContext; import com.jozufozu.flywheel.backend.ShaderSources; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; -import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.backend.material.MaterialSpec; import com.jozufozu.flywheel.backend.loading.InstancedArraysTemplate; import com.jozufozu.flywheel.backend.loading.Program; import com.jozufozu.flywheel.backend.loading.ProgramTemplate; diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java new file mode 100644 index 000000000..ee361a15d --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java @@ -0,0 +1,42 @@ +package com.jozufozu.flywheel.core.crumbling; + +import com.jozufozu.flywheel.backend.gl.GlTextureUnit; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialGroup; +import com.jozufozu.flywheel.backend.state.IRenderState; +import com.jozufozu.flywheel.core.atlas.AtlasInfo; +import com.jozufozu.flywheel.core.atlas.SheetData; +import com.jozufozu.flywheel.core.shader.IProgramCallback; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.vector.Matrix4f; + +public class CrumblingGroup

extends MaterialGroup

{ + + private final int width; + private final int height; + + public CrumblingGroup(MaterialManager

owner, IRenderState state) { + super(owner, state); + + ResourceLocation texture = state.getTexture(GlTextureUnit.T0); + + if (texture != null) { + SheetData atlasData = AtlasInfo.getAtlasData(texture); + + width = atlasData.width; + height = atlasData.height; + } else { + width = height = 256; + } + } + + @Override + public void render(Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { + super.render(viewProjection, camX, camY, camZ, ((IProgramCallback

) this::setup).andThen(callback)); + } + + private void setup(P p) { + p.setAtlasSize(width, height); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java index 3e3446a88..cad068663 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core.crumbling; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java deleted file mode 100644 index b846a2f43..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.jozufozu.flywheel.core.crumbling; - -import java.util.ArrayList; -import java.util.Map; - -import com.jozufozu.flywheel.backend.gl.GlTextureUnit; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; -import com.jozufozu.flywheel.backend.instancing.MaterialRenderer; -import com.jozufozu.flywheel.backend.state.IRenderState; -import com.jozufozu.flywheel.core.WorldContext; -import com.jozufozu.flywheel.core.atlas.AtlasInfo; -import com.jozufozu.flywheel.core.atlas.SheetData; -import com.jozufozu.flywheel.core.shader.IProgramCallback; - -import net.minecraft.client.renderer.RenderType; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.vector.Matrix4f; - -public class CrumblingMaterialManager extends MaterialManager { - - public CrumblingMaterialManager(WorldContext context) { - super(context); - } - - /** - * Render every model for every material. - * - * @param layer Which vanilla {@link RenderType} is being drawn? - * @param viewProjection How do we get from camera space to clip space? - * @param callback Provide additional uniforms or state here. - */ - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback callback) { - camX -= originCoordinate.getX(); - camY -= originCoordinate.getY(); - camZ -= originCoordinate.getZ(); - - Matrix4f translate = Matrix4f.createTranslateMatrix((float) -camX, (float) -camY, (float) -camZ); - - translate.multiplyBackward(viewProjection); - - for (Map.Entry>> entry : renderers.entrySet()) { - IRenderState key = entry.getKey(); - key.bind(); - - int width; - int height; - - ResourceLocation texture = key.getTexture(GlTextureUnit.T0); - - if (texture != null) { - SheetData atlasData = AtlasInfo.getAtlasData(texture); - - width = atlasData.width; - height = atlasData.height; - } else { - width = height = 256; - } - - for (MaterialRenderer materialRenderer : entry.getValue()) { - materialRenderer.render(layer, translate, camX, camY, camZ, p -> p.setAtlasSize(width, height)); - } - - key.unbind(); - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java index 75ee052dd..941e2d44b 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java @@ -11,8 +11,10 @@ import java.util.List; import java.util.SortedSet; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.gl.GlTextureUnit; import com.jozufozu.flywheel.backend.instancing.InstanceManager; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.util.Lazy; @@ -84,9 +86,9 @@ public class CrumblingRenderer { renderer.beginFrame(info); - glActiveTexture(GL_TEXTURE4); + GlTextureUnit.T4.makeActive(); glBindTexture(GL_TEXTURE_2D, breaking.getId()); - materials.render(RenderType.cutoutMipped(), viewProjection, cameraX, cameraY, cameraZ); + materials.render(RenderLayer.SOLID, viewProjection, cameraX, cameraY, cameraZ); renderer.invalidate(); } @@ -95,7 +97,7 @@ public class CrumblingRenderer { crumblingLayer.clearRenderState(); - glActiveTexture(GL_TEXTURE0); + GlTextureUnit.T0.makeActive(); Texture breaking = textureManager.getTexture(ModelBakery.BREAKING_LOCATIONS.get(0)); if (breaking != null) glBindTexture(GL_TEXTURE_2D, breaking.getId()); } @@ -146,7 +148,7 @@ public class CrumblingRenderer { private final InstanceManager instanceManager; private State() { - materialManager = new CrumblingMaterialManager(Contexts.CRUMBLING); + materialManager = new MaterialManager<>(Contexts.CRUMBLING).setGroupFactory(CrumblingGroup::new); instanceManager = new CrumblingInstanceManager(materialManager); } diff --git a/src/main/java/com/jozufozu/flywheel/core/shader/IProgramCallback.java b/src/main/java/com/jozufozu/flywheel/core/shader/IProgramCallback.java index 4dae733e9..af1f3b650 100644 --- a/src/main/java/com/jozufozu/flywheel/core/shader/IProgramCallback.java +++ b/src/main/java/com/jozufozu/flywheel/core/shader/IProgramCallback.java @@ -11,6 +11,8 @@ public interface IProgramCallback

{ void call(P program); default IProgramCallback

andThen(IProgramCallback

other) { + if (other == null) return this; + return program -> { call(program); other.call(program); diff --git a/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java b/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java index 43e84469f..ed08b5dc7 100644 --- a/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java +++ b/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java @@ -6,7 +6,19 @@ import net.minecraft.util.math.vector.Quaternion; public class MatrixTransformStack implements TransformStack { - private final MatrixStack internal = new MatrixStack(); + private final MatrixStack internal; + + public MatrixTransformStack() { + this(new MatrixStack()); + } + + public MatrixTransformStack(MatrixStack internal) { + this.internal = internal; + } + + public static MatrixTransformStack of(MatrixStack ms) { + return new MatrixTransformStack(ms); + } public MatrixStack unwrap() { return internal; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index 0209fd586..7419c229a 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.vanilla; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.core.Materials; @@ -58,8 +58,9 @@ public class BellInstance extends TileEntityInstance implements } private OrientedData createBellInstance() { - return materialManager.getMaterial(Materials.ORIENTED) - .get(tile.getType(), BellInstance::createBellModel) + return materialManager.defaultCutout() + .material(Materials.ORIENTED) + .model(tile.getType(), BellInstance::createBellModel) .createInstance(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index 149e97355..ebf9dc822 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -5,9 +5,10 @@ import java.util.Calendar; import javax.annotation.Nonnull; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.model.BufferedModel; +import com.jozufozu.flywheel.backend.state.TextureRenderState; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.ModelData; import com.jozufozu.flywheel.core.materials.OrientedData; @@ -119,15 +120,17 @@ public class ChestInstance extends TileEntityI private OrientedData baseInstance() { - return materialManager.getMaterial(Materials.ORIENTED, renderMaterial.atlasLocation()) - .get("base_" + renderMaterial.texture(), this::getBaseModel) + return materialManager.solid(TextureRenderState.get(renderMaterial.atlasLocation())) + .material(Materials.ORIENTED) + .model("base_" + renderMaterial.texture(), this::getBaseModel) .createInstance(); } private ModelData lidInstance() { - return materialManager.getMaterial(Materials.TRANSFORMED, renderMaterial.atlasLocation()) - .get("lid_" + renderMaterial.texture(), this::getLidModel) + return materialManager.solid(TextureRenderState.get(renderMaterial.atlasLocation())) + .material(Materials.TRANSFORMED) + .model("lid_" + renderMaterial.texture(), this::getLidModel) .createInstance(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/RenderStates.java b/src/main/java/com/jozufozu/flywheel/vanilla/RenderStates.java index 55aed1b32..f9c96ca24 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/RenderStates.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/RenderStates.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import com.jozufozu.flywheel.backend.state.IRenderState; import com.jozufozu.flywheel.backend.state.NoCullRenderState; import com.jozufozu.flywheel.backend.state.RenderState; +import com.jozufozu.flywheel.backend.state.TextureRenderState; import net.minecraft.client.renderer.Atlases; import net.minecraft.client.renderer.model.RenderMaterial; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index f4c3589c2..59b5d5a0f 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.vanilla; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.core.Materials; @@ -88,14 +88,16 @@ public class ShulkerBoxInstance extends TileEntityInstance } private ModelData makeBaseInstance() { - return materialManager.getMaterial(Materials.TRANSFORMED, RenderStates.SHULKER) - .get("base_" + texture.getName(), this::makeBaseModel) + return materialManager.cutout(RenderStates.SHULKER) + .material(Materials.TRANSFORMED) + .model("base_" + texture.getName(), this::makeBaseModel) .createInstance(); } private ModelData makeLidInstance() { - return materialManager.getMaterial(Materials.TRANSFORMED, RenderStates.SHULKER) - .get("lid_" + texture.getName(), this::makeLidModel) + return materialManager.cutout(RenderStates.SHULKER) + .material(Materials.TRANSFORMED) + .model("lid_" + texture.getName(), this::makeLidModel) .createInstance(); }