From 14d39491347a024c33407cfbc2ca94693e009410 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 22 Jul 2022 16:41:39 -0700 Subject: [PATCH] A Performance on the (Render)Stage - Add RenderStage enum for better control over when a Material should be rendered - Add getRenderStage method to Material - Replace RenderLayerEvent with RenderStageEvent - Pass more information to RenderContext including camera and projection matrix - Pass RenderContext instead of Camera to all beginFrame-related methods - Remove RenderContext.CURRENT - Remove FrustumMixin and CameraMixin - Remove default BasicModelSupplier constructor - Convert Material to interface and create SimpleMaterial implementation - Move API instancer classes to instancer package - Organize imports --- .../java/com/jozufozu/flywheel/Flywheel.java | 4 +- .../jozufozu/flywheel/api/RenderStage.java | 16 ++ .../api/instance/DynamicInstance.java | 4 +- .../api/instance/TickableInstance.java | 4 +- .../api/{ => instancer}/InstancedPart.java | 2 +- .../api/{ => instancer}/Instancer.java | 2 +- .../api/{ => instancer}/InstancerFactory.java | 2 +- .../api/{ => instancer}/InstancerManager.java | 2 +- .../flywheel/api/material/Material.java | 9 +- .../flywheel/api/struct/StructType.java | 2 +- .../jozufozu/flywheel/backend/Backend.java | 2 +- .../flywheel/backend/gl/GlObject.java | 2 - .../backend/gl/buffer/GlBufferType.java | 1 - .../flywheel/backend/gl/shader/GlShader.java | 2 +- .../backend/instancing/AbstractInstance.java | 2 +- .../backend/instancing/AbstractInstancer.java | 4 +- .../backend/instancing/DrawBuffer.java | 2 - .../flywheel/backend/instancing/Engine.java | 2 +- .../backend/instancing/InstanceManager.java | 11 +- .../backend/instancing/InstanceWorld.java | 35 ++-- .../instancing/InstancedRenderDispatcher.java | 19 +- .../instancing/InstancedRenderRegistry.java | 2 +- .../backend/instancing/One2OneStorage.java | 3 +- .../backend/instancing/RenderDispatcher.java | 8 +- .../instancing/batching/BatchLists.java | 2 +- .../instancing/batching/BatchedModel.java | 2 +- .../instancing/batching/BatchingEngine.java | 28 +-- .../instancing/batching/CPUInstancer.java | 2 +- .../batching/CPUInstancerFactory.java | 6 +- .../instancing/batching/TransformSet.java | 2 +- .../blockentity/BlockEntityInstance.java | 6 +- .../BlockEntityInstanceManager.java | 4 +- .../BlockEntityInstancingController.java | 2 +- ...SimpleBlockEntityInstancingController.java | 2 +- .../backend/instancing/effect/Effect.java | 2 +- .../effect/EffectInstanceManager.java | 2 +- .../instancing/entity/EntityInstance.java | 2 +- .../entity/EntityInstanceManager.java | 4 +- .../entity/EntityInstancingController.java | 2 +- .../SimpleEntityInstancingController.java | 2 +- .../instancing/instancing/GPUInstancer.java | 2 +- .../instancing/GPUInstancerFactory.java | 8 +- .../instancing/instancing/InstancedModel.java | 3 +- .../instancing/InstancingEngine.java | 81 ++++---- .../instancing/instancing/RenderLists.java | 50 +++-- .../flywheel/backend/struct/BufferWriter.java | 2 +- .../backend/struct/UnsafeBufferWriter.java | 2 +- .../flywheel/core/BasicModelSupplier.java | 11 +- .../flywheel/core/CoreShaderInfoMap.java | 1 + .../flywheel/core/LastActiveCamera.java | 21 -- .../com/jozufozu/flywheel/core/Models.java | 13 +- .../jozufozu/flywheel/core/QuadConverter.java | 2 - .../jozufozu/flywheel/core/RenderContext.java | 17 +- .../flywheel/core/compile/VertexCompiler.java | 2 - .../crumbling/CrumblingInstanceManager.java | 2 +- .../core/crumbling/CrumblingRenderer.java | 43 ++-- .../flywheel/core/hardcoded/ModelPart.java | 1 - .../core/instancing/ConditionalInstance.java | 4 +- .../core/instancing/GroupInstance.java | 4 +- .../core/instancing/SelectInstance.java | 4 +- .../core/material/SimpleMaterial.java | 41 ++++ .../flywheel/core/model/ModelUtil.java | 2 - .../flywheel/core/structs/ColoredLitPart.java | 2 +- .../flywheel/core/structs/FlatLit.java | 2 +- .../flywheel/core/vertex/BlockVertexList.java | 1 - .../core/vertex/BlockVertexListUnsafe.java | 1 - .../vertex/PosTexNormalVertexListUnsafe.java | 2 - .../flywheel/event/BeginFrameEvent.java | 32 +-- .../flywheel/event/EntityWorldHandler.java | 3 - .../jozufozu/flywheel/event/ForgeEvents.java | 10 +- .../flywheel/event/RenderLayerEvent.java | 69 ------- .../flywheel/event/RenderStageEvent.java | 54 ++++++ .../jozufozu/flywheel/mixin/CameraMixin.java | 21 -- .../jozufozu/flywheel/mixin/FrustumMixin.java | 28 --- .../mixin/LevelRendererDispatchMixin.java | 183 ------------------ .../flywheel/mixin/LevelRendererMixin.java | 105 ++++++++-- .../flywheel/vanilla/BellInstance.java | 9 +- .../flywheel/vanilla/ChestInstance.java | 8 +- .../flywheel/vanilla/MinecartInstance.java | 7 +- .../flywheel/vanilla/ShulkerBoxInstance.java | 8 +- .../vanilla/effect/ExampleEffect.java | 2 +- src/main/resources/flywheel.mixins.json | 3 - 82 files changed, 451 insertions(+), 627 deletions(-) create mode 100644 src/main/java/com/jozufozu/flywheel/api/RenderStage.java rename src/main/java/com/jozufozu/flywheel/api/{ => instancer}/InstancedPart.java (94%) rename src/main/java/com/jozufozu/flywheel/api/{ => instancer}/Instancer.java (97%) rename src/main/java/com/jozufozu/flywheel/api/{ => instancer}/InstancerFactory.java (91%) rename src/main/java/com/jozufozu/flywheel/api/{ => instancer}/InstancerManager.java (83%) delete mode 100644 src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java delete mode 100644 src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java create mode 100644 src/main/java/com/jozufozu/flywheel/event/RenderStageEvent.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/LevelRendererDispatchMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 7d7465897..41b4e9aff 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -4,8 +4,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.slf4j.Logger; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.RenderWork; +import com.jozufozu.flywheel.backend.ShadersModHandler; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.model.MeshPool; import com.jozufozu.flywheel.config.BackendTypeArgument; @@ -28,7 +28,6 @@ import com.jozufozu.flywheel.event.ForgeEvents; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.mixin.PausedPartialTickAccessor; import com.jozufozu.flywheel.vanilla.VanillaInstances; -import com.jozufozu.flywheel.vanilla.effect.ExampleEffect; import com.mojang.logging.LogUtils; import net.minecraft.commands.synchronization.ArgumentTypes; @@ -92,6 +91,7 @@ public class Flywheel { forgeEventBus.addListener(CrumblingRenderer::onReloadRenderers); forgeEventBus.addListener(InstancedRenderDispatcher::onReloadRenderers); + forgeEventBus.addListener(InstancedRenderDispatcher::onRenderStage); forgeEventBus.addListener(InstancedRenderDispatcher::onBeginFrame); forgeEventBus.addListener(InstancedRenderDispatcher::tick); diff --git a/src/main/java/com/jozufozu/flywheel/api/RenderStage.java b/src/main/java/com/jozufozu/flywheel/api/RenderStage.java new file mode 100644 index 000000000..42d36d1cc --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/api/RenderStage.java @@ -0,0 +1,16 @@ +package com.jozufozu.flywheel.api; + +public enum RenderStage { + BEFORE_SKY, + AFTER_SKY, + BEFORE_TERRAIN, + AFTER_SOLID_TERRAIN, + BEFORE_ENTITIES, + AFTER_ENTITIES, + AFTER_BLOCK_ENTITIES, + BEFORE_CRUMBLING, + AFTER_FINAL_END_BATCH, + AFTER_TRANSLUCENT_TERRAIN, + AFTER_PARTICLES, + AFTER_WEATHER; +} diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java index 63668c034..2a4976a48 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/DynamicInstance.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.api.instance; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; /** diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java index 8a91965cd..1d114fa14 100644 --- a/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java +++ b/src/main/java/com/jozufozu/flywheel/api/instance/TickableInstance.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.api.instance; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; /** diff --git a/src/main/java/com/jozufozu/flywheel/api/InstancedPart.java b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancedPart.java similarity index 94% rename from src/main/java/com/jozufozu/flywheel/api/InstancedPart.java rename to src/main/java/com/jozufozu/flywheel/api/instancer/InstancedPart.java index 5f42a9499..50379c54e 100644 --- a/src/main/java/com/jozufozu/flywheel/api/InstancedPart.java +++ b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancedPart.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.api; +package com.jozufozu.flywheel.api.instancer; import com.jozufozu.flywheel.api.struct.StructType; diff --git a/src/main/java/com/jozufozu/flywheel/api/Instancer.java b/src/main/java/com/jozufozu/flywheel/api/instancer/Instancer.java similarity index 97% rename from src/main/java/com/jozufozu/flywheel/api/Instancer.java rename to src/main/java/com/jozufozu/flywheel/api/instancer/Instancer.java index 7a0bc0798..8e2a384eb 100644 --- a/src/main/java/com/jozufozu/flywheel/api/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/api/instancer/Instancer.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.api; +package com.jozufozu.flywheel.api.instancer; /** * An instancer is how you interact with an instanced model. diff --git a/src/main/java/com/jozufozu/flywheel/api/InstancerFactory.java b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerFactory.java similarity index 91% rename from src/main/java/com/jozufozu/flywheel/api/InstancerFactory.java rename to src/main/java/com/jozufozu/flywheel/api/instancer/InstancerFactory.java index 7efb7e4e1..85ac11cea 100644 --- a/src/main/java/com/jozufozu/flywheel/api/InstancerFactory.java +++ b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerFactory.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.api; +package com.jozufozu.flywheel.api.instancer; import com.jozufozu.flywheel.core.model.ModelSupplier; diff --git a/src/main/java/com/jozufozu/flywheel/api/InstancerManager.java b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java similarity index 83% rename from src/main/java/com/jozufozu/flywheel/api/InstancerManager.java rename to src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java index 0b174a397..2078b9edd 100644 --- a/src/main/java/com/jozufozu/flywheel/api/InstancerManager.java +++ b/src/main/java/com/jozufozu/flywheel/api/instancer/InstancerManager.java @@ -1,4 +1,4 @@ -package com.jozufozu.flywheel.api; +package com.jozufozu.flywheel.api.instancer; import com.jozufozu.flywheel.api.struct.StructType; diff --git a/src/main/java/com/jozufozu/flywheel/api/material/Material.java b/src/main/java/com/jozufozu/flywheel/api/material/Material.java index c9b80ef43..42df89830 100644 --- a/src/main/java/com/jozufozu/flywheel/api/material/Material.java +++ b/src/main/java/com/jozufozu/flywheel/api/material/Material.java @@ -1,9 +1,16 @@ package com.jozufozu.flywheel.api.material; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.core.source.FileResolution; import net.minecraft.client.renderer.RenderType; -public record Material(RenderType renderType, FileResolution vertexShader, FileResolution fragmentShader) { +public interface Material { + RenderStage getRenderStage(); + RenderType getRenderType(); + + FileResolution getVertexShader(); + + FileResolution getFragmentShader(); } diff --git a/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java b/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java index cf994e2df..12bb3f1e5 100644 --- a/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java +++ b/src/main/java/com/jozufozu/flywheel/api/struct/StructType.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.api.struct; import java.nio.ByteBuffer; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.core.layout.BufferLayout; import com.jozufozu.flywheel.core.model.ModelTransformer; import com.jozufozu.flywheel.core.source.FileResolution; diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index a9e826e70..b24df2eb6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -17,7 +17,7 @@ import net.minecraft.world.level.LevelAccessor; public class Backend { public static final Logger LOGGER = LogUtils.getLogger(); - public static boolean DUMP_SHADER_SOURCE = System.getProperty("flw.dumpShaderSource") != null; + public static final boolean DUMP_SHADER_SOURCE = System.getProperty("flw.dumpShaderSource") != null; private static BackendType TYPE; 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 48904d20c..9fffe7a88 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlObject.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.backend.gl; -import com.jozufozu.flywheel.backend.RenderWork; - // Utility class for safely dealing with gl object handles. public abstract class GlObject { private static final int INVALID_HANDLE = Integer.MIN_VALUE; diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java index 91553e7ca..ead96fb03 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBufferType.java @@ -10,7 +10,6 @@ import org.lwjgl.opengl.GL43; import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; public enum GlBufferType { ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER), diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java index 988cb4414..bacab4c7c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java @@ -22,7 +22,7 @@ public class GlShader extends GlObject { private final List parts; private final ShaderConstants constants; - public GlShader(String source, ShaderType type, List parts, ShaderConstants constants) { + public GlShader(String source, ShaderType type, List parts, ShaderConstants constants) throws ShaderCompilationException { this.parts = parts; this.type = type; this.constants = constants; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java index d75ec3a2d..38315bf87 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstance.java @@ -3,10 +3,10 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.Arrays; import java.util.stream.Stream; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; import com.jozufozu.flywheel.core.structs.FlatLit; import com.jozufozu.flywheel.light.LightListener; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java index bc656df99..78bf26d6a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/AbstractInstancer.java @@ -3,8 +3,8 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.ArrayList; import java.util.BitSet; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; import com.jozufozu.flywheel.api.struct.StructType; public abstract class AbstractInstancer implements Instancer { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java index 9fa6d9470..8ba605f23 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/DrawBuffer.java @@ -1,9 +1,7 @@ package com.jozufozu.flywheel.backend.instancing; -import java.lang.ref.Cleaner; import java.nio.ByteBuffer; -import com.jozufozu.flywheel.backend.FlywheelMemory; import com.jozufozu.flywheel.backend.model.BufferBuilderExtension; import com.jozufozu.flywheel.backend.model.DirectVertexConsumer; import com.mojang.blaze3d.platform.MemoryTracker; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java index 13416bedb..4389fcb94 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Engine.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.List; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; public interface Engine extends RenderDispatcher, InstancerManager { void attachManagers(InstanceManager... listener); 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 7dbe4ca4c..297d9d0e9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -13,6 +13,7 @@ import com.jozufozu.flywheel.backend.instancing.ratelimit.BandedPrimeLimiter; import com.jozufozu.flywheel.backend.instancing.ratelimit.DistanceUpdateLimiter; import com.jozufozu.flywheel.backend.instancing.ratelimit.NonLimiter; import com.jozufozu.flywheel.config.FlwConfig; +import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.light.LightUpdater; import com.mojang.math.Vector3f; @@ -102,19 +103,21 @@ public abstract class InstanceManager { if (tick.shouldUpdate(dX, dY, dZ)) instance.tick(); } - public void beginFrame(TaskEngine taskEngine, Camera camera) { + public void beginFrame(TaskEngine taskEngine, RenderContext context) { frame.tick(); processQueuedAdditions(); + Camera camera = context.camera(); Vector3f look = camera.getLookVector(); float lookX = look.x(); float lookY = look.y(); float lookZ = look.z(); // integer camera pos - int cX = (int) camera.getPosition().x; - int cY = (int) camera.getPosition().y; - int cZ = (int) camera.getPosition().z; + BlockPos cameraIntPos = camera.getBlockPosition(); + int cX = cameraIntPos.getX(); + int cY = cameraIntPos.getY(); + int cZ = cameraIntPos.getZ(); var instances = getStorage().getInstancesForUpdate(); distributeWork(taskEngine, instances, instance -> updateInstance(instance, lookX, lookY, lookZ, cX, cY, cZ)); 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 78ba4c6c3..839817d22 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.instancing; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.backend.Backend; @@ -13,12 +14,9 @@ import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.util.ClientLevelExtension; -import com.jozufozu.flywheel.vanilla.effect.ExampleEffect; -import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.RenderType; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.entity.BlockEntity; @@ -92,18 +90,18 @@ public class InstanceWorld { *

*/ public void beginFrame(BeginFrameEvent event) { - Camera camera = event.getCamera(); - boolean shifted = engine.maintainOriginCoordinate(camera); + RenderContext context = event.getContext(); + boolean shifted = engine.maintainOriginCoordinate(context.camera()); taskEngine.syncPoint(); if (!shifted) { - blockEntities.beginFrame(taskEngine, camera); - entities.beginFrame(taskEngine, camera); - effects.beginFrame(taskEngine, camera); + blockEntities.beginFrame(taskEngine, context); + entities.beginFrame(taskEngine, context); + effects.beginFrame(taskEngine, context); } - engine.beginFrame(taskEngine, camera); + engine.beginFrame(taskEngine, context); } /** @@ -131,24 +129,13 @@ public class InstanceWorld { } /** - * Draw the given layer. + * Draw all instances for the given stage. */ - public void renderSpecificType(RenderContext context, RenderType type) { + public void renderStage(RenderContext context, RenderStage stage) { taskEngine.syncPoint(); context.pushPose(); - context.translateBack(context.camX(), context.camY(), context.camZ()); - engine.renderSpecificType(taskEngine, context, type); - context.popPose(); - } - - /** - * Draw the given layer. - */ - public void renderAllRemaining(RenderContext context) { - taskEngine.syncPoint(); - context.pushPose(); - context.translateBack(context.camX(), context.camY(), context.camZ()); - engine.renderAllRemaining(taskEngine, context); + context.translateBack(context.camera().getPosition()); + engine.renderStage(taskEngine, context, stage); context.popPose(); } 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 ab05356a4..2c85a026b 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -6,16 +6,14 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.effect.Effect; import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwConfig; -import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent; +import com.jozufozu.flywheel.event.RenderStageEvent; import com.jozufozu.flywheel.util.AnimationTickHolder; import com.jozufozu.flywheel.util.WorldAttached; -import com.jozufozu.flywheel.vanilla.effect.ExampleEffect; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.RenderType; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.entity.BlockEntity; @@ -89,23 +87,16 @@ public class InstancedRenderDispatcher { public static void onBeginFrame(BeginFrameEvent event) { if (Backend.isGameActive() && Backend.isOn()) { - instanceWorlds.get(event.getWorld()) + instanceWorlds.get(event.getContext().level()) .beginFrame(event); } } - public static void renderSpecificType(RenderContext context, RenderType type) { - ClientLevel world = context.level(); + public static void onRenderStage(RenderStageEvent event) { + ClientLevel world = event.getContext().level(); if (!Backend.canUseInstancing(world)) return; - instanceWorlds.get(world).renderSpecificType(context, type); - } - - public static void renderAllRemaining(RenderContext context) { - ClientLevel world = context.level(); - if (!Backend.canUseInstancing(world)) return; - - instanceWorlds.get(world).renderAllRemaining(context); + instanceWorlds.get(world).renderStage(event.getContext(), event.getStage()); } public static void onReloadRenderers(ReloadRenderersEvent event) { 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 79248b22f..3059aaa13 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -6,7 +6,7 @@ import java.util.function.Predicate; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstancingController; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityTypeExtension; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/One2OneStorage.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/One2OneStorage.java index 1c615176d..75ede30b6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/One2OneStorage.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/One2OneStorage.java @@ -4,13 +4,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.light.LightUpdater; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java index d53c29a58..2d110c08f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderDispatcher.java @@ -1,15 +1,13 @@ package com.jozufozu.flywheel.backend.instancing; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.core.RenderContext; import net.minecraft.client.Camera; -import net.minecraft.client.renderer.RenderType; public interface RenderDispatcher { - void renderAllRemaining(TaskEngine taskEngine, RenderContext context); - - void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type); + void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage); /** * Maintain the integer origin coordinate to be within a certain distance from the camera in all directions, @@ -18,7 +16,7 @@ public interface RenderDispatcher { */ boolean maintainOriginCoordinate(Camera camera); - void beginFrame(TaskEngine taskEngine, Camera info); + void beginFrame(TaskEngine taskEngine, RenderContext context); void delete(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchLists.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchLists.java index c5ec268b4..b870acb9d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchLists.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchLists.java @@ -12,6 +12,6 @@ public class BatchLists { public final Map>> renderLists = new HashMap<>(); public void add(TransformSet set) { - renderLists.computeIfAbsent(set.material.renderType(), k -> new ArrayList<>()).add(set); + renderLists.computeIfAbsent(set.material.getRenderType(), k -> new ArrayList<>()).add(set); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedModel.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedModel.java index 16fca800d..61a7bd048 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedModel.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.ModelSupplier; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java index 585015cb0..c12a67431 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchingEngine.java @@ -5,10 +5,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.ShadersModHandler; -import com.jozufozu.flywheel.backend.instancing.*; +import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker; +import com.jozufozu.flywheel.backend.instancing.Engine; +import com.jozufozu.flywheel.backend.instancing.InstanceManager; +import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.util.FlwUtil; import com.mojang.blaze3d.platform.Lighting; @@ -16,7 +20,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import net.minecraft.client.Camera; -import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.world.phys.Vec3; @@ -65,12 +68,11 @@ public class BatchingEngine implements Engine { } @Override - public void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type) { - - } - - @Override - public void renderAllRemaining(TaskEngine taskEngine, RenderContext context) { + public void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage) { + // FIXME: properly support material stages + if (stage != RenderStage.AFTER_FINAL_END_BATCH) { + return; + } // FIXME: this probably breaks some vanilla stuff but it works much better for flywheel Matrix4f mat = new Matrix4f(); @@ -96,15 +98,15 @@ public class BatchingEngine implements Engine { } @Override - public void beginFrame(TaskEngine taskEngine, Camera info) { + public void beginFrame(TaskEngine taskEngine, RenderContext context) { for (var model : uninitializedModels) { model.init(batchLists); } uninitializedModels.clear(); - Vec3 cameraPos = info.getPosition(); - var stack = FlwUtil.copyPoseStack(RenderContext.CURRENT.stack()); + Vec3 cameraPos = context.camera().getPosition(); + var stack = FlwUtil.copyPoseStack(context.stack()); stack.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z); submitTasks(stack, taskEngine); @@ -118,7 +120,5 @@ public class BatchingEngine implements Engine { @Override public void addDebugInfo(List info) { info.add("Batching"); - info.add("Instances: " + 0); - info.add("Vertices: " + 0); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java index 4166ef078..97fc5737f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancer.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancerFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancerFactory.java index 005e044f1..f24bbccaa 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancerFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/CPUInstancerFactory.java @@ -4,9 +4,9 @@ import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; -import com.jozufozu.flywheel.api.InstancerFactory; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancerFactory; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.core.model.ModelSupplier; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/TransformSet.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/TransformSet.java index 8e4d52b7e..3fc42e21e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/TransformSet.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/batching/TransformSet.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.batching; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.model.DirectVertexConsumer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java index 1ca88861b..39a53e444 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstance.java @@ -3,11 +3,11 @@ package com.jozufozu.flywheel.backend.instancing.blockentity; import java.util.ArrayList; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.InstancerFactory; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancerFactory; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.model.TransformedPart; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstanceManager.java index a3cdff0c6..7059e4763 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstanceManager.java @@ -2,11 +2,11 @@ package com.jozufozu.flywheel.backend.instancing.blockentity; import java.util.List; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.InstanceManager; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.One2OneStorage; import com.jozufozu.flywheel.backend.instancing.Storage; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java index 1ee9016c5..37d0b8c6c 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/BlockEntityInstancingController.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.blockentity; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/SimpleBlockEntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/SimpleBlockEntityInstancingController.java index 93ac43df6..6b86086fe 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/SimpleBlockEntityInstancingController.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/blockentity/SimpleBlockEntityInstancingController.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.instancing.blockentity; import java.util.function.BiFunction; import java.util.function.Predicate; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import net.minecraft.world.level.block.entity.BlockEntity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/Effect.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/Effect.java index e25b7143c..fd91116b0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/Effect.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/Effect.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.instancing.effect; import java.util.Collection; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; public interface Effect { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java index e6f4b544b..fda91b5a7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/effect/EffectInstanceManager.java @@ -7,9 +7,9 @@ import java.util.Set; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.Storage; 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 aed1461a1..4e6926317 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 @@ -1,8 +1,8 @@ package com.jozufozu.flywheel.backend.instancing.entity; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; import com.jozufozu.flywheel.light.LightListener; 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 3643c30e3..8a729a559 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 @@ -2,11 +2,11 @@ package com.jozufozu.flywheel.backend.instancing.entity; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.InstanceManager; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.instancing.One2OneStorage; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java index c2f3eb9cc..b86c8f005 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstancingController.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.backend.instancing.entity; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/SimpleEntityInstancingController.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/SimpleEntityInstancingController.java index 91490d8e2..95e964068 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/SimpleEntityInstancingController.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/SimpleEntityInstancingController.java @@ -3,7 +3,7 @@ package com.jozufozu.flywheel.backend.instancing.entity; import java.util.function.BiFunction; import java.util.function.Predicate; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java index 1b5d7425c..1394cd948 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancer.java @@ -4,7 +4,7 @@ import java.util.HashSet; import java.util.Set; import com.jozufozu.flywheel.Flywheel; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.struct.StructWriter; import com.jozufozu.flywheel.backend.gl.GlVertexArray; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancerFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancerFactory.java index ff20915db..c209a5f7d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancerFactory.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/GPUInstancerFactory.java @@ -4,15 +4,13 @@ import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; -import com.jozufozu.flywheel.api.InstancerFactory; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancerFactory; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; import com.jozufozu.flywheel.core.model.ModelSupplier; -import net.minecraft.client.renderer.RenderType; - /** * A collection of Instancers that all have the same format. * @param diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedModel.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedModel.java index bd5abab4c..854ca0fac 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedModel.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancedModel.java @@ -2,9 +2,8 @@ package com.jozufozu.flywheel.backend.instancing.instancing; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; -import com.jozufozu.flywheel.backend.instancing.AbstractInstancer; import com.jozufozu.flywheel.core.model.ModelSupplier; public class InstancedModel { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index 9e1043636..2e651f573 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -12,15 +12,16 @@ import org.jetbrains.annotations.NotNull; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimaps; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.backend.gl.GlVertexArray; import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; -import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.Engine; +import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; @@ -75,8 +76,6 @@ public class InstancingEngine

implements Engine { * The set of instance managers that are attached to this engine. */ private final WeakHashSet> instanceManagers; - private int vertexCount; - private int instanceCount; public InstancingEngine(ProgramCompiler

context) { this.context = context; @@ -97,48 +96,62 @@ public class InstancingEngine

implements Engine { } @Override - public void renderAllRemaining(TaskEngine taskEngine, RenderContext context) { - var camX = context.camX() - originCoordinate.getX(); - var camY = context.camY() - originCoordinate.getY(); - var camZ = context.camZ() - originCoordinate.getZ(); + public void renderStage(TaskEngine taskEngine, RenderContext context, RenderStage stage) { + if (!renderLists.process(stage)) { + return; + } + + var camPos = context.camera().getPosition(); + var camX = camPos.x - originCoordinate.getX(); + var camY = camPos.y - originCoordinate.getY(); + var camZ = camPos.z - originCoordinate.getZ(); // don't want to mutate viewProjection var vp = context.viewProjection().copy(); vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ); - for (RenderType renderType : renderLists.drainLayers()) { - render(renderType, camX, camY, camZ, vp, context.level()); + var renderList = renderLists.get(stage); + for (var entry : renderList.entrySet()) { + var multimap = entry.getValue(); + + if (multimap.isEmpty()) { + return; + } + + render(entry.getKey(), multimap, camX, camY, camZ, vp, context.level()); } } - @Override - public void renderSpecificType(TaskEngine taskEngine, RenderContext context, RenderType type) { - if (!renderLists.process(type)) { + // TODO: Is this useful? Should it be added to the base interface? Currently it is only used for the old CrumblingRenderer. + @Deprecated + public void renderAll(TaskEngine taskEngine, RenderContext context) { + if (renderLists.isEmpty()) { return; } - var camX = context.camX() - originCoordinate.getX(); - var camY = context.camY() - originCoordinate.getY(); - var camZ = context.camZ() - originCoordinate.getZ(); + var camPos = context.camera().getPosition(); + var camX = camPos.x - originCoordinate.getX(); + var camY = camPos.y - originCoordinate.getY(); + var camZ = camPos.z - originCoordinate.getZ(); // don't want to mutate viewProjection var vp = context.viewProjection().copy(); vp.multiplyWithTranslation((float) -camX, (float) -camY, (float) -camZ); - render(type, camX, camY, camZ, vp, context.level()); - } - - protected void render(RenderType type, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) { - vertexCount = 0; - instanceCount = 0; - - var multimap = renderLists.get(type); - - if (multimap.isEmpty()) { - return; + for (RenderStage stage : renderLists.stagesToProcess) { + var renderList = renderLists.get(stage); + for (var entry : renderList.entrySet()) { + var multimap = entry.getValue(); + + if (multimap.isEmpty()) { + return; + } + + render(entry.getKey(), multimap, camX, camY, camZ, vp, context.level()); + } } - render(type, multimap, camX, camY, camZ, viewProjection, level); + renderLists.stagesToProcess.clear(); } protected void render(RenderType type, ListMultimap multimap, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) { @@ -176,7 +189,7 @@ public class InstancingEngine

implements Engine { Material material = desc.material(); P program = context.getProgram(new ProgramCompiler.Context(vertexType, instanceShader, - material.vertexShader(), material.fragmentShader(), coreShaderInfo.getAdjustedAlphaDiscard(), + material.getVertexShader(), material.getFragmentShader(), coreShaderInfo.getAdjustedAlphaDiscard(), coreShaderInfo.fogType(), ctx)); program.bind(); @@ -223,7 +236,7 @@ public class InstancingEngine

implements Engine { } @Override - public void beginFrame(TaskEngine taskEngine, Camera info) { + public void beginFrame(TaskEngine taskEngine, RenderContext context) { for (var model : uninitializedModels) { model.init(renderLists); } @@ -246,8 +259,6 @@ public class InstancingEngine

implements Engine { @Override public void addDebugInfo(List info) { info.add("GL33 Instanced Arrays"); - info.add("Instances: " + instanceCount); - info.add("Vertices: " + vertexCount); info.add("Origin: " + originCoordinate.getX() + ", " + originCoordinate.getY() + ", " + originCoordinate.getZ()); } @@ -299,13 +310,13 @@ public class InstancingEngine

implements Engine { continue; } - material.renderType().setupRenderState(); + material.getRenderType().setupRenderState(); CoreShaderInfo coreShaderInfo = CoreShaderInfo.get(); CrumblingProgram program = Contexts.CRUMBLING.getProgram(new ProgramCompiler.Context(Formats.POS_TEX_NORMAL, - structType.getInstanceShader(), material.vertexShader(), material.fragmentShader(), + structType.getInstanceShader(), material.getVertexShader(), material.getFragmentShader(), coreShaderInfo.getAdjustedAlphaDiscard(), coreShaderInfo.fogType(), GameStateRegistry.takeSnapshot())); @@ -332,7 +343,7 @@ public class InstancingEngine

implements Engine { for (var blockEntityInstance : entry.getValue()) { for (var part : blockEntityInstance.getCrumblingParts()) { - if (part.getOwner() instanceof GPUInstancer instancer) { + if (part.getOwner() instanceof GPUInstancer instancer) { // queue the instances for copying to the crumbling instance buffer map.computeIfAbsent(instancer.parent.getModel(), k -> new ArrayList<>()).add(part); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/RenderLists.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/RenderLists.java index b5aa12258..34ecab81a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/RenderLists.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/RenderLists.java @@ -1,49 +1,57 @@ package com.jozufozu.flywheel.backend.instancing.instancing; +import java.util.Collections; +import java.util.EnumMap; +import java.util.EnumSet; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.api.material.Material; import net.minecraft.client.renderer.RenderType; public class RenderLists { - private final Map> renderLists = new HashMap<>(); - public final Set layersToProcess = new HashSet<>(); + private final Map>> renderLists = new EnumMap<>(RenderStage.class); + public final Set stagesToProcess = EnumSet.noneOf(RenderStage.class); - public ListMultimap get(RenderType type) { - return renderLists.computeIfAbsent(type, k -> ArrayListMultimap.create()); + public Map> get(RenderStage stage) { + var renderList = renderLists.get(stage); + if (renderList == null) { + return Collections.emptyMap(); + } + return renderList; } public void add(ShaderState shaderState, DrawCall layer) { - RenderType renderType = shaderState.material() - .renderType(); + Material material = shaderState.material(); - get(renderType).put(shaderState, layer); + renderLists + .computeIfAbsent(material.getRenderStage(), k -> new HashMap<>()) + .computeIfAbsent(material.getRenderType(), k -> ArrayListMultimap.create()) + .put(shaderState, layer); } public void prepare() { - layersToProcess.clear(); + stagesToProcess.clear(); - layersToProcess.addAll(renderLists.keySet()); - } - - public Iterable drainLayers() { - var out = new HashSet<>(layersToProcess); - layersToProcess.clear(); - return out; + stagesToProcess.addAll(renderLists.keySet()); } /** - * Check and mark a layer as processed. - * @param type The layer to check. - * @return {@code true} if the layer should be processed. + * Check and mark a stage as processed. + * @param stage The stage to check. + * @return {@code true} if the stage should be processed. */ - public boolean process(RenderType type) { - return layersToProcess.remove(type); + public boolean process(RenderStage stage) { + return stagesToProcess.remove(stage); + } + + public boolean isEmpty() { + return stagesToProcess.isEmpty(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java b/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java index 943559acc..49ce4969d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/BufferWriter.java @@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.struct; import java.nio.ByteBuffer; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.struct.StructWriter; diff --git a/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java index 96e675bbd..7aa852de1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java +++ b/src/main/java/com/jozufozu/flywheel/backend/struct/UnsafeBufferWriter.java @@ -4,7 +4,7 @@ import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; /** diff --git a/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java b/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java index e64837738..f4c456691 100644 --- a/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java +++ b/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java @@ -6,23 +6,14 @@ import org.jetbrains.annotations.NotNull; import com.google.common.collect.ImmutableMap; import com.jozufozu.flywheel.api.material.Material; -import com.jozufozu.flywheel.core.material.MaterialShaders; import com.jozufozu.flywheel.core.model.Mesh; import com.jozufozu.flywheel.core.model.ModelSupplier; import com.jozufozu.flywheel.util.Lazy; import com.jozufozu.flywheel.util.NonNullSupplier; -import net.minecraft.client.renderer.RenderType; - public class BasicModelSupplier implements ModelSupplier { - private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), MaterialShaders.DEFAULT_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); - - private Material material; private final Lazy supplier; - - public BasicModelSupplier(NonNullSupplier supplier) { - this(supplier, DEFAULT_MATERIAL); - } + private Material material; public BasicModelSupplier(NonNullSupplier supplier, Material material) { this.supplier = Lazy.of(supplier); diff --git a/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java b/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java index 9e6e16ffb..33dfb683f 100644 --- a/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java +++ b/src/main/java/com/jozufozu/flywheel/core/CoreShaderInfoMap.java @@ -10,6 +10,7 @@ import java.util.Map; import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.backend.ShadersModHandler; +import com.jozufozu.flywheel.core.CoreShaderInfoMap.CoreShaderInfo.FogType; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.renderer.ShaderInstance; diff --git a/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java b/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java deleted file mode 100644 index 60e36f463..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/LastActiveCamera.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jozufozu.flywheel.core; - -import net.minecraft.client.Camera; - -/** - * A class tracking which object last had {@link Camera#setup} called on it. - * - * @see com.jozufozu.flywheel.mixin.CameraMixin - */ -public class LastActiveCamera { - - private static Camera camera; - - public static void _setActiveCamera(Camera camera) { - LastActiveCamera.camera = camera; - } - - public static Camera getActiveCamera() { - return camera; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/Models.java b/src/main/java/com/jozufozu/flywheel/core/Models.java index 063453a7e..cebc63d0a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Models.java +++ b/src/main/java/com/jozufozu/flywheel/core/Models.java @@ -4,23 +4,30 @@ import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.api.material.Material; +import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.material.SimpleMaterial; import com.jozufozu.flywheel.core.model.BlockMesh; import com.jozufozu.flywheel.core.model.ModelUtil; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.util.Pair; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; public class Models { + public static final Material DEFAULT_MATERIAL = new SimpleMaterial(RenderStage.AFTER_SOLID_TERRAIN, RenderType.cutout(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); + public static BasicModelSupplier block(BlockState state) { - return BLOCK_STATE.computeIfAbsent(state, it -> new BasicModelSupplier(() -> new BlockMesh(it))); + return BLOCK_STATE.computeIfAbsent(state, it -> new BasicModelSupplier(() -> new BlockMesh(it), DEFAULT_MATERIAL)); } public static BasicModelSupplier partial(PartialModel partial) { - return PARTIAL.computeIfAbsent(partial, it -> new BasicModelSupplier(() -> new BlockMesh(it))); + return PARTIAL.computeIfAbsent(partial, it -> new BasicModelSupplier(() -> new BlockMesh(it), DEFAULT_MATERIAL)); } public static BasicModelSupplier partial(PartialModel partial, Direction dir) { @@ -28,7 +35,7 @@ public class Models { } public static BasicModelSupplier partial(PartialModel partial, Direction dir, Supplier modelTransform) { - return PARTIAL_DIR.computeIfAbsent(Pair.of(dir, partial), $ -> new BasicModelSupplier(() -> new BlockMesh(partial, modelTransform.get()))); + return PARTIAL_DIR.computeIfAbsent(Pair.of(dir, partial), $ -> new BasicModelSupplier(() -> new BlockMesh(partial, modelTransform.get()), DEFAULT_MATERIAL)); } public static void onReload(ReloadRenderersEvent ignored) { diff --git a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java index d55568b13..901e324f7 100644 --- a/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java +++ b/src/main/java/com/jozufozu/flywheel/core/QuadConverter.java @@ -1,8 +1,6 @@ package com.jozufozu.flywheel.core; -import java.nio.Buffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/jozufozu/flywheel/core/RenderContext.java b/src/main/java/com/jozufozu/flywheel/core/RenderContext.java index d49f724f1..6fd3effbb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/RenderContext.java +++ b/src/main/java/com/jozufozu/flywheel/core/RenderContext.java @@ -1,18 +1,20 @@ package com.jozufozu.flywheel.core; +import org.jetbrains.annotations.NotNull; + import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; import com.mojang.math.Quaternion; +import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; -public record RenderContext(ClientLevel level, PoseStack stack, Matrix4f viewProjection, RenderBuffers buffers, - double camX, double camY, double camZ) implements TransformStack { - - public static RenderContext CURRENT; +public record RenderContext(LevelRenderer renderer, ClientLevel level, PoseStack stack, Matrix4f viewProjection, + Matrix4f projection, RenderBuffers buffers, Camera camera) implements TransformStack { @Override public TransformStack multiply(Quaternion quaternion) { @@ -50,4 +52,11 @@ public record RenderContext(ClientLevel level, PoseStack stack, Matrix4f viewPro public TransformStack translate(double x, double y, double z) { return TransformStack.cast(stack).translate(x, y, z); } + + @NotNull + public static Matrix4f createViewProjection(PoseStack view, Matrix4f projection) { + var viewProjection = projection.copy(); + viewProjection.multiply(view.last().pose()); + return viewProjection; + } } diff --git a/src/main/java/com/jozufozu/flywheel/core/compile/VertexCompiler.java b/src/main/java/com/jozufozu/flywheel/core/compile/VertexCompiler.java index 1c6c2c7d5..c54cafe62 100644 --- a/src/main/java/com/jozufozu/flywheel/core/compile/VertexCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/core/compile/VertexCompiler.java @@ -12,8 +12,6 @@ import com.jozufozu.flywheel.core.source.FileIndex; import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.ShaderField; import com.jozufozu.flywheel.core.source.SourceFile; -import com.jozufozu.flywheel.core.source.parse.ShaderStruct; -import com.jozufozu.flywheel.core.source.parse.StructField; import com.jozufozu.flywheel.core.source.span.Span; import com.jozufozu.flywheel.util.Pair; 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 df67c6c48..c58b5984d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.core.crumbling; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager; public class CrumblingInstanceManager extends BlockEntityInstanceManager { 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 2624cf2f1..ce7867afc 100644 --- a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingRenderer.java @@ -4,24 +4,25 @@ import java.util.ArrayList; import java.util.List; import java.util.SortedSet; +import com.google.common.collect.ListMultimap; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlStateTracker; import com.jozufozu.flywheel.backend.instancing.InstanceManager; import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine; +import com.jozufozu.flywheel.backend.instancing.instancing.DrawCall; import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine; +import com.jozufozu.flywheel.backend.instancing.instancing.ShaderState; import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.mixin.LevelRendererAccessor; import com.jozufozu.flywheel.util.Lazy; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderType; @@ -29,7 +30,6 @@ import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.core.BlockPos; import net.minecraft.server.level.BlockDestructionProgress; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.phys.Vec3; // TODO: merge directly into InstancingEngine for efficiency /** @@ -43,45 +43,34 @@ public class CrumblingRenderer { _init(); } - public static void renderCrumbling(LevelRenderer levelRenderer, ClientLevel level, PoseStack poseStack, Camera camera, Matrix4f projectionMatrix) { + public static void renderCrumbling(RenderContext context) { // TODO: one pass base/crumbling if (true) return; - Int2ObjectMap> activeStages = getActiveStageBlockEntities(levelRenderer, level); + Int2ObjectMap> activeStages = getActiveStageBlockEntities(context.renderer(), context.level()); if (activeStages.isEmpty()) return; try (var restoreState = GlStateTracker.getRestoreState()) { - - Matrix4f viewProjection = poseStack.last() - .pose() - .copy(); - viewProjection.multiplyBackward(projectionMatrix); - State state = STATE.get(); var instanceManager = state.instanceManager; var engine = state.instancerManager; - renderCrumblingInner(activeStages, instanceManager, engine, level, poseStack, camera, viewProjection); + renderCrumblingInner(activeStages, instanceManager, engine, context); } } - private static void renderCrumblingInner(Int2ObjectMap> activeStages, InstanceManager instanceManager, CrumblingEngine engine, ClientLevel level, PoseStack stack, Camera camera, Matrix4f viewProjection) { - Vec3 cameraPos = camera.getPosition(); - RenderContext ctx = new RenderContext(level, stack, viewProjection, null, cameraPos.x, cameraPos.y, cameraPos.z); - + private static void renderCrumblingInner(Int2ObjectMap> activeStages, InstanceManager instanceManager, CrumblingEngine engine, RenderContext ctx) { for (Int2ObjectMap.Entry> stage : activeStages.int2ObjectEntrySet()) { RenderType currentLayer = ModelBakery.DESTROY_TYPES.get(stage.getIntKey()); // something about when we call this means that the textures are not ready for use on the first frame they should appear if (currentLayer != null) { - engine.currentLayer = currentLayer; - stage.getValue().forEach(instanceManager::add); - instanceManager.beginFrame(SerialTaskEngine.INSTANCE, camera); - engine.beginFrame(SerialTaskEngine.INSTANCE, camera); + instanceManager.beginFrame(SerialTaskEngine.INSTANCE, ctx); + engine.beginFrame(SerialTaskEngine.INSTANCE, ctx); - engine.renderAllRemaining(SerialTaskEngine.INSTANCE, ctx); + engine.renderAll(SerialTaskEngine.INSTANCE, ctx); instanceManager.invalidate(); } @@ -154,25 +143,17 @@ public class CrumblingRenderer { } private static class CrumblingEngine extends InstancingEngine { - private RenderType currentLayer; - public CrumblingEngine() { super(Contexts.CRUMBLING); } @Override - protected void render(RenderType type, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) { + protected void render(RenderType type, ListMultimap multimap, double camX, double camY, double camZ, Matrix4f viewProjection, ClientLevel level) { if (!type.affectsCrumbling()) { return; } - var multimap = renderLists.get(type); - - if (multimap.isEmpty()) { - return; - } - - render(currentLayer, multimap, camX, camY, camZ, viewProjection, level); + super.render(type, multimap, camX, camY, camZ, viewProjection, level); } } } diff --git a/src/main/java/com/jozufozu/flywheel/core/hardcoded/ModelPart.java b/src/main/java/com/jozufozu/flywheel/core/hardcoded/ModelPart.java index a723692a8..a60aa14cb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/hardcoded/ModelPart.java +++ b/src/main/java/com/jozufozu/flywheel/core/hardcoded/ModelPart.java @@ -9,7 +9,6 @@ import com.jozufozu.flywheel.core.model.Mesh; import com.jozufozu.flywheel.core.vertex.Formats; import com.jozufozu.flywheel.core.vertex.PosTexNormalVertex; import com.jozufozu.flywheel.core.vertex.PosTexNormalWriterUnsafe; -import com.mojang.blaze3d.platform.MemoryTracker; public class ModelPart implements Mesh { diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java index db420b2e9..d915d63b8 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java @@ -5,8 +5,8 @@ import java.util.function.Consumer; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; public class ConditionalInstance { diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java index 8ccdc143d..a48c5c3a9 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/GroupInstance.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; public class GroupInstance extends AbstractCollection { diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java index 81c6de015..d8fdf5cf4 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/SelectInstance.java @@ -6,8 +6,8 @@ import java.util.Optional; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.Instancer; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.Instancer; public class SelectInstance { diff --git a/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java b/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java new file mode 100644 index 000000000..c3880e5bd --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/material/SimpleMaterial.java @@ -0,0 +1,41 @@ +package com.jozufozu.flywheel.core.material; + +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.api.material.Material; +import com.jozufozu.flywheel.core.source.FileResolution; + +import net.minecraft.client.renderer.RenderType; + +public class SimpleMaterial implements Material { + protected final RenderStage stage; + protected final RenderType type; + protected final FileResolution vertexShader; + protected final FileResolution fragmentShader; + + public SimpleMaterial(RenderStage stage, RenderType type, FileResolution vertexShader, FileResolution fragmentShader) { + this.stage = stage; + this.type = type; + this.vertexShader = vertexShader; + this.fragmentShader = fragmentShader; + } + + @Override + public RenderStage getRenderStage() { + return stage; + } + + @Override + public RenderType getRenderType() { + return type; + } + + @Override + public FileResolution getVertexShader() { + return vertexShader; + } + + @Override + public FileResolution getFragmentShader() { + return fragmentShader; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index 8c5e4342b..97013adb8 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -1,7 +1,6 @@ package com.jozufozu.flywheel.core.model; import java.lang.reflect.Field; -import java.nio.ByteBuffer; import java.util.EnumMap; import java.util.Random; @@ -11,7 +10,6 @@ import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.datafixers.util.Pair; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitPart.java b/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitPart.java index db8936937..ca75d2f40 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitPart.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitPart.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core.structs; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.util.Color; diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/FlatLit.java b/src/main/java/com/jozufozu/flywheel/core/structs/FlatLit.java index 01fd710a7..b0f753503 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/FlatLit.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/FlatLit.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.core.structs; -import com.jozufozu.flywheel.api.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancedPart; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockAndTintGetter; diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java index f595d4c1b..586679472 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java @@ -1,7 +1,6 @@ package com.jozufozu.flywheel.core.vertex; import com.jozufozu.flywheel.api.vertex.ShadedVertexList; -import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder; import com.jozufozu.flywheel.util.RenderMath; diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java index 7b1065899..a5073832c 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexListUnsafe.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.vertex; -import java.lang.ref.Cleaner; import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java index dbae103b0..95189b2fb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/PosTexNormalVertexListUnsafe.java @@ -4,9 +4,7 @@ import java.nio.ByteBuffer; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.api.vertex.VertexList; import com.jozufozu.flywheel.api.vertex.VertexType; -import com.jozufozu.flywheel.backend.FlywheelMemory; import com.jozufozu.flywheel.util.RenderMath; public class PosTexNormalVertexListUnsafe extends AbstractVertexList { diff --git a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java index db4d6fd1f..4ef40af54 100644 --- a/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java +++ b/src/main/java/com/jozufozu/flywheel/event/BeginFrameEvent.java @@ -1,35 +1,17 @@ package com.jozufozu.flywheel.event; -import net.minecraft.client.Camera; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.world.phys.Vec3; +import com.jozufozu.flywheel.core.RenderContext; + import net.minecraftforge.eventbus.api.Event; public class BeginFrameEvent extends Event { - private final ClientLevel world; - private final Camera camera; - private final Frustum frustum; + private final RenderContext context; - public BeginFrameEvent(ClientLevel world, Camera camera, Frustum frustum) { - this.world = world; - this.camera = camera; - this.frustum = frustum; + public BeginFrameEvent(RenderContext context) { + this.context = context; } - public ClientLevel getWorld() { - return world; - } - - public Camera getCamera() { - return camera; - } - - public Frustum getFrustum() { - return frustum; - } - - public Vec3 getCameraPos() { - return camera.getPosition(); + public RenderContext getContext() { + return context; } } diff --git a/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java b/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java index 6746fd963..a6848009c 100644 --- a/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java +++ b/src/main/java/com/jozufozu/flywheel/event/EntityWorldHandler.java @@ -3,11 +3,8 @@ package com.jozufozu.flywheel.event; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.EntityLeaveWorldEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; public class EntityWorldHandler { diff --git a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java index e398b8698..1310235f7 100644 --- a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java +++ b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java @@ -10,25 +10,21 @@ import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.util.WorldAttached; import net.minecraft.client.Minecraft; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; public class ForgeEvents { public static void addToDebugScreen(RenderGameOverlayEvent.Text event) { - if (Minecraft.getInstance().options.renderDebug) { - ArrayList debug = event.getRight(); debug.add(""); debug.add("Flywheel: " + Flywheel.getVersion()); InstancedRenderDispatcher.getDebugString(debug); + // TODO: compress into one line debug.add("Memory used:"); debug.add("GPU: " + FlywheelMemory.getGPUMemory()); debug.add("CPU: " + FlywheelMemory.getCPUMemory()); @@ -39,8 +35,8 @@ public class ForgeEvents { WorldAttached.invalidateWorld(event.getWorld()); } - public static void tickLight(TickEvent.ClientTickEvent e) { - if (e.phase == TickEvent.Phase.END && Backend.isGameActive()) { + public static void tickLight(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.END && Backend.isGameActive()) { LightUpdater.get(Minecraft.getInstance().level) .tick(); } diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java deleted file mode 100644 index 83d45bab6..000000000 --- a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.jozufozu.flywheel.event; - -import org.jetbrains.annotations.NotNull; - -import com.jozufozu.flywheel.core.RenderContext; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; - -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.RenderBuffers; -import net.minecraft.client.renderer.RenderType; -import net.minecraftforge.eventbus.api.Event; - -public class RenderLayerEvent extends Event { - public final RenderContext context; - public final RenderType type; - - public RenderLayerEvent(RenderContext context, RenderType type) { - this.context = context; - this.type = type; - } - - @NotNull - public static Matrix4f createViewProjection(PoseStack view) { - var viewProjection = view.last() - .pose() - .copy(); - viewProjection.multiplyBackward(RenderSystem.getProjectionMatrix()); - return viewProjection; - } - - @Override - public String toString() { - return "RenderLayerEvent{" + context + "}"; - } - - public ClientLevel getWorld() { - return context.level(); - } - - public RenderType getType() { - return type; - } - - public PoseStack getStack() { - return context.stack(); - } - - public Matrix4f getViewProjection() { - return context.viewProjection(); - } - - public RenderBuffers getBuffers() { - return context.buffers(); - } - - public double getCamX() { - return context.camX(); - } - - public double getCamY() { - return context.camY(); - } - - public double getCamZ() { - return context.camZ(); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderStageEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderStageEvent.java new file mode 100644 index 000000000..17bbb2d0f --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/event/RenderStageEvent.java @@ -0,0 +1,54 @@ +package com.jozufozu.flywheel.event; + +import com.jozufozu.flywheel.api.RenderStage; +import com.jozufozu.flywheel.core.RenderContext; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Matrix4f; + +import net.minecraft.client.Camera; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.RenderBuffers; +import net.minecraftforge.eventbus.api.Event; + +public class RenderStageEvent extends Event { + private final RenderContext context; + private final RenderStage stage; + + public RenderStageEvent(RenderContext context, RenderStage stage) { + this.context = context; + this.stage = stage; + } + + public RenderContext getContext() { + return context; + } + + public RenderStage getStage() { + return stage; + } + + public ClientLevel getLevel() { + return context.level(); + } + + public PoseStack getStack() { + return context.stack(); + } + + public Matrix4f getViewProjection() { + return context.viewProjection(); + } + + public RenderBuffers getBuffers() { + return context.buffers(); + } + + public Camera getCamera() { + return context.camera(); + } + + @Override + public String toString() { + return "RenderStageEvent{" + context + "}"; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java deleted file mode 100644 index 52e6043ef..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/CameraMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.jozufozu.flywheel.core.LastActiveCamera; - -import net.minecraft.client.Camera; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.BlockGetter; - -@Mixin(Camera.class) -public class CameraMixin { - - @Inject(method = "setup", at = @At("TAIL")) - private void setup(BlockGetter level, Entity entity, boolean is3rdPerson, boolean isMirrored, float pt, CallbackInfo ci) { - LastActiveCamera._setActiveCamera((Camera)(Object) this); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java deleted file mode 100644 index 2da2c0e8e..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.jozufozu.flywheel.backend.ShadersModHandler; -import com.jozufozu.flywheel.backend.gl.GlStateTracker; -import com.jozufozu.flywheel.core.LastActiveCamera; -import com.jozufozu.flywheel.event.BeginFrameEvent; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.culling.Frustum; -import net.minecraftforge.common.MinecraftForge; - -@Mixin(Frustum.class) -public class FrustumMixin { - - @Inject(method = "prepare", at = @At("TAIL")) - private void onPrepare(double x, double y, double z, CallbackInfo ci) { - if (ShadersModHandler.isRenderingShadowPass()) { - try (var restoreState = GlStateTracker.getRestoreState()) { - MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(Minecraft.getInstance().level, LastActiveCamera.getActiveCamera(), (Frustum) (Object) this)); - } - } - } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererDispatchMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererDispatchMixin.java deleted file mode 100644 index aac392311..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererDispatchMixin.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.gl.GlStateTracker; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; -import com.jozufozu.flywheel.core.RenderContext; -import com.jozufozu.flywheel.event.RenderLayerEvent; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; - -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.Sheets; -import net.minecraft.client.renderer.texture.TextureAtlas; -import net.minecraftforge.common.MinecraftForge; - -@Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after sodium -public class LevelRendererDispatchMixin { - - @Inject(at = @At("TAIL"), method = "renderChunkLayer") - private void renderChunkLayer(RenderType pRenderType, PoseStack pPoseStack, double pCamX, double pCamY, double pCamZ, Matrix4f pProjectionMatrix, CallbackInfo ci) { - try (var restoreState = GlStateTracker.getRestoreState()) { - - // TODO: Is this necessary? - InstancedRenderDispatcher.renderSpecificType(RenderContext.CURRENT, pRenderType); - MinecraftForge.EVENT_BUS.post(new RenderLayerEvent(RenderContext.CURRENT, pRenderType)); - } - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V")) - private void endBatch(CallbackInfo ci) { - if (RenderContext.CURRENT != null && Backend.isGameActive() && Backend.isOn()) { - try (var restoreState = GlStateTracker.getRestoreState()) { - InstancedRenderDispatcher.renderAllRemaining(RenderContext.CURRENT); - } - } - } - - @Unique - private void flywheel$dispatch(RenderType pRenderType) { - if (RenderContext.CURRENT != null && Backend.isGameActive() && Backend.isOn()) { - try (var restoreState = GlStateTracker.getRestoreState()) { - InstancedRenderDispatcher.renderSpecificType(RenderContext.CURRENT, pRenderType); - } - } - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entitySolid(CallbackInfo ci) { - flywheel$dispatch(RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS)); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entityCutout(CallbackInfo ci) { - flywheel$dispatch(RenderType.entityCutout(TextureAtlas.LOCATION_BLOCKS)); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 2, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entityCutoutNoCull(CallbackInfo ci) { - flywheel$dispatch(RenderType.entityCutoutNoCull(TextureAtlas.LOCATION_BLOCKS)); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 3, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entitySmoothCutout(CallbackInfo ci) { - flywheel$dispatch(RenderType.entitySmoothCutout(TextureAtlas.LOCATION_BLOCKS)); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 4, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$solid(CallbackInfo ci) { - flywheel$dispatch(RenderType.solid()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 5, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$endPortal(CallbackInfo ci) { - flywheel$dispatch(RenderType.endPortal()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 6, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$endGateway(CallbackInfo ci) { - flywheel$dispatch(RenderType.endGateway()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 7, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$solidBlockSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.solidBlockSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 8, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$cutoutBlockSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.cutoutBlockSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 9, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$bedSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.bedSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 10, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$shulkerBoxSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.shulkerBoxSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 11, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$signSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.signSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 12, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$chestSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.chestSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 13, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$translucentCullBlockSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.translucentCullBlockSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 14, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$bannerSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.bannerSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 15, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$shieldSheet(CallbackInfo ci) { - flywheel$dispatch(Sheets.shieldSheet()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 16, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$armorGlint(CallbackInfo ci) { - flywheel$dispatch(RenderType.armorGlint()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 17, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$armorEntityGlint(CallbackInfo ci) { - flywheel$dispatch(RenderType.armorEntityGlint()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 18, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$glint(CallbackInfo ci) { - flywheel$dispatch(RenderType.glint()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 19, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$glintDirect(CallbackInfo ci) { - flywheel$dispatch(RenderType.glintDirect()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 20, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$glintTranslucent(CallbackInfo ci) { - flywheel$dispatch(RenderType.glintTranslucent()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 21, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entityGlint(CallbackInfo ci) { - flywheel$dispatch(RenderType.entityGlint()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 22, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$entityGlintDirect(CallbackInfo ci) { - flywheel$dispatch(RenderType.entityGlintDirect()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 23, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$waterMask(CallbackInfo ci) { - flywheel$dispatch(RenderType.waterMask()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 24, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$lines1(CallbackInfo ci) { - flywheel$dispatch(RenderType.lines()); - } - - @Inject(method = "renderLevel", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 25, target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch(Lnet/minecraft/client/renderer/RenderType;)V")) - private void renderLayer$lines2(CallbackInfo ci) { - flywheel$dispatch(RenderType.lines()); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java index 12fa21441..89952c908 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.mixin; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,14 +10,14 @@ import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlStateTracker; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.core.RenderContext; import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent; -import com.jozufozu.flywheel.event.RenderLayerEvent; +import com.jozufozu.flywheel.event.RenderStageEvent; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; @@ -26,13 +27,10 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.RenderBuffers; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.MinecraftForge; @Mixin(value = LevelRenderer.class, priority = 1001) // Higher priority to go after sodium public class LevelRendererMixin { - @Shadow private ClientLevel level; @@ -40,19 +38,21 @@ public class LevelRendererMixin { @Final private RenderBuffers renderBuffers; + @Unique + private RenderContext renderContext; + @Inject(at = @At("HEAD"), method = "renderLevel") private void beginRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) { - Vec3 position = pCamera.getPosition(); - RenderContext.CURRENT = new RenderContext(level, pPoseStack, RenderLayerEvent.createViewProjection(pPoseStack), renderBuffers, position.x, position.y, position.z); + renderContext = new RenderContext((LevelRenderer) (Object) this, level, pPoseStack, RenderContext.createViewProjection(pPoseStack, pProjectionMatrix), pProjectionMatrix, renderBuffers, pCamera); try (var restoreState = GlStateTracker.getRestoreState()) { - MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, pCamera, null)); + MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(renderContext)); } } @Inject(at = @At("TAIL"), method = "renderLevel") private void endRender(PoseStack pPoseStack, float pPartialTick, long pFinishNanoTime, boolean pRenderBlockOutline, Camera pCamera, GameRenderer pGameRenderer, LightTexture pLightTexture, Matrix4f pProjectionMatrix, CallbackInfo ci) { - RenderContext.CURRENT = null; + renderContext = null; } @Inject(at = @At("TAIL"), method = "allChanged") @@ -64,7 +64,90 @@ public class LevelRendererMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2 // after the game renders the breaking overlay normally ), method = "renderLevel") - private void renderBlockBreaking(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) { - CrumblingRenderer.renderCrumbling((LevelRenderer) (Object) this, level, poseStack, camera, projectionMatrix); + private void renderCrumbling(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci) { + if (renderContext != null) { + CrumblingRenderer.renderCrumbling(renderContext); + } + } + + // STAGE DISPATCHING + + @Unique + private void flywheel$dispatch(RenderStage stage) { + if (renderContext != null) { + try (var restoreState = GlStateTracker.getRestoreState()) { + MinecraftForge.EVENT_BUS.post(new RenderStageEvent(renderContext, stage)); + } + } + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=sky")) + private void onStage$beforeSky(CallbackInfo ci) { + flywheel$dispatch(RenderStage.BEFORE_SKY); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=fog")) + private void onStage$afterSky(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_SKY); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=terrain")) + private void onStage$beforeTerrain(CallbackInfo ci) { + flywheel$dispatch(RenderStage.BEFORE_TERRAIN); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=entities")) + private void onStage$afterSolidTerrain(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_SOLID_TERRAIN); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;bufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 0)) + private void onStage$beforeEntities(CallbackInfo ci) { + flywheel$dispatch(RenderStage.BEFORE_ENTITIES); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=blockentities")) + private void onStage$beforeBlockEntities(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_ENTITIES); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/OutlineBufferSource;endOutlineBatch()V", ordinal = 0)) + private void onStage$afterSolidBlockEntities(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_BLOCK_ENTITIES); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 0)) + private void onStage$beforeCrumbling(CallbackInfo ci) { + flywheel$dispatch(RenderStage.BEFORE_CRUMBLING); + } + + @Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;translucentTarget:Lcom/mojang/blaze3d/pipeline/RenderTarget;", opcode = Opcodes.GETFIELD, ordinal = 0)) + private void onStage$afterFinalEndBatch$fabulous(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_FINAL_END_BATCH); + } + + @Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;particlesTarget:Lcom/mojang/blaze3d/pipeline/RenderTarget;", opcode = Opcodes.GETFIELD, ordinal = 0)) + private void onStage$afterTranslucentTerrain$fabulous(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 2, shift = Shift.AFTER)) + private void onStage$afterFinalEndBatch(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_FINAL_END_BATCH); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V", ordinal = 6, shift = Shift.AFTER)) + private void onStage$afterTranslucentTerrain(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_TRANSLUCENT_TERRAIN); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;FLnet/minecraft/client/renderer/culling/Frustum;)V", shift = Shift.AFTER)) + private void onStage$afterParticles(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_PARTICLES); + } + + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderSnowAndRain(Lnet/minecraft/client/renderer/LightTexture;FDDD)V", shift = Shift.AFTER)) + private void onStage$afterWeather(CallbackInfo ci) { + flywheel$dispatch(RenderStage.AFTER_WEATHER); } } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index e1746a006..a87e5fa04 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -5,14 +5,15 @@ import java.util.List; import org.jetbrains.annotations.NotNull; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; -import com.jozufozu.flywheel.api.material.Material; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; import com.jozufozu.flywheel.core.BasicModelSupplier; import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.material.SimpleMaterial; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.oriented.OrientedPart; import com.jozufozu.flywheel.util.AnimationTickHolder; @@ -26,7 +27,7 @@ import net.minecraft.world.level.block.entity.BellBlockEntity; public class BellInstance extends BlockEntityInstance implements DynamicInstance { - private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); + private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); private final OrientedPart bell; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index d444378ea..92828149c 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -7,13 +7,15 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.NotNull; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; import com.jozufozu.flywheel.core.BasicModelSupplier; import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.material.SimpleMaterial; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.model.TransformedPart; import com.jozufozu.flywheel.core.structs.oriented.OrientedPart; @@ -37,7 +39,7 @@ import net.minecraft.world.level.block.state.properties.ChestType; public class ChestInstance extends BlockEntityInstance implements DynamicInstance { - private static final com.jozufozu.flywheel.api.material.Material CHEST_MATERIAL = new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); + private static final com.jozufozu.flywheel.api.material.Material CHEST_MATERIAL = new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); private static final BiFunction LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), CHEST_MATERIAL)); private static final BiFunction BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), CHEST_MATERIAL)); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index 7adb8713f..6a7afc30f 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -2,15 +2,16 @@ package com.jozufozu.flywheel.vanilla; import org.jetbrains.annotations.NotNull; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; -import com.jozufozu.flywheel.api.material.Material; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; import com.jozufozu.flywheel.core.BasicModelSupplier; import com.jozufozu.flywheel.core.Models; import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.material.SimpleMaterial; import com.jozufozu.flywheel.core.model.Mesh; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.model.TransformedPart; @@ -31,7 +32,7 @@ import net.minecraft.world.phys.Vec3; public class MinecartInstance extends EntityInstance implements DynamicInstance, TickableInstance { private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); - private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); + private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new SimpleMaterial(RenderStage.AFTER_ENTITIES, RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); private final PoseStack stack = new PoseStack(); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index e02349d79..b5d3b8874 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -4,14 +4,16 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; -import com.jozufozu.flywheel.api.InstancedPart; -import com.jozufozu.flywheel.api.InstancerManager; +import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; +import com.jozufozu.flywheel.api.instancer.InstancedPart; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstance; import com.jozufozu.flywheel.core.BasicModelSupplier; import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.material.SimpleMaterial; import com.jozufozu.flywheel.core.structs.StructTypes; import com.jozufozu.flywheel.core.structs.model.TransformedPart; import com.jozufozu.flywheel.util.AnimationTickHolder; @@ -31,7 +33,7 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; public class ShulkerBoxInstance extends BlockEntityInstance implements DynamicInstance { - private static final Material SHULKER_BOX_MATERIAL = new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); + private static final Material SHULKER_BOX_MATERIAL = new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); private static final Function BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), SHULKER_BOX_MATERIAL)); private static final Function LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), SHULKER_BOX_MATERIAL)); diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java index cfbe63506..238ef654c 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/effect/ExampleEffect.java @@ -5,9 +5,9 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import com.jozufozu.flywheel.api.InstancerManager; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; +import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.backend.instancing.AbstractInstance; import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.effect.Effect; diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 71f847654..202a065d3 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -9,17 +9,14 @@ "BlockEntityTypeMixin", "BufferBuilderMixin", "BufferUploaderMixin", - "CameraMixin", "ChunkRebuildHooksMixin", "ClientLevelMixin", "EntityTypeMixin", "FixFabulousDepthMixin", - "FrustumMixin", "GlStateManagerMixin", "InstanceAddMixin", "InstanceRemoveMixin", "LevelRendererAccessor", - "LevelRendererDispatchMixin", "LevelRendererInstanceUpdateMixin", "LevelRendererMixin", "PausedPartialTickAccessor",