Skip to content

Commit 3da26d7

Browse files
authored
Merge pull request godotengine#115022 from BastiaanOlij/openxr_custom_version
OpenXR: Allow setting a specific version of OpenXR to initialize.
2 parents b94faa2 + 7d445c0 commit 3da26d7

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,9 @@
36103610
<member name="xr/openxr/submit_depth_buffer" type="bool" setter="" getter="" default="false">
36113611
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.
36123612
</member>
3613+
<member name="xr/openxr/target_api_version" type="String" setter="" getter="" default="&quot;&quot;">
3614+
Optionally sets a specific API version of OpenXR to initialize in [code]major.minor.patch[/code] notation. Some XR runtimes gate old behavior behind version checks. This is non-standard OpenXR behavior.
3615+
</member>
36133616
<member name="xr/openxr/view_configuration" type="int" setter="" getter="" default="&quot;1&quot;" keywords="mono, stereo">
36143617
Specify the view configuration with which to configure OpenXR setting up either Mono or Stereo rendering.
36153618
</member>

main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,6 +2788,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
27882788
#ifndef _3D_DISABLED
27892789
// XR project settings.
27902790
GLOBAL_DEF_RST_BASIC("xr/openxr/enabled", false);
2791+
GLOBAL_DEF(PropertyInfo(Variant::STRING, "xr/openxr/target_api_version"), "");
27912792
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "xr/openxr/default_action_map", PROPERTY_HINT_FILE, "*.tres"), "res://openxr_action_map.tres");
27922793
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/form_factor", PROPERTY_HINT_ENUM, "Head Mounted,Handheld"), "0");
27932794
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/view_configuration", PROPERTY_HINT_ENUM, "Mono,Stereo"), "1"); // "Mono,Stereo,Quad,Observer"

modules/openxr/openxr_api.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,21 @@ XrResult OpenXRAPI::attempt_create_instance(XrVersion p_version) {
659659
bool OpenXRAPI::create_instance() {
660660
// Create our OpenXR instance, this will query any registered extension wrappers for extensions we need to enable.
661661

662-
XrResult result = attempt_create_instance(XR_API_VERSION_1_1);
663-
if (result == XR_ERROR_API_VERSION_UNSUPPORTED) {
664-
// Couldn't initialize OpenXR 1.1, try 1.0
662+
XrVersion init_version = XR_API_VERSION_1_1;
663+
664+
String custom_version = GLOBAL_GET("xr/openxr/target_api_version");
665+
if (!custom_version.is_empty()) {
666+
Vector<int> ints = custom_version.split_ints(".", false);
667+
ERR_FAIL_COND_V_MSG(ints.size() != 3, false, "OpenXR target API version must be major.minor.patch.");
668+
init_version = XR_MAKE_VERSION(ints[0], ints[1], ints[2]);
669+
}
670+
671+
XrResult result = attempt_create_instance(init_version);
672+
if (result == XR_ERROR_API_VERSION_UNSUPPORTED && init_version == XR_API_VERSION_1_1) {
665673
print_verbose("OpenXR: Falling back to OpenXR 1.0");
666674

667-
result = attempt_create_instance(XR_API_VERSION_1_0);
675+
init_version = XR_API_VERSION_1_0;
676+
result = attempt_create_instance(init_version);
668677
}
669678
ERR_FAIL_COND_V_MSG(XR_FAILED(result), false, "Failed to create XR instance [" + get_error_string(result) + "].");
670679

0 commit comments

Comments
 (0)