diff options
author | David Snopek <dsnopek@gmail.com> | 2022-08-16 16:54:55 -0500 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2022-09-14 20:55:56 -0500 |
commit | e82cd46a746053217d749ea39b4a52f040aaf1e3 (patch) | |
tree | 707c67b36030c1da068c2b2a2620ea0e6f650049 /scene | |
parent | 0a0843a67d51eaacf5d3350d6c39a3893e3c1d6c (diff) |
Fix XR rendering in 'opengl3' driver and expose true size via the Viewport node
Diffstat (limited to 'scene')
-rw-r--r-- | scene/main/viewport.cpp | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 5295de5c09..879d494909 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -795,11 +795,20 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, stretch_transform = p_stretch_transform; to_screen_rect = p_to_screen_rect; - if (p_allocated) { - RS::get_singleton()->viewport_set_size(viewport, size.width, size.height); - } else { - RS::get_singleton()->viewport_set_size(viewport, 0, 0); - } +#ifndef _3D_DISABLED + if (!use_xr) { +#endif + + if (p_allocated) { + RS::get_singleton()->viewport_set_size(viewport, size.width, size.height); + } else { + RS::get_singleton()->viewport_set_size(viewport, 0, 0); + } + +#ifndef _3D_DISABLED + } // if (!use_xr) +#endif + _update_global_transform(); update_configuration_warnings(); @@ -813,6 +822,19 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, } Size2i Viewport::_get_size() const { +#ifndef _3D_DISABLED + if (use_xr) { + if (XRServer::get_singleton() != nullptr) { + Ref<XRInterface> xr_interface = XRServer::get_singleton()->get_primary_interface(); + if (xr_interface.is_valid() && xr_interface->is_initialized()) { + Size2 xr_size = xr_interface->get_render_target_size(); + return (Size2i)xr_size; + } + } + return Size2i(); + } +#endif // _3D_DISABLED + return size; } @@ -3612,9 +3634,20 @@ void Viewport::_propagate_exit_world_3d(Node *p_node) { } void Viewport::set_use_xr(bool p_use_xr) { - use_xr = p_use_xr; + if (use_xr != p_use_xr) { + use_xr = p_use_xr; - RS::get_singleton()->viewport_set_use_xr(viewport, use_xr); + RS::get_singleton()->viewport_set_use_xr(viewport, use_xr); + + if (!use_xr) { + // Set viewport to previous size when exiting XR. + if (size_allocated) { + RS::get_singleton()->viewport_set_size(viewport, size.width, size.height); + } else { + RS::get_singleton()->viewport_set_size(viewport, 0, 0); + } + } + } } bool Viewport::is_using_xr() { |