summaryrefslogtreecommitdiff
path: root/modules/openxr/openxr_api.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openxr/openxr_api.cpp')
-rw-r--r--modules/openxr/openxr_api.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index 08b76ddc6b..16879ac4e5 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -49,8 +49,10 @@
#include "extensions/openxr_vulkan_extension.h"
#endif
+#include "extensions/openxr_fb_passthrough_extension_wrapper.h"
#include "extensions/openxr_hand_tracking_extension.h"
#include "extensions/openxr_htc_vive_tracker_extension.h"
+#include "extensions/openxr_palm_pose_extension.h"
#include "modules/openxr/openxr_interface.h"
@@ -186,6 +188,20 @@ bool OpenXRAPI::is_extension_supported(const String &p_extension) const {
return false;
}
+bool OpenXRAPI::is_path_supported(const String &p_path) {
+ // This checks with extensions whether a path is *unsupported* and returns false if this is so.
+ // This allows us to filter out paths that are only available if related extensions are supported.
+ // WARNING: This method will return true for unknown/mistyped paths as we have no way to validate those.
+
+ for (OpenXRExtensionWrapper *wrapper : registered_extension_wrappers) {
+ if (!wrapper->is_path_supported(p_path)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
void OpenXRAPI::copy_string_to_char_buffer(const String p_string, char *p_buffer, int p_buffer_len) {
CharString char_string = p_string.utf8();
int len = char_string.length();
@@ -1481,6 +1497,10 @@ void OpenXRAPI::pre_render() {
// 2) It will use the previous timing to pause our thread so that rendering starts as close to displaying as possible
// This must thus be called as close to when we start rendering as possible
XrFrameWaitInfo frame_wait_info = { XR_TYPE_FRAME_WAIT_INFO, nullptr };
+ frame_state.predictedDisplayTime = 0;
+ frame_state.predictedDisplayPeriod = 0;
+ frame_state.shouldRender = false;
+
XrResult result = xrWaitFrame(session, &frame_wait_info, &frame_state);
if (XR_FAILED(result)) {
print_line("OpenXR: xrWaitFrame() was not successful [", get_error_string(result), "]");
@@ -1742,8 +1762,10 @@ OpenXRAPI::OpenXRAPI() {
#endif
// register our other extensions
+ register_extension_wrapper(memnew(OpenXRPalmPoseExtension(this)));
register_extension_wrapper(memnew(OpenXRHTCViveTrackerExtension(this)));
register_extension_wrapper(memnew(OpenXRHandTrackingExtension(this)));
+ register_extension_wrapper(memnew(OpenXRFbPassthroughExtensionWrapper(this)));
}
OpenXRAPI::~OpenXRAPI() {
@@ -1852,6 +1874,18 @@ void OpenXRAPI::parse_velocities(const XrSpaceVelocity &p_velocity, Vector3 &r_l
}
}
+bool OpenXRAPI::xr_result(XrResult result, const char *format, Array args) const {
+ if (XR_SUCCEEDED(result))
+ return true;
+
+ char resultString[XR_MAX_RESULT_STRING_SIZE];
+ xrResultToString(instance, result, resultString);
+
+ print_error(String("OpenXR ") + String(format).format(args) + String(" [") + String(resultString) + String("]"));
+
+ return false;
+}
+
RID OpenXRAPI::get_tracker_rid(XrPath p_path) {
List<RID> current;
tracker_owner.get_owned_list(&current);
@@ -2170,6 +2204,11 @@ XrPath OpenXRAPI::get_interaction_profile_path(RID p_interaction_profile) {
}
RID OpenXRAPI::interaction_profile_create(const String p_name) {
+ if (!is_path_supported(p_name)) {
+ // The extension enabling this path must not be active, we will silently skip this interaction profile
+ return RID();
+ }
+
InteractionProfile new_interaction_profile;
XrResult result = xrStringToPath(instance, p_name.utf8().get_data(), &new_interaction_profile.path);
@@ -2206,6 +2245,11 @@ void OpenXRAPI::interaction_profile_clear_bindings(RID p_interaction_profile) {
}
bool OpenXRAPI::interaction_profile_add_binding(RID p_interaction_profile, RID p_action, const String p_path) {
+ if (!is_path_supported(p_path)) {
+ // The extension enabling this path must not be active, we will silently skip this binding
+ return false;
+ }
+
InteractionProfile *ip = interaction_profile_owner.get_or_null(p_interaction_profile);
ERR_FAIL_NULL_V(ip, false);
@@ -2533,3 +2577,11 @@ bool OpenXRAPI::trigger_haptic_pulse(RID p_action, RID p_tracker, float p_freque
return true;
}
+
+void OpenXRAPI::register_composition_layer_provider(OpenXRCompositionLayerProvider *provider) {
+ composition_layer_providers.append(provider);
+}
+
+void OpenXRAPI::unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider) {
+ composition_layer_providers.erase(provider);
+}