From dca9f09386088649a7fe87d0fd3a91afebf75b85 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Mon, 25 Jan 2021 08:35:26 -0600 Subject: [PATCH] Support mono devices in WebXR --- modules/webxr/godot_webxr.h | 1 + modules/webxr/native/library_godot_webxr.js | 9 +++++++++ modules/webxr/webxr_interface_js.cpp | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/webxr/godot_webxr.h b/modules/webxr/godot_webxr.h index 5e50ffde288..41a690f473d 100644 --- a/modules/webxr/godot_webxr.h +++ b/modules/webxr/godot_webxr.h @@ -61,6 +61,7 @@ extern void godot_webxr_initialize( GodotWebXRSimpleEventCallback p_on_simple_event); extern void godot_webxr_uninitialize(); +extern int godot_webxr_get_view_count(); extern int *godot_webxr_get_render_targetsize(); extern float *godot_webxr_get_transform_for_eye(int p_eye); extern float *godot_webxr_get_projection_for_eye(int p_eye); diff --git a/modules/webxr/native/library_godot_webxr.js b/modules/webxr/native/library_godot_webxr.js index b3d2bc20253..c70c6f5eef0 100644 --- a/modules/webxr/native/library_godot_webxr.js +++ b/modules/webxr/native/library_godot_webxr.js @@ -395,6 +395,15 @@ const GodotWebXR = { GodotWebXR.pauseResumeMainLoop(); }, + godot_webxr_get_view_count__proxy: 'sync', + godot_webxr_get_view_count__sig: 'i', + godot_webxr_get_view_count: function () { + if (!GodotWebXR.session || !GodotWebXR.pose) { + return 0; + } + return GodotWebXR.pose.views.length; + }, + godot_webxr_get_render_targetsize__proxy: 'sync', godot_webxr_get_render_targetsize__sig: 'i', godot_webxr_get_render_targetsize: function () { diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 0e17e5436bd..991035df025 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -199,12 +199,11 @@ StringName WebXRInterfaceJS::get_name() const { }; int WebXRInterfaceJS::get_capabilities() const { - return ARVRInterface::ARVR_STEREO; + return ARVRInterface::ARVR_STEREO | ARVRInterface::ARVR_MONO; }; bool WebXRInterfaceJS::is_stereo() { - // @todo WebXR can be mono! So, how do we know? Count the views in the frame? - return true; + return godot_webxr_get_view_count() == 2; }; bool WebXRInterfaceJS::is_initialized() const {