diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java index 801a93cd8..b36bcb5ce 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java @@ -17,15 +17,15 @@ public abstract class GlObject { } protected final void checkHandle() { - if (!this.isHandleValid()) { + if (this.isInvalid()) { String descriptor = getDescriptor(); String message = (descriptor == null ? "" : (descriptor + " ")) + "handle is not valid."; throw new IllegalStateException(message); } } - protected final boolean isHandleValid() { - return this.handle != INVALID_HANDLE; + protected final boolean isInvalid() { + return this.handle == INVALID_HANDLE; } protected final void invalidateHandle() { @@ -33,7 +33,7 @@ public abstract class GlObject { } public void delete() { - if (!isHandleValid()) { + if (isInvalid()) { String descriptor = getDescriptor(); String message = (descriptor == null ? "" : (descriptor + " ")) + "handle already deleted."; throw new IllegalStateException(message); 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 be81b970a..113a4d83e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -1,33 +1,26 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Objects; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.function.Consumer; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.material.MaterialManager; -import com.jozufozu.flywheel.util.RenderMath; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectArraySet; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3f; -public abstract class InstanceManager implements MaterialManager.OriginShiftListener { +public abstract class InstanceManager implements MaterialManagerImpl.OriginShiftListener { - public final MaterialManager materialManager; + public final MaterialManager materialManager; private final Set queuedAdditions; private final Set queuedUpdates; @@ -39,7 +32,7 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL protected int frame; protected int tick; - public InstanceManager(MaterialManager materialManager) { + public InstanceManager(MaterialManagerImpl materialManager) { this.materialManager = materialManager; this.queuedUpdates = new HashSet<>(64); this.queuedAdditions = new HashSet<>(64); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java index e2c54a561..880173feb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.instancing; 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.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.event.BeginFrameEvent; @@ -13,8 +13,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IWorld; -import net.minecraftforge.event.TickEvent; /** * A manager class for a single world where instancing is supported. @@ -23,19 +21,19 @@ import net.minecraftforge.event.TickEvent; *

*/ public class InstanceWorld { - protected final MaterialManager materialManager; + protected final MaterialManagerImpl materialManager; protected final InstanceManager entityInstanceManager; protected final InstanceManager tileEntityInstanceManager; public InstanceWorld() { - materialManager = MaterialManager.builder(Contexts.WORLD) + materialManager = MaterialManagerImpl.builder(Contexts.WORLD) .build(); entityInstanceManager = new EntityInstanceManager(materialManager); tileEntityInstanceManager = new TileInstanceManager(materialManager); } - public MaterialManager getMaterialManager() { + public MaterialManager getMaterialManager() { return materialManager; } @@ -72,7 +70,7 @@ public class InstanceWorld { *

*/ public void beginFrame(BeginFrameEvent event) { - materialManager.checkAndShiftOrigin(event.getInfo()); + materialManager.beginFrame(event.getInfo()); tileEntityInstanceManager.beginFrame(event.getInfo()); entityInstanceManager.beginFrame(event.getInfo()); 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 399ed3bb8..a44b2b6da 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -77,7 +77,7 @@ public class InstancedRenderRegistry { @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance create(MaterialManager manager, T tile) { + public TileEntityInstance create(MaterialManager manager, T tile) { TileEntityType type = tile.getType(); ITileInstanceFactory factory = (ITileInstanceFactory) this.tiles.get(type); @@ -88,7 +88,7 @@ public class InstancedRenderRegistry { @SuppressWarnings("unchecked") @Nullable - public EntityInstance create(MaterialManager manager, T tile) { + public EntityInstance create(MaterialManager manager, T tile) { EntityType type = tile.getType(); IEntityInstanceFactory factory = (IEntityInstanceFactory) this.entities.get(type); 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 0b3d874c4..1ceaa6953 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java @@ -10,7 +10,7 @@ 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.ModelPool; +import com.jozufozu.flywheel.backend.model.ModelAllocator; import com.jozufozu.flywheel.backend.model.IBufferedModel; import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.util.AttribUtil; @@ -35,7 +35,7 @@ import com.jozufozu.flywheel.util.AttribUtil; */ public class Instancer { - private final ModelPool modelAllocator; + private final ModelAllocator modelAllocator; private final IModel modelData; private final VertexFormat instanceFormat; private final IInstanceFactory factory; @@ -53,11 +53,11 @@ public class Instancer { boolean anyToRemove; boolean anyToUpdate; - public Instancer(ModelPool modelAllocator, IModel model, MaterialSpec spec) { + public Instancer(ModelAllocator modelAllocator, IModel model, IInstanceFactory factory, VertexFormat instanceFormat) { this.modelAllocator = modelAllocator; this.modelData = model; - this.factory = spec.getInstanceFactory(); - this.instanceFormat = spec.getInstanceFormat(); + this.factory = factory; + this.instanceFormat = instanceFormat; } /** @@ -105,14 +105,13 @@ public class Instancer { vao = new GlVertexArray(); - model = modelAllocator.alloc(modelData) - .setReallocCallback(arenaModel -> { - vao.bind(); + model = modelAllocator.alloc(modelData, arenaModel -> { + vao.bind(); - model.setupState(); + model.setupState(); - vao.unbind(); - }); + vao.unbind(); + }); vao.bind(); 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 d3370626e..dd19d80b7 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 @@ -41,11 +41,11 @@ import net.minecraft.world.World; */ public abstract class EntityInstance implements IInstance { - protected final MaterialManager materialManager; + protected final MaterialManager materialManager; protected final E entity; protected final World world; - public EntityInstance(MaterialManager materialManager, E entity) { + public EntityInstance(MaterialManager materialManager, E entity) { this.materialManager = materialManager; this.entity = entity; this.world = entity.level; 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 7d2da71aa..d72100e62 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.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; @@ -13,7 +13,7 @@ import net.minecraft.world.World; public class EntityInstanceManager extends InstanceManager { - public EntityInstanceManager(MaterialManager materialManager) { + public EntityInstanceManager(MaterialManagerImpl materialManager) { super(materialManager); } 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 d199fb2a8..22ac1cea6 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 @@ -6,5 +6,5 @@ import net.minecraft.entity.Entity; @FunctionalInterface public interface IEntityInstanceFactory { - EntityInstance create(MaterialManager manager, E te); + EntityInstance create(MaterialManager manager, E te); } 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 11de652ca..2484b790b 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 @@ -6,5 +6,5 @@ import net.minecraft.tileentity.TileEntity; @FunctionalInterface public interface ITileInstanceFactory { - TileEntityInstance create(MaterialManager manager, T te); + TileEntityInstance create(MaterialManager manager, T te); } 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 6c7f5bb77..9e94753ab 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 @@ -8,6 +8,7 @@ import com.jozufozu.flywheel.backend.instancing.IInstance; import com.jozufozu.flywheel.backend.instancing.ITickableInstance; import com.jozufozu.flywheel.backend.material.InstanceMaterial; import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.materials.IFlatLight; import com.jozufozu.flywheel.core.materials.ModelData; @@ -38,14 +39,14 @@ import net.minecraft.world.World; */ public abstract class TileEntityInstance implements IInstance { - protected final MaterialManager materialManager; + protected final MaterialManager materialManager; protected final T tile; protected final World world; protected final BlockPos pos; protected final BlockPos instancePos; protected final BlockState blockState; - public TileEntityInstance(MaterialManager materialManager, T tile) { + public TileEntityInstance(MaterialManager materialManager, T tile) { this.materialManager = materialManager; this.tile = tile; this.world = tile.getLevel(); 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 b8878e019..2e4080ad4 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.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -13,7 +13,7 @@ import net.minecraft.world.World; public class TileInstanceManager extends InstanceManager { - public TileInstanceManager(MaterialManager materialManager) { + public TileInstanceManager(MaterialManagerImpl materialManager) { super(materialManager); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java index efe069d98..6ef2f9ba0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterial.java @@ -1,14 +1,10 @@ package com.jozufozu.flywheel.backend.material; -import java.util.concurrent.ExecutionException; import java.util.function.Supplier; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.jozufozu.flywheel.backend.RenderWork; import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.model.ModelPool; +import com.jozufozu.flywheel.core.Formats; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.model.BlockModel; import com.jozufozu.flywheel.core.model.IModel; @@ -19,78 +15,29 @@ import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; -/** - * A collection of Instancers that all have the same format. - * @param - */ -public class InstanceMaterial { - - final ModelPool modelPool; - protected final Cache> models; - protected final MaterialSpec spec; - - public InstanceMaterial(MaterialSpec spec) { - this.spec = spec; - - modelPool = new ModelPool(spec.getModelFormat(), spec.getModelFormat().getStride() * 64); - this.models = CacheBuilder.newBuilder() - .removalListener(notification -> { - Instancer instancer = (Instancer) notification.getValue(); - RenderWork.enqueue(instancer::delete); - }) - .build(); - } - +public interface InstanceMaterial { /** * Get an instancer for the given model. Calling this method twice with the same key will return the same instancer. * - * @param key An object that uniquely identifies the model. + * @param key An object that uniquely identifies the model. * @param modelSupplier A factory that creates the IModel that you want to render. * @return An instancer for the given model, capable of rendering many copies for little cost. */ - public Instancer model(Object key, Supplier modelSupplier) { - try { - return models.get(key, () -> new Instancer<>(modelPool, modelSupplier.get(), spec)); - } catch (ExecutionException e) { - throw new RuntimeException("error creating instancer", e); - } + Instancer model(Object key, Supplier modelSupplier); + + default Instancer getModel(PartialModel partial, BlockState referenceState) { + return model(partial, () -> new BlockModel(Formats.UNLIT_MODEL, partial.get(), referenceState)); } - public Instancer getModel(PartialModel partial, BlockState referenceState) { - return model(partial, () -> new BlockModel(spec.getModelFormat(), partial.get(), referenceState)); - } - - public Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir) { + default Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir) { return getModel(partial, referenceState, dir, RenderUtil.rotateToFace(dir)); } - public Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { - return model(Pair.of(dir, partial), () -> new BlockModel(spec.getModelFormat(), partial.get(), referenceState, modelTransform.get())); + default Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { + return model(Pair.of(dir, partial), () -> new BlockModel(Formats.UNLIT_MODEL, partial.get(), referenceState, modelTransform.get())); } - public Instancer getModel(BlockState toRender) { - return model(toRender, () -> new BlockModel(spec.getModelFormat(), toRender)); + default Instancer getModel(BlockState toRender) { + return model(toRender, () -> new BlockModel(Formats.UNLIT_MODEL, toRender)); } - - public boolean nothingToRender() { - return models.size() > 0 && models.asMap() - .values() - .stream() - .allMatch(Instancer::isEmpty); - } - - public void delete() { - models.invalidateAll(); - modelPool.delete(); - } - - /** - * Clear all instance data without freeing resources. - */ - public void clear() { - models.asMap() - .values() - .forEach(Instancer::clear); - } - } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java new file mode 100644 index 000000000..7f91c98e9 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/material/InstanceMaterialImpl.java @@ -0,0 +1,73 @@ +package com.jozufozu.flywheel.backend.material; + +import java.util.concurrent.ExecutionException; +import java.util.function.Supplier; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.jozufozu.flywheel.backend.RenderWork; +import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.model.ModelPool; +import com.jozufozu.flywheel.core.model.IModel; + +/** + * A collection of Instancers that all have the same format. + * @param + */ +public class InstanceMaterialImpl implements InstanceMaterial { + + final ModelPool modelPool; + protected final Cache> models; + protected final MaterialSpec spec; + + public InstanceMaterialImpl(MaterialSpec spec) { + this.spec = spec; + + modelPool = new ModelPool(spec.getModelFormat(), spec.getModelFormat().getStride() * 64); + this.models = CacheBuilder.newBuilder() + .removalListener(notification -> { + Instancer instancer = (Instancer) notification.getValue(); + RenderWork.enqueue(instancer::delete); + }) + .build(); + } + + /** + * Get an instancer for the given model. Calling this method twice with the same key will return the same instancer. + * + * @param key An object that uniquely identifies the model. + * @param modelSupplier A factory that creates the IModel that you want to render. + * @return An instancer for the given model, capable of rendering many copies for little cost. + */ + @Override + public Instancer model(Object key, Supplier modelSupplier) { + try { + return models.get(key, () -> new Instancer<>(modelPool, modelSupplier.get(), spec.getInstanceFactory(), spec.getInstanceFormat())); + } catch (ExecutionException e) { + throw new RuntimeException("error creating instancer", e); + } + } + + public boolean nothingToRender() { + return models.size() > 0 && models.asMap() + .values() + .stream() + .allMatch(Instancer::isEmpty); + } + + public void delete() { + models.invalidateAll(); + modelPool.delete(); + } + + /** + * Clear all instance data without freeing resources. + */ + public void clear() { + models.asMap() + .values() + .forEach(Instancer::clear); + } + +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java index 9dacda4c6..ac2e4d6cd 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroup.java @@ -1,73 +1,14 @@ 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.WorldProgram; - -import net.minecraft.util.math.vector.Matrix4f; - -/** - * A group of materials all rendered with the same GL state. - * - * The children of a material group will all be rendered at the same time. - * No guarantees are made about the order of draw calls. - */ -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 interface MaterialGroup { /** * Get the material as defined by the given {@link MaterialSpec spec}. + * * @param spec The material you want to create instances with. - * @param The type representing the per instance data. - * @return A + * @param The type representing the per instance data. + * @return A material you can use to render models. */ - @SuppressWarnings("unchecked") - public InstanceMaterial material(MaterialSpec spec) { - return (InstanceMaterial) materials.computeIfAbsent(spec, this::createInstanceMaterial); - } - - public void render(Matrix4f viewProjection, double camX, double camY, double camZ) { - for (MaterialRenderer

renderer : renderers) { - renderer.render(viewProjection, camX, camY, camZ); - } - } - - public void setup(P program) { - - } - - public void clear() { - materials.values().forEach(InstanceMaterial::clear); - } - - public void delete() { - materials.values() - .forEach(InstanceMaterial::delete); - - materials.clear(); - renderers.clear(); - } - - private InstanceMaterial createInstanceMaterial(MaterialSpec type) { - InstanceMaterial material = new InstanceMaterial<>(type); - - this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup)); - - return material; - } + InstanceMaterial material(MaterialSpec spec); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroupImpl.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroupImpl.java new file mode 100644 index 000000000..3c6ab0a32 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialGroupImpl.java @@ -0,0 +1,74 @@ +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.WorldProgram; + +import net.minecraft.util.math.vector.Matrix4f; + +/** + * A group of materials all rendered with the same GL state. + * + * The children of a material group will all be rendered at the same time. + * No guarantees are made about the order of draw calls. + */ +public class MaterialGroupImpl

implements MaterialGroup { + + protected final MaterialManagerImpl

owner; + protected final IRenderState state; + + private final ArrayList> renderers = new ArrayList<>(); + + private final Map, InstanceMaterialImpl> materials = new HashMap<>(); + + public MaterialGroupImpl(MaterialManagerImpl

owner, IRenderState state) { + this.owner = owner; + this.state = state; + } + + /** + * Get the material as defined by the given {@link MaterialSpec spec}. + * @param spec The material you want to create instances with. + * @param The type representing the per instance data. + * @return A + */ + @SuppressWarnings("unchecked") + @Override + public InstanceMaterialImpl material(MaterialSpec spec) { + return (InstanceMaterialImpl) materials.computeIfAbsent(spec, this::createInstanceMaterial); + } + + public void render(Matrix4f viewProjection, double camX, double camY, double camZ) { + for (MaterialRenderer

renderer : renderers) { + renderer.render(viewProjection, camX, camY, camZ); + } + } + + public void setup(P program) { + + } + + public void clear() { + materials.values().forEach(InstanceMaterialImpl::clear); + } + + public void delete() { + materials.values() + .forEach(InstanceMaterialImpl::delete); + + materials.clear(); + renderers.clear(); + } + + private InstanceMaterialImpl createInstanceMaterial(MaterialSpec type) { + InstanceMaterialImpl material = new InstanceMaterialImpl<>(type); + + this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup)); + + return material; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java index cb33d618b..cf15fc608 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java @@ -1,63 +1,13 @@ package com.jozufozu.flywheel.backend.material; -import java.util.EnumMap; -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.WorldProgram; -import com.jozufozu.flywheel.util.WeakHashSet; -import net.minecraft.client.renderer.ActiveRenderInfo; 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 BlockPos originCoordinate = BlockPos.ZERO; - - protected final WorldContext

context; - protected final GroupFactory

groupFactory; - protected final boolean ignoreOriginCoordinate; - - protected final Map>> layers; - - private final WeakHashSet listeners; - - public MaterialManager(WorldContext

context) { - this(context, MaterialGroup::new, false); - } - - public static

Builder

builder(WorldContext

context) { - return new Builder<>(context); - } - - public MaterialManager(WorldContext

context, GroupFactory

groupFactory, boolean ignoreOriginCoordinate) { - this.context = context; - this.ignoreOriginCoordinate = ignoreOriginCoordinate; - - this.listeners = new WeakHashSet<>(); - this.groupFactory = groupFactory; - - this.layers = new EnumMap<>(RenderLayer.class); - for (RenderLayer value : RenderLayer.values()) { - layers.put(value, new HashMap<>()); - } - } +public interface MaterialManager { /** * Get a material group that will render in the given layer with the given state. @@ -66,162 +16,31 @@ public class MaterialManager

{ * @param state The {@link IRenderState} you need to draw with. * @return A material group whose children will */ - public MaterialGroup

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

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

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

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

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

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

defaultTransparent() { + default MaterialGroup defaultTransparent() { return transparent(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS)); } - - /** - * Render every model for every material. - * @param layer Which of the 3 {@link RenderLayer render layers} 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) { - 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); - state.unbind(); - } - } - - public void delete() { - for (Map> groups : layers.values()) { - - groups.values().forEach(MaterialGroup::delete); - } - } - - @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 Vector3i getOriginCoordinate() { - return originCoordinate; - } - - public void addListener(OriginShiftListener listener) { - listeners.add(listener); - } - - /** - * Maintain the integer origin coordinate to be within a certain distance from the camera in all directions. - * - * This prevents floating point precision issues at high coordinates. - */ - 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); - } - - public static class Builder

{ - protected final WorldContext

context; - protected GroupFactory

groupFactory = MaterialGroup::new; - protected boolean ignoreOriginCoordinate; - - public Builder(WorldContext

context) { - this.context = context; - } - - public Builder

setGroupFactory(GroupFactory

groupFactory) { - this.groupFactory = groupFactory; - return this; - } - - public Builder

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

build() { - return new MaterialManager<>(context, groupFactory, ignoreOriginCoordinate); - } - } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManagerImpl.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManagerImpl.java new file mode 100644 index 000000000..f6771ddf7 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManagerImpl.java @@ -0,0 +1,179 @@ +package com.jozufozu.flywheel.backend.material; + +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +import com.jozufozu.flywheel.backend.state.IRenderState; +import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.util.WeakHashSet; + +import net.minecraft.client.renderer.ActiveRenderInfo; +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 MaterialManagerImpl

implements MaterialManager { + + public static int MAX_ORIGIN_DISTANCE = 100; + + protected BlockPos originCoordinate = BlockPos.ZERO; + + protected final WorldContext

context; + protected final GroupFactory

groupFactory; + protected final boolean ignoreOriginCoordinate; + + protected final Map>> layers; + + private final WeakHashSet listeners; + + public MaterialManagerImpl(WorldContext

context) { + this(context, MaterialGroupImpl::new, false); + } + + public static

Builder

builder(WorldContext

context) { + return new Builder<>(context); + } + + public MaterialManagerImpl(WorldContext

context, GroupFactory

groupFactory, boolean ignoreOriginCoordinate) { + this.context = context; + this.ignoreOriginCoordinate = ignoreOriginCoordinate; + + this.listeners = new WeakHashSet<>(); + this.groupFactory = groupFactory; + + this.layers = new EnumMap<>(RenderLayer.class); + for (RenderLayer value : RenderLayer.values()) { + layers.put(value, new HashMap<>()); + } + } + + /** + * Get a material group that will render in the given layer with the given state. + * + * @param layer The {@link RenderLayer} you want to draw in. + * @param state The {@link IRenderState} you need to draw with. + * @return A material group whose children will + */ + @Override + public MaterialGroup state(RenderLayer layer, IRenderState state) { + return layers.get(layer).computeIfAbsent(state, this::createGroup); + } + + /** + * Render every model for every material. + * @param layer Which of the 3 {@link RenderLayer render layers} 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) { + 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(); + MaterialGroupImpl

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

getProgram(ResourceLocation name) { + return context.getProgramSupplier(name); + } + + @Override + public Vector3i getOriginCoordinate() { + return originCoordinate; + } + + public void addListener(OriginShiftListener listener) { + listeners.add(listener); + } + + /** + * Maintain the integer origin coordinate to be within a certain distance from the camera in all directions. + * + * This prevents floating point precision issues at high coordinates. + */ + public void beginFrame(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(MaterialGroupImpl::clear); + } + + listeners.forEach(OriginShiftListener::onOriginShift); + } + } + + private MaterialGroupImpl

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

{ + MaterialGroupImpl

create(MaterialManagerImpl

materialManager, IRenderState state); + } + + public static class Builder

{ + protected final WorldContext

context; + protected GroupFactory

groupFactory = MaterialGroupImpl::new; + protected boolean ignoreOriginCoordinate; + + public Builder(WorldContext

context) { + this.context = context; + } + + public Builder

setGroupFactory(GroupFactory

groupFactory) { + this.groupFactory = groupFactory; + return this; + } + + public Builder

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

build() { + return new MaterialManagerImpl<>(context, groupFactory, ignoreOriginCoordinate); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java index 7b27259c7..af695a27c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialRenderer.java @@ -12,11 +12,11 @@ import net.minecraft.util.math.vector.Matrix4f; public class MaterialRenderer

{ protected final Supplier

program; - protected final InstanceMaterial material; + protected final InstanceMaterialImpl material; protected final Consumer

setupFunc; - public MaterialRenderer(Supplier

programSupplier, InstanceMaterial material, Consumer

setupFunc) { + public MaterialRenderer(Supplier

programSupplier, InstanceMaterialImpl material, Consumer

setupFunc) { this.program = programSupplier; this.material = material; this.setupFunc = setupFunc; diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java b/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java new file mode 100644 index 000000000..7da671ca0 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ImmediateAllocator.java @@ -0,0 +1,15 @@ +package com.jozufozu.flywheel.backend.model; + +import com.jozufozu.flywheel.core.model.IModel; + +public class ImmediateAllocator implements ModelAllocator { + + public static final ImmediateAllocator INSTANCE = new ImmediateAllocator(); + + @Override + public IBufferedModel alloc(IModel model, Callback allocationCallback) { + IndexedModel out = new IndexedModel(model); + allocationCallback.onAlloc(out); + return out; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java new file mode 100644 index 000000000..afa45904a --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelAllocator.java @@ -0,0 +1,18 @@ +package com.jozufozu.flywheel.backend.model; + +import com.jozufozu.flywheel.core.model.IModel; + +public interface ModelAllocator { + /** + * Allocate a model. + * + * @param model The model to allocate. + * @return A handle to the allocated model. + */ + IBufferedModel alloc(IModel model, Callback allocationCallback); + + @FunctionalInterface + interface Callback { + void onAlloc(IBufferedModel arenaModel); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java index 7e687e1ef..c905ca44f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java +++ b/src/main/java/com/jozufozu/flywheel/backend/model/ModelPool.java @@ -12,9 +12,8 @@ import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.gl.buffer.MappedGlBuffer; import com.jozufozu.flywheel.core.model.IModel; import com.jozufozu.flywheel.util.AttribUtil; -import com.jozufozu.flywheel.util.StringUtil; -public class ModelPool { +public class ModelPool implements ModelAllocator { protected final VertexFormat format; @@ -47,8 +46,10 @@ public class ModelPool { * @param model The model to allocate. * @return A handle to the allocated model. */ - public PooledModel alloc(IModel model) { + @Override + public PooledModel alloc(IModel model, Callback callback) { PooledModel bufferedModel = new PooledModel(model, vertices); + bufferedModel.callback = callback; vertices += model.vertexCount(); models.add(bufferedModel); pendingUpload.add(bufferedModel); @@ -117,7 +118,7 @@ public class ModelPool { for (PooledModel model : models) { model.model.buffer(buffer); if (model.callback != null) - model.callback.invoke(model); + model.callback.onAlloc(model); } buffer.flush(); @@ -132,7 +133,7 @@ public class ModelPool { buffer.position(pos); model.model.buffer(buffer); if (model.callback != null) - model.callback.invoke(model); + model.callback.onAlloc(model); } pendingUpload.clear(); @@ -199,7 +200,7 @@ public class ModelPool { ebo.bind(); - Backend.log.info(StringUtil.args("drawElementsInstancedBaseVertex", GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, instanceCount, first)); + //Backend.log.info(StringUtil.args("drawElementsInstancedBaseVertex", GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, instanceCount, first)); Backend.getInstance().compat.baseVertex.drawElementsInstancedBaseVertex(GlPrimitive.TRIANGLES, ebo.elementCount, ebo.eboIndexType, 0, instanceCount, first); } @@ -215,15 +216,6 @@ public class ModelPool { anyToRemove = true; remove = true; } - - public PooledModel setReallocCallback(Callback callback) { - this.callback = callback; - return this; - } } - @FunctionalInterface - public interface Callback { - void invoke(PooledModel arenaModel); - } } diff --git a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java index bdff17230..dc52087e5 100644 --- a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java +++ b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java @@ -83,7 +83,7 @@ public class QuadConverter { } } - public void free() { + public void delete() { ebos.values() .forEach(GlBuffer::delete); ebos.clear(); @@ -172,6 +172,6 @@ public class QuadConverter { // make sure this gets reset first so it has a chance to repopulate @SubscribeEvent(priority = EventPriority.HIGHEST) public static void onRendererReload(ReloadRenderersEvent event) { - if (INSTANCE != null) INSTANCE.free(); + if (INSTANCE != null) INSTANCE.delete(); } } diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java index 81159c784..ef3b24588 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingGroup.java @@ -1,20 +1,20 @@ package com.jozufozu.flywheel.core.crumbling; import com.jozufozu.flywheel.backend.gl.GlTextureUnit; -import com.jozufozu.flywheel.backend.material.MaterialGroup; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialGroupImpl; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.backend.state.IRenderState; import com.jozufozu.flywheel.core.atlas.AtlasInfo; import com.jozufozu.flywheel.core.atlas.SheetData; import net.minecraft.util.ResourceLocation; -public class CrumblingGroup

extends MaterialGroup

{ +public class CrumblingGroup

extends MaterialGroupImpl

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

owner, IRenderState state) { + public CrumblingGroup(MaterialManagerImpl

owner, IRenderState state) { super(owner, state); ResourceLocation texture = state.getTexture(GlTextureUnit.T0); 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 27447a0fe..059b366b1 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java @@ -1,13 +1,13 @@ package com.jozufozu.flywheel.core.crumbling; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; -import com.jozufozu.flywheel.backend.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import net.minecraft.util.math.BlockPos; public class CrumblingInstanceManager extends TileInstanceManager { - public CrumblingInstanceManager(MaterialManager materialManager) { + public CrumblingInstanceManager(MaterialManagerImpl materialManager) { super(materialManager); } 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 5415512dc..d9cd5f838 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java @@ -11,6 +11,7 @@ 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.material.MaterialManager; +import com.jozufozu.flywheel.backend.material.MaterialManagerImpl; import com.jozufozu.flywheel.backend.state.RenderLayer; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.event.ReloadRenderersEvent; @@ -69,7 +70,7 @@ public class CrumblingRenderer { TextureManager textureManager = Minecraft.getInstance().textureManager; ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getMainCamera(); - MaterialManager materials = state.materialManager; + MaterialManagerImpl materials = state.materialManager; layer.setupRenderState(); for (Int2ObjectMap.Entry> stage : activeStages.int2ObjectEntrySet()) { @@ -140,11 +141,11 @@ public class CrumblingRenderer { } private static class State { - private final MaterialManager materialManager; + private final MaterialManagerImpl materialManager; private final InstanceManager instanceManager; private State() { - materialManager = MaterialManager.builder(Contexts.CRUMBLING) + materialManager = MaterialManagerImpl.builder(Contexts.CRUMBLING) .setGroupFactory(CrumblingGroup::new) .build(); instanceManager = new CrumblingInstanceManager(materialManager); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index 42358f7e1..a4a83a711 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -20,7 +20,7 @@ public class BellInstance extends TileEntityInstance implements private float lastRingTime = Float.NaN; - public BellInstance(MaterialManager materialManager, BellTileEntity tile) { + public BellInstance(MaterialManager materialManager, BellTileEntity tile) { super(materialManager, tile); bell = createBellInstance() diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index d859d3d5b..d7911e195 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -42,7 +42,7 @@ public class ChestInstance extends TileEntityI private float lastProgress = Float.NaN; - public ChestInstance(MaterialManager materialManager, T tile) { + public ChestInstance(MaterialManager materialManager, T tile) { super(materialManager, tile); Block block = blockState.getBlock(); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index 4b01400c1..08c4b62c7 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -28,7 +28,7 @@ public class ShulkerBoxInstance extends TileEntityInstance private float lastProgress = Float.NaN; - public ShulkerBoxInstance(MaterialManager materialManager, ShulkerBoxTileEntity tile) { + public ShulkerBoxInstance(MaterialManager materialManager, ShulkerBoxTileEntity tile) { super(materialManager, tile); DyeColor color = tile.getColor();