st/oxr: Refactor pose and fov copies into helpers

This commit is contained in:
Jakob Bornecrantz 2022-03-14 23:04:07 +00:00 committed by Jakob Bornecrantz
parent 1fb5656862
commit 85a2abaec6
3 changed files with 36 additions and 33 deletions

View file

@ -173,6 +173,37 @@ enum oxr_image_state
};
/*
*
* Helpers
*
*/
/*!
* Safely copy a xrt_pose to a XrPosef.
*/
#define OXR_XRT_POSE_TO_XRPOSEF(FROM, TO) \
do { \
union { \
struct xrt_pose xrt; \
XrPosef oxr; \
} safe_copy = {FROM}; \
TO = safe_copy.oxr; \
} while (false)
/*!
* Safely copy a xrt_fov to a XrFovf.
*/
#define OXR_XRT_FOV_TO_XRFOVF(FROM, TO) \
do { \
union { \
struct xrt_fov xrt; \
XrFovf oxr; \
} safe_copy = {FROM}; \
TO = safe_copy.oxr; \
} while (false)
/*
*
* oxr_handle_base.c

View file

@ -382,12 +382,7 @@ oxr_session_locate_views(struct oxr_logger *log,
if (!oxr_space_pure_relation_in_space(log, viewLocateInfo->displayTime, &pure_head_relation, baseSpc, true,
&head_relation_in_base_space)) {
for (uint32_t i = 0; i < view_count; i++) {
union {
struct xrt_pose xrt;
struct XrPosef oxr;
} safe_copy_pose = {0};
safe_copy_pose.xrt = (struct xrt_pose)XRT_POSE_IDENTITY;
views[i].pose = safe_copy_pose.oxr;
OXR_XRT_POSE_TO_XRPOSEF(XRT_POSE_IDENTITY, views[i].pose);
}
return XR_SUCCESS;
}
@ -405,12 +400,7 @@ oxr_session_locate_views(struct oxr_logger *log,
m_relation_chain_push_pose_if_not_identity(&xrc, &view_pose);
m_relation_chain_push_relation(&xrc, &head_relation_in_base_space);
m_relation_chain_resolve(&xrc, &result);
union {
struct xrt_pose xrt;
struct XrPosef oxr;
} safe_copy_pose = {0};
safe_copy_pose.xrt = result.pose;
views[i].pose = safe_copy_pose.oxr;
OXR_XRT_POSE_TO_XRPOSEF(result.pose, views[i].pose);
/*
@ -418,13 +408,7 @@ oxr_session_locate_views(struct oxr_logger *log,
*/
const struct xrt_fov fov = fovs[i];
union {
struct xrt_fov xrt;
XrFovf oxr;
} safe_copy_fov = {0};
safe_copy_fov.xrt = fov;
views[i].fov = safe_copy_fov.oxr;
OXR_XRT_FOV_TO_XRFOVF(fov, views[i].fov);
/*

View file

@ -443,12 +443,7 @@ oxr_space_locate(
if (!has_pure_relation) {
location->locationFlags = 0;
// Copy
union {
struct xrt_pose xrt;
XrPosef oxr;
} safe_copy = {XRT_POSE_IDENTITY};
location->pose = safe_copy.oxr;
OXR_XRT_POSE_TO_XRPOSEF(XRT_POSE_IDENTITY, location->pose);
XrSpaceVelocity *vel = (XrSpaceVelocity *)location->next;
if (vel) {
@ -476,14 +471,7 @@ oxr_space_locate(
m_relation_chain_push_inverted_pose_if_not_identity(&xrc, &baseSpc->pose);
m_relation_chain_resolve(&xrc, &result);
// Copy
union {
struct xrt_pose xrt;
XrPosef oxr;
} safe_copy = {0};
safe_copy.xrt = result.pose;
location->pose = safe_copy.oxr;
OXR_XRT_POSE_TO_XRPOSEF(result.pose, location->pose);
location->locationFlags = xrt_to_xr_space_location_flags(result.relation_flags);
XrSpaceVelocity *vel = (XrSpaceVelocity *)location->next;