From e6e27f8be4bdc69b83169ad7bae835ac43376668 Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Mon, 12 Jun 2023 21:29:38 +1000 Subject: [PATCH] Fix OpenXR Passthrough mode --- ...penxr_fb_passthrough_extension_wrapper.cpp | 24 ++++++++++++------- .../openxr_fb_passthrough_extension_wrapper.h | 15 ------------ 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp index 569895a6203..f730f2bd2c3 100644 --- a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp +++ b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.cpp @@ -107,10 +107,6 @@ bool OpenXRFbPassthroughExtensionWrapper::is_passthrough_enabled() { return fb_passthrough_ext && passthrough_handle != XR_NULL_HANDLE && passthrough_layer != XR_NULL_HANDLE; } -bool OpenXRFbPassthroughExtensionWrapper::is_composition_passthrough_layer_ready() { - return fb_passthrough_ext && passthrough_handle != XR_NULL_HANDLE && composition_passthrough_layer.layerHandle != XR_NULL_HANDLE; -} - bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() { if (passthrough_handle == XR_NULL_HANDLE) { return false; @@ -128,6 +124,13 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() { } // Create the passthrough layer + XrPassthroughLayerCreateInfoFB passthrough_layer_config = { + XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB, + nullptr, + passthrough_handle, + XR_PASSTHROUGH_IS_RUNNING_AT_CREATION_BIT_FB, + XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB, + }; result = xrCreatePassthroughLayerFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_layer_config, &passthrough_layer); if (!is_valid_passthrough_result(result, "Failed to create the passthrough layer")) { stop_passthrough(); @@ -140,14 +143,18 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() { print_error("Main viewport doesn't have transparent background! Passthrough may not properly render."); } - composition_passthrough_layer.layerHandle = passthrough_layer; - return true; } void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession session) { if (fb_passthrough_ext) { // Create the passthrough feature and start it. + XrPassthroughCreateInfoFB passthrough_create_info = { + XR_TYPE_PASSTHROUGH_CREATE_INFO_FB, + nullptr, + 0, + }; + XrResult result = xrCreatePassthroughFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_create_info, &passthrough_handle); if (!OpenXRAPI::get_singleton()->xr_result(result, "Failed to create passthrough")) { passthrough_handle = XR_NULL_HANDLE; @@ -157,7 +164,8 @@ void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession ses } XrCompositionLayerBaseHeader *OpenXRFbPassthroughExtensionWrapper::get_composition_layer() { - if (is_composition_passthrough_layer_ready()) { + if (is_passthrough_enabled()) { + composition_passthrough_layer.layerHandle = passthrough_layer; return (XrCompositionLayerBaseHeader *)&composition_passthrough_layer; } else { return nullptr; @@ -169,8 +177,6 @@ void OpenXRFbPassthroughExtensionWrapper::stop_passthrough() { return; } - composition_passthrough_layer.layerHandle = XR_NULL_HANDLE; - XrResult result; if (passthrough_layer != XR_NULL_HANDLE) { // Destroy the layer diff --git a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.h b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.h index c01394529e9..e8fa3f08a61 100644 --- a/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.h +++ b/modules/openxr/extensions/openxr_fb_passthrough_extension_wrapper.h @@ -212,27 +212,12 @@ private: Viewport *get_main_viewport(); - bool is_composition_passthrough_layer_ready(); - static OpenXRFbPassthroughExtensionWrapper *singleton; bool fb_passthrough_ext = false; // required for any passthrough functionality bool fb_triangle_mesh_ext = false; // only use for projected passthrough - XrPassthroughCreateInfoFB passthrough_create_info = { - XR_TYPE_PASSTHROUGH_CREATE_INFO_FB, - nullptr, - 0, - }; XrPassthroughFB passthrough_handle = XR_NULL_HANDLE; - - XrPassthroughLayerCreateInfoFB passthrough_layer_config = { - XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB, - nullptr, - passthrough_handle, - XR_PASSTHROUGH_IS_RUNNING_AT_CREATION_BIT_FB, - XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB, - }; XrPassthroughLayerFB passthrough_layer = XR_NULL_HANDLE; XrCompositionLayerPassthroughFB composition_passthrough_layer = {