summaryrefslogtreecommitdiffstats
path: root/servers/xr_server.h
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2024-03-21 18:58:24 +1100
committerBastiaan Olij <mux213@gmail.com>2024-05-01 14:24:41 +1000
commitcbab7dc04942ccb07a2ca0bc942498a319e57e35 (patch)
treecbdea1856b04a1e1b6f0c9eb388dd73246306490 /servers/xr_server.h
parentd282e4f0e6b6ebcf3bd6e05cd62f2a8fe1f9a238 (diff)
downloadredot-engine-cbab7dc04942ccb07a2ca0bc942498a319e57e35.tar.gz
OpenXR: Change timing of xrWaitFrame and add thread safety features to OpenXR
Diffstat (limited to 'servers/xr_server.h')
-rw-r--r--servers/xr_server.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/servers/xr_server.h b/servers/xr_server.h
index 717728171a..cd9c241bb0 100644
--- a/servers/xr_server.h
+++ b/servers/xr_server.h
@@ -36,6 +36,7 @@
#include "core/os/thread_safe.h"
#include "core/templates/rid.h"
#include "core/variant/variant.h"
+#include "rendering_server.h"
class XRInterface;
class XRTracker;
@@ -92,10 +93,46 @@ private:
Ref<XRInterface> primary_interface; /* we'll identify one interface as primary, this will be used by our viewports */
- double world_scale; /* scale by which we multiply our tracker positions */
+ double world_scale = 1.0; /* scale by which we multiply our tracker positions */
Transform3D world_origin; /* our world origin point, maps a location in our virtual world to the origin point in our real world tracking volume */
Transform3D reference_frame; /* our reference frame */
+ // As we may be updating our main state for our next frame while we're still rendering our previous frame,
+ // we need to keep copies around.
+ struct RenderState {
+ double world_scale = 1.0; /* scale by which we multiply our tracker positions */
+ Transform3D world_origin; /* our world origin point, maps a location in our virtual world to the origin point in our real world tracking volume */
+ Transform3D reference_frame; /* our reference frame */
+ } render_state;
+
+ static void _set_render_world_scale(double p_world_scale);
+ static void _set_render_world_origin(const Transform3D &p_world_origin);
+ static void _set_render_reference_frame(const Transform3D &p_reference_frame);
+
+ _FORCE_INLINE_ void set_render_world_scale(double p_world_scale) {
+ // If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
+ RenderingServer *rendering_server = RenderingServer::get_singleton();
+ ERR_FAIL_NULL(rendering_server);
+
+ rendering_server->call_on_render_thread(callable_mp_static(&XRServer::_set_render_world_scale).bind(p_world_scale));
+ }
+
+ _FORCE_INLINE_ void set_render_world_origin(const Transform3D &p_world_origin) {
+ // If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
+ RenderingServer *rendering_server = RenderingServer::get_singleton();
+ ERR_FAIL_NULL(rendering_server);
+
+ rendering_server->call_on_render_thread(callable_mp_static(&XRServer::_set_render_world_origin).bind(p_world_origin));
+ }
+
+ _FORCE_INLINE_ void set_render_reference_frame(const Transform3D &p_reference_frame) {
+ // If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
+ RenderingServer *rendering_server = RenderingServer::get_singleton();
+ ERR_FAIL_NULL(rendering_server);
+
+ rendering_server->call_on_render_thread(callable_mp_static(&XRServer::_set_render_reference_frame).bind(p_reference_frame));
+ }
+
protected:
static XRServer *singleton;