summaryrefslogtreecommitdiff
path: root/modules/webxr/webxr_interface_js.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/webxr/webxr_interface_js.cpp')
-rw-r--r--modules/webxr/webxr_interface_js.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp
index 7cfaf31495..74789fc98e 100644
--- a/modules/webxr/webxr_interface_js.cpp
+++ b/modules/webxr/webxr_interface_js.cpp
@@ -78,6 +78,8 @@ void _emwebxr_on_session_failed(char *p_message) {
Ref<XRInterface> interface = xr_server->find_interface("WebXR");
ERR_FAIL_COND(interface.is_null());
+ interface->uninitialize();
+
String message = String(p_message);
interface->emit_signal("session_failed", message);
}
@@ -224,6 +226,12 @@ bool WebXRInterfaceJS::initialize() {
// make this our primary interface
xr_server->set_primary_interface(this);
+ // Clear render_targetsize to make sure it gets reset to the new size.
+ // Clearing in uninitialize() doesn't work because a frame can still be
+ // rendered after it's called, which will fill render_targetsize again.
+ render_targetsize.width = 0;
+ render_targetsize.height = 0;
+
initialized = true;
godot_webxr_initialize(
@@ -277,22 +285,24 @@ Transform WebXRInterfaceJS::_js_matrix_to_transform(float *p_js_matrix) {
}
Size2 WebXRInterfaceJS::get_render_targetsize() {
- Size2 target_size;
+ if (render_targetsize.width != 0 && render_targetsize.height != 0) {
+ return render_targetsize;
+ }
int *js_size = godot_webxr_get_render_targetsize();
if (!initialized || js_size == nullptr) {
- // As a default, use half the window size.
- target_size = DisplayServer::get_singleton()->window_get_size();
- target_size.width /= 2.0;
- return target_size;
+ // As a temporary default (until WebXR is fully initialized), use half the window size.
+ Size2 temp = DisplayServer::get_singleton()->window_get_size();
+ temp.width /= 2.0;
+ return temp;
}
- target_size.width = js_size[0];
- target_size.height = js_size[1];
+ render_targetsize.width = js_size[0];
+ render_targetsize.height = js_size[1];
free(js_size);
- return target_size;
+ return render_targetsize;
};
Transform WebXRInterfaceJS::get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) {