Skip to content
Open
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
6 changes: 6 additions & 0 deletions atumvr-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ dependencies {
api("org.lwjgl:lwjgl-openxr")


// Windows natives
api("org.lwjgl:lwjgl::natives-windows")
api("org.lwjgl:lwjgl-opengl::natives-windows")
api("org.lwjgl:lwjgl-glfw::natives-windows")
api("org.lwjgl:lwjgl-openxr::natives-windows")

// Linux natives
api("org.lwjgl:lwjgl::natives-linux")
api("org.lwjgl:lwjgl-opengl::natives-linux")
api("org.lwjgl:lwjgl-glfw::natives-linux")
api("org.lwjgl:lwjgl-openxr::natives-linux")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,47 @@ public Struct<?> createGraphicsBinding(MemoryStack stack,
GLFWNativeWGL.glfwGetWGLContext(windowHandle)
);
} else if (Platform.get() == Platform.LINUX) {
long xDisplay = GLFWNativeX11.glfwGetX11Display();

long glXContext = GLFWNativeGLX.glfwGetGLXContext(windowHandle);
long glXWindowHandle = GLFWNativeGLX.glfwGetGLXWindow(windowHandle);

int fbXID = glXQueryDrawable(xDisplay, glXWindowHandle, GLX_FBCONFIG_ID);
PointerBuffer fbConfigBuf = glXChooseFBConfig(
xDisplay, X11.XDefaultScreen(xDisplay),
stackInts(GLX_FBCONFIG_ID, fbXID, 0)
);
if (fbConfigBuf == null) {
throw new AtumVRException("Framebuffer config is null");
try {
long xDisplay = GLFWNativeX11.glfwGetX11Display();

if (xDisplay == 0L) {
throw new AtumVRException(
"X11 display is null! Visor currently only supports X11/XWayland on Linux. " +
"If you are using Wayland, please force Minecraft to run through XWayland"
);
}

long glXContext = GLFWNativeGLX.glfwGetGLXContext(windowHandle);
long glXWindowHandle = GLFWNativeGLX.glfwGetGLXWindow(windowHandle);

int fbXID = glXQueryDrawable(xDisplay, glXWindowHandle, GLX_FBCONFIG_ID);
PointerBuffer fbConfigBuf = glXChooseFBConfig(
xDisplay, X11.XDefaultScreen(xDisplay),
stackInts(GLX_FBCONFIG_ID, fbXID, 0)
);

if (fbConfigBuf == null) {
throw new AtumVRException("Framebuffer config is null");
}

long fbConfig = fbConfigBuf.get();
return XrGraphicsBindingOpenGLXlibKHR.calloc(stack).set(
KHROpenGLEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR,
NULL,
xDisplay,
(int) Objects.requireNonNull(glXGetVisualFromFBConfig(xDisplay, fbConfig)).visualid(),
fbConfig,
glXWindowHandle,
glXContext
);
} catch (AtumVRException e) {
throw e;
} catch (Throwable t) {
throw new AtumVRException(
"Failed to initialize Linux graphics binding. Ensure you are running under X11/XWayland, not native Wayland",
t
);
}
long fbConfig = fbConfigBuf.get();

return XrGraphicsBindingOpenGLXlibKHR.calloc(stack).set(
KHROpenGLEnable.XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR,
NULL,
xDisplay,
(int) Objects.requireNonNull(glXGetVisualFromFBConfig(xDisplay, fbConfig)).visualid(),
fbConfig,
glXWindowHandle,
glXContext
);
} else {
throw new AtumVRException("MacOS not supported");
}
Expand Down