diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiFreeMoveSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiFreeMoveSettings.java index 86458d09c..21f4b81fa 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiFreeMoveSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiFreeMoveSettings.java @@ -12,7 +12,6 @@ public class GuiFreeMoveSettings extends GuiVROptionsBase VRSettings.VrOptions.FREEMOVE_MODE, VRSettings.VrOptions.FREEMOVE_FLY_MODE, VRSettings.VrOptions.FOV_REDUCTION, - VRSettings.VrOptions.INERTIA_FACTOR, VRSettings.VrOptions.MOVEMENT_MULTIPLIER, VRSettings.VrOptions.AUTO_SPRINT, VRSettings.VrOptions.AUTO_SPRINT_THRESHOLD, @@ -20,8 +19,7 @@ public class GuiFreeMoveSettings extends GuiVROptionsBase }; private static VRSettings.VrOptions[] seatedSettings = new VRSettings.VrOptions[] { VRSettings.VrOptions.SEATED_HMD, - VRSettings.VrOptions.FOV_REDUCTION, - VRSettings.VrOptions.INERTIA_FACTOR + VRSettings.VrOptions.FOV_REDUCTION }; private static VRSettings.VrOptions[] fovRed = new VRSettings.VrOptions[] { VRSettings.VrOptions.FOV_REDUCTION_MIN, diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiMainVRSettings.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiMainVRSettings.java index 4dad5599f..f395429f0 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiMainVRSettings.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiMainVRSettings.java @@ -16,19 +16,6 @@ public class GuiMainVRSettings extends GuiVROptionsBase new VROptionLayout(GuiOtherHUDSettings.class, VROptionLayout.Position.POS_RIGHT, 2.0F, true, "vivecraft.options.screen.guiother.button"), new VROptionLayout(VRSettings.VrOptions.WORLD_SCALE, VROptionLayout.Position.POS_LEFT, 6.0F, true, (String)null), new VROptionLayout(VRSettings.VrOptions.WORLD_ROTATION, VROptionLayout.Position.POS_RIGHT, 6.0F, true, (String)null), - new VROptionLayout(VRSettings.VrOptions.PLAY_MODE_SEATED, (button, mousePos) -> { - this.reinit = true; - - if (!this.dataholder.vrSettings.seated) - { - this.isConfirm = true; - return true; - } - else { - return false; - } - }, VROptionLayout.Position.POS_LEFT, 0.0F, true, (String)null), - new VROptionLayout(VRSettings.VrOptions.VR_HOTSWITCH, VROptionLayout.Position.POS_RIGHT, 0.0F, true, (String)null), new VROptionLayout(VRSettings.VrOptions.LOW_HEALTH_INDICATOR, VROptionLayout.Position.POS_RIGHT, 7.0F, true, (String)null) }; private VROptionLayout[] vrStandingOptions = new VROptionLayout[] { 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 8b45a7cc2..fc0e3eef9 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 @@ -37,6 +37,10 @@ import java.util.List; public abstract class VRRenderer { + public int nativeImageL, nativeImageR; + public int width, height; + public int pbo1; + public int pbo2; public static final String RENDER_SETUP_FAILURE_MESSAGE = "Failed to initialise stereo rendering plugin: "; public RenderTarget cameraFramebuffer; public RenderTarget cameraRenderFramebuffer; @@ -63,8 +67,8 @@ public abstract class VRRenderer { public int lastRenderDistanceChunks = -1; public long lastWindow = 0L; public float lastWorldScale = 0.0F; - protected int LeftEyeTextureId = -1; - protected int RightEyeTextureId = -1; + public int LeftEyeTextureId = -1; + public int RightEyeTextureId = -1; public int mirrorFBHeight; public int mirrorFBWidth; protected boolean reinitFramebuffers = true; diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java index 1e7df2a38..7db4ca1cf 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java @@ -15,6 +15,7 @@ import org.vivecraft.client_vr.provider.VRRenderer; import org.vivecraft.client_vr.render.RenderConfigException; import org.vivecraft.client_vr.render.RenderPass; +import org.vivecraft.utils.VLoader; import static org.lwjgl.openvr.VRCompositor.*; import static org.lwjgl.openvr.VRSystem.*; @@ -89,13 +90,15 @@ public void createRenderTexture(int lwidth, int lheight) { RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GlStateManager._texImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, lwidth, lheight, 0, GL11.GL_RGBA, GL11.GL_INT, null); RenderSystem.bindTexture(i); - this.openvr.texType0.handle(this.LeftEyeTextureId); + nativeImageL = VLoader.createGLImage(lwidth, lheight); + this.openvr.texType0.handle(nativeImageL); this.openvr.texType0.eColorSpace(VR.EColorSpace_ColorSpace_Gamma); this.openvr.texType0.eType(VR.ETextureType_TextureType_OpenGL); this.RightEyeTextureId = GlStateManager._genTexture(); i = GlStateManager._getInteger(GL11.GL_TEXTURE_BINDING_2D); - RenderSystem.bindTexture(this.RightEyeTextureId); + nativeImageR = VLoader.createGLImage(lwidth, lheight); + this.openvr.texType0.handle(nativeImageR); RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GlStateManager._texImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, lwidth, lheight, 0, GL11.GL_RGBA, GL11.GL_INT, null); diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java index 975b6318b..7a76526b7 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java @@ -415,9 +415,9 @@ public enum ChatServerPluginMessage implements OptionEnum { @SettingField(VrOptions.SHOW_PLUGIN_MISSING) public boolean showServerPluginMissingMessageAlways = true; @SettingField - public boolean vrEnabled = false; + public boolean vrEnabled = true; @SettingField(VrOptions.VR_HOTSWITCH) - public boolean vrHotswitchingEnabled = true; + public boolean vrHotswitchingEnabled = false; /** * This isn't actually used, it's only a dummy field to save the value from vanilla Options. diff --git a/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java b/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java index e649e1fdd..95c94051a 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java @@ -30,60 +30,10 @@ protected TitleScreenMixin(Component component) { private Button updateButton; - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/TitleScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;", shift = At.Shift.AFTER, ordinal = 1), method = "createNormalMenuOptions") - public void initFullGame(CallbackInfo ci) { - addVRModeButton(); - } - - @Inject(at = @At("TAIL"), method = "createDemoMenuOptions") - public void initDemo(CallbackInfo ci) { - addVRModeButton(); - } - - private void addVRModeButton() { - - vrModeButton = new Button( - this.width / 2 + 104, this.height / 4 + 72, - 56, 20, - new TranslatableComponent("vivecraft.gui.vr", getIcon() , VRState.vrEnabled ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF), - (button) -> { - showError = false; - VRState.vrEnabled = !VRState.vrEnabled; - ClientDataHolderVR.getInstance().vrSettings.vrEnabled = VRState.vrEnabled; - ClientDataHolderVR.getInstance().vrSettings.saveOptions(); - button.setMessage(new TranslatableComponent("vivecraft.gui.vr", getIcon(), VRState.vrEnabled ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF)); - }); - - this.addRenderableWidget(vrModeButton); - - updateButton = new Button( - this.width / 2 + 104, this.height / 4 + 96, - 56, 20, - new TranslatableComponent("vivecraft.gui.update"), - (button) -> minecraft.setScreen(new UpdateScreen())); - - updateButton.visible = UpdateChecker.hasUpdate; - - this.addRenderableWidget(updateButton); - } - private String getIcon() { return (showError ? "§c\u26A0§r " : ""); } - @Inject(at = @At("TAIL"), method = "render") - public void renderToolTip(PoseStack poseStack, int i, int j, float f, CallbackInfo ci) { - updateButton.visible = UpdateChecker.hasUpdate; - - if (vrModeButton.isMouseOver(i, j)) { - renderTooltip(poseStack, font.split(new TranslatableComponent("vivecraft.options.VR_MODE.tooltip"), Math.max(width / 2 - 43, 170)), i, j); - } - if (VRState.vrInitialized && !VRState.vrRunning) { - Component hotswitchMessage = new TranslatableComponent("vivecraft.messages.vrhotswitchinginfo"); - renderTooltip(poseStack, font.split(hotswitchMessage, 280), width / 2 - 140 - 12, 17); - } - } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/PanoramaRenderer;render(FF)V"), method = "render") public void maybeNoPanorama(PanoramaRenderer instance, float f, float g){ if (VRState.vrRunning && ClientDataHolderVR.getInstance().menuWorldRenderer.isReady()){ 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 0653ac2c5..016ec9c59 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 @@ -51,6 +51,9 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.lwjgl.glfw.GLFW; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; +import org.lwjgl.opengl.GL21; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -358,7 +361,7 @@ public void replaceTick(boolean bl, CallbackInfo callback) { if (VRState.vrEnabled) { VRState.initializeVR(); } else if (VRState.vrInitialized) { - VRState.destroyVR(true); + VRState.destroyVR(false); resizeDisplay(); } if (!VRState.vrInitialized) { @@ -600,6 +603,16 @@ public void newRunTick(boolean bl) { this.renderSingleView(renderpass, f, bl); this.profiler.pop(); + if(renderpass == RenderPass.LEFT) { + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ClientDataHolderVR.getInstance().vrRenderer.LeftEyeTextureId); + GL20.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, ClientDataHolderVR.getInstance().vrRenderer.pbo1); + GL20.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0); + } else if(renderpass == RenderPass.RIGHT) { + GL11.glBindTexture(GL11.GL_TEXTURE_2D, ClientDataHolderVR.getInstance().vrRenderer.RightEyeTextureId); + GL20.glBindBuffer(GL21.GL_PIXEL_PACK_BUFFER, ClientDataHolderVR.getInstance().vrRenderer.pbo2); + GL20.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0); + } + if (ClientDataHolderVR.getInstance().grabScreenShot) { boolean flag; @@ -684,7 +697,7 @@ public void preRender(boolean tick) { } catch (RenderConfigException renderConfigException) { // TODO: could disabling VR here cause issues? Minecraft.getInstance().setScreen(new ErrorScreen("VR Render Error", new TranslatableComponent("vivecraft.messages.rendersetupfailed", renderConfigException.error + "\nVR provider: " + ClientDataHolderVR.getInstance().vr.getName()))); - VRState.destroyVR(true); + VRState.destroyVR(false); return; } catch (Exception exception2) { exception2.printStackTrace(); diff --git a/common/src/main/java/org/vivecraft/utils/VLoader.java b/common/src/main/java/org/vivecraft/utils/VLoader.java new file mode 100644 index 000000000..d7a89c79f --- /dev/null +++ b/common/src/main/java/org/vivecraft/utils/VLoader.java @@ -0,0 +1,10 @@ +package org.vivecraft.utils; + +public class VLoader { + static { + System.loadLibrary("openvr_api"); + } + + public static native int createGLImage(int width, int height); + public static native void writeImage(int tex, int width, int height, long byteBuf); +} \ No newline at end of file