| 1 | /**************************************************************************/ | 
| 2 | /*  openxr_api.h                                                          */ | 
| 3 | /**************************************************************************/ | 
| 4 | /*                         This file is part of:                          */ | 
| 5 | /*                             GODOT ENGINE                               */ | 
| 6 | /*                        https://godotengine.org                         */ | 
| 7 | /**************************************************************************/ | 
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
| 10 | /*                                                                        */ | 
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
| 12 | /* a copy of this software and associated documentation files (the        */ | 
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
| 17 | /* the following conditions:                                              */ | 
| 18 | /*                                                                        */ | 
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
| 21 | /*                                                                        */ | 
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
| 29 | /**************************************************************************/ | 
| 30 |  | 
| 31 | #ifndef OPENXR_API_H | 
| 32 | #define OPENXR_API_H | 
| 33 |  | 
| 34 | #include "action_map/openxr_action.h" | 
| 35 | #include "extensions/openxr_composition_layer_provider.h" | 
| 36 | #include "extensions/openxr_extension_wrapper.h" | 
| 37 | #include "util.h" | 
| 38 |  | 
| 39 | #include "core/error/error_macros.h" | 
| 40 | #include "core/math/projection.h" | 
| 41 | #include "core/math/transform_3d.h" | 
| 42 | #include "core/math/vector2.h" | 
| 43 | #include "core/os/memory.h" | 
| 44 | #include "core/string/print_string.h" | 
| 45 | #include "core/string/ustring.h" | 
| 46 | #include "core/templates/rb_map.h" | 
| 47 | #include "core/templates/rid_owner.h" | 
| 48 | #include "core/templates/vector.h" | 
| 49 | #include "servers/xr/xr_pose.h" | 
| 50 |  | 
| 51 | #include <openxr/openxr.h> | 
| 52 |  | 
| 53 | // Note, OpenXR code that we wrote for our plugin makes use of C++20 notation for initializing structs which ensures zeroing out unspecified members. | 
| 54 | // Godot is currently restricted to C++17 which doesn't allow this notation. Make sure critical fields are set. | 
| 55 |  | 
| 56 | // forward declarations, we don't want to include these fully | 
| 57 | class OpenXRVulkanExtension; | 
| 58 | class OpenXRInterface; | 
| 59 |  | 
| 60 | class OpenXRAPI { | 
| 61 | private: | 
| 62 | 	// our singleton | 
| 63 | 	static OpenXRAPI *singleton; | 
| 64 |  | 
| 65 | 	// Registered extension wrappers | 
| 66 | 	static Vector<OpenXRExtensionWrapper *> registered_extension_wrappers; | 
| 67 |  | 
| 68 | 	// linked XR interface | 
| 69 | 	OpenXRInterface *xr_interface = nullptr; | 
| 70 |  | 
| 71 | 	// layers | 
| 72 | 	uint32_t num_layer_properties = 0; | 
| 73 | 	XrApiLayerProperties *layer_properties = nullptr; | 
| 74 |  | 
| 75 | 	// extensions | 
| 76 | 	uint32_t num_supported_extensions = 0; | 
| 77 | 	XrExtensionProperties *supported_extensions = nullptr; | 
| 78 | 	Vector<CharString> enabled_extensions; | 
| 79 |  | 
| 80 | 	// composition layer providers | 
| 81 | 	Vector<OpenXRCompositionLayerProvider *> composition_layer_providers; | 
| 82 |  | 
| 83 | 	// view configuration | 
| 84 | 	uint32_t num_view_configuration_types = 0; | 
| 85 | 	XrViewConfigurationType *supported_view_configuration_types = nullptr; | 
| 86 |  | 
| 87 | 	// reference spaces | 
| 88 | 	uint32_t num_reference_spaces = 0; | 
| 89 | 	XrReferenceSpaceType *supported_reference_spaces = nullptr; | 
| 90 |  | 
| 91 | 	// swapchains (note these are platform dependent) | 
| 92 | 	uint32_t num_swapchain_formats = 0; | 
| 93 | 	int64_t *supported_swapchain_formats = nullptr; | 
| 94 |  | 
| 95 | 	// system info | 
| 96 | 	String runtime_name; | 
| 97 | 	String runtime_version; | 
| 98 |  | 
| 99 | 	// configuration | 
| 100 | 	XrFormFactor form_factor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY; | 
| 101 | 	XrViewConfigurationType view_configuration = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO; | 
| 102 | 	XrReferenceSpaceType reference_space = XR_REFERENCE_SPACE_TYPE_STAGE; | 
| 103 | 	bool submit_depth_buffer = false; // if set to true we submit depth buffers to OpenXR if a suitable extension is enabled. | 
| 104 |  | 
| 105 | 	// blend mode | 
| 106 | 	XrEnvironmentBlendMode environment_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; | 
| 107 | 	uint32_t num_supported_environment_blend_modes = 0; | 
| 108 | 	XrEnvironmentBlendMode *supported_environment_blend_modes = nullptr; | 
| 109 |  | 
| 110 | 	// state | 
| 111 | 	XrInstance instance = XR_NULL_HANDLE; | 
| 112 | 	XrSystemId system_id = 0; | 
| 113 | 	String system_name; | 
| 114 | 	uint32_t vendor_id = 0; | 
| 115 | 	XrSystemTrackingProperties tracking_properties; | 
| 116 | 	XrSession session = XR_NULL_HANDLE; | 
| 117 | 	XrSessionState session_state = XR_SESSION_STATE_UNKNOWN; | 
| 118 | 	bool running = false; | 
| 119 | 	XrFrameState frame_state = { XR_TYPE_FRAME_STATE, NULL, 0, 0, false }; | 
| 120 | 	double render_target_size_multiplier = 1.0; | 
| 121 |  | 
| 122 | 	OpenXRGraphicsExtensionWrapper *graphics_extension = nullptr; | 
| 123 | 	XrSystemGraphicsProperties graphics_properties; | 
| 124 |  | 
| 125 | 	uint32_t view_count = 0; | 
| 126 | 	XrViewConfigurationView *view_configuration_views = nullptr; | 
| 127 | 	XrView *views = nullptr; | 
| 128 | 	XrCompositionLayerProjectionView *projection_views = nullptr; | 
| 129 | 	XrCompositionLayerDepthInfoKHR *depth_views = nullptr; // Only used by Composition Layer Depth Extension if available | 
| 130 |  | 
| 131 | 	enum OpenXRSwapChainTypes { | 
| 132 | 		OPENXR_SWAPCHAIN_COLOR, | 
| 133 | 		OPENXR_SWAPCHAIN_DEPTH, | 
| 134 | 		// OPENXR_SWAPCHAIN_VELOCITY, | 
| 135 | 		OPENXR_SWAPCHAIN_MAX | 
| 136 | 	}; | 
| 137 |  | 
| 138 | 	struct OpenXRSwapChainInfo { | 
| 139 | 		XrSwapchain swapchain = XR_NULL_HANDLE; | 
| 140 | 		void *swapchain_graphics_data = nullptr; | 
| 141 | 		uint32_t image_index = 0; | 
| 142 | 		bool image_acquired = false; | 
| 143 | 	}; | 
| 144 |  | 
| 145 | 	OpenXRSwapChainInfo swapchains[OPENXR_SWAPCHAIN_MAX]; | 
| 146 |  | 
| 147 | 	XrSpace play_space = XR_NULL_HANDLE; | 
| 148 | 	XrSpace view_space = XR_NULL_HANDLE; | 
| 149 | 	bool view_pose_valid = false; | 
| 150 | 	XRPose::TrackingConfidence head_pose_confidence = XRPose::XR_TRACKING_CONFIDENCE_NONE; | 
| 151 |  | 
| 152 | 	bool load_layer_properties(); | 
| 153 | 	bool load_supported_extensions(); | 
| 154 | 	bool is_extension_supported(const String &p_extension) const; | 
| 155 | 	bool is_extension_enabled(const String &p_extension) const; | 
| 156 |  | 
| 157 | 	bool openxr_loader_init(); | 
| 158 | 	bool resolve_instance_openxr_symbols(); | 
| 159 |  | 
| 160 | #ifdef ANDROID_ENABLED | 
| 161 | 	// On Android we keep tracker of our external OpenXR loader | 
| 162 | 	void *openxr_loader_library_handle = nullptr; | 
| 163 | #endif | 
| 164 |  | 
| 165 | 	// function pointers | 
| 166 | #ifdef ANDROID_ENABLED | 
| 167 | 	// On non-Android platforms we use the OpenXR symbol linked into the engine binary. | 
| 168 | 	PFN_xrGetInstanceProcAddr xrGetInstanceProcAddr = nullptr; | 
| 169 | #endif | 
| 170 | 	EXT_PROTO_XRRESULT_FUNC3(xrAcquireSwapchainImage, (XrSwapchain), swapchain, (const XrSwapchainImageAcquireInfo *), acquireInfo, (uint32_t *), index) | 
| 171 | 	EXT_PROTO_XRRESULT_FUNC3(, (XrSession), session, (const XrHapticActionInfo *), hapticActionInfo, (const XrHapticBaseHeader *), hapticFeedback) | 
| 172 | 	EXT_PROTO_XRRESULT_FUNC2(xrAttachSessionActionSets, (XrSession), session, (const XrSessionActionSetsAttachInfo *), attachInfo) | 
| 173 | 	EXT_PROTO_XRRESULT_FUNC2(xrBeginFrame, (XrSession), session, (const XrFrameBeginInfo *), frameBeginInfo) | 
| 174 | 	EXT_PROTO_XRRESULT_FUNC2(xrBeginSession, (XrSession), session, (const XrSessionBeginInfo *), beginInfo) | 
| 175 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateAction, (XrActionSet), actionSet, (const XrActionCreateInfo *), createInfo, (XrAction *), action) | 
| 176 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateActionSet, (XrInstance), instance, (const XrActionSetCreateInfo *), createInfo, (XrActionSet *), actionSet) | 
| 177 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateActionSpace, (XrSession), session, (const XrActionSpaceCreateInfo *), createInfo, (XrSpace *), space) | 
| 178 | 	EXT_PROTO_XRRESULT_FUNC2(xrCreateInstance, (const XrInstanceCreateInfo *), createInfo, (XrInstance *), instance) | 
| 179 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateReferenceSpace, (XrSession), session, (const XrReferenceSpaceCreateInfo *), createInfo, (XrSpace *), space) | 
| 180 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateSession, (XrInstance), instance, (const XrSessionCreateInfo *), createInfo, (XrSession *), session) | 
| 181 | 	EXT_PROTO_XRRESULT_FUNC3(xrCreateSwapchain, (XrSession), session, (const XrSwapchainCreateInfo *), createInfo, (XrSwapchain *), swapchain) | 
| 182 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroyAction, (XrAction), action) | 
| 183 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroyActionSet, (XrActionSet), actionSet) | 
| 184 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroyInstance, (XrInstance), instance) | 
| 185 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroySession, (XrSession), session) | 
| 186 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroySpace, (XrSpace), space) | 
| 187 | 	EXT_PROTO_XRRESULT_FUNC1(xrDestroySwapchain, (XrSwapchain), swapchain) | 
| 188 | 	EXT_PROTO_XRRESULT_FUNC2(xrEndFrame, (XrSession), session, (const XrFrameEndInfo *), frameEndInfo) | 
| 189 | 	EXT_PROTO_XRRESULT_FUNC1(xrEndSession, (XrSession), session) | 
| 190 | 	EXT_PROTO_XRRESULT_FUNC3(xrEnumerateApiLayerProperties, (uint32_t), propertyCapacityInput, (uint32_t *), propertyCountOutput, (XrApiLayerProperties *), properties) | 
| 191 | 	EXT_PROTO_XRRESULT_FUNC6(xrEnumerateEnvironmentBlendModes, (XrInstance), instance, (XrSystemId), systemId, (XrViewConfigurationType), viewConfigurationType, (uint32_t), environmentBlendModeCapacityInput, (uint32_t *), environmentBlendModeCountOutput, (XrEnvironmentBlendMode *), environmentBlendModes) | 
| 192 | 	EXT_PROTO_XRRESULT_FUNC4(xrEnumerateInstanceExtensionProperties, (const char *), layerName, (uint32_t), propertyCapacityInput, (uint32_t *), propertyCountOutput, (XrExtensionProperties *), properties) | 
| 193 | 	EXT_PROTO_XRRESULT_FUNC4(xrEnumerateReferenceSpaces, (XrSession), session, (uint32_t), spaceCapacityInput, (uint32_t *), spaceCountOutput, (XrReferenceSpaceType *), spaces) | 
| 194 | 	EXT_PROTO_XRRESULT_FUNC4(xrEnumerateSwapchainFormats, (XrSession), session, (uint32_t), formatCapacityInput, (uint32_t *), formatCountOutput, (int64_t *), formats) | 
| 195 | 	EXT_PROTO_XRRESULT_FUNC5(xrEnumerateViewConfigurations, (XrInstance), instance, (XrSystemId), systemId, (uint32_t), viewConfigurationTypeCapacityInput, (uint32_t *), viewConfigurationTypeCountOutput, (XrViewConfigurationType *), viewConfigurationTypes) | 
| 196 | 	EXT_PROTO_XRRESULT_FUNC6(xrEnumerateViewConfigurationViews, (XrInstance), instance, (XrSystemId), systemId, (XrViewConfigurationType), viewConfigurationType, (uint32_t), viewCapacityInput, (uint32_t *), viewCountOutput, (XrViewConfigurationView *), views) | 
| 197 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetActionStateBoolean, (XrSession), session, (const XrActionStateGetInfo *), getInfo, (XrActionStateBoolean *), state) | 
| 198 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetActionStateFloat, (XrSession), session, (const XrActionStateGetInfo *), getInfo, (XrActionStateFloat *), state) | 
| 199 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetActionStateVector2f, (XrSession), session, (const XrActionStateGetInfo *), getInfo, (XrActionStateVector2f *), state) | 
| 200 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetCurrentInteractionProfile, (XrSession), session, (XrPath), topLevelUserPath, (XrInteractionProfileState *), interactionProfile) | 
| 201 | 	EXT_PROTO_XRRESULT_FUNC2(xrGetInstanceProperties, (XrInstance), instance, (XrInstanceProperties *), instanceProperties) | 
| 202 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetSystem, (XrInstance), instance, (const XrSystemGetInfo *), getInfo, (XrSystemId *), systemId) | 
| 203 | 	EXT_PROTO_XRRESULT_FUNC3(xrGetSystemProperties, (XrInstance), instance, (XrSystemId), systemId, (XrSystemProperties *), properties) | 
| 204 | 	EXT_PROTO_XRRESULT_FUNC4(xrLocateSpace, (XrSpace), space, (XrSpace), baseSpace, (XrTime), time, (XrSpaceLocation *), location) | 
| 205 | 	EXT_PROTO_XRRESULT_FUNC6(xrLocateViews, (XrSession), session, (const XrViewLocateInfo *), viewLocateInfo, (XrViewState *), viewState, (uint32_t), viewCapacityInput, (uint32_t *), viewCountOutput, (XrView *), views) | 
| 206 | 	EXT_PROTO_XRRESULT_FUNC5(xrPathToString, (XrInstance), instance, (XrPath), path, (uint32_t), bufferCapacityInput, (uint32_t *), bufferCountOutput, (char *), buffer) | 
| 207 | 	EXT_PROTO_XRRESULT_FUNC2(xrPollEvent, (XrInstance), instance, (XrEventDataBuffer *), eventData) | 
| 208 | 	EXT_PROTO_XRRESULT_FUNC2(xrReleaseSwapchainImage, (XrSwapchain), swapchain, (const XrSwapchainImageReleaseInfo *), releaseInfo) | 
| 209 | 	EXT_PROTO_XRRESULT_FUNC3(xrResultToString, (XrInstance), instance, (XrResult), value, (char *), buffer) | 
| 210 | 	EXT_PROTO_XRRESULT_FUNC3(xrStringToPath, (XrInstance), instance, (const char *), pathString, (XrPath *), path) | 
| 211 | 	EXT_PROTO_XRRESULT_FUNC2(xrSuggestInteractionProfileBindings, (XrInstance), instance, (const XrInteractionProfileSuggestedBinding *), suggestedBindings) | 
| 212 | 	EXT_PROTO_XRRESULT_FUNC2(xrSyncActions, (XrSession), session, (const XrActionsSyncInfo *), syncInfo) | 
| 213 | 	EXT_PROTO_XRRESULT_FUNC3(xrWaitFrame, (XrSession), session, (const XrFrameWaitInfo *), frameWaitInfo, (XrFrameState *), frameState) | 
| 214 | 	EXT_PROTO_XRRESULT_FUNC2(xrWaitSwapchainImage, (XrSwapchain), swapchain, (const XrSwapchainImageWaitInfo *), waitInfo) | 
| 215 |  | 
| 216 | 	// instance | 
| 217 | 	bool create_instance(); | 
| 218 | 	bool get_system_info(); | 
| 219 | 	bool load_supported_view_configuration_types(); | 
| 220 | 	bool load_supported_environmental_blend_modes(); | 
| 221 | 	bool is_view_configuration_supported(XrViewConfigurationType p_configuration_type) const; | 
| 222 | 	bool load_supported_view_configuration_views(XrViewConfigurationType p_configuration_type); | 
| 223 | 	void destroy_instance(); | 
| 224 |  | 
| 225 | 	// session | 
| 226 | 	bool create_session(); | 
| 227 | 	bool load_supported_reference_spaces(); | 
| 228 | 	bool is_reference_space_supported(XrReferenceSpaceType p_reference_space); | 
| 229 | 	bool setup_spaces(); | 
| 230 | 	bool load_supported_swapchain_formats(); | 
| 231 | 	bool is_swapchain_format_supported(int64_t p_swapchain_format); | 
| 232 | 	bool create_swapchains(); | 
| 233 | 	void destroy_session(); | 
| 234 |  | 
| 235 | 	// swapchains | 
| 236 | 	bool create_swapchain(XrSwapchainUsageFlags p_usage_flags, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, XrSwapchain &r_swapchain, void **r_swapchain_graphics_data); | 
| 237 | 	bool acquire_image(OpenXRSwapChainInfo &p_swapchain); | 
| 238 | 	bool release_image(OpenXRSwapChainInfo &p_swapchain); | 
| 239 |  | 
| 240 | 	// action map | 
| 241 | 	struct Tracker { // Trackers represent tracked physical objects such as controllers, pucks, etc. | 
| 242 | 		String name; // Name for this tracker (i.e. "/user/hand/left") | 
| 243 | 		XrPath toplevel_path; // OpenXR XrPath for this tracker | 
| 244 | 		RID active_profile_rid; // RID of the active profile for this tracker | 
| 245 | 	}; | 
| 246 | 	RID_Owner<Tracker, true> tracker_owner; | 
| 247 | 	RID get_tracker_rid(XrPath p_path); | 
| 248 |  | 
| 249 | 	struct ActionSet { // Action sets define a set of actions that can be enabled together | 
| 250 | 		String name; // Name for this action set (i.e. "godot_action_set") | 
| 251 | 		bool is_attached; // If true our action set has been attached to the session and can no longer be modified | 
| 252 | 		XrActionSet handle; // OpenXR handle for this action set | 
| 253 | 	}; | 
| 254 | 	RID_Owner<ActionSet, true> action_set_owner; | 
| 255 |  | 
| 256 | 	struct ActionTracker { // Links and action to a tracker | 
| 257 | 		RID tracker_rid; // RID of the tracker | 
| 258 | 		XrSpace space; // Optional space for pose actions | 
| 259 | 		bool was_location_valid; // If true the last position we obtained was valid | 
| 260 | 	}; | 
| 261 |  | 
| 262 | 	struct Action { // Actions define the inputs and outputs in OpenXR | 
| 263 | 		RID action_set_rid; // RID of the action set this action belongs to | 
| 264 | 		String name; // Name for this action (i.e. "aim_pose") | 
| 265 | 		XrActionType action_type; // Type of action (bool, float, etc.) | 
| 266 | 		Vector<ActionTracker> trackers; // The trackers this action can be used with | 
| 267 | 		XrAction handle; // OpenXR handle for this action | 
| 268 | 	}; | 
| 269 | 	RID_Owner<Action, true> action_owner; | 
| 270 | 	RID get_action_rid(XrAction p_action); | 
| 271 |  | 
| 272 | 	struct InteractionProfile { // Interaction profiles define suggested bindings between the physical inputs on controller types and our actions | 
| 273 | 		String name; // Name of the interaction profile (i.e. "/interaction_profiles/valve/index_controller") | 
| 274 | 		XrPath path; // OpenXR path for this profile | 
| 275 | 		Vector<XrActionSuggestedBinding> bindings; // OpenXR action bindings | 
| 276 | 	}; | 
| 277 | 	RID_Owner<InteractionProfile, true> interaction_profile_owner; | 
| 278 | 	RID get_interaction_profile_rid(XrPath p_path); | 
| 279 | 	XrPath get_interaction_profile_path(RID p_interaction_profile); | 
| 280 |  | 
| 281 | 	// state changes | 
| 282 | 	bool poll_events(); | 
| 283 | 	bool on_state_idle(); | 
| 284 | 	bool on_state_ready(); | 
| 285 | 	bool on_state_synchronized(); | 
| 286 | 	bool on_state_visible(); | 
| 287 | 	bool on_state_focused(); | 
| 288 | 	bool on_state_stopping(); | 
| 289 | 	bool on_state_loss_pending(); | 
| 290 | 	bool on_state_exiting(); | 
| 291 |  | 
| 292 | 	// convenience | 
| 293 | 	void copy_string_to_char_buffer(const String p_string, char *p_buffer, int p_buffer_len); | 
| 294 |  | 
| 295 | public: | 
| 296 | 	XrInstance get_instance() const { return instance; }; | 
| 297 | 	XrSystemId get_system_id() const { return system_id; }; | 
| 298 | 	XrSession get_session() const { return session; }; | 
| 299 | 	String get_runtime_name() const { return runtime_name; }; | 
| 300 | 	String get_runtime_version() const { return runtime_version; }; | 
| 301 |  | 
| 302 | 	// helper method to convert an XrPosef to a Transform3D | 
| 303 | 	Transform3D transform_from_pose(const XrPosef &p_pose); | 
| 304 |  | 
| 305 | 	// helper method to get a valid Transform3D from an openxr space location | 
| 306 | 	XRPose::TrackingConfidence transform_from_location(const XrSpaceLocation &p_location, Transform3D &r_transform); | 
| 307 | 	XRPose::TrackingConfidence transform_from_location(const XrHandJointLocationEXT &p_location, Transform3D &r_transform); | 
| 308 | 	void parse_velocities(const XrSpaceVelocity &p_velocity, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity); | 
| 309 |  | 
| 310 | 	bool xr_result(XrResult result, const char *format, Array args = Array()) const; | 
| 311 | 	bool is_top_level_path_supported(const String &p_toplevel_path); | 
| 312 | 	bool is_interaction_profile_supported(const String &p_ip_path); | 
| 313 | 	bool interaction_profile_supports_io_path(const String &p_ip_path, const String &p_io_path); | 
| 314 |  | 
| 315 | 	static bool openxr_is_enabled(bool p_check_run_in_editor = true); | 
| 316 | 	_FORCE_INLINE_ static OpenXRAPI *get_singleton() { return singleton; } | 
| 317 |  | 
| 318 | 	XrResult try_get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr); | 
| 319 | 	XrResult get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr); | 
| 320 | 	String get_error_string(XrResult result); | 
| 321 | 	String get_swapchain_format_name(int64_t p_swapchain_format) const; | 
| 322 |  | 
| 323 | 	void set_xr_interface(OpenXRInterface *p_xr_interface); | 
| 324 | 	static void register_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper); | 
| 325 | 	static void unregister_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper); | 
| 326 | 	static void register_extension_metadata(); | 
| 327 | 	static void cleanup_extension_wrappers(); | 
| 328 |  | 
| 329 | 	void set_form_factor(XrFormFactor p_form_factor); | 
| 330 | 	XrFormFactor get_form_factor() const { return form_factor; } | 
| 331 |  | 
| 332 | 	void set_view_configuration(XrViewConfigurationType p_view_configuration); | 
| 333 | 	XrViewConfigurationType get_view_configuration() const { return view_configuration; } | 
| 334 |  | 
| 335 | 	void set_reference_space(XrReferenceSpaceType p_reference_space); | 
| 336 | 	XrReferenceSpaceType get_reference_space() const { return reference_space; } | 
| 337 |  | 
| 338 | 	void set_submit_depth_buffer(bool p_submit_depth_buffer); | 
| 339 | 	bool get_submit_depth_buffer() const { return submit_depth_buffer; } | 
| 340 |  | 
| 341 | 	bool is_initialized(); | 
| 342 | 	bool is_running(); | 
| 343 | 	bool initialize(const String &p_rendering_driver); | 
| 344 | 	bool initialize_session(); | 
| 345 | 	void finish(); | 
| 346 |  | 
| 347 | 	XrSpace get_play_space() const { return play_space; } | 
| 348 | 	XrTime get_next_frame_time() { return frame_state.predictedDisplayTime + frame_state.predictedDisplayPeriod; } | 
| 349 | 	bool can_render() { return instance != XR_NULL_HANDLE && session != XR_NULL_HANDLE && running && view_pose_valid && frame_state.shouldRender; } | 
| 350 |  | 
| 351 | 	Size2 get_recommended_target_size(); | 
| 352 | 	XRPose::TrackingConfidence get_head_center(Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity); | 
| 353 | 	bool get_view_transform(uint32_t p_view, Transform3D &r_transform); | 
| 354 | 	bool get_view_projection(uint32_t p_view, double p_z_near, double p_z_far, Projection &p_camera_matrix); | 
| 355 | 	bool process(); | 
| 356 |  | 
| 357 | 	void pre_render(); | 
| 358 | 	bool pre_draw_viewport(RID p_render_target); | 
| 359 | 	RID get_color_texture(); | 
| 360 | 	RID get_depth_texture(); | 
| 361 | 	void post_draw_viewport(RID p_render_target); | 
| 362 | 	void end_frame(); | 
| 363 |  | 
| 364 | 	// Display refresh rate | 
| 365 | 	float get_display_refresh_rate() const; | 
| 366 | 	void set_display_refresh_rate(float p_refresh_rate); | 
| 367 | 	Array get_available_display_refresh_rates() const; | 
| 368 |  | 
| 369 | 	// Render Target size multiplier | 
| 370 | 	double get_render_target_size_multiplier() const; | 
| 371 | 	void set_render_target_size_multiplier(double multiplier); | 
| 372 |  | 
| 373 | 	// action map | 
| 374 | 	String get_default_action_map_resource_name(); | 
| 375 |  | 
| 376 | 	RID tracker_create(const String p_name); | 
| 377 | 	String tracker_get_name(RID p_tracker); | 
| 378 | 	void tracker_check_profile(RID p_tracker, XrSession p_session = XR_NULL_HANDLE); | 
| 379 | 	void tracker_free(RID p_tracker); | 
| 380 |  | 
| 381 | 	RID action_set_create(const String p_name, const String p_localized_name, const int p_priority); | 
| 382 | 	String action_set_get_name(RID p_action_set); | 
| 383 | 	bool attach_action_sets(const Vector<RID> &p_action_sets); | 
| 384 | 	void action_set_free(RID p_action_set); | 
| 385 |  | 
| 386 | 	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); | 
| 387 | 	String action_get_name(RID p_action); | 
| 388 | 	void action_free(RID p_action); | 
| 389 |  | 
| 390 | 	RID interaction_profile_create(const String p_name); | 
| 391 | 	String interaction_profile_get_name(RID p_interaction_profile); | 
| 392 | 	void interaction_profile_clear_bindings(RID p_interaction_profile); | 
| 393 | 	bool interaction_profile_add_binding(RID p_interaction_profile, RID p_action, const String p_path); | 
| 394 | 	bool interaction_profile_suggest_bindings(RID p_interaction_profile); | 
| 395 | 	void interaction_profile_free(RID p_interaction_profile); | 
| 396 |  | 
| 397 | 	bool sync_action_sets(const Vector<RID> p_active_sets); | 
| 398 | 	bool get_action_bool(RID p_action, RID p_tracker); | 
| 399 | 	float get_action_float(RID p_action, RID p_tracker); | 
| 400 | 	Vector2 get_action_vector2(RID p_action, RID p_tracker); | 
| 401 | 	XRPose::TrackingConfidence get_action_pose(RID p_action, RID p_tracker, Transform3D &r_transform, Vector3 &r_linear_velocity, Vector3 &r_angular_velocity); | 
| 402 | 	bool trigger_haptic_pulse(RID p_action, RID p_tracker, float p_frequency, float p_amplitude, XrDuration p_duration_ns); | 
| 403 |  | 
| 404 | 	void register_composition_layer_provider(OpenXRCompositionLayerProvider *provider); | 
| 405 | 	void unregister_composition_layer_provider(OpenXRCompositionLayerProvider *provider); | 
| 406 |  | 
| 407 | 	const XrEnvironmentBlendMode *get_supported_environment_blend_modes(uint32_t &count); | 
| 408 | 	bool is_environment_blend_mode_supported(XrEnvironmentBlendMode p_blend_mode) const; | 
| 409 | 	bool set_environment_blend_mode(XrEnvironmentBlendMode p_blend_mode); | 
| 410 | 	XrEnvironmentBlendMode get_environment_blend_mode() const { return environment_blend_mode; } | 
| 411 |  | 
| 412 | 	OpenXRAPI(); | 
| 413 | 	~OpenXRAPI(); | 
| 414 | }; | 
| 415 |  | 
| 416 | #endif // OPENXR_API_H | 
| 417 |  |