From 7818a5b9cf6cbae6723ddd4c937fb4cd2b1a7ea8 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 21 Jul 2020 14:57:21 +0100 Subject: [PATCH] st/oxr: Implement xrEnumerateBoundSourcesForAction --- doc/changes/state_trackers/mr.451.2.md | 2 ++ src/xrt/state_trackers/oxr/oxr_input.c | 42 ++++++++++++++++++++++++ src/xrt/state_trackers/oxr/oxr_objects.h | 25 ++++++++------ 3 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 doc/changes/state_trackers/mr.451.2.md diff --git a/doc/changes/state_trackers/mr.451.2.md b/doc/changes/state_trackers/mr.451.2.md new file mode 100644 index 000000000..1905be1a4 --- /dev/null +++ b/doc/changes/state_trackers/mr.451.2.md @@ -0,0 +1,2 @@ +OpenXR: Implement the function `xrEnumerateBoundSourcesForAction`, currently we +only bind one input per top level user path and it's easy to track this. diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c index 1fe67f3e6..0a43f63c1 100644 --- a/src/xrt/state_trackers/oxr/oxr_input.c +++ b/src/xrt/state_trackers/oxr/oxr_input.c @@ -16,6 +16,7 @@ #include "oxr_objects.h" #include "oxr_logger.h" #include "oxr_handle.h" +#include "oxr_two_call.h" #include "oxr_input_transform.h" #include @@ -1154,6 +1155,7 @@ oxr_action_bind_inputs(struct oxr_logger *log, cache->inputs[i] = inputs[i]; } cache->num_inputs = num_inputs; + cache->bound_path = bound_path; } if (num_outputs > 0) { @@ -1164,6 +1166,7 @@ oxr_action_bind_inputs(struct oxr_logger *log, cache->outputs[i] = outputs[i]; } cache->num_outputs = num_outputs; + cache->bound_path = bound_path; } } @@ -1403,6 +1406,45 @@ oxr_action_sync_data(struct oxr_logger *log, return oxr_session_success_focused_result(sess); } +XrResult +oxr_action_enumerate_bound_sources(struct oxr_logger *log, + struct oxr_session *sess, + uint32_t act_key, + uint32_t sourceCapacityInput, + uint32_t *sourceCountOutput, + XrPath *sources) +{ + struct oxr_action_attachment *act_attached = NULL; + size_t num_paths = 0; + XrPath temp[32] = {0}; + + oxr_session_get_action_attachment(sess, act_key, &act_attached); + if (act_attached == NULL) { + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, + "act_key did not find any action"); + } + + if (act_attached->head.bound_path != XR_NULL_PATH) { + temp[num_paths++] = act_attached->head.bound_path; + } + if (act_attached->left.bound_path != XR_NULL_PATH) { + temp[num_paths++] = act_attached->left.bound_path; + } + if (act_attached->right.bound_path != XR_NULL_PATH) { + temp[num_paths++] = act_attached->right.bound_path; + } + if (act_attached->gamepad.bound_path != XR_NULL_PATH) { + temp[num_paths++] = act_attached->gamepad.bound_path; + } + if (act_attached->user.bound_path != XR_NULL_PATH) { + temp[num_paths++] = act_attached->user.bound_path; + } + + OXR_TWO_CALL_HELPER(log, sourceCapacityInput, sourceCountOutput, + sources, num_paths, temp, + oxr_session_success_result(sess)); +} + /* * diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 9f3520e95..057923d78 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -429,6 +429,18 @@ oxr_action_sync_data(struct oxr_logger *log, struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets); + +/*! + * @public @memberof oxr_session + */ +XrResult +oxr_action_enumerate_bound_sources(struct oxr_logger *log, + struct oxr_session *sess, + uint32_t act_key, + uint32_t sourceCapacityInput, + uint32_t *sourceCountOutput, + XrPath *sources); + /*! * @public @memberof oxr_session */ @@ -562,16 +574,6 @@ oxr_action_get_input_source_localized_name( uint32_t *bufferCountOutput, char *buffer); -/*! - * @public @memberof oxr_session - */ -XrResult -oxr_action_enumerate_bound_sources(struct oxr_logger *log, - struct oxr_session *sess, - uint64_t key, - uint32_t sourceCapacityInput, - uint32_t *sourceCountOutput, - XrPath *sources); /*! * @} */ @@ -1487,6 +1489,9 @@ struct oxr_action_cache { struct oxr_action_state current; + //! Which action is proving the binding. + XrPath bound_path; + size_t num_inputs; struct oxr_action_input *inputs;