summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-12-07 13:25:42 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-12-07 13:25:42 +0100
commita565ddcd09316b508f61647eb2d6e0b44fbc5a27 (patch)
tree68b02dbb4f780e5c59914e64dc54c19537aee9cc
parentf9bd2ace0bc8839c5c0c6524ba578122b8bbfb34 (diff)
parent484cd90d29781cf4523f886fcf76d27505c8a4d8 (diff)
Merge pull request #69654 from BastiaanOlij/openxr_submit_depth_optional
Make submitting depth buffer in OpenXR optional
-rw-r--r--doc/classes/ProjectSettings.xml3
-rw-r--r--main/main.cpp2
-rw-r--r--modules/openxr/openxr_api.cpp33
-rw-r--r--modules/openxr/openxr_api.h13
4 files changed, 48 insertions, 3 deletions
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 1f0a8d91fa..dce9d5a55c 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -2299,6 +2299,9 @@
<member name="xr/openxr/reference_space" type="int" setter="" getter="" default="&quot;1&quot;">
Specify the default reference space.
</member>
+ <member name="xr/openxr/submit_depth_buffer" type="bool" setter="" getter="" default="false">
+ If [code]true[/code], OpenXR will manage the depth buffer and use the depth buffer for advanced reprojection provided this is supported by the XR runtime. Note that some rendering features in Godot can't be used with this feature.
+ </member>
<member name="xr/openxr/view_configuration" type="int" setter="" getter="" default="&quot;1&quot;">
Specify the view configuration with which to configure OpenXR setting up either Mono or Stereo rendering.
</member>
diff --git a/main/main.cpp b/main/main.cpp
index fd1dfabb1b..83703c55c2 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1862,6 +1862,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
GLOBAL_DEF_BASIC("xr/openxr/reference_space", "1");
ProjectSettings::get_singleton()->set_custom_property_info("xr/openxr/reference_space", PropertyInfo(Variant::INT, "xr/openxr/reference_space", PROPERTY_HINT_ENUM, "Local,Stage"));
+ GLOBAL_DEF_BASIC("xr/openxr/submit_depth_buffer", false);
+
#ifdef TOOLS_ENABLED
// Disabled for now, using XR inside of the editor we'll be working on during the coming months.
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index 71e1d9c351..b652ca4617 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -740,9 +740,10 @@ bool OpenXRAPI::create_swapchains() {
ERR_FAIL_NULL_V_MSG(projection_views, false, "OpenXR Couldn't allocate memory for projection views");
// We create our depth swapchain if:
+ // - we've enabled submitting depth buffer
// - we support our depth layer extension
// - we have our spacewarp extension (not yet implemented)
- if (OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) {
+ if (submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) {
// Build a vector with swapchain formats we want to use, from best fit to worst
Vector<int64_t> usable_swapchain_formats;
int64_t swapchain_format_to_use = 0;
@@ -790,7 +791,7 @@ bool OpenXRAPI::create_swapchains() {
projection_views[i].subImage.imageRect.extent.width = recommended_size.width;
projection_views[i].subImage.imageRect.extent.height = recommended_size.height;
- if (OpenXRCompositionLayerDepthExtension::get_singleton()->is_available() && depth_views) {
+ if (submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available() && depth_views) {
projection_views[i].next = &depth_views[i];
depth_views[i].type = XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR;
@@ -1066,6 +1067,30 @@ bool OpenXRAPI::on_state_exiting() {
return true;
}
+void OpenXRAPI::set_form_factor(XrFormFactor p_form_factor) {
+ ERR_FAIL_COND(is_initialized());
+
+ form_factor = p_form_factor;
+}
+
+void OpenXRAPI::set_view_configuration(XrViewConfigurationType p_view_configuration) {
+ ERR_FAIL_COND(is_initialized());
+
+ view_configuration = p_view_configuration;
+}
+
+void OpenXRAPI::set_reference_space(XrReferenceSpaceType p_reference_space) {
+ ERR_FAIL_COND(is_initialized());
+
+ reference_space = p_reference_space;
+}
+
+void OpenXRAPI::set_submit_depth_buffer(bool p_submit_depth_buffer) {
+ ERR_FAIL_COND(is_initialized());
+
+ submit_depth_buffer = p_submit_depth_buffer;
+}
+
bool OpenXRAPI::is_initialized() {
return (instance != XR_NULL_HANDLE);
}
@@ -1684,7 +1709,7 @@ RID OpenXRAPI::get_color_texture() {
}
RID OpenXRAPI::get_depth_texture() {
- if (swapchains[OPENXR_SWAPCHAIN_DEPTH].image_acquired) {
+ if (submit_depth_buffer && swapchains[OPENXR_SWAPCHAIN_DEPTH].image_acquired) {
return graphics_extension->get_texture(swapchains[OPENXR_SWAPCHAIN_DEPTH].swapchain_graphics_data, swapchains[OPENXR_SWAPCHAIN_DEPTH].image_index);
} else {
return RID();
@@ -1862,6 +1887,8 @@ OpenXRAPI::OpenXRAPI() {
default:
break;
}
+
+ submit_depth_buffer = GLOBAL_GET("xr/openxr/submit_depth_buffer");
}
// reset a few things that can't be done in our class definition
diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h
index 5dce749351..ac4bbff94c 100644
--- a/modules/openxr/openxr_api.h
+++ b/modules/openxr/openxr_api.h
@@ -104,6 +104,7 @@ private:
XrViewConfigurationType view_configuration = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
XrReferenceSpaceType reference_space = XR_REFERENCE_SPACE_TYPE_STAGE;
// XrEnvironmentBlendMode environment_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
+ bool submit_depth_buffer = false; // if set to true we submit depth buffers to OpenXR if a suitable extension is enabled.
// state
XrInstance instance = XR_NULL_HANDLE;
@@ -312,6 +313,18 @@ public:
void set_xr_interface(OpenXRInterface *p_xr_interface);
void register_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper);
+ void set_form_factor(XrFormFactor p_form_factor);
+ XrFormFactor get_form_factor() const { return form_factor; }
+
+ void set_view_configuration(XrViewConfigurationType p_view_configuration);
+ XrViewConfigurationType get_view_configuration() const { return view_configuration; }
+
+ void set_reference_space(XrReferenceSpaceType p_reference_space);
+ XrReferenceSpaceType get_reference_space() const { return reference_space; }
+
+ void set_submit_depth_buffer(bool p_submit_depth_buffer);
+ bool get_submit_depth_buffer() const { return submit_depth_buffer; }
+
bool is_initialized();
bool is_running();
bool initialize(const String &p_rendering_driver);