diff --git a/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java b/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java index 308d8f9d0..3d302a552 100644 --- a/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java +++ b/src/main/java/grondag/canvas/mixin/MixinAccessibilityOptionsScreen.java @@ -25,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.client.Minecraft; import net.minecraft.client.OptionInstance; import net.minecraft.client.Options; import net.minecraft.client.gui.screens.AccessibilityOptionsScreen; @@ -33,7 +32,6 @@ import net.minecraft.client.gui.screens.SimpleOptionsSubScreen; import net.minecraft.network.chat.Component; -import grondag.canvas.apiimpl.CanvasState; import grondag.canvas.shader.data.AccessibilityData; @Mixin(AccessibilityOptionsScreen.class) @@ -44,18 +42,12 @@ public MixinAccessibilityOptionsScreen(Screen screen, Options options, Component @Inject(at = @At("HEAD"), method = "method_31384") void onClosing(CallbackInfo ci) { - canvas_onClose(); + AccessibilityData.onCloseOptionScreen(); } @Override public void onClose() { - canvas_onClose(); + AccessibilityData.onCloseOptionScreen(); super.onClose(); } - - private static void canvas_onClose() { - if (AccessibilityData.checkChanged() && Minecraft.getInstance().level != null) { - CanvasState.recompileIfNeeded(true); - } - } } diff --git a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java index c00164baa..111d10b7b 100644 --- a/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java +++ b/src/main/java/grondag/canvas/mixin/MixinModelBlockRenderer.java @@ -21,7 +21,9 @@ package grondag.canvas.mixin; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -35,17 +37,13 @@ import grondag.canvas.apiimpl.rendercontext.CanvasBlockRenderContext; -// WIP: change this an inject with cancel so that mods that hook in here don't break directly - esp C&B // WIP: move hooks upstream so that multi-consumer is available in more cases @Mixin(ModelBlockRenderer.class) public abstract class MixinModelBlockRenderer { - /** - * @author grondag - * @reason performance; less bad than inject and cancel at head - */ - @Overwrite - public void tesselateBlock(BlockAndTintGetter blockView, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource randomSource, long seed, int overlay) { + @Inject(at = @At("HEAD"), method = "tesselateBlock", cancellable = true) + public void beforeTesselateBlock(BlockAndTintGetter blockView, BakedModel model, BlockState state, BlockPos pos, PoseStack poseStack, VertexConsumer buffer, boolean checkSides, RandomSource randomSource, long seed, int overlay, CallbackInfo ci) { // PERF: try to avoid threadlocal lookup here CanvasBlockRenderContext.get().render((ModelBlockRenderer) (Object) this, blockView, model, state, pos, poseStack, buffer, checkSides, seed, overlay); + ci.cancel(); } } diff --git a/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java b/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java index 0d1836bdb..35c237a27 100644 --- a/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java +++ b/src/main/java/grondag/canvas/mixin/MixinVideoSettingsScreen.java @@ -29,6 +29,7 @@ import net.minecraft.client.gui.screens.VideoSettingsScreen; import net.minecraft.network.chat.Component; +import grondag.canvas.shader.data.AccessibilityData; import grondag.canvas.varia.CanvasButtonWidget; @Mixin(VideoSettingsScreen.class) @@ -41,4 +42,15 @@ public MixinVideoSettingsScreen(Component title) { private void onInit(CallbackInfo info) { CanvasButtonWidget.parent = this; } + + @Inject(at = @At("HEAD"), method = "method_19865") + void onClosing(CallbackInfo ci) { + AccessibilityData.onCloseOptionScreen(); + } + + @Override + public void onClose() { + AccessibilityData.onCloseOptionScreen(); + super.onClose(); + } } diff --git a/src/main/java/grondag/canvas/pipeline/PipelineManager.java b/src/main/java/grondag/canvas/pipeline/PipelineManager.java index 47449a62c..7851f5113 100644 --- a/src/main/java/grondag/canvas/pipeline/PipelineManager.java +++ b/src/main/java/grondag/canvas/pipeline/PipelineManager.java @@ -61,6 +61,9 @@ public class PipelineManager { private static int oldTex0; private static int oldTex1; + private static boolean pendingInitPass; + private static boolean pendingResizePass; + public static int width() { return w; } @@ -103,8 +106,8 @@ public static void init(PrimaryFrameBuffer primary, int width, int height) { collector.clear(); // releases storage - renderFullFramePasses(Pipeline.onInit); - renderFullFramePasses(Pipeline.onResize); + pendingInitPass = true; + pendingResizePass = true; } private static void addVertex(float x, float y, float z, float u, float v, int[] target, int index) { @@ -123,10 +126,20 @@ public static void onResize(PrimaryFrameBuffer primary, int newWidth, int newHei Pipeline.onResize(primary, w, h); - renderFullFramePasses(Pipeline.onResize); + pendingResizePass = true; } public static void beforeWorldRender() { + if (pendingInitPass) { + renderFullFramePasses(Pipeline.onInit); + pendingInitPass = false; + } + + if (pendingResizePass) { + renderFullFramePasses(Pipeline.onResize); + pendingResizePass = false; + } + renderFullFramePasses(Pipeline.onWorldRenderStart, Timekeeper.ProfilerGroup.BeforeWorld); Pipeline.defaultFbo.bind(); } diff --git a/src/main/java/grondag/canvas/shader/data/AccessibilityData.java b/src/main/java/grondag/canvas/shader/data/AccessibilityData.java index 68264fa74..062781228 100644 --- a/src/main/java/grondag/canvas/shader/data/AccessibilityData.java +++ b/src/main/java/grondag/canvas/shader/data/AccessibilityData.java @@ -23,6 +23,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import grondag.canvas.apiimpl.CanvasState; + public class AccessibilityData { static final ResourceLocation id = new ResourceLocation("canvas:accessibility"); @@ -33,6 +35,12 @@ public class AccessibilityData { static String cache = null; + public static void onCloseOptionScreen() { + if (AccessibilityData.checkChanged() && Minecraft.getInstance().level != null) { + CanvasState.recompileIfNeeded(true); + } + } + public static boolean checkChanged() { final var mc = Minecraft.getInstance();