From 5c714152de1831b1f6241b44f0621255b1925842 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Mon, 9 Dec 2024 01:32:16 +0100 Subject: [PATCH] fix radial menu/pointer keyboard rendering fix mirror switching text, by using the vanilla target as an intermediary --- .../client/gui/framework/TwoHandedScreen.java | 5 +++-- .../vivecraft/client_vr/provider/VRRenderer.java | 7 +++++++ .../client_vr/render/helpers/RenderHelper.java | 13 +++++++++---- .../client_vr/render/helpers/VRPassHelper.java | 8 ++++---- .../vivecraft/mixin/client_vr/MinecraftVRMixin.java | 9 +++++++++ gradle.properties | 2 +- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/org/vivecraft/client/gui/framework/TwoHandedScreen.java b/common/src/main/java/org/vivecraft/client/gui/framework/TwoHandedScreen.java index 26c207e8c..b3d8c2040 100644 --- a/common/src/main/java/org/vivecraft/client/gui/framework/TwoHandedScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/framework/TwoHandedScreen.java @@ -10,6 +10,7 @@ import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; import org.vivecraft.client_vr.provider.ControllerType; import org.vivecraft.client_vr.provider.MCVR; +import org.vivecraft.client_vr.render.helpers.RenderHelper; public abstract class TwoHandedScreen extends Screen { protected ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); @@ -76,7 +77,7 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar this.lastHoveredButtonId2 = abstractwidget1; } - ((GuiExtension) this.minecraft.gui).vivecraft$drawMouseMenuQuad((int) d0, (int) d1); - ((GuiExtension) this.minecraft.gui).vivecraft$drawMouseMenuQuad((int) d2, (int) d3); + RenderHelper.drawMouseMenuQuad(guiGraphics, (int) d0, (int) d1); + RenderHelper.drawMouseMenuQuad(guiGraphics, (int) d2, (int) d3); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index 645f85fbc..413edb44b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -41,6 +41,7 @@ import org.vivecraft.client_vr.render.ShaderHelper; import org.vivecraft.client_vr.render.VRShaders; import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.client_xr.render_pass.RenderPassManager; import org.vivecraft.client_xr.render_pass.WorldRenderPass; import org.vivecraft.mod_compat_vr.ShadersHelper; import org.vivecraft.mod_compat_vr.resolutioncontrol.ResolutionControlHelper; @@ -483,6 +484,12 @@ public void setupRenderConfiguration() throws Exception { this.reinitFrameBuffers("gfx setting change"); } + if (this.resizeFrameBuffers || this.reinitFramebuffers) { + // resize mirror + RenderPassManager.INSTANCE.vanillaRenderTarget.resize(((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenWidth(), ((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenHeight()); + } + + if (this.resizeFrameBuffers && !this.reinitFramebuffers) { resizeFrameBuffers = false; Tuple tuple = this.getRenderTextureSizes(); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java index ed5528858..d9770520f 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java @@ -8,12 +8,10 @@ import com.mojang.math.Axis; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.CoreShaders; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.ShaderProgram; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; @@ -260,6 +258,7 @@ public static void drawScreen(DeltaTracker.Timer timer, Screen screen, GuiGraphi GlStateManager.DestFactor.ONE); screen.render(guiGraphics, 0, 0, timer.getRealtimeDeltaTicks()); + guiGraphics.flush(); RenderSystem.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, @@ -275,6 +274,12 @@ public static void drawScreen(DeltaTracker.Timer timer, Screen screen, GuiGraphi main.unbindRead(); } + public static void drawMouseMenuQuad(GuiGraphics guiGraphics, int mouseX, int mouseY) { + float size = 15.0F * Math.max(ClientDataHolderVR.getInstance().vrSettings.menuCrosshairScale, 1.0F / (float) mc.getWindow().getGuiScale()); + + guiGraphics.blitSprite(RenderType::crosshair, Gui.CROSSHAIR_SPRITE, (int) (mouseX - size * 0.5F + 1), (int) (mouseY - size * 0.5F + 1), (int) size, (int) size); + } + public static void drawSizedQuad(float displayWidth, float displayHeight, float size) { drawSizedQuad(displayWidth, displayHeight, size, new float[]{1, 1, 1, 1}); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java index 9a7eb4ab9..bfeb9e8fe 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java @@ -242,6 +242,7 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer RenderSystem.enableCull(); Profiler.get().push("gui cursor"); + GuiGraphics guiGraphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); // draw cursor on Gui Layer if (mc.screen != null || !mc.mouseHandler.isMouseGrabbed()) { Matrix4fStack poseStack = RenderSystem.getModelViewStack(); @@ -251,7 +252,9 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer int x = (int) (Minecraft.getInstance().mouseHandler.xpos() * (double) Minecraft.getInstance().getWindow().getGuiScaledWidth() / (double) Minecraft.getInstance().getWindow().getScreenWidth()); int y = (int) (Minecraft.getInstance().mouseHandler.ypos() * (double) Minecraft.getInstance().getWindow().getGuiScaledHeight() / (double) Minecraft.getInstance().getWindow().getScreenHeight()); - ((GuiExtension) mc.gui).vivecraft$drawMouseMenuQuad(x, y); + + RenderHelper.drawMouseMenuQuad(guiGraphics, x, y); + guiGraphics.flush(); poseStack.popMatrix(); } @@ -266,13 +269,11 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer mc.mainRenderTarget.unbindRead(); Profiler.get().popPush("2D Keyboard"); - GuiGraphics guiGraphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); if (KeyboardHandler.Showing && !dataHolder.vrSettings.physicalKeyboard) { mc.mainRenderTarget = KeyboardHandler.Framebuffer; mc.mainRenderTarget.clear(); mc.mainRenderTarget.bindWrite(true); RenderHelper.drawScreen(timer, KeyboardHandler.UI, guiGraphics); - guiGraphics.flush(); } Profiler.get().popPush("Radial Menu"); @@ -281,7 +282,6 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer mc.mainRenderTarget.clear(); mc.mainRenderTarget.bindWrite(true); RenderHelper.drawScreen(timer, RadialHandler.UI, guiGraphics); - guiGraphics.flush(); } Profiler.get().pop(); checkGLError("post 2d "); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java index aad11b75f..683a70b77 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java @@ -378,8 +378,17 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { instance.blitToScreen(width, height); } else { Profiler.get().popPush("vrMirror"); + // use the vanilla main target as the mirror target + RenderPassManager.setVanillaRenderPass(); + this.mainRenderTarget.clear(); + this.mainRenderTarget.bindWrite(false); + this.vivecraft$copyToMirror(); this.vivecraft$drawNotifyMirror(); + + this.mainRenderTarget.unbindWrite(); + this.mainRenderTarget.blitToScreen(this.mainRenderTarget.width, this.mainRenderTarget.height); + RenderPassManager.setGUIRenderPass(); this.vivecraft$checkGLError("post-mirror "); } } diff --git a/gradle.properties b/gradle.properties index f4cbfea95..a008d1f01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.21.3 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft -mod_version=1.1.14-b2 +mod_version=1.1.14-b3 maven_group=org.vivecraft architectury_version=14.0.3