Skip to content

Commit

Permalink
Workaround SteamVR-for-Linux issue 421
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHaag authored and BastiaanOlij committed Aug 19, 2021
1 parent 37253ae commit 9d27091
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/openxr/OpenXRApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,28 @@ bool OpenXRApi::initialiseInstance() {
}
free(enabledExtensions);

XrInstanceProperties instanceProps = {
.type = XR_TYPE_INSTANCE_PROPERTIES
};
result = xrGetInstanceProperties(instance, &instanceProps);
if (!xr_result(result, "Failed to get XR instance properties.")) {
// not fatal probably
return true;
}

Godot::print("Running on OpenXR runtime: {0} {1}.{2}.{3}",
instanceProps.runtimeName,
XR_VERSION_MAJOR(instanceProps.runtimeVersion),
XR_VERSION_MINOR(instanceProps.runtimeVersion),
XR_VERSION_PATCH(instanceProps.runtimeVersion));

if (strcmp(instanceProps.runtimeName, "SteamVR/OpenXR") == 0) {
#ifdef __linux__
Godot::print("Running on Linux, using SteamVR workaround for issue https://github.com/ValveSoftware/SteamVR-for-Linux/issues/421");
#endif
is_steamvr = true;
}

return true;
}

Expand Down Expand Up @@ -1942,6 +1964,13 @@ void OpenXRApi::render_openxr(int eye, uint32_t texid, bool has_external_texture
return;
}
}

#ifdef __linux__
// TODO: should not be necessary, but is for SteamVR since 1.16.x
if (is_steamvr) {
glXMakeCurrent(graphics_binding_gl.xDisplay, graphics_binding_gl.glxDrawable, graphics_binding_gl.glxContext);
}
#endif
}

void OpenXRApi::fill_projection_matrix(int eye, godot_real p_z_near, godot_real p_z_far, godot_real *p_projection) {
Expand Down Expand Up @@ -2309,6 +2338,13 @@ int OpenXRApi::get_external_texture_for_eye(int eye, bool *has_support) {
return 0;
}

#ifdef __linux__
// TODO: should not be necessary, but is for SteamVR since 1.16.x
if (is_steamvr) {
glXMakeCurrent(graphics_binding_gl.xDisplay, graphics_binding_gl.glxDrawable, graphics_binding_gl.glxContext);
}
#endif

// process should be called by now but just in case...
if (state > XR_SESSION_STATE_UNKNOWN && buffer_index != NULL) {
// make sure we know that we're rendering directly to our
Expand Down Expand Up @@ -2535,6 +2571,13 @@ void OpenXRApi::process_openxr() {
// TODO: Tell godot not do render VR to save resources.
// See render_openxr() for the corresponding early exit.
}

#ifdef __linux__
// TODO: should not be necessary, but is for SteamVR since 1.16.x
if (is_steamvr) {
glXMakeCurrent(graphics_binding_gl.xDisplay, graphics_binding_gl.glxDrawable, graphics_binding_gl.glxContext);
}
#endif
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/openxr/OpenXRApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class OpenXRApi {
XrSession session = XR_NULL_HANDLE;
XrSessionState state = XR_SESSION_STATE_UNKNOWN;

bool is_steamvr = false;

bool keep_3d_linear = true;
#ifdef WIN32
XrGraphicsBindingOpenGLWin32KHR graphics_binding_gl;
Expand Down

0 comments on commit 9d27091

Please sign in to comment.