From 40034daa6473e1b0f5f0f92d72878d7b78bcbd75 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 15 Sep 2021 14:27:51 -0700 Subject: [PATCH] Minecraft already stores the projection matrix mixins-- --- .../jozufozu/flywheel/backend/Backend.java | 10 ----- .../flywheel/event/RenderLayerEvent.java | 5 +-- .../flywheel/mixin/RenderHooksMixin.java | 4 +- .../mixin/StoreProjectionMatrixMixin.java | 38 ------------------- src/main/resources/flywheel.mixins.json | 1 - 5 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/StoreProjectionMatrixMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index c352f951f..a6b40f781 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -21,7 +21,6 @@ import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; -import com.mojang.math.Matrix4f; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.Level; @@ -39,7 +38,6 @@ public class Backend { public GLCapabilities capabilities; public GlCompat compat; - private Matrix4f projectionMatrix = new Matrix4f(); private boolean instancedArrays; private boolean enabled; public boolean chunkCachingEnabled; @@ -160,14 +158,6 @@ public class Backend { return contexts; } - public Matrix4f getProjectionMatrix() { - return projectionMatrix; - } - - public void setProjectionMatrix(Matrix4f projectionMatrix) { - this.projectionMatrix = projectionMatrix; - } - /** * Used to avoid calling Flywheel functions on (fake) worlds that don't specifically support it. */ diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java index 25573406c..53f210c7d 100644 --- a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java +++ b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java @@ -2,8 +2,8 @@ package com.jozufozu.flywheel.event; import javax.annotation.Nullable; -import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.state.RenderLayer; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.RenderType; @@ -31,8 +31,7 @@ public class RenderLayerEvent extends Event { viewProjection = stack.last() .pose() .copy(); - viewProjection.multiplyBackward(Backend.getInstance() - .getProjectionMatrix()); + viewProjection.multiplyBackward(RenderSystem.getProjectionMatrix()); this.buffers = buffers; this.camX = camX; diff --git a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java index a207069ad..94176676c 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/RenderHooksMixin.java @@ -15,6 +15,7 @@ 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.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.world.level.block.state.BlockState; @@ -84,8 +85,7 @@ public class RenderHooksMixin { Matrix4f view = stack.last() .pose(); Matrix4f viewProjection = view.copy(); - viewProjection.multiplyBackward(Backend.getInstance() - .getProjectionMatrix()); + viewProjection.multiplyBackward(RenderSystem.getProjectionMatrix()); Vec3 cameraPos = info.getPosition(); CrumblingRenderer.renderBreaking(level, viewProjection, cameraPos.x, cameraPos.y, cameraPos.z); diff --git a/src/main/java/com/jozufozu/flywheel/mixin/StoreProjectionMatrixMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/StoreProjectionMatrixMixin.java deleted file mode 100644 index 4480c68ee..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/StoreProjectionMatrixMixin.java +++ /dev/null @@ -1,38 +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.mojang.blaze3d.vertex.PoseStack; - -import net.minecraft.client.renderer.GameRenderer; -import com.mojang.math.Matrix4f; - -@Mixin(GameRenderer.class) -public abstract class StoreProjectionMatrixMixin { - - @Unique - private boolean shouldCopy = false; - - /** - * We only want to copy the projection matrix if it is going to be used to render the world. - * We don't care about the mat for your hand. - */ - @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;resetProjectionMatrix(Lcom/mojang/math/Matrix4f;)V")) - private void projectionMatrixReady(float p_228378_1_, long p_228378_2_, PoseStack p_228378_4_, CallbackInfo ci) { - shouldCopy = true; - } - - @Inject(method = "resetProjectionMatrix", at = @At("TAIL")) - private void onProjectionMatrixLoad(Matrix4f projection, CallbackInfo ci) { - if (shouldCopy) { - Backend.getInstance() - .setProjectionMatrix(projection.copy()); - shouldCopy = false; - } - } -} diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index ff2974d91..15f9272c1 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -10,7 +10,6 @@ "FixFabulousDepthMixin", "RenderHooksMixin", "ShaderCloseMixin", - "StoreProjectionMatrixMixin", "TileRemoveMixin", "TileWorldHookMixin", "atlas.AtlasDataMixin",