Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

OpenXR: Use normal play space with spatial containers in immersive mode

David Snopeka26a12a47722
diff --git a/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.cpp b/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.cpp
index 9124c80f400..426229a0d16 100644
--- a/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.cpp
+++ b/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.cpp
@@ -188,6 +188,15 @@ bool OpenXRSpatialContainerExtension::on_event_polled(const XrEventDataBuffer &e
const XrEventDataSpatialContainerBoundsChangedEXT *event_data = (XrEventDataSpatialContainerBoundsChangedEXT *)&event;
if (event_data->spatialContainer == spatial_container_data.spatial_container_handle) {
print_verbose("OpenXR: Spatial container bounds changed...");
+ XrSpatialContainerBoundsModeEXT new_bounds_mode = event_data->boundsMode;
+ if (spatial_container_data.current_bounds_mode != new_bounds_mode) {
+ spatial_container_data.current_bounds_mode = new_bounds_mode;
+ if (new_bounds_mode == XR_SPATIAL_CONTAINER_BOUNDS_MODE_IMMERSIVE_EXT) {
+ openxr_api->set_custom_play_space(XR_NULL_HANDLE);
+ } else {
+ openxr_api->set_custom_play_space(spatial_container_data.space_handle);
+ }
+ }
emit_signal(SNAME("spatial_container_bounds_changed"), spatial_container_data.spatial_container_rid, event_data->infiniteBounds, OpenXRSpatialContainerState::_to_bounds_mode(event_data->boundsMode), Vector3(event_data->bounds.width, event_data->bounds.height, event_data->bounds.depth));
return true;
}
@@ -363,7 +372,15 @@ XrResult OpenXRSpatialContainerExtension::locate_spatial_container_views(XrView
return XR_ERROR_INITIALIZATION_FAILED;
}
- return rendering_mechanism->locate_spatial_container_views(spatial_container_data.spatial_container_rid, p_views, r_view_pose_valid, r_should_submit_layers);
+ OpenXRAPI *openxr_api = OpenXRAPI::get_singleton();
+ ERR_FAIL_NULL_V(openxr_api, XR_ERROR_VALIDATION_FAILURE);
+
+ return rendering_mechanism->locate_spatial_container_views(
+ spatial_container_data.spatial_container_rid,
+ spatial_container_data.current_bounds_mode == XR_SPATIAL_CONTAINER_BOUNDS_MODE_IMMERSIVE_EXT ? openxr_api->get_play_space() : spatial_container_data.space_handle,
+ p_views,
+ r_view_pose_valid,
+ r_should_submit_layers);
}
bool OpenXRSpatialContainerExtension::request_spatial_container_visible(bool p_visible) {
diff --git a/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.h b/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.h
index 1209c423880..a0afc575402 100644
--- a/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.h
+++ b/modules/openxr/extensions/spatial_container/openxr_spatial_container_extension.h
@@ -50,6 +50,7 @@ public:
RID spatial_container_rid = RID();
XrSpatialContainerEXT spatial_container_handle = XR_NULL_HANDLE;
XrSpace space_handle = XR_NULL_HANDLE;
+ XrSpatialContainerBoundsModeEXT current_bounds_mode = XR_SPATIAL_CONTAINER_BOUNDS_MODE_MAX_ENUM_EXT;
};
static OpenXRSpatialContainerExtension *get_singleton();
diff --git a/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.cpp b/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.cpp
index 0b72eff072d..f05a4e4f1c9 100644
--- a/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.cpp
+++ b/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.cpp
@@ -196,10 +196,6 @@ void OpenXRSpatialContainerSelfRenderingExtension::_add_spatial_container_to_ren
print_verbose("OpenXR: Setting active spatial container.");
active_spatial_container = p_container_data.spatial_container_handle;
- active_view_locate_info.viewConfigurationType = openxr_api->get_view_configuration();
- active_view_locate_info.space = p_container_data.space_handle;
- active_view_locate_info.spatialContainer = active_spatial_container;
-
active_view_state.viewConfigurationType = openxr_api->get_view_configuration();
active_layer.spatialContainer = active_spatial_container;
@@ -231,10 +227,6 @@ void OpenXRSpatialContainerSelfRenderingExtension::_remove_spatial_container_fro
print_verbose("OpenXR: Resetting active spatial container.");
active_spatial_container = XR_NULL_HANDLE;
- active_view_locate_info.viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
- active_view_locate_info.space = XR_NULL_HANDLE;
- active_view_locate_info.spatialContainer = XR_NULL_HANDLE;
-
active_view_state.viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
active_view_state.viewStateFlags = 0;
active_view_state.shouldSubmitLayers = false;
@@ -284,7 +276,7 @@ void *OpenXRSpatialContainerSelfRenderingExtension::set_projection_layer_and_get
return &container_view_config;
}
-XrResult OpenXRSpatialContainerSelfRenderingExtension::locate_spatial_container_views(RID p_spatial_container_rid, XrView *p_views, bool &r_view_pose_valid, bool &r_should_submit_layers) {
+XrResult OpenXRSpatialContainerSelfRenderingExtension::locate_spatial_container_views(RID p_spatial_container_rid, XrSpace p_space, XrView *p_views, bool &r_view_pose_valid, bool &r_should_submit_layers) {
if (!is_enabled() || active_spatial_container == XR_NULL_HANDLE) {
return XR_ERROR_INITIALIZATION_FAILED;
}
@@ -301,12 +293,20 @@ XrResult OpenXRSpatialContainerSelfRenderingExtension::locate_spatial_container_
}
}
+ XrSpatialContainerViewLocateInfoEXT view_locate_info = {
+ XR_TYPE_SPATIAL_CONTAINER_VIEW_LOCATE_INFO_EXT, // type
+ nullptr, // next
+ openxr_api->get_view_configuration(), // viewConfigurationType
+ p_space, // space
+ active_spatial_container, // spatialContainer
+ };
+
XrSpatialContainerViewsLocateInfoEXT locate_info = {
XR_TYPE_SPATIAL_CONTAINER_VIEWS_LOCATE_INFO_EXT, // type
spatial_container_views_locate_info_next_pointer, // next
openxr_api->get_predicted_display_time(), // displayTime
1, // viewLocateInfoCount
- &active_view_locate_info, // viewLocateInfos
+ &view_locate_info, // viewLocateInfos
};
uint32_t total_view_count = openxr_api->get_view_count();
diff --git a/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.h b/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.h
index 9f224eb213d..38a53524434 100644
--- a/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.h
+++ b/modules/openxr/extensions/spatial_container/openxr_spatial_container_self_rendering_extension.h
@@ -65,7 +65,7 @@ public:
void on_spatial_container_visibility_changed(const OpenXRSpatialContainerExtension::SpatialContainerData &p_container, bool p_visible);
void on_spatial_container_closed(const OpenXRSpatialContainerExtension::SpatialContainerData &p_container);
XrSpatialContainerGraphicsPresentationEXT get_spatial_container_graphics_presentation() const;
- XrResult locate_spatial_container_views(RID p_spatial_container_rid, XrView *p_views, bool &r_view_pose_valid, bool &r_should_submit_layers);
+ XrResult locate_spatial_container_views(RID p_spatial_container_rid, XrSpace p_space, XrView *p_views, bool &r_view_pose_valid, bool &r_should_submit_layers);
protected:
static void _bind_methods();
@@ -97,13 +97,6 @@ private:
bool spatial_container_self_rendering_ext = false;
XrSpatialContainerEXT active_spatial_container = XR_NULL_HANDLE;
- XrSpatialContainerViewLocateInfoEXT active_view_locate_info = {
- XR_TYPE_SPATIAL_CONTAINER_VIEW_LOCATE_INFO_EXT, // type
- nullptr, // next
- XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, // viewConfigurationType
- XR_NULL_HANDLE, // space
- XR_NULL_HANDLE, // spatialContainer
- };
XrSpatialContainerViewStateEXT active_view_state = {
XR_TYPE_SPATIAL_CONTAINER_VIEW_STATE_EXT, // type
nullptr, // next