summaryrefslogtreecommitdiff
path: root/modules/openxr/openxr_api.h
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openxr/openxr_api.h')
-rw-r--r--modules/openxr/openxr_api.h118
1 files changed, 76 insertions, 42 deletions
diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h
index 33b503543a..dc224c4237 100644
--- a/modules/openxr/openxr_api.h
+++ b/modules/openxr/openxr_api.h
@@ -28,16 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef OPENXR_DRIVER_H
-#define OPENXR_DRIVER_H
+#ifndef OPENXR_API_H
+#define OPENXR_API_H
#include "core/error/error_macros.h"
-#include "core/math/camera_matrix.h"
+#include "core/math/projection.h"
#include "core/math/transform_3d.h"
#include "core/math/vector2.h"
#include "core/os/memory.h"
#include "core/string/ustring.h"
-#include "core/templates/map.h"
+#include "core/templates/rb_map.h"
#include "core/templates/rid_owner.h"
#include "core/templates/vector.h"
#include "servers/xr/xr_pose.h"
@@ -55,12 +55,16 @@
// forward declarations, we don't want to include these fully
class OpenXRVulkanExtension;
+class OpenXRInterface;
class OpenXRAPI {
private:
// our singleton
static OpenXRAPI *singleton;
+ // linked XR interface
+ OpenXRInterface *xr_interface = nullptr;
+
// layers
uint32_t num_layer_properties = 0;
XrApiLayerProperties *layer_properties = nullptr;
@@ -69,7 +73,13 @@ private:
uint32_t num_supported_extensions = 0;
XrExtensionProperties *supported_extensions = nullptr;
Vector<OpenXRExtensionWrapper *> registered_extension_wrappers;
- Vector<const char *> enabled_extensions;
+ Vector<CharString> enabled_extensions;
+
+ bool ext_hp_mixed_reality_available = false;
+ bool ext_samsung_odyssey_available = false;
+ bool ext_vive_cosmos_available = false;
+ bool ext_vive_focus3_available = false;
+ bool ext_huawei_controller_available = false;
// composition layer providers
Vector<OpenXRCompositionLayerProvider *> composition_layer_providers;
@@ -94,9 +104,9 @@ private:
// state
XrInstance instance = XR_NULL_HANDLE;
- XrSystemId system_id;
+ XrSystemId system_id = 0;
String system_name;
- uint32_t vendor_id;
+ uint32_t vendor_id = 0;
XrSystemTrackingProperties tracking_properties;
XrSession session = XR_NULL_HANDLE;
XrSessionState session_state = XR_SESSION_STATE_UNKNOWN;
@@ -122,7 +132,7 @@ private:
bool load_layer_properties();
bool load_supported_extensions();
- bool is_extension_supported(const char *p_extension) const;
+ bool is_extension_supported(const String &p_extension) const;
// instance
bool create_instance();
@@ -148,29 +158,45 @@ private:
bool release_image(XrSwapchain p_swapchain);
// action map
- struct Path {
- XrPath path;
+ struct Tracker { // Trackers represent tracked physical objects such as controllers, pucks, etc.
+ String name; // Name for this tracker (i.e. "/user/hand/left")
+ XrPath toplevel_path; // OpenXR XrPath for this tracker
+ RID active_profile_rid; // RID of the active profile for this tracker
};
- RID_Owner<Path, true> xr_path_owner;
+ RID_Owner<Tracker, true> tracker_owner;
+ RID get_tracker_rid(XrPath p_path);
- struct ActionSet {
- bool is_attached;
- XrActionSet handle;
+ struct ActionSet { // Action sets define a set of actions that can be enabled together
+ String name; // Name for this action set (i.e. "godot_action_set")
+ bool is_attached; // If true our action set has been attached to the session and can no longer be modified
+ XrActionSet handle; // OpenXR handle for this action set
};
RID_Owner<ActionSet, true> action_set_owner;
- struct PathWithSpace {
- XrPath toplevel_path;
- XrSpace space;
- bool was_location_valid;
+ struct ActionTracker { // Links and action to a tracker
+ RID tracker_rid; // RID of the tracker
+ XrSpace space; // Optional space for pose actions
+ bool was_location_valid; // If true the last position we obtained was valid
};
- struct Action {
- XrActionType action_type;
- Vector<PathWithSpace> toplevel_paths;
- XrAction handle;
+ struct Action { // Actions define the inputs and outputs in OpenXR
+ RID action_set_rid; // RID of the action set this action belongs to
+ String name; // Name for this action (i.e. "aim_pose")
+ XrActionType action_type; // Type of action (bool, float, etc.)
+ Vector<ActionTracker> trackers; // The trackers this action can be used with
+ XrAction handle; // OpenXR handle for this action
};
RID_Owner<Action, true> action_owner;
+ RID get_action_rid(XrAction p_action);
+
+ struct InteractionProfile { // Interaction profiles define suggested bindings between the physical inputs on controller types and our actions
+ String name; // Name of the interaction profile (i.e. "/interaction_profiles/valve/index_controller")
+ XrPath path; // OpenXR path for this profile
+ Vector<XrActionSuggestedBinding> bindings; // OpenXR action bindings
+ };
+ RID_Owner<InteractionProfile, true> interaction_profile_owner;
+ RID get_interaction_profile_rid(XrPath p_path);
+ XrPath get_interaction_profile_path(RID p_interaction_profile);
// state changes
bool poll_events();
@@ -199,22 +225,22 @@ protected:
// helper method to get a valid Transform3D from an openxr space location
XRPose::TrackingConfidence transform_from_location(const XrSpaceLocation &p_location, Transform3D &r_transform);
XRPose::TrackingConfidence transform_from_location(const XrHandJointLocationEXT &p_location, Transform3D &r_transform);
- void parse_velocities(const XrSpaceVelocity &p_velocity, Vector3 &r_linear_velocity, Vector3 r_angular_velocity);
+ void parse_velocities(const XrSpaceVelocity &p_velocity, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
public:
- static void setup_global_defs();
- static bool openxr_is_enabled();
+ static bool openxr_is_enabled(bool p_check_run_in_editor = true);
static OpenXRAPI *get_singleton();
String get_error_string(XrResult result);
String get_swapchain_format_name(int64_t p_swapchain_format) const;
+ void set_xr_interface(OpenXRInterface *p_xr_interface);
void register_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper);
bool is_initialized();
bool is_running();
- bool initialise(const String &p_rendering_driver);
- bool initialise_session();
+ bool initialize(const String &p_rendering_driver);
+ bool initialize_session();
void finish();
XrTime get_next_frame_time() { return frame_state.predictedDisplayTime + frame_state.predictedDisplayPeriod; };
@@ -223,7 +249,7 @@ public:
Size2 get_recommended_target_size();
XRPose::TrackingConfidence get_head_center(Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
bool get_view_transform(uint32_t p_view, Transform3D &r_transform);
- bool get_view_projection(uint32_t p_view, double p_z_near, double p_z_far, CameraMatrix &p_camera_matrix);
+ bool get_view_projection(uint32_t p_view, double p_z_near, double p_z_far, Projection &p_camera_matrix);
bool process();
void pre_render();
@@ -233,29 +259,37 @@ public:
// action map
String get_default_action_map_resource_name();
- RID path_create(const String p_name);
- void path_free(RID p_path);
+
+ RID tracker_create(const String p_name);
+ String tracker_get_name(RID p_tracker);
+ void tracker_check_profile(RID p_tracker, XrSession p_session = XR_NULL_HANDLE);
+ void tracker_free(RID p_tracker);
+
RID action_set_create(const String p_name, const String p_localized_name, const int p_priority);
+ String action_set_get_name(RID p_action_set);
bool action_set_attach(RID p_action_set);
void action_set_free(RID p_action_set);
- RID action_create(RID p_action_set, const String p_name, const String p_localized_name, OpenXRAction::ActionType p_action_type, const Vector<RID> &p_toplevel_paths);
+
+ RID action_create(RID p_action_set, const String p_name, const String p_localized_name, OpenXRAction::ActionType p_action_type, const Vector<RID> &p_trackers);
+ String action_get_name(RID p_action);
void action_free(RID p_action);
- struct Binding {
- RID action;
- String path;
- };
- bool suggest_bindings(const String p_interaction_profile, const Vector<Binding> p_bindings);
+ RID interaction_profile_create(const String p_name);
+ String interaction_profile_get_name(RID p_interaction_profile);
+ void interaction_profile_clear_bindings(RID p_interaction_profile);
+ bool interaction_profile_add_binding(RID p_interaction_profile, RID p_action, const String p_path);
+ bool interaction_profile_suggest_bindings(RID p_interaction_profile);
+ void interaction_profile_free(RID p_interaction_profile);
bool sync_action_sets(const Vector<RID> p_active_sets);
- bool get_action_bool(RID p_action, RID p_path);
- float get_action_float(RID p_action, RID p_path);
- Vector2 get_action_vector2(RID p_action, RID p_path);
- XRPose::TrackingConfidence get_action_pose(RID p_action, RID p_path, Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
- bool trigger_haptic_pulse(RID p_action, RID p_path, float p_frequency, float p_amplitude, XrDuration p_duration_ns);
+ bool get_action_bool(RID p_action, RID p_tracker);
+ float get_action_float(RID p_action, RID p_tracker);
+ Vector2 get_action_vector2(RID p_action, RID p_tracker);
+ XRPose::TrackingConfidence get_action_pose(RID p_action, RID p_tracker, Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity);
+ bool trigger_haptic_pulse(RID p_action, RID p_tracker, float p_frequency, float p_amplitude, XrDuration p_duration_ns);
OpenXRAPI();
~OpenXRAPI();
};
-#endif // !OPENXR_DRIVER_H
+#endif // OPENXR_API_H