Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add openXR support #291

Draft
wants to merge 18 commits into
base: Multiloader-1.20.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ subprojects {
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.layered() {
// The following line declares the mojmap mappings, you may use other mappings as well
officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
// "net.fabricmc:yarn:1.18.2+build.4:v2"
// parchment mappings as backup
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:${rootProject.parchment_version}@zip")
}
implementation("org.lwjgl:lwjgl-openvr:${rootProject.lwjgl_version}")
implementation("org.lwjgl:lwjgl-openvr:${rootProject.lwjgl_version}:natives-linux")
implementation("org.lwjgl:lwjgl-openvr:${rootProject.lwjgl_version}:natives-macos")
implementation("org.lwjgl:lwjgl-openvr:${rootProject.lwjgl_version}:natives-windows")

// Use custom OpenXR lib for Android and GLES bindings
implementation("QuestCraftPlusPlus:lwjgl3:${rootProject.lwjgl_version}:lwjgl-openxr-${rootProject.lwjgl_version}")
implementation("org.lwjgl:lwjgl-openxr:${rootProject.lwjgl_version}:natives-linux")
implementation("org.lwjgl:lwjgl-openxr:${rootProject.lwjgl_version}:natives-windows")
}

tasks.withType(JavaCompile).configureEach {
Expand Down Expand Up @@ -152,17 +154,16 @@ allprojects {
exclusiveContent {
forRepository {
ivy {
name = "Discord"
url = "https://cdn.discordapp.com/attachments/"
name = "GitHub"
url = "https://github.com/"
patternLayout {
artifact '/[organisation]/[module]/[revision].[ext]'
artifact '/[organisation]/[module]/releases/download/[revision]/[classifier].jar'
}
metadataSources { artifact() }
}
}
filter {
// discords are always just numbers
includeGroupByRegex "^\\d*\$"

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
compileOnly('com.electronwill.night-config:toml:3.6.6')

//LaunchPopup
implementation 'com.github.Vivecraft:LaunchPopup:1.1.1'
implementation 'Vivecraft:LaunchPopup:1.1.1:LaunchPopup-1.1.1'
}
// extract the LaunchPopup classes
jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public interface RenderTargetExtension {
* @return if the RenderTarget is set to use mipmaps
*/
boolean vivecraft$hasMipmaps();

/**
* Sets the color id
* @param colorid the color id to set
*/
void vivecraft$setColorid(int colorid);
}
2 changes: 1 addition & 1 deletion common/src/main/java/org/vivecraft/client_vr/VRData.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public VRData(Vec3 origin, float walkMul, float worldScale, float rotation) {
Vector3f scaleOffset = new Vector3f(scaledPos.x - hmd_raw.x, 0.0F, scaledPos.z - hmd_raw.z);

// headset
this.hmd = new VRDevicePose(this, mcVR.hmdRotation, scaledPos, mcVR.getHmdVector());
this.hmd = new VRDevicePose(this, mcVR.getEyeRotation(RenderPass.CENTER), scaledPos, mcVR.getHmdVector());

this.eye0 = new VRDevicePose(this,
mcVR.getEyeRotation(RenderPass.LEFT),
Expand Down
13 changes: 8 additions & 5 deletions common/src/main/java/org/vivecraft/client_vr/VRState.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.vivecraft.client_vr.menuworlds.MenuWorldRenderer;
import org.vivecraft.client_vr.provider.nullvr.NullVR;
import org.vivecraft.client_vr.provider.openvr_lwjgl.MCOpenVR;
import org.vivecraft.client_vr.provider.openxr.MCOpenXR;
import org.vivecraft.client_vr.render.RenderConfigException;
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.client_xr.render_pass.RenderPassManager;
Expand Down Expand Up @@ -50,11 +51,13 @@ public static void initializeVR() {
}

ClientDataHolderVR dh = ClientDataHolderVR.getInstance();
if (dh.vrSettings.stereoProviderPluginID == VRSettings.VRProvider.OPENVR) {
dh.vr = new MCOpenVR(Minecraft.getInstance(), dh);
} else {
dh.vr = new NullVR(Minecraft.getInstance(), dh);
Minecraft instance = Minecraft.getInstance();
switch (dh.vrSettings.stereoProviderPluginID) {
case OPENVR -> dh.vr = new MCOpenVR(instance, dh);
case OPENXR -> dh.vr = new MCOpenXR(instance, dh);
default -> dh.vr = new NullVR(instance, dh);
}

if (!dh.vr.init()) {
throw new RenderConfigException(Component.translatable("vivecraft.messages.vriniterror"),
Component.translatable("vivecraft.messages.rendersetupfailed", dh.vr.initStatus, dh.vr.getName()));
Expand All @@ -65,7 +68,7 @@ public static void initializeVR() {
// everything related to VR is created now
VR_INITIALIZED = true;

dh.vrRenderer.setupRenderConfiguration();
dh.vrRenderer.setupRenderConfiguration(false); //For openXR, setup but don't render yet
RenderPassManager.setVanillaRenderPass();

dh.vrPlayer = new VRPlayer();
Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.vivecraft.client_vr;

import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL30;
import org.vivecraft.client.Xplat;
import org.vivecraft.client.extensions.RenderTargetExtension;

Expand Down Expand Up @@ -34,6 +36,17 @@ public VRTextureTarget(String name, int width, int height, boolean useDepth, int
this.setClearColor(0, 0, 0, 0);
}

public VRTextureTarget(String name, int width, int height, int colorid, int index) {
super(true);
this.name = name;
RenderSystem.assertOnGameThreadOrInit();
this.resize(width, height, Minecraft.ON_OSX);
((RenderTargetExtension) this).vivecraft$setColorid(colorid);
GlStateManager._glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferId);
GL30.glFramebufferTextureLayer(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, colorid, 0, index);
this.setClearColor(0, 0, 0, 0);
}

@Override
public String toString() {
return """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack poseStack
direction = DH.vrPlayer.vrdata_world_render.getController(0).getDirection();
guirot = guirot.mul(DH.vr.getAimRotation(0), guirot);
} else {
guirot = guirot.mul(DH.vr.hmdRotation, guirot);
guirot = guirot.mul(DH.vr.getEyeRotation(RenderPass.CENTER), guirot);
}

guipos = new Vec3(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.network.chat.Component;
import org.vivecraft.client.gui.framework.TwoHandedScreen;
import org.vivecraft.client_vr.provider.MCVR;
import org.vivecraft.client_vr.provider.openvr_lwjgl.VRInputAction;
import org.vivecraft.client_vr.provider.control.VRInputAction;

public class GuiRadial extends TwoHandedScreen {
private boolean isShift = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.vivecraft.client_vr.provider;

import org.vivecraft.client_vr.provider.openvr_lwjgl.control.VRInputActionSet;
import org.vivecraft.client_vr.provider.control.VRInputActionSet;

/**
* holds the parameters for a VR action key
Expand Down
Loading