st/oxr: Add support for reference space usage

This commit is contained in:
Jakob Bornecrantz 2023-11-17 15:14:18 +00:00
parent a0a0f7cfa6
commit c197ba999f
2 changed files with 42 additions and 1 deletions
src/xrt/state_trackers/oxr

View file

@ -11,6 +11,7 @@
#pragma once
#include "xrt/xrt_defines.h"
#include "xrt/xrt_space.h"
#include "xrt/xrt_vulkan_includes.h"
#include "xrt/xrt_openxr_includes.h"
@ -99,3 +100,28 @@ xr_ref_space_to_string(XrReferenceSpaceType space_type)
default: return "UNKNOWN REFERENCE SPACE";
}
}
static inline enum xrt_reference_space_type
oxr_ref_space_to_xrt(enum oxr_space_type space_type)
{
switch (space_type) {
case OXR_SPACE_TYPE_REFERENCE_VIEW: return XRT_SPACE_REFERENCE_TYPE_VIEW;
case OXR_SPACE_TYPE_REFERENCE_LOCAL: return XRT_SPACE_REFERENCE_TYPE_LOCAL;
case OXR_SPACE_TYPE_REFERENCE_LOCAL_FLOOR: return XRT_SPACE_REFERENCE_TYPE_LOCAL_FLOOR;
case OXR_SPACE_TYPE_REFERENCE_STAGE: return XRT_SPACE_REFERENCE_TYPE_STAGE;
case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT: return XRT_SPACE_REFERENCE_TYPE_UNBOUNDED;
// Has no mapping to a Monado semantic space.
case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO: return XRT_SPACE_REFERENCE_TYPE_INVALID;
case OXR_SPACE_TYPE_ACTION: return XRT_SPACE_REFERENCE_TYPE_INVALID;
}
/*
* This is the default case, we do not have a explicit default case
* so that we get warnings for unhandled enum members. This is fine
* because the C specification says if there is no default case and
* and a non-matching value is given no case is executed.
*/
return XRT_SPACE_REFERENCE_TYPE_INVALID;
}

View file

@ -119,6 +119,12 @@ oxr_space_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{
struct oxr_space *spc = (struct oxr_space *)hb;
// Unreference the reference space.
enum xrt_reference_space_type xtype = oxr_ref_space_to_xrt(spc->space_type);
if (xtype != XRT_SPACE_REFERENCE_TYPE_INVALID) {
xrt_space_overseer_ref_space_inc(spc->sess->sys->xso, xtype);
}
xrt_space_reference(&spc->action.xs, NULL);
spc->action.xdev = NULL;
spc->action.name = 0;
@ -164,12 +170,21 @@ oxr_space_reference_create(struct oxr_logger *log,
return oxr_error(log, XR_ERROR_POSE_INVALID, "(createInfo->poseInReferenceSpace)");
}
// Convert the type into the different enums.
enum oxr_space_type oxr_type = xr_ref_space_to_oxr(createInfo->referenceSpaceType);
enum xrt_reference_space_type xtype = oxr_ref_space_to_xrt(oxr_type);
struct oxr_space *spc = NULL;
OXR_ALLOCATE_HANDLE_OR_RETURN(log, spc, OXR_XR_DEBUG_SPACE, oxr_space_destroy, &sess->handle);
spc->sess = sess;
spc->space_type = xr_ref_space_to_oxr(createInfo->referenceSpaceType);
spc->space_type = oxr_type;
memcpy(&spc->pose, &createInfo->poseInReferenceSpace, sizeof(spc->pose));
// Reference the reference space, if not supported by Monado just skip.
if (xtype != XRT_SPACE_REFERENCE_TYPE_INVALID) {
xrt_space_overseer_ref_space_inc(sess->sys->xso, xtype);
}
*out_space = spc;
return XR_SUCCESS;