2023-01-05 13:25:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  openxr_api.cpp                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                         This file is part of:                          */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                             GODOT ENGINE                               */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                        https://godotengine.org                         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Permission is hereby granted, free of charge, to any person obtaining  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* a copy of this software and associated documentation files (the        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* "Software"), to deal in the Software without restriction, including    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* without limitation the rights to use, copy, modify, merge, publish,    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* distribute, sublicense, and/or sell copies of the Software, and to     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* permit persons to whom the Software is furnished to do so, subject to  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* the following conditions:                                              */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* The above copyright notice and this permission notice shall be         */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* included in all copies or substantial portions of the Software.        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**************************************************************************/  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "openxr_api.h" 
  
						 
					
						
							
								
									
										
										
										
											2023-06-13 16:56:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "openxr_interface.h" 
  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  "openxr_util.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "core/config/engine.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "core/config/project_settings.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "core/os/memory.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "core/version.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "openxr_platform_inc.h" 
  
						 
					
						
							
								
									
										
										
										
											2022-10-22 20:29:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# ifdef VULKAN_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2023-12-27 14:49:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/platform/openxr_vulkan_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 09:37:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef METAL_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "extensions/platform/openxr_metal_extension.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-19 00:02:47 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# if defined(GLES3_ENABLED) && !defined(MACOS_ENABLED) 
  
						 
					
						
							
								
									
										
										
										
											2023-12-27 14:49:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/platform/openxr_opengl_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2022-10-22 20:29:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-07 18:29:52 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef D3D12_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "extensions/platform/openxr_d3d12_extension.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_composition_layer_depth_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_debug_utils_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_eye_gaze_interaction.h" 
  
						 
					
						
							
								
									
										
										
										
											2022-10-10 18:51:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_fb_display_refresh_rate_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_fb_foveation_extension.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "extensions/openxr_fb_update_swapchain_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2024-02-18 20:06:36 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "extensions/openxr_hand_tracking_extension.h" 
  
						 
					
						
							
								
									
										
										
										
											2022-03-09 19:09:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifndef DISABLE_DEPRECATED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "extensions/openxr_extension_wrapper_extension.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif  // DISABLE_DEPRECATED
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-13 16:56:21 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef ANDROID_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define OPENXR_LOADER_NAME "libopenxr_loader.so" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								////////////////////////////////////
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// OpenXRAPI::OpenXRSwapChainInfo
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Vector < OpenXRAPI : : OpenXRSwapChainInfo >  OpenXRAPI : : OpenXRSwapChainInfo : : free_queue ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : OpenXRSwapChainInfo : : create ( XrSwapchainCreateFlags  p_create_flags ,  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 )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( openxr_api ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSession  xr_session  =  openxr_api - > get_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( xr_session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRGraphicsExtensionWrapper  * xr_graphics_extension  =  openxr_api - > get_graphics_extension ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( xr_graphics_extension ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We already have a swapchain?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( swapchain  ! =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  openxr_api - > get_registered_extension_wrappers ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_swapchain_create_info_and_get_next_pointer ( next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSwapchainCreateInfo  swapchain_create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SWAPCHAIN_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										next_pointer ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_create_flags ,  // createFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_usage_flags ,  // usageFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_swapchain_format ,  // format
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_sample_count ,  // sampleCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_width ,  // width
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_height ,  // height
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										1 ,  // faceCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_array_size ,  // arraySize
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										1  // mipCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSwapchain  new_swapchain ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  =  openxr_api - > xrCreateSwapchain ( xr_session ,  & swapchain_create_info ,  & new_swapchain ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get swapchain [ " ,  openxr_api - > get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! xr_graphics_extension - > get_swapchain_image_data ( new_swapchain ,  p_swapchain_format ,  p_width ,  p_height ,  p_sample_count ,  p_array_size ,  & swapchain_graphics_data ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_api - > xrDestroySwapchain ( new_swapchain ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									swapchain  =  new_swapchain ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : OpenXRSwapChainInfo : : queue_free ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( image_acquired )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										release ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( swapchain  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										free_queue . push_back ( * this ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swapchain_graphics_data  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swapchain  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : OpenXRSwapChainInfo : : free_queued ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRAPI : : OpenXRSwapChainInfo  & swapchain_info  :  free_queue )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swapchain_info . free ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									free_queue . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : OpenXRSwapChainInfo : : free ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( image_acquired )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										release ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( openxr_api - > get_graphics_extension ( )  & &  swapchain_graphics_data  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_api - > get_graphics_extension ( ) - > cleanup_swapchain_graphics_data ( & swapchain_graphics_data ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( swapchain  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_api - > xrDestroySwapchain ( swapchain ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										swapchain  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : OpenXRSwapChainInfo : : acquire ( bool  & p_should_render )  {  
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( image_acquired ,  true ) ;  // This was not released when it should be, error out and reuse...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( openxr_api ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! skip_acquire_swapchain )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrSwapchainImageAcquireInfo  swapchain_image_acquire_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  openxr_api - > xrAcquireSwapchainImage ( swapchain ,  & swapchain_image_acquire_info ,  & image_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! XR_UNQUALIFIED_SUCCESS ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Make sure end_frame knows we need to submit an empty frame
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											p_should_render  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// Unexpected failure, log this!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												print_line ( " OpenXR: failed to acquire swapchain image [ " ,  openxr_api - > get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// In this scenario we silently fail, the XR runtime is simply not ready yet to acquire the swapchain.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSwapchainImageWaitInfo  swapchain_image_wait_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										1000000000  // 1s timeout in nanoseconds
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Wait for a maximum of 10 seconds before calling it a critical failure...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  retry  =  0 ;  retry  <  10 ;  retry + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  openxr_api - > xrWaitSwapchainImage ( swapchain ,  & swapchain_image_wait_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( result  ! =  XR_TIMEOUT_EXPIRED )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										WARN_PRINT ( " OpenXR: timed out waiting for swapchain image. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! XR_UNQUALIFIED_SUCCESS ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Make sure end_frame knows we need to submit an empty frame
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_should_render  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Unexpected failure, log this!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR: failed to wait for swapchain image [ " ,  openxr_api - > get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											WARN_PRINT ( " OpenXR: couldn't to wait for swapchain but not a complete error [ "  +  openxr_api - > get_error_string ( result )  +  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// Make sure to skip trying to acquire the swapchain image in the next frame
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											skip_acquire_swapchain  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										skip_acquire_swapchain  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									image_acquired  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : OpenXRSwapChainInfo : : release ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! image_acquired )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Already released or never acquired.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									image_acquired  =  false ;  // Regardless if we succeed or not, consider this released.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( openxr_api ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSwapchainImageReleaseInfo  swapchain_image_release_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  openxr_api - > xrReleaseSwapchainImage ( swapchain ,  & swapchain_image_release_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to release swapchain image! [ " ,  openxr_api - > get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								RID  OpenXRAPI : : OpenXRSwapChainInfo : : get_image ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( image_acquired  & &  openxr_api  & &  openxr_api - > get_graphics_extension ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  OpenXRAPI : : get_singleton ( ) - > get_graphics_extension ( ) - > get_texture ( swapchain_graphics_data ,  image_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 10:34:48 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : OpenXRSwapChainInfo : : get_density_map ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( image_acquired  & &  openxr_api  & &  openxr_api - > get_graphics_extension ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  openxr_api - > get_graphics_extension ( ) - > get_density_map ( swapchain_graphics_data ,  image_index ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								////////////////////////////////////
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// OpenXRAPI
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								OpenXRAPI  * OpenXRAPI : : singleton  =  nullptr ;  
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Vector < OpenXRExtensionWrapper  * >  OpenXRAPI : : registered_extension_wrappers ;  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-17 10:24:47 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : openxr_is_enabled ( bool  p_check_run_in_editor )  {  
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( XRServer : : get_xr_mode ( )  = =  XRServer : : XRMODE_DEFAULT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( Engine : : get_singleton ( ) - > is_editor_hint ( )  & &  p_check_run_in_editor )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-11 14:31:54 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// For now, don't start OpenXR when the editor starts up. In the future, this may change
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// if we want to integrate more XR features into the editor experience.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-24 20:43:30 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  GLOBAL_GET ( " xr/openxr/enabled " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-24 20:43:30 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRServer : : get_xr_mode ( )  = =  XRServer : : XRMODE_ON ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								String  OpenXRAPI : : get_default_action_map_resource_name ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									String  name  =  GLOBAL_GET ( " xr/openxr/default_action_map " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 20:03:16 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : get_error_string ( XrResult  p_result )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_SUCCEEDED ( p_result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  String ( " Succeeded " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( instance  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 20:03:16 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Array  args  =  {  Variant ( p_result )  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  String ( " Error code {0} " ) . format ( args ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									char  resultString [ XR_MAX_RESULT_STRING_SIZE ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 20:03:16 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrResultToString ( instance ,  p_result ,  resultString ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_ENUM_SWITCH ( XrResult ,  p_result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  String ( resultString ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								String  OpenXRAPI : : get_swapchain_format_name ( int64_t  p_swapchain_format )  const  {  
						 
					
						
							
								
									
										
										
										
											2022-03-31 14:06:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// This is rendering engine dependent...
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( graphics_extension )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  graphics_extension - > get_swapchain_format_name ( p_swapchain_format ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  String ( " Swapchain format  " )  +  String : : num_int64 ( int64_t ( p_swapchain_format ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_object_name ( XrObjectType  p_object_type ,  uint64_t  p_object_handle ,  const  String  & p_object_name )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDebugUtilsExtension  * debug_utils  =  OpenXRDebugUtilsExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! debug_utils  | |  ! debug_utils - > get_active ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Not enabled/active? Ignore.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									debug_utils - > set_object_name ( p_object_type ,  p_object_handle ,  p_object_name . utf8 ( ) . get_data ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : begin_debug_label_region ( const  String  & p_label_name )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDebugUtilsExtension  * debug_utils  =  OpenXRDebugUtilsExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! debug_utils  | |  ! debug_utils - > get_active ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Not enabled/active? Ignore.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									debug_utils - > begin_debug_label_region ( p_label_name . utf8 ( ) . get_data ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : end_debug_label_region ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDebugUtilsExtension  * debug_utils  =  OpenXRDebugUtilsExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! debug_utils  | |  ! debug_utils - > get_active ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Not enabled/active? Ignore.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									debug_utils - > end_debug_label_region ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : insert_debug_label ( const  String  & p_label_name )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDebugUtilsExtension  * debug_utils  =  OpenXRDebugUtilsExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! debug_utils  | |  ! debug_utils - > get_active ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Not enabled/active? Ignore.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									debug_utils - > insert_debug_label ( p_label_name . utf8 ( ) . get_data ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_layer_properties ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// This queries additional layers that are available and can be initialized when we create our OpenXR instance
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! layer_properties . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// already retrieved this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Note, instance is not yet setup so we can't use get_error_string to retrieve our error
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_layer_properties  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateApiLayerProperties ( 0 ,  & num_layer_properties ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate number of api layer properties " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									layer_properties . resize ( num_layer_properties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( XrApiLayerProperties  & layer  :  layer_properties )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										layer . type  =  XR_TYPE_API_LAYER_PROPERTIES ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										layer . next  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateApiLayerProperties ( num_layer_properties ,  & num_layer_properties ,  layer_properties . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate api layer properties " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrApiLayerProperties  & layer  :  layer_properties )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: Found OpenXR layer %s. " ,  layer . layerName ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_extensions ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// This queries supported extensions that are available and can be initialized when we create our OpenXR instance
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! supported_extensions . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// already retrieved this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Note, instance is not yet setup so we can't use get_error_string to retrieve our error
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_supported_extensions  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateInstanceExtensionProperties ( nullptr ,  0 ,  & num_supported_extensions ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate number of extension properties " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_extensions . resize ( num_supported_extensions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// set our types
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( XrExtensionProperties  & extension  :  supported_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										extension . type  =  XR_TYPE_EXTENSION_PROPERTIES ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										extension . next  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateInstanceExtensionProperties ( nullptr ,  num_supported_extensions ,  & num_supported_extensions ,  supported_extensions . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate extension properties " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrExtensionProperties  & extension  :  supported_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: Found OpenXR extension %s. " ,  extension . extensionName ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-13 15:04:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_extension_supported ( const  String  & p_extension )  const  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrExtensionProperties  & extension  :  supported_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( extension . extensionName  = =  p_extension )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_extension_enabled ( const  String  & p_extension )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CharString  extension  =  p_extension . ascii ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 13:20:12 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  enabled_extensions . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( strcmp ( enabled_extensions [ i ] . ptr ( ) ,  extension . ptr ( ) )  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 13:20:12 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_top_level_path_supported ( const  String  & p_toplevel_path )  {  
						 
					
						
							
								
									
										
										
										
											2023-08-26 17:39:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									String  required_extension  =  OpenXRInteractionProfileMetadata : : get_singleton ( ) - > get_top_level_extension ( p_toplevel_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If unsupported is returned we likely have a misspelled interaction profile path in our action map. Always output that as an error.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-16 21:14:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( required_extension  = =  XR_PATH_UNSUPPORTED_NAME ,  false ,  " OpenXR: Unsupported toplevel path  "  +  p_toplevel_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( required_extension  = =  " " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// no extension needed, core top level are always "supported", they just won't be used if not really supported
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_extension_enabled ( required_extension ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// It is very likely we have top level paths for which the extension is not available so don't flood the logs with unnecessary spam.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( " OpenXR: Top level path  "  +  p_toplevel_path  +  "  requires extension  "  +  required_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_interaction_profile_supported ( const  String  & p_ip_path )  {  
						 
					
						
							
								
									
										
										
										
											2023-08-26 17:39:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									String  required_extension  =  OpenXRInteractionProfileMetadata : : get_singleton ( ) - > get_interaction_profile_extension ( p_ip_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If unsupported is returned we likely have a misspelled interaction profile path in our action map. Always output that as an error.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( required_extension  = =  XR_PATH_UNSUPPORTED_NAME ,  false ,  " OpenXR: Unsupported interaction profile  "  +  p_ip_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( required_extension  = =  " " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// no extension needed, core interaction profiles are always "supported", they just won't be used if not really supported
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_extension_enabled ( required_extension ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// It is very likely we have interaction profiles for which the extension is not available so don't flood the logs with unnecessary spam.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( " OpenXR: Interaction profile  "  +  p_ip_path  +  "  requires extension  "  +  required_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : interaction_profile_supports_io_path ( const  String  & p_ip_path ,  const  String  & p_io_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_interaction_profile_supported ( p_ip_path ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-26 17:39:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  OpenXRInteractionProfileMetadata : : IOPath  * io_path  =  OpenXRInteractionProfileMetadata : : get_singleton ( ) - > get_io_path ( p_ip_path ,  p_io_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-26 17:39:43 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// If the io_path is not part of our metadata we've likely got a misspelled name or a bad action map, report
 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V_MSG ( io_path ,  false ,  " OpenXR: Unsupported io path  "  +  String ( p_ip_path )  +  String ( p_io_path ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( io_path - > openxr_extension_name  = =  " " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// no extension needed, core io paths are always "supported", they just won't be used if not really supported
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_extension_enabled ( io_path - > openxr_extension_name ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// It is very likely we have io paths for which the extension is not available so don't flood the logs with unnecessary spam.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( " OpenXR: IO path  "  +  String ( p_ip_path )  +  String ( p_io_path )  +  "  requires extension  "  +  io_path - > openxr_extension_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 13:20:12 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : copy_string_to_char_buffer ( const  String  & p_string ,  char  * p_buffer ,  int  p_buffer_len )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									CharString  char_string  =  p_string . utf8 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  len  =  char_string . length ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( len  <  p_buffer_len  -  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// was having weird CI issues with strcpy so....
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										memcpy ( p_buffer ,  char_string . get_data ( ) ,  len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_buffer [ len ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										memcpy ( p_buffer ,  char_string . get_data ( ) ,  p_buffer_len  -  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_buffer [ p_buffer_len  -  1 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								PackedStringArray  OpenXRAPI : : get_all_requested_extensions ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This returns all extensions we will request regardless of whether they are available.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This is mostly used by the editor to filter features not enabled through project settings.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PackedStringArray  requested_extensions ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  HashMap < String ,  bool  * >  & wrapper_request_extensions  =  wrapper - > get_requested_extensions ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( const  KeyValue < String ,  bool  * >  & requested_extension  :  wrapper_request_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! requested_extensions . has ( requested_extension . key ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												requested_extensions . push_back ( requested_extension . key ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  requested_extensions ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : create_instance ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Create our OpenXR instance, this will query any registered extension wrappers for extensions we need to enable.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// We can request an extension multiple times if there are dependencies
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  RequestExtension  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										String  name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bool  * enabled ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Find all extensions we wish to enable.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector < RequestExtension >  requested_extensions ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  HashMap < String ,  bool  * >  & wrapper_request_extensions  =  wrapper - > get_requested_extensions ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-07 14:39:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( const  KeyValue < String ,  bool  * >  & requested_extension  :  wrapper_request_extensions )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											requested_extensions . push_back ( {  requested_extension . key ,  requested_extension . value  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-07 14:39:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Check which extensions are supported.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									enabled_extensions . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-13 15:04:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( RequestExtension  & requested_extension  :  requested_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! is_extension_supported ( requested_extension . name ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( requested_extension . enabled  = =  nullptr )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-11 23:01:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// Null means this is a mandatory extension so we fail.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ERR_FAIL_V_MSG ( false ,  String ( " OpenXR: OpenXR Runtime does not support  " )  +  requested_extension . name  +  String ( "  extension! " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-07 14:39:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// Set this extension as not supported.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												* requested_extension . enabled  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( requested_extension . enabled  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// Set this extension as supported.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												* requested_extension . enabled  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// And record that we want to enable it (dependent extensions may be requested multiple times).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											CharString  ext_name  =  requested_extension . name . ascii ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! enabled_extensions . has ( ext_name ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												enabled_extensions . push_back ( ext_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-13 15:04:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Vector < const  char  * >  extension_ptrs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  enabled_extensions . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-08 16:29:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_verbose ( String ( " OpenXR: Enabling extension  " )  +  String ( enabled_extensions [ i ] . get_data ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-13 15:04:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										extension_ptrs . push_back ( enabled_extensions [ i ] . get_data ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-07-22 09:19:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// We explicitly set the version to 1.0.48 in order to workaround a bug (see #108850) in Meta's runtime.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Once that is fixed, restore this to using XR_API_VERSION_1_0, which is the version associated with the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// OpenXR headers that we're using.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrVersion  openxr_version  =  XR_MAKE_VERSION ( 1 ,  0 ,  48 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Create our OpenXR instance
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrApplicationInfo  application_info { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										" Godot Engine " ,  // applicationName, if we're running a game we'll update this down below.
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										1 ,  // applicationVersion, we don't currently have this
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										" Godot Engine " ,  // engineName
 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-03 22:27:29 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										GODOT_VERSION_MAJOR  *  10000  +  GODOT_VERSION_MINOR  *  100  +  GODOT_VERSION_PATCH ,  // engineVersion 4.0 -> 40000, 4.0.1 -> 40001, 4.1 -> 40100, etc.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-22 09:19:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										openxr_version ,  // apiVersion
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-29 16:39:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_instance_create_info_and_get_next_pointer ( next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrInstanceCreateInfo  instance_create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_INSTANCE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-29 16:39:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										next_pointer ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										0 ,  // createFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										application_info ,  // applicationInfo
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // enabledApiLayerCount, need to find out if we need support for this?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // enabledApiLayerNames
 
							 
						 
					
						
							
								
									
										
										
										
											2022-05-13 15:04:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										uint32_t ( extension_ptrs . size ( ) ) ,  // enabledExtensionCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										extension_ptrs . ptr ( )  // enabledExtensionNames
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-20 10:24:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Get our project name
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									String  project_name  =  GLOBAL_GET ( " application/config/name " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! project_name . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										copy_string_to_char_buffer ( project_name ,  instance_create_info . applicationInfo . applicationName ,  XR_MAX_APPLICATION_NAME_SIZE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrCreateInstance ( & instance_create_info ,  & instance ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-12 20:25:43 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " Failed to create XR instance [ "  +  get_error_string ( result )  +  " ]. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// from this point on we can use get_error_string to get more info about our errors...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrInstanceProperties  instanceProps  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_INSTANCE_PROPERTIES ,  // type;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // runtimeVersion, from here will be set by our get call
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" "  // runtimeName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetInstanceProperties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									result  =  xrGetInstanceProperties ( instance ,  & instanceProps ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// not fatal probably
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get XR instance properties [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-13 12:26:10 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										runtime_name  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										runtime_version  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-13 12:26:10 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										runtime_name  =  instanceProps . runtimeName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										runtime_version  =  OpenXRUtil : : make_xr_version_string ( instanceProps . runtimeVersion ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Running on OpenXR runtime:  " ,  runtime_name ,  "   " ,  runtime_version ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_instance_created ( instance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : get_system_info ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Retrieve basic OpenXR system info based on the form factor we desire
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Retrieve the system for our form factor, fails if form factor is not available
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSystemGetInfo  system_get_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SYSTEM_GET_INFO ,  // type;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										form_factor  // formFactor
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetSystem ( instance ,  & system_get_info ,  & system_id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get system for our form factor [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// obtain info about our system, writing this out completely to make CI on Linux happy..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_system_properties_and_get_next_pointer ( next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSystemProperties  system_properties  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SYSTEM_PROPERTIES ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										next_pointer ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // systemId, from here will be set by our get call
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // vendorId
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" " ,  // systemName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0 ,  // maxSwapchainImageHeight
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0 ,  // maxSwapchainImageWidth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0 ,  // maxLayerCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  // graphicsProperties
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												false ,  // orientationTracking
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												false  // positionTracking
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  // trackingProperties
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  =  xrGetSystemProperties ( instance ,  system_id ,  & system_properties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get System properties [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// remember this state, we'll use it later
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									system_name  =  String ( system_properties . systemName ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									vendor_id  =  system_properties . vendorId ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									graphics_properties  =  system_properties . graphicsProperties ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									tracking_properties  =  system_properties . trackingProperties ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_view_configuration_types ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-31 14:06:10 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// This queries the supported configuration types, likely there will only be one choosing between Mono (phone AR) and Stereo (HMDs)
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_view_configuration_types . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_view_configuration_types  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateViewConfigurations ( instance ,  system_id ,  0 ,  & num_view_configuration_types ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get view configuration count [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_view_configuration_types . resize ( num_view_configuration_types ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateViewConfigurations ( instance ,  system_id ,  num_view_configuration_types ,  & num_view_configuration_types ,  supported_view_configuration_types . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerateview configurations " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( num_view_configuration_types  = =  0 ,  false ,  " OpenXR: Failed to enumerateview configurations " ) ;  // JIC there should be at least 1!
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrViewConfigurationType  & view_configuration_type  :  supported_view_configuration_types )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: Found supported view configuration %s. " ,  OpenXRUtil : : get_view_configuration_name ( view_configuration_type ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Check value we loaded at startup...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_view_configuration_supported ( view_configuration ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: %s isn't supported, defaulting to %s. " ,  OpenXRUtil : : get_view_configuration_name ( view_configuration ) ,  OpenXRUtil : : get_view_configuration_name ( supported_view_configuration_types [ 0 ] ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										view_configuration  =  supported_view_configuration_types [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_environmental_blend_modes ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This queries the supported environmental blend modes.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_environment_blend_modes . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_supported_environment_blend_modes  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateEnvironmentBlendModes ( instance ,  system_id ,  view_configuration ,  0 ,  & num_supported_environment_blend_modes ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get supported environmental blend mode count [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_environment_blend_modes . resize ( num_supported_environment_blend_modes ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateEnvironmentBlendModes ( instance ,  system_id ,  view_configuration ,  num_supported_environment_blend_modes ,  & num_supported_environment_blend_modes ,  supported_environment_blend_modes . ptrw ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate environmental blend modes " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( num_supported_environment_blend_modes  = =  0 ,  false ,  " OpenXR: Failed to enumerate environmental blend modes " ) ;  // JIC there should be at least 1!
 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrEnvironmentBlendMode  & supported_environment_blend_mode  :  supported_environment_blend_modes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: Found environmental blend mode %s. " ,  OpenXRUtil : : get_environment_blend_mode_name ( supported_environment_blend_mode ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_view_configuration_supported ( XrViewConfigurationType  p_configuration_type )  const  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_view_configuration_types . has ( p_configuration_type ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_view_configuration_views ( XrViewConfigurationType  p_configuration_type )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// This loads our view configuration for each view so for a stereo HMD, we'll get two entries (that are likely identical)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The returned data supplies us with the recommended render target size
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_view_configuration_supported ( p_configuration_type ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: View configuration  " ,  OpenXRUtil : : get_view_configuration_name ( view_configuration ) ,  "  is not supported. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! view_configuration_views . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// free previous results
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										view_configuration_views . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  view_count  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateViewConfigurationViews ( instance ,  system_id ,  p_configuration_type ,  0 ,  & view_count ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get view configuration count [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									view_configuration_views . resize ( view_count ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( XrViewConfigurationView  & view_configuration_view  :  view_configuration_views )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										view_configuration_view . type  =  XR_TYPE_VIEW_CONFIGURATION_VIEW ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										view_configuration_view . next  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateViewConfigurationViews ( instance ,  system_id ,  p_configuration_type ,  view_count ,  & view_count ,  view_configuration_views . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate view configurations " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrViewConfigurationView  & view_configuration_view  :  view_configuration_views )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_verbose ( " OpenXR: Found supported view configuration view " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_verbose ( String ( "  - width:  " )  +  itos ( view_configuration_view . maxImageRectWidth ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( "  - height:  " )  +  itos ( view_configuration_view . maxImageRectHeight ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( "  - sample count:  " )  +  itos ( view_configuration_view . maxSwapchainSampleCount ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( "  - recommended render width:  " )  +  itos ( view_configuration_view . recommendedImageRectWidth ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( "  - recommended render height:  " )  +  itos ( view_configuration_view . recommendedImageRectHeight ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( "  - recommended render sample count:  " )  +  itos ( view_configuration_view . recommendedSwapchainSampleCount ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : destroy_instance ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									view_configuration_views . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									supported_view_configuration_types . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									supported_environment_blend_modes . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( instance  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											wrapper - > on_instance_destroyed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroyInstance ( instance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										instance  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enabled_extensions . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-15 16:57:42 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( graphics_extension  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										unregister_extension_wrapper ( graphics_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										memdelete ( graphics_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										graphics_extension  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : create_session ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  ! =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_session_create_and_get_next_pointer ( next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSessionCreateInfo  session_create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SESSION_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										next_pointer ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // createFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										system_id  // systemId
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrCreateSession ( instance ,  & session_create_info ,  & session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to create session [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_object_name ( XR_OBJECT_TYPE_SESSION ,  uint64_t ( session ) ,  " Main Godot OpenXR Session " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									begin_debug_label_region ( " Godot session active " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_session_created ( session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-07-19 16:20:01 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Check our environment blend mode. This needs to happen after we call `on_session_created()`
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// on the extension wrappers, so they can emulate alpha blend mode.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! set_environment_blend_mode ( environment_blend_mode ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( " OpenXR:  " )  +  OpenXRUtil : : get_environment_blend_mode_name ( environment_blend_mode )  +  String ( "  isn't supported, defaulting to  " )  +  OpenXRUtil : : get_environment_blend_mode_name ( supported_environment_blend_modes [ 0 ] ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										set_environment_blend_mode ( supported_environment_blend_modes [ 0 ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_reference_spaces ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// loads the supported reference spaces for our OpenXR session
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_reference_spaces . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_reference_spaces  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateReferenceSpaces ( session ,  0 ,  & num_reference_spaces ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get reference space count [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_reference_spaces . resize ( num_reference_spaces ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateReferenceSpaces ( session ,  num_reference_spaces ,  & num_reference_spaces ,  supported_reference_spaces . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate reference spaces " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( num_reference_spaces  = =  0 ,  false ,  " OpenXR: Failed to enumerate reference spaces " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  XrReferenceSpaceType  & supported_reference_space  :  supported_reference_spaces )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( vformat ( " OpenXR: Found supported reference space %s. " ,  OpenXRUtil : : get_reference_space_name ( supported_reference_space ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_reference_space_supported ( XrReferenceSpaceType  p_reference_space )  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_reference_spaces . has ( p_reference_space ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : setup_play_space ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrPosef  identityPose  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0 ,  1.0  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrReferenceSpaceType  new_reference_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpace  new_play_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  will_emulate_local_floor  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( custom_play_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										new_play_space  =  custom_play_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// We use this to mark custom reference spaces.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										new_reference_space  =  XR_REFERENCE_SPACE_TYPE_MAX_ENUM ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( is_reference_space_supported ( requested_reference_space ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										new_reference_space  =  requested_reference_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( requested_reference_space  = =  XR_REFERENCE_SPACE_TYPE_LOCAL_FLOOR_EXT  & &  is_reference_space_supported ( XR_REFERENCE_SPACE_TYPE_STAGE ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( " OpenXR: LOCAL_FLOOR space isn't supported, emulating using STAGE and LOCAL spaces. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										new_reference_space  =  XR_REFERENCE_SPACE_TYPE_LOCAL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										will_emulate_local_floor  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( local_floor_emulation . local_space  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XrReferenceSpaceCreateInfo  create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XR_TYPE_REFERENCE_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XR_REFERENCE_SPACE_TYPE_LOCAL ,  // referenceSpaceType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												identityPose ,  // poseInReferenceSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XrResult  result  =  xrCreateReferenceSpace ( session ,  & create_info ,  & local_floor_emulation . local_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												print_line ( " OpenXR: Failed to create LOCAL space in order to emulate LOCAL_FLOOR [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												will_emulate_local_floor  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											set_object_name ( XR_OBJECT_TYPE_SPACE ,  uint64_t ( local_floor_emulation . local_space ) ,  " Emulation local space " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( local_floor_emulation . stage_space  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XrReferenceSpaceCreateInfo  create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XR_TYPE_REFERENCE_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XR_REFERENCE_SPACE_TYPE_STAGE ,  // referenceSpaceType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												identityPose ,  // poseInReferenceSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XrResult  result  =  xrCreateReferenceSpace ( session ,  & create_info ,  & local_floor_emulation . stage_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												print_line ( " OpenXR: Failed to create STAGE space in order to emulate LOCAL_FLOOR [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												will_emulate_local_floor  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											set_object_name ( XR_OBJECT_TYPE_SPACE ,  uint64_t ( local_floor_emulation . stage_space ) ,  " Emulation stage space " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! will_emulate_local_floor )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( local_floor_emulation . local_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												xrDestroySpace ( local_floor_emulation . local_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												local_floor_emulation . local_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( local_floor_emulation . stage_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												xrDestroySpace ( local_floor_emulation . stage_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												local_floor_emulation . stage_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Fallback on LOCAL, which all OpenXR runtimes are required to support.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( " OpenXR:  " )  +  OpenXRUtil : : get_reference_space_name ( requested_reference_space )  +  String ( "  isn't supported, defaulting to LOCAL space. " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										new_reference_space  =  XR_REFERENCE_SPACE_TYPE_LOCAL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( new_play_space  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											void  * np  =  wrapper - > set_reference_space_create_info_and_get_next_pointer ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													new_reference_space ,  next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										XrReferenceSpaceCreateInfo  play_space_create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_REFERENCE_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											new_reference_space ,  // referenceSpaceType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											identityPose ,  // poseInReferenceSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrResult  result  =  xrCreateReferenceSpace ( session ,  & play_space_create_info ,  & new_play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR: Failed to create play space [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// If we've previously created a play space, clean it up first.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// But if it was a custom reference space, we don't touch it - it's the job of the extension that
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// created it to clean it up.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( play_space  ! =  XR_NULL_HANDLE  & &  reference_space  ! =  XR_REFERENCE_SPACE_TYPE_MAX_ENUM )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// TODO Investigate if destroying our play space here is safe,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// it may still be used in the rendering thread.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										xrDestroySpace ( play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									play_space  =  new_play_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									reference_space  =  new_reference_space ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_object_name ( XR_OBJECT_TYPE_SPACE ,  uint64_t ( play_space ) ,  " Play space " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									local_floor_emulation . enabled  =  will_emulate_local_floor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									local_floor_emulation . should_reset_floor_height  =  will_emulate_local_floor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Update render state so this play space is used rendering the upcoming frame.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									set_render_play_space ( play_space ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : setup_view_space ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! is_reference_space_supported ( XR_REFERENCE_SPACE_TYPE_VIEW ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: reference space XR_REFERENCE_SPACE_TYPE_VIEW is not supported. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrPosef  identityPose  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0 ,  1.0  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_reference_space_create_info_and_get_next_pointer ( XR_REFERENCE_SPACE_TYPE_VIEW ,  next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrReferenceSpaceCreateInfo  view_space_create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_REFERENCE_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										next_pointer ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										XR_REFERENCE_SPACE_TYPE_VIEW ,  // referenceSpaceType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										identityPose  // poseInReferenceSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrCreateReferenceSpace ( session ,  & view_space_create_info ,  & view_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to create view space [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_object_name ( XR_OBJECT_TYPE_SPACE ,  uint64_t ( view_space ) ,  " View space " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : reset_emulated_floor_height ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( ! local_floor_emulation . enabled ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( local_floor_emulation . local_space  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( local_floor_emulation . stage_space  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpaceLocation  stage_location  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SPACE_LOCATION ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // locationFlags
 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{  {  0.0 ,  0.0 ,  0.0 ,  1.0  } ,  {  0.0 ,  0.0 ,  0.0  }  } ,  // pose
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrLocateSpace ( local_floor_emulation . stage_space ,  local_floor_emulation . local_space ,  get_predicted_display_time ( ) ,  & stage_location ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to locate STAGE space in LOCAL space, in order to emulate LOCAL_FLOOR [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrPosef  pose  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0 ,  1.0  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  stage_location . pose . position . y ,  0.0  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrReferenceSpaceCreateInfo  create_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_REFERENCE_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_REFERENCE_SPACE_TYPE_LOCAL ,  // referenceSpaceType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pose ,  // poseInReferenceSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrSpace  new_play_space ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  wrapper - > set_reference_space_create_info_and_get_next_pointer ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												create_info . referenceSpaceType ,  next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									create_info . next  =  next_pointer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrCreateReferenceSpace ( session ,  & create_info ,  & new_play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to recreate emulated LOCAL_FLOOR play space with latest floor estimate [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									xrDestroySpace ( play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									play_space  =  new_play_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If we've made it this far, it means we can properly emulate LOCAL_FLOOR, so we'll
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// report that as the reference space to the outside world.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									reference_space  =  XR_REFERENCE_SPACE_TYPE_LOCAL_FLOOR_EXT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Update render state so this play space is used rendering the upcoming frame.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									set_render_play_space ( play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : load_supported_swapchain_formats ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_swapchain_formats . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  num_swapchain_formats  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrEnumerateSwapchainFormats ( session ,  0 ,  & num_swapchain_formats ,  nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get swapchain format count [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_swapchain_formats . resize ( num_swapchain_formats ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  =  xrEnumerateSwapchainFormats ( session ,  num_swapchain_formats ,  & num_swapchain_formats ,  supported_swapchain_formats . ptrw ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( XR_FAILED ( result ) ,  false ,  " OpenXR: Failed to enumerate swapchain formats " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( int64_t  swapchain_format  :  supported_swapchain_formats )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( " OpenXR: Found supported swapchain format  " )  +  get_swapchain_format_name ( swapchain_format ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_swapchain_format_supported ( int64_t  p_swapchain_format )  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_swapchain_formats . has ( p_swapchain_format ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : obtain_swapchain_formats ( )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( graphics_extension ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Build a vector with swapchain formats we want to use, from best fit to worst
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Vector < int64_t >  usable_swapchain_formats ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										color_swapchain_format  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										graphics_extension - > get_usable_swapchain_formats ( usable_swapchain_formats ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// now find out which one is supported
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( int  i  =  0 ;  i  <  usable_swapchain_formats . size ( )  & &  color_swapchain_format  = =  0 ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( is_swapchain_format_supported ( usable_swapchain_formats [ i ] ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												color_swapchain_format  =  usable_swapchain_formats [ i ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 09:37:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ERR_FAIL_COND_V_MSG ( color_swapchain_format  = =  0 ,  false ,  " OpenXR: No usable color swap chain format available! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( " Using color swap chain format: " )  +  get_swapchain_format_name ( color_swapchain_format ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Build a vector with swapchain formats we want to use, from best fit to worst
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Vector < int64_t >  usable_swapchain_formats ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										depth_swapchain_format  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										graphics_extension - > get_usable_depth_formats ( usable_swapchain_formats ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// now find out which one is supported
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( int  i  =  0 ;  i  <  usable_swapchain_formats . size ( )  & &  depth_swapchain_format  = =  0 ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( is_swapchain_format_supported ( usable_swapchain_formats [ i ] ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-25 08:07:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												depth_swapchain_format  =  usable_swapchain_formats [ i ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 09:37:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ERR_FAIL_COND_V_MSG ( depth_swapchain_format  = =  0 ,  false ,  " OpenXR: No usable depth swap chain format available! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( String ( " Using depth swap chain format: " )  +  get_swapchain_format_name ( depth_swapchain_format ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : create_main_swapchains ( const  Size2i  & p_size )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( graphics_extension ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-22 19:03:08 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										TODO :  We  need  to  improve  on  this ,  for  now  we ' re  taking  our  old  approach  of  creating  our  main  swapchains  and  substituting 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										those  for  the  ones  Godot  normally  creates . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										This  however  means  we  can  only  use  swapchains  for  our  main  XR  view . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										It  would  have  been  nicer  if  we  could  override  the  swapchain  creation  in  Godot  with  ours  but  we  have  a  timing  issue  here . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										We  can ' t  create  XR  swapchains  until  after  our  XR  session  is  fully  instantiated ,  yet  Godot  creates  its  swapchain  much  earlier . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										We  only  creates  a  swapchain  for  the  main  output  here . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Additional  swapchains  may  be  created  through  our  composition  layer  extension . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Finally  an  area  we  need  to  expand  upon  is  that  Foveated  rendering  is  only  enabled  for  the  swap  chain  we  create , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										as  we  render  3 D  content  into  internal  buffers  that  are  copied  into  the  swapchain ,  we  do  now  have  ( basic )  VRS  support 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . main_swapchain_size  =  p_size ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint32_t  sample_count  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We start with our color swapchain...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( color_swapchain_format  ! =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . create ( 0 ,  XR_SWAPCHAIN_USAGE_SAMPLED_BIT  |  XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT  |  XR_SWAPCHAIN_USAGE_MUTABLE_FORMAT_BIT ,  color_swapchain_format ,  render_state . main_swapchain_size . width ,  render_state . main_swapchain_size . height ,  sample_count ,  view_configuration_views . size ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										set_object_name ( XR_OBJECT_TYPE_SWAPCHAIN ,  uint64_t ( render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . get_swapchain ( ) ) ,  " Main color swapchain " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We create our depth swapchain if:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// - we've enabled submitting depth buffer
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// - we support our depth layer extension
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// - we have our spacewarp extension (not yet implemented)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( depth_swapchain_format  ! =  0  & &  submit_depth_buffer  & &  OpenXRCompositionLayerDepthExtension : : get_singleton ( ) - > is_available ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! render_state . main_swapchains [ OPENXR_SWAPCHAIN_DEPTH ] . create ( 0 ,  XR_SWAPCHAIN_USAGE_SAMPLED_BIT  |  XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ,  depth_swapchain_format ,  render_state . main_swapchain_size . width ,  render_state . main_swapchain_size . height ,  sample_count ,  view_configuration_views . size ( ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-22 19:03:08 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-21 09:56:19 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set_object_name ( XR_OBJECT_TYPE_SWAPCHAIN ,  uint64_t ( render_state . main_swapchains [ OPENXR_SWAPCHAIN_DEPTH ] . get_swapchain ( ) ) ,  " Main depth swapchain " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We create our velocity swapchain if:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// - we have our spacewarp extension (not yet implemented)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// TBD
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( uint32_t  i  =  0 ;  i  <  render_state . views . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . swapchain  =  render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . get_swapchain ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . imageArrayIndex  =  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . imageRect . offset . x  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . imageRect . offset . y  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . imageRect . extent . width  =  render_state . main_swapchain_size . width ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ i ] . subImage . imageRect . extent . height  =  render_state . main_swapchain_size . height ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( render_state . submit_depth_buffer  & &  OpenXRCompositionLayerDepthExtension : : get_singleton ( ) - > is_available ( )  & &  ! render_state . depth_views . is_empty ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											render_state . projection_views [ i ] . next  =  & render_state . depth_views [ i ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . swapchain  =  render_state . main_swapchains [ OPENXR_SWAPCHAIN_DEPTH ] . get_swapchain ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . imageArrayIndex  =  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . imageRect . offset . x  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . imageRect . offset . y  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . imageRect . extent . width  =  render_state . main_swapchain_size . width ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . subImage . imageRect . extent . height  =  render_state . main_swapchain_size . height ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-09 16:15:42 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// OpenXR spec says that: minDepth < maxDepth.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . minDepth  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . maxDepth  =  1.0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-09 16:15:42 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// But we can reverse near and far for reverse-Z.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . nearZ  =  100.0 ;  // Near and far Z will be set to the correct values in fill_projection_matrix
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . depth_views [ i ] . farZ  =  0.01 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-20 11:15:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_main_swapchains_created ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-07 10:57:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : destroy_session ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// TODO need to figure out if we're still rendering our current frame
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in a separate rendering thread and if so,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// if we need to wait for completion.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We could be pulling the rug from underneath rendering...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( session  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											xrEndSession ( session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										running  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . running  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . views . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_state . projection_views . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_state . depth_views . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									free_main_swapchains ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRSwapChainInfo : : free_queued ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_swapchain_formats . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// destroy our spaces
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( play_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroySpace ( play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										play_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . play_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( view_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroySpace ( view_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										view_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( local_floor_emulation . local_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroySpace ( local_floor_emulation . local_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										local_floor_emulation . local_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( local_floor_emulation . stage_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroySpace ( local_floor_emulation . stage_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										local_floor_emulation . stage_space  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									local_floor_emulation . enabled  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									local_floor_emulation . should_reset_floor_height  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_reference_spaces . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( session  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											wrapper - > on_session_destroyed ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										end_debug_label_region ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										xrDestroySession ( session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										session  =  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_idle ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state idle " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_idle ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_ready ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state ready " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// begin session
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSessionBeginInfo  session_begin_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SESSION_BEGIN_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										view_configuration  // primaryViewConfigurationType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrBeginSession ( session ,  & session_begin_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to begin session [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// we're running
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									running  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_render_session_running ( true ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_ready ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_ready ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_synchronized ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state synchronized " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_synchronized ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-06-17 17:36:38 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_synchronized ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_visible ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state visible " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_visible ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_visible ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_focused ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state focused " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_focused ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_focused ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_stopping ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state stopping " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_stopping ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_stopping ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrResult  result  =  xrEndSession ( session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// we only report this..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR: Failed to end session [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										running  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set_render_session_running ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_loss_pending ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state loss pending " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_loss_pending ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_loss_pending ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : on_state_exiting ( )  {  
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_verbose ( " On state existing " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xr_interface - > on_state_exiting ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_state_exiting ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_form_factor ( XrFormFactor  p_form_factor )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND ( is_initialized ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									form_factor  =  p_form_factor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-09 17:09:22 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								uint32_t  OpenXRAPI : : get_view_count ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  view_configuration_views . size ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-09 17:09:22 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_view_configuration ( XrViewConfigurationType  p_view_configuration )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND ( is_initialized ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									view_configuration  =  p_view_configuration ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : set_requested_reference_space ( XrReferenceSpaceType  p_requested_reference_space )  {  
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( custom_play_space  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									requested_reference_space  =  p_requested_reference_space ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									play_space_is_dirty  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_custom_play_space ( XrSpace  p_custom_space )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									custom_play_space  =  p_custom_space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									play_space_is_dirty  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_submit_depth_buffer ( bool  p_submit_depth_buffer )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND ( is_initialized ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									submit_depth_buffer  =  p_submit_depth_buffer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_initialized ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ( instance  ! =  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_running ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( instance  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( session  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  running ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : openxr_loader_init ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef ANDROID_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( openxr_loader_library_handle  ! =  nullptr ,  false ,  " OpenXR Loader library is already loaded. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Error  error_code  =  OS : : get_singleton ( ) - > open_dynamic_library ( OPENXR_LOADER_NAME ,  openxr_loader_library_handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_COND_V_MSG ( error_code  ! =  OK ,  false ,  " OpenXR loader not found. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Error  error_code  =  OS : : get_singleton ( ) - > get_dynamic_library_symbol_handle ( openxr_loader_library_handle ,  " xrGetInstanceProcAddr " ,  ( void  * & ) xrGetInstanceProcAddr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_COND_V_MSG ( error_code  ! =  OK ,  false ,  " Symbol xrGetInstanceProcAddr not found in OpenXR Loader library. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Resolve the symbols that don't require an instance
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateInstance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateApiLayerProperties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateInstanceExtensionProperties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : resolve_instance_openxr_symbols ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrAcquireSwapchainImage ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrApplyHapticFeedback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrAttachSessionActionSets ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrBeginFrame ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrBeginSession ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateAction ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateActionSet ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateActionSpace ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateReferenceSpace ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateSession ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrCreateSwapchain ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroyAction ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroyActionSet ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroyInstance ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroySession ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroySpace ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrDestroySwapchain ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEndFrame ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEndSession ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateEnvironmentBlendModes ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateReferenceSpaces ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateSwapchainFormats ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateViewConfigurations ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrEnumerateViewConfigurationViews ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetActionStateBoolean ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetActionStateFloat ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetActionStateVector2f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetCurrentInteractionProfile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 16:34:29 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetReferenceSpaceBoundsRect ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetSystem ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrGetSystemProperties ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrLocateViews ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrLocateSpace ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrPathToString ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrPollEvent ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrReleaseSwapchainImage ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrResultToString ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrStringToPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrSuggestInteractionProfileBindings ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrSyncActions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrWaitFrame ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OPENXR_API_INIT_XR_FUNC_V ( xrWaitSwapchainImage ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-07 18:41:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrResult  OpenXRAPI : : try_get_instance_proc_addr ( const  char  * p_name ,  PFN_xrVoidFunction  * p_addr )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  xrGetInstanceProcAddr ( instance ,  p_name ,  p_addr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrResult  OpenXRAPI : : get_instance_proc_addr ( const  char  * p_name ,  PFN_xrVoidFunction  * p_addr )  {  
						 
					
						
							
								
									
										
										
										
											2023-01-07 18:41:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  try_get_instance_proc_addr ( p_name ,  p_addr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( result  ! =  XR_SUCCESS )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										String  error_message  =  String ( " Symbol  " )  +  p_name  +  "  not found in OpenXR instance. " ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-18 10:20:48 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ERR_FAIL_V_MSG ( result ,  error_message . utf8 ( ) . get_data ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : initialize ( const  String  & p_rendering_driver )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V_MSG ( instance  ! =  XR_NULL_HANDLE ,  false ,  " OpenXR instance was already created " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! openxr_loader_init ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( p_rendering_driver  = =  " vulkan " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef VULKAN_ENABLED 
  
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										graphics_extension  =  memnew ( OpenXRVulkanExtension ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										register_extension_wrapper ( graphics_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// shouldn't be possible...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-05 09:37:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( p_rendering_driver  = =  " metal " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef METAL_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										graphics_extension  =  memnew ( OpenXRMetalExtension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										register_extension_wrapper ( graphics_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// shouldn't be possible...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( p_rendering_driver  = =  " opengl3 " )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-19 00:02:47 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# if defined(GLES3_ENABLED) && !defined(MACOS_ENABLED) 
  
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										graphics_extension  =  memnew ( OpenXROpenGLExtension ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-22 20:29:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										register_extension_wrapper ( graphics_extension ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// shouldn't be possible...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-07 18:29:52 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( p_rendering_driver  = =  " d3d12 " )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef D3D12_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										graphics_extension  =  memnew ( OpenXRD3D12Extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										register_extension_wrapper ( graphics_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# else 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// shouldn't be possible...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V_MSG ( false ,  " OpenXR: Unsupported rendering device. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Also register our rendering extensions
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									register_extension_wrapper ( memnew ( OpenXRFBUpdateSwapchainExtension ( p_rendering_driver ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									register_extension_wrapper ( memnew ( OpenXRFBFoveationExtension ( p_rendering_driver ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// initialize
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_before_instance_created ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( ! load_layer_properties ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! load_supported_extensions ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! create_instance ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! resolve_instance_openxr_symbols ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( ! get_system_info ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! load_supported_view_configuration_types ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! load_supported_view_configuration_views ( view_configuration ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! load_supported_environmental_blend_modes ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : initialize_session ( )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( ! create_session ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! load_supported_reference_spaces ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 10:30:54 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! setup_view_space ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! load_supported_swapchain_formats ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! obtain_swapchain_formats ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									allocate_view_buffers ( view_configuration_views . size ( ) ,  submit_depth_buffer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : finish ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									destroy_session ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									destroy_instance ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_xr_interface ( OpenXRInterface  * p_xr_interface )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									xr_interface  =  p_xr_interface ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : register_extension_wrapper ( OpenXRExtensionWrapper  * p_extension_wrapper )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( openxr_api  & &  openxr_api - > instance  ! =  XR_NULL_HANDLE ,  " Cannot register OpenXR extension wrappers after the OpenXR instance has been created. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									registered_extension_wrappers . push_back ( p_extension_wrapper ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-15 16:57:42 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : unregister_extension_wrapper ( OpenXRExtensionWrapper  * p_extension_wrapper )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( openxr_api  & &  openxr_api - > instance  ! =  XR_NULL_HANDLE ,  " Cannot unregister OpenXR extension wrappers after the OpenXR instance has been created. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-15 16:57:42 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									registered_extension_wrappers . erase ( p_extension_wrapper ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:14:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  Vector < OpenXRExtensionWrapper  * >  & OpenXRAPI : : get_registered_extension_wrappers ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  registered_extension_wrappers ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : register_extension_metadata ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension_wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										extension_wrapper - > on_register_metadata ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : cleanup_extension_wrappers ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension_wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifndef DISABLE_DEPRECATED 
  
						 
					
						
							
								
									
										
										
										
											2024-02-22 16:50:39 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Fix crash when the extension wrapper comes from GDExtension.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OpenXRExtensionWrapperExtension  * gdextension_extension_wrapper  =  dynamic_cast < OpenXRExtensionWrapperExtension  * > ( extension_wrapper ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( gdextension_extension_wrapper )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											memdelete ( gdextension_extension_wrapper ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-22 16:50:39 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											memdelete ( extension_wrapper ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-29 16:34:25 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									registered_extension_wrappers . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-18 20:06:36 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrHandTrackerEXT  OpenXRAPI : : get_hand_tracker ( int  p_hand_index )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_INDEX_V ( p_hand_index ,  OpenXRHandTrackingExtension : : HandTrackedHands : : OPENXR_MAX_TRACKED_HANDS ,  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-22 13:03:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRHandTrackingExtension  * hand_tracking  =  OpenXRHandTrackingExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( hand_tracking ,  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-18 20:06:36 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRHandTrackingExtension : : HandTrackedHands  hand  =  static_cast < OpenXRHandTrackingExtension : : HandTrackedHands > ( p_hand_index ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-22 13:03:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hand_tracking - > get_hand_tracker ( hand ) - > hand_tracker ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-18 20:06:36 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Size2  OpenXRAPI : : get_recommended_target_size ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RenderingServer  * rendering_server  =  RenderingServer : : get_singleton ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( view_configuration_views . is_empty ( ) ,  Size2 ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Size2  target_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( rendering_server  & &  rendering_server - > is_on_render_thread ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										target_size . width  =  view_configuration_views [ 0 ] . recommendedImageRectWidth  *  render_state . render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										target_size . height  =  view_configuration_views [ 0 ] . recommendedImageRectHeight  *  render_state . render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										target_size . width  =  view_configuration_views [ 0 ] . recommendedImageRectWidth  *  render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										target_size . height  =  view_configuration_views [ 0 ] . recommendedImageRectHeight  *  render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  target_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 07:33:03 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XRPose : : TrackingConfidence  OpenXRAPI : : get_head_center ( Transform3D  & r_transform ,  Vector3  & r_linear_velocity ,  Vector3  & r_angular_velocity )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-11 14:12:34 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Get display time
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrTime  display_time  =  get_predicted_display_time ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( display_time  = =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpaceVelocity  velocity  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SPACE_VELOCITY ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // velocityFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  } ,  // linearVelocity
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  }  // angularVelocity
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpaceLocation  location  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SPACE_LOCATION ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										& velocity ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // locationFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{  0.0 ,  0.0 ,  0.0 ,  0.0  } ,  // orientation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{  0.0 ,  0.0 ,  0.0  }  // position
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  // pose
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  =  xrLocateSpace ( view_space ,  play_space ,  display_time ,  & location ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to locate view space in play space [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XRPose : : TrackingConfidence  confidence  =  transform_from_location ( location ,  r_transform ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									parse_velocities ( velocity ,  r_linear_velocity ,  r_angular_velocity ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( head_pose_confidence  ! =  confidence )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// prevent error spam
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										head_pose_confidence  =  confidence ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( head_pose_confidence  = =  XRPose : : XR_TRACKING_CONFIDENCE_NONE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR head space location not valid (check tracking?) " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  if  ( head_pose_confidence  = =  XRPose : : XR_TRACKING_CONFIDENCE_LOW )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_verbose ( " OpenVR Head pose now tracking with low confidence " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_verbose ( " OpenVR Head pose now tracking with high confidence " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  confidence ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : get_view_transform ( uint32_t  p_view ,  Transform3D  & r_transform )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! render_state . running )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// we don't have valid view info
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . views . is_empty ( )  | |  ! render_state . view_pose_valid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Note, the timing of this is set right before rendering, which is what we need here.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									r_transform  =  transform_from_pose ( render_state . views [ p_view ] . pose ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
											
												Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
											 
										 
										
											2022-07-20 01:11:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : get_view_projection ( uint32_t  p_view ,  double  p_z_near ,  double  p_z_far ,  Projection  & p_camera_matrix )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( graphics_extension ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! render_state . running )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// we don't have valid view info
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . views . is_empty ( )  | |  ! render_state . view_pose_valid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// if we're using depth views, make sure we update our near and far there...
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! render_state . depth_views . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( XrCompositionLayerDepthInfoKHR  & depth_view  :  render_state . depth_views )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-09 16:15:42 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// As we are using reverse-Z these need to be flipped.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											depth_view . nearZ  =  p_z_far ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											depth_view . farZ  =  p_z_near ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . z_near  =  p_z_near ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_state . z_far  =  p_z_far ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// now update our projection
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  graphics_extension - > create_projection_fov ( render_state . views [ p_view ] . fov ,  p_z_near ,  p_z_far ,  p_camera_matrix ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Vector2  OpenXRAPI : : get_eye_focus ( uint32_t  p_view ,  float  p_aspect )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( graphics_extension ,  Vector2 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! render_state . running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// xrWaitFrame not run yet
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( render_state . predicted_display_time  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// we don't have valid view info
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . views . is_empty ( )  | |  ! render_state . view_pose_valid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Projection  cm ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! graphics_extension - > create_projection_fov ( render_state . views [ p_view ] . fov ,  0.1 ,  1000.0 ,  cm ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Default focus to center...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector3  focus  =  cm . xform ( Vector3 ( 0.0 ,  0.0 ,  999.9 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Lets check for eye tracking...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXREyeGazeInteractionExtension  * eye_gaze_interaction  =  OpenXREyeGazeInteractionExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( eye_gaze_interaction  & &  eye_gaze_interaction - > supports_eye_gaze_interaction ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Vector3  eye_gaze_pose ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( eye_gaze_interaction - > get_eye_gaze_pose ( 1.0 ,  eye_gaze_pose ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Transform3D  view_transform  =  transform_from_pose ( render_state . views [ p_view ] . pose ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											eye_gaze_pose  =  view_transform . xform_inv ( eye_gaze_pose ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											focus  =  cm . xform ( eye_gaze_pose ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  Vector2 ( focus . x ,  focus . y ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : poll_events ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrEventDataBuffer  runtimeEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									runtimeEvent . type  =  XR_TYPE_EVENT_DATA_BUFFER ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									runtimeEvent . next  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// runtimeEvent.varying = ...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  pollResult  =  xrPollEvent ( instance ,  & runtimeEvent ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									while  ( pollResult  = =  XR_SUCCESS )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bool  handled  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											handled  | =  wrapper - > on_event_polled ( runtimeEvent ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( runtimeEvent . type )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											case  XR_TYPE_EVENT_DATA_EVENTS_LOST :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XrEventDataEventsLost  * event  =  ( XrEventDataEventsLost  * ) & runtimeEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// We probably didn't poll fast enough, just output warning
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												WARN_PRINT ( " OpenXR EVENT:  "  +  itos ( event - > lostEventCount )  +  "  event data lost! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XrEventDataInstanceLossPending  * event  =  ( XrEventDataInstanceLossPending  * ) & runtimeEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// TODO We get this event if we're about to loose our OpenXR instance.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// We should queue exiting Godot at this point.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												print_verbose ( String ( " OpenXR EVENT: instance loss pending at  " )  +  itos ( event - > lossTime ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											case  XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XrEventDataSessionStateChanged  * event  =  ( XrEventDataSessionStateChanged  * ) & runtimeEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												session_state  =  event - > state ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( session_state  > =  XR_SESSION_STATE_MAX_ENUM )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													print_verbose ( String ( " OpenXR EVENT: session state changed to UNKNOWN -  " )  +  itos ( session_state ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													print_verbose ( String ( " OpenXR EVENT: session state changed to  " )  +  OpenXRUtil : : get_session_state_name ( session_state ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													switch  ( session_state )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_IDLE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_idle ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_READY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_ready ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_SYNCHRONIZED : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_synchronized ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_VISIBLE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_visible ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_FOCUSED : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_focused ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_STOPPING : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_stopping ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_LOSS_PENDING : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_loss_pending ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														case  XR_SESSION_STATE_EXITING : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															on_state_exiting ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											case  XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XrEventDataReferenceSpaceChangePending  * event  =  ( XrEventDataReferenceSpaceChangePending  * ) & runtimeEvent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												print_verbose ( String ( " OpenXR EVENT: reference space type  " )  +  OpenXRUtil : : get_reference_space_name ( event - > referenceSpaceType )  +  "  change pending! " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( local_floor_emulation . enabled )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													local_floor_emulation . should_reset_floor_height  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-13 14:20:06 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													xr_interface - > on_reference_space_change_pending ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												print_verbose ( " OpenXR EVENT: interaction profile changed! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XrEventDataInteractionProfileChanged  * event  =  ( XrEventDataInteractionProfileChanged  * ) & runtimeEvent ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-06-17 17:36:38 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( event - > session  = =  session )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Make sure we get our interaction profile change
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													interaction_profile_changed  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ! handled )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													print_verbose ( String ( " OpenXR Unhandled event type  " )  +  OpenXRUtil : : get_structure_type_name ( runtimeEvent . type ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										runtimeEvent . type  =  XR_TYPE_EVENT_DATA_BUFFER ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pollResult  =  xrPollEvent ( instance ,  & runtimeEvent ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( pollResult  = =  XR_EVENT_UNAVAILABLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// processed all events in the queue
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V_MSG ( false ,  " OpenXR: Failed to poll events! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _allocate_view_buffers_rt ( uint32_t  p_view_count ,  bool  p_submit_depth_buffer )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									openxr_api - > render_state . submit_depth_buffer  =  p_submit_depth_buffer ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Allocate buffers we'll be populating with view information.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									openxr_api - > render_state . views . resize ( p_view_count ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . projection_views . resize ( p_view_count ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-21 15:03:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( uint32_t  i  =  0 ;  i  <  p_view_count ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_api - > render_state . views [ i ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_VIEW ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ } ,  // pose
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ } ,  // fov
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_api - > render_state . projection_views [ i ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ } ,  // pose
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ } ,  // fov
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ } ,  // subImage
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( p_submit_depth_buffer  & &  OpenXRCompositionLayerDepthExtension : : get_singleton ( ) - > is_available ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										openxr_api - > render_state . depth_views . resize ( p_view_count ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-21 15:03:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( uint32_t  i  =  0 ;  i  <  p_view_count ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											openxr_api - > render_state . depth_views [ i ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ } ,  // subImage
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0.0 ,  // minDepth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0.0 ,  // maxDepth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0.0 ,  // nearZ
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												0.0 ,  // farZ
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_session_running_rt ( bool  p_is_running )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . running  =  p_is_running ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_display_info_rt ( XrTime  p_predicted_display_time ,  bool  p_should_render )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . predicted_display_time  =  p_predicted_display_time ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . should_render  =  p_should_render ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_environment_blend_mode_rt ( int32_t  p_environment_blend_mode )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . environment_blend_mode  =  XrEnvironmentBlendMode ( p_environment_blend_mode ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_play_space_rt ( uint64_t  p_play_space )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . play_space  =  XrSpace ( p_play_space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_state_multiplier_rt ( double  p_render_target_size_multiplier )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . render_target_size_multiplier  =  p_render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : _set_render_state_render_region_rt ( const  Rect2i  & p_render_region )  {  
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRAPI  * openxr_api  =  OpenXRAPI : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									openxr_api - > render_state . render_region  =  p_render_region ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : process ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! poll_events ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We call xrWaitFrame as early as possible, this will allow OpenXR to get
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// proper timing info between this point, and when we're ready to start rendering.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// As the name suggests, OpenXR can pause the thread to minimize the time between
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// retrieving tracking data and using that tracking data to render.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// OpenXR thus works best if rendering is performed on a separate thread.
 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * frame_wait_info_next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension  :  frame_info_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  extension - > set_frame_wait_info_and_get_next_pointer ( frame_wait_info_next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											frame_wait_info_next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrFrameWaitInfo  frame_wait_info  =  {  XR_TYPE_FRAME_WAIT_INFO ,  frame_wait_info_next_pointer  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 13:20:12 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									frame_state . predictedDisplayTime  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									frame_state . predictedDisplayPeriod  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									frame_state . shouldRender  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrWaitFrame ( session ,  & frame_wait_info ,  & frame_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: xrWaitFrame() was not successful [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// reset just in case
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										frame_state . predictedDisplayTime  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										frame_state . predictedDisplayPeriod  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										frame_state . shouldRender  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set_render_display_info ( 0 ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( frame_state . predictedDisplayPeriod  >  500000000 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// display period more then 0.5 seconds? must be wrong data
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_verbose ( String ( " OpenXR resetting invalid display period  " )  +  rtos ( frame_state . predictedDisplayPeriod ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										frame_state . predictedDisplayPeriod  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_render_display_info ( frame_state . predictedDisplayTime ,  frame_state . shouldRender ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-06-27 14:12:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// This is before setup_play_space() to ensure that it happens on the frame after
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// the play space has been created.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( unlikely ( local_floor_emulation . should_reset_floor_height  & &  ! play_space_is_dirty ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										reset_emulated_floor_height ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										local_floor_emulation . should_reset_floor_height  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( unlikely ( play_space_is_dirty ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										setup_play_space ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										play_space_is_dirty  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_process ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : free_main_swapchains ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  OPENXR_SWAPCHAIN_MAX ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . main_swapchains [ i ] . queue_free ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : pre_render ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND ( session  = =  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! render_state . running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Process any swapchains that were queued to be freed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRSwapChainInfo : : free_queued ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Size2i  swapchain_size  =  get_recommended_target_size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( swapchain_size  ! =  render_state . main_swapchain_size )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Out with the old.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										free_main_swapchains ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// In with the new.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										create_main_swapchains ( swapchain_size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * view_locate_info_next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension  :  frame_info_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  extension - > set_view_locate_info_and_get_next_pointer ( view_locate_info_next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											view_locate_info_next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Get our view info for the frame we're about to render, note from the OpenXR manual:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// "Repeatedly calling xrLocateViews with the same time may not necessarily return the same result. Instead the prediction gets increasingly accurate as the function is called closer to the given time for which a prediction is made"
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// We're calling this "relatively" early, the positioning we're obtaining here will be used to do our frustum culling,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// occlusion culling, etc. There is however a technique that we can investigate in the future where after our entire
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Vulkan command buffer is build, but right before vkSubmitQueue is called, we call xrLocateViews one more time and
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// update the view and projection matrix once more with a slightly more accurate predication and then submit the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// command queues.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// That is not possible yet but worth investigating in the future.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrViewLocateInfo  view_locate_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_VIEW_LOCATE_INFO ,  // type
 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										view_locate_info_next_pointer ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										view_configuration ,  // viewConfigurationType
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . predicted_display_time ,  // displayTime
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . play_space  // space
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrViewState  view_state  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_VIEW_STATE ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0  // viewStateFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uint32_t  view_count_output ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrLocateViews ( session ,  & view_locate_info ,  & view_state ,  render_state . views . size ( ) ,  & view_count_output ,  render_state . views . ptr ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Couldn't locate views [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  pose_valid  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( uint64_t  i  =  0 ;  i  <  view_count_output ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ( view_state . viewStateFlags  &  XR_VIEW_STATE_ORIENTATION_VALID_BIT )  = =  0  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												( view_state . viewStateFlags  &  XR_VIEW_STATE_POSITION_VALID_BIT )  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											pose_valid  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . view_pose_valid  ! =  pose_valid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . view_pose_valid  =  pose_valid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! render_state . view_pose_valid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_verbose ( " OpenXR View pose became invalid " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 20:19:18 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_verbose ( " OpenXR View pose became valid " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// We should get our frame no from the rendering server, but this will do.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									begin_debug_label_region ( String ( " Session Frame  " )  +  String : : num_uint64 ( + + render_state . frame ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// let's start our frame..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrFrameBeginInfo  frame_begin_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_FRAME_BEGIN_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  =  xrBeginFrame ( session ,  & frame_begin_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to begin frame [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Reset this, we haven't found a viewport for output yet
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . has_xr_viewport  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-20 15:15:19 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_pre_render ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : pre_draw_viewport ( RID  p_render_target )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// We found an XR viewport!
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . has_xr_viewport  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( instance  = =  XR_NULL_HANDLE  | |  session  = =  XR_NULL_HANDLE  | |  ! render_state . running  | |  ! render_state . view_pose_valid  | |  ! render_state . should_render )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Acquire our images
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  OPENXR_SWAPCHAIN_MAX ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! render_state . main_swapchains [ i ] . is_image_acquired ( )  & &  render_state . main_swapchains [ i ] . get_swapchain ( )  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! render_state . main_swapchains [ i ] . acquire ( render_state . should_render ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 14:17:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_pre_draw_viewport ( p_render_target ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrSwapchain  OpenXRAPI : : get_color_swapchain ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . get_swapchain ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_color_texture ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . get_image ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_depth_texture ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-22 19:03:08 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Note, image will not be acquired if we didn't have a suitable swap chain format.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . submit_depth_buffer  & &  render_state . main_swapchains [ OPENXR_SWAPCHAIN_DEPTH ] . is_image_acquired ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  render_state . main_swapchains [ OPENXR_SWAPCHAIN_DEPTH ] . get_image ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-27 10:34:48 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_density_map_texture ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( fov_ext  & &  fov_ext - > is_enabled ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . get_density_map ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_velocity_texture ( RID  p_render_target )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									velocity_texture  =  p_render_target ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_velocity_texture ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  velocity_texture ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_velocity_depth_texture ( RID  p_render_target )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									velocity_depth_texture  =  p_render_target ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_velocity_depth_texture ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  velocity_depth_texture ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_velocity_target_size ( const  Size2i  & p_target_size )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									velocity_target_size  =  p_target_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Size2i  OpenXRAPI : : get_velocity_target_size ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  velocity_target_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  XrCompositionLayerProjection  * OpenXRAPI : : get_projection_layer ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD_V ( nullptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & render_state . projection_layer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : post_draw_viewport ( RID  p_render_target )  {  
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( instance  = =  XR_NULL_HANDLE  | |  session  = =  XR_NULL_HANDLE  | |  ! render_state . running  | |  ! render_state . view_pose_valid  | |  ! render_state . should_render )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-03-14 14:17:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_post_draw_viewport ( p_render_target ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-07 10:57:21 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : end_frame ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND ( session  = =  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Must be called from rendering thread!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_NOT_ON_RENDER_THREAD ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! render_state . running )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( render_state . should_render  & &  render_state . view_pose_valid )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! render_state . has_xr_viewport )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_line ( " OpenXR: No viewport was marked with use_xr, there is no rendered output! " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}  else  if  ( ! render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . is_image_acquired ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 20:32:41 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_line ( " OpenXR: No swapchain could be acquired to render to! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Rect2i  new_render_region  =  ( render_state . render_region  ! =  Rect2i ( ) )  ?  render_state . render_region  :  Rect2i ( Point2i ( 0 ,  0 ) ,  render_state . main_swapchain_size ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( XrCompositionLayerProjectionView  & projection_view  :  render_state . projection_views )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										projection_view . subImage . imageRect . offset . x  =  new_render_region . position . x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										projection_view . subImage . imageRect . offset . y  =  new_render_region . position . y ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										projection_view . subImage . imageRect . extent . width  =  new_render_region . size . width ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										projection_view . subImage . imageRect . extent . height  =  new_render_region . size . height ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( render_state . submit_depth_buffer  & &  OpenXRCompositionLayerDepthExtension : : get_singleton ( ) - > is_available ( )  & &  ! render_state . depth_views . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( XrCompositionLayerDepthInfoKHR  & depth_view  :  render_state . depth_views )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											depth_view . subImage . imageRect . offset . x  =  new_render_region . position . x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											depth_view . subImage . imageRect . offset . y  =  new_render_region . position . y ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											depth_view . subImage . imageRect . extent . width  =  new_render_region . size . width ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											depth_view . subImage . imageRect . extent . height  =  new_render_region . size . height ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// must have:
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// - should_render set to true
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// - a valid view pose for projection_views[eye].pose to submit layer
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// - an image to render
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! render_state . should_render  | |  ! render_state . view_pose_valid  | |  ! render_state . main_swapchains [ OPENXR_SWAPCHAIN_COLOR ] . is_image_acquired ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// submit 0 layers when we shouldn't render
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrFrameEndInfo  frame_end_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_FRAME_END_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											render_state . predicted_display_time ,  // displayTime
 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											render_state . environment_blend_mode ,  // environmentBlendMode
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											0 ,  // layerCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr  // layers
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										result  =  xrEndFrame ( session ,  & frame_end_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 16:25:57 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											print_line ( " OpenXR: rendering skipped and failed to end frame! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										end_debug_label_region ( ) ;  // Session frame #
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// neither eye is rendered
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// release our swapchain image if we acquired it
 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  OPENXR_SWAPCHAIN_MAX ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( render_state . main_swapchains [ i ] . is_image_acquired ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . main_swapchains [ i ] . release ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( uint32_t  eye  =  0 ;  eye  <  render_state . views . size ( ) ;  eye + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . projection_views [ eye ] . fov  =  render_state . views [ eye ] . fov ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										render_state . projection_views [ eye ] . pose  =  render_state . views [ eye ] . pose ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 23:29:13 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Vector < OrderedCompositionLayer >  ordered_layers_list ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  projection_layer_is_first  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Add composition layers from providers
 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension  :  composition_layer_providers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( int  i  =  0 ;  i  <  extension - > get_composition_layer_count ( ) ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 23:29:13 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											OrderedCompositionLayer  layer  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												extension - > get_composition_layer ( i ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												extension - > get_composition_layer_order ( i ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 23:29:13 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( layer . composition_layer )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ordered_layers_list . push_back ( layer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( layer . sort_order  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													WARN_PRINT_ONCE_ED ( " Composition layer returned sort order 0, it may be overwritten by projection layer. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  if  ( layer . sort_order  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													projection_layer_is_first  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrCompositionLayerFlags  layer_flags  =  XR_COMPOSITION_LAYER_CORRECT_CHROMATIC_ABERRATION_BIT ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! projection_layer_is_first  | |  render_state . environment_blend_mode  ! =  XR_ENVIRONMENT_BLEND_MODE_OPAQUE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										layer_flags  | =  XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . projection_layer . layerFlags  =  layer_flags ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_state . projection_layer . space  =  render_state . play_space ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									render_state . projection_layer . viewCount  =  ( uint32_t ) render_state . projection_views . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_state . projection_layer . views  =  render_state . projection_views . ptr ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( projection_views_extensions . size ( )  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( uint32_t  v  =  0 ;  v  <  render_state . projection_views . size ( ) ;  v + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											void  * next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( OpenXRExtensionWrapper  * wrapper  :  projection_views_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												void  * np  =  wrapper - > set_projection_views_and_get_next_pointer ( v ,  next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											render_state . projection_views [ v ] . next  =  next_pointer ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ordered_layers_list . push_back ( {  ( const  XrCompositionLayerBaseHeader  * ) & render_state . projection_layer ,  0  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 23:29:13 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Sort our layers.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ordered_layers_list . sort_custom < OrderedCompositionLayer > ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Now make a list we can pass on to OpenXR.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector < const  XrCompositionLayerBaseHeader  * >  layers_list ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OrderedCompositionLayer  & ordered_layer  :  ordered_layers_list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										layers_list . push_back ( ordered_layer . composition_layer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * frame_end_info_next_pointer  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * extension  :  frame_info_extensions )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										void  * np  =  extension - > set_frame_end_info_and_get_next_pointer ( frame_end_info_next_pointer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( np  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											frame_end_info_next_pointer  =  np ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									XrFrameEndInfo  frame_end_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_FRAME_END_INFO ,  // type
 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										frame_end_info_next_pointer ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . predicted_display_time ,  // displayTime
 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										render_state . environment_blend_mode ,  // environmentBlendMode
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										static_cast < uint32_t > ( layers_list . size ( ) ) ,  // layerCount
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										layers_list . ptr ( )  // layers
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result  =  xrEndFrame ( session ,  & frame_end_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to end frame! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									end_debug_label_region ( ) ;  // Session frame #
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-10 18:51:53 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								float  OpenXRAPI : : get_display_refresh_rate ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDisplayRefreshRateExtension  * drrext  =  OpenXRDisplayRefreshRateExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( drrext )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  drrext - > get_refresh_rate ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_display_refresh_rate ( float  p_refresh_rate )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDisplayRefreshRateExtension  * drrext  =  OpenXRDisplayRefreshRateExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( drrext  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										drrext - > set_refresh_rate ( p_refresh_rate ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Array  OpenXRAPI : : get_available_display_refresh_rates ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRDisplayRefreshRateExtension  * drrext  =  OpenXRDisplayRefreshRateExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( drrext  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  drrext - > get_available_refresh_rates ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  Array ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-02-18 10:50:55 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								double  OpenXRAPI : : get_render_target_size_multiplier ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  render_target_size_multiplier ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_render_target_size_multiplier ( double  multiplier )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_target_size_multiplier  =  multiplier ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_render_state_multiplier ( multiplier ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-18 10:50:55 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-20 15:57:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Rect2i  OpenXRAPI : : get_render_region ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  render_region ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_render_region ( const  Rect2i  & p_render_region )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									render_region  =  p_render_region ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									set_render_state_render_region ( p_render_region ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 17:45:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_foveation_supported ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  fov_ext  ! =  nullptr  & &  fov_ext - > is_enabled ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								int  OpenXRAPI : : get_foveation_level ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( fov_ext  ! =  nullptr  & &  fov_ext - > is_enabled ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( fov_ext - > get_foveation_level ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_FOVEATION_LEVEL_NONE_FB : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_FOVEATION_LEVEL_LOW_FB : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_FOVEATION_LEVEL_MEDIUM_FB : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  XR_FOVEATION_LEVEL_HIGH_FB : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  3 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_foveation_level ( int  p_foveation_level )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_UNSIGNED_INDEX ( p_foveation_level ,  4 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( fov_ext  ! =  nullptr  & &  fov_ext - > is_enabled ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrFoveationLevelFB  levels [ ]  =  {  XR_FOVEATION_LEVEL_NONE_FB ,  XR_FOVEATION_LEVEL_LOW_FB ,  XR_FOVEATION_LEVEL_MEDIUM_FB ,  XR_FOVEATION_LEVEL_HIGH_FB  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fov_ext - > set_foveation_level ( levels [ p_foveation_level ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : get_foveation_dynamic ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( fov_ext  ! =  nullptr  & &  fov_ext - > is_enabled ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  fov_ext - > get_foveation_dynamic ( )  = =  XR_FOVEATION_DYNAMIC_LEVEL_ENABLED_FB ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_foveation_dynamic ( bool  p_foveation_dynamic )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRFBFoveationExtension  * fov_ext  =  OpenXRFBFoveationExtension : : get_singleton ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( fov_ext  ! =  nullptr  & &  fov_ext - > is_enabled ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fov_ext - > set_foveation_dynamic ( p_foveation_dynamic  ?  XR_FOVEATION_DYNAMIC_LEVEL_ENABLED_FB  :  XR_FOVEATION_DYNAMIC_DISABLED_FB ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-11-21 16:34:29 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Size2  OpenXRAPI : : get_play_space_bounds ( )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Size2  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  Size2 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrExtent2Df  extents ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetReferenceSpaceBoundsRect ( session ,  reference_space ,  & extents ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to get play space bounds! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ret . width  =  extents . width ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ret . height  =  extents . height ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								PackedInt64Array  OpenXRAPI : : get_supported_swapchain_formats ( )  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_swapchain_formats ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								OpenXRAPI : : OpenXRAPI ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// OpenXRAPI is only constructed if OpenXR is enabled.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									singleton  =  this ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( Engine : : get_singleton ( ) - > is_editor_hint ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Enabled OpenXR in the editor? Adjust our settings for the editor
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Load settings from project settings
 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int  form_factor_setting  =  GLOBAL_GET ( " xr/openxr/form_factor " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( form_factor_setting )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											case  0 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												form_factor  =  XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  1 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												form_factor  =  XR_FORM_FACTOR_HANDHELD_DISPLAY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int  view_configuration_setting  =  GLOBAL_GET ( " xr/openxr/view_configuration " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( view_configuration_setting )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											case  0 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												view_configuration  =  XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  1 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												view_configuration  =  XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											/* we don't support quad and observer configurations (yet)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  2 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												view_configuration  =  XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  3 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												view_configuration  =  XR_VIEW_CONFIGURATION_TYPE_SECONDARY_MONO_FIRST_PERSON_OBSERVER_MSFT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int  reference_space_setting  =  GLOBAL_GET ( " xr/openxr/reference_space " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( reference_space_setting )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											case  0 :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												requested_reference_space  =  XR_REFERENCE_SPACE_TYPE_LOCAL ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  1 :  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-15 16:26:55 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												requested_reference_space  =  XR_REFERENCE_SPACE_TYPE_STAGE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  2 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												requested_reference_space  =  XR_REFERENCE_SPACE_TYPE_LOCAL_FLOOR_EXT ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int  environment_blend_mode_setting  =  GLOBAL_GET ( " xr/openxr/environment_blend_mode " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( environment_blend_mode_setting )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  0 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												environment_blend_mode  =  XR_ENVIRONMENT_BLEND_MODE_OPAQUE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  1 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												environment_blend_mode  =  XR_ENVIRONMENT_BLEND_MODE_ADDITIVE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case  2 :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												environment_blend_mode  =  XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-12-06 22:20:51 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										submit_depth_buffer  =  GLOBAL_GET ( " xr/openxr/submit_depth_buffer " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								OpenXRAPI : : ~ OpenXRAPI ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									composition_layer_providers . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									frame_info_extensions . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									supported_extensions . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									layer_properties . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef ANDROID_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( openxr_loader_library_handle )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OS : : get_singleton ( ) - > close_dynamic_library ( openxr_loader_library_handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										openxr_loader_library_handle  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-24 22:10:43 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									singleton  =  nullptr ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Transform3D  OpenXRAPI : : transform_from_pose ( const  XrPosef  & p_pose )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Quaternion  q ( p_pose . orientation . x ,  p_pose . orientation . y ,  p_pose . orientation . z ,  p_pose . orientation . w ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Basis  basis ( q ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector3  origin ( p_pose . position . x ,  p_pose . position . y ,  p_pose . position . z ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  Transform3D ( basis ,  origin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 20:03:16 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrPosef  OpenXRAPI : : pose_from_transform ( const  Transform3D  & p_transform )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrPosef  pose ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Quaternion  q ( p_transform . basis ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . orientation . x  =  q . x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . orientation . y  =  q . y ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . orientation . z  =  q . z ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . orientation . w  =  q . w ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . position . x  =  p_transform . origin . x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . position . y  =  p_transform . origin . y ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pose . position . z  =  p_transform . origin . z ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  pose ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								template  < typename  T >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XRPose : : TrackingConfidence  _transform_from_location ( const  T  & p_location ,  Transform3D  & r_transform )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XRPose : : TrackingConfidence  confidence  =  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-07 14:39:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  XrPosef  & pose  =  p_location . pose ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Check orientation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_location . locationFlags  &  XR_SPACE_LOCATION_ORIENTATION_VALID_BIT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Quaternion  q ( pose . orientation . x ,  pose . orientation . y ,  pose . orientation . z ,  pose . orientation . w ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_transform . basis  =  Basis ( q ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( p_location . locationFlags  &  XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Fully valid orientation, so either 3DOF or 6DOF tracking with high confidence so default to HIGH_TRACKING
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											confidence  =  XRPose : : XR_TRACKING_CONFIDENCE_HIGH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Orientation is being tracked but we're using old/predicted data, so low tracking confidence
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											confidence  =  XRPose : : XR_TRACKING_CONFIDENCE_LOW ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_transform . basis  =  Basis ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Check location
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_location . locationFlags  &  XR_SPACE_LOCATION_POSITION_VALID_BIT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_transform . origin  =  Vector3 ( pose . position . x ,  pose . position . y ,  pose . position . z ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ( p_location . locationFlags  &  XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Location is being tracked but we're using old/predicted data, so low tracking confidence
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											confidence  =  XRPose : : XR_TRACKING_CONFIDENCE_LOW ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  if  ( confidence  = =  XRPose : : XR_TRACKING_CONFIDENCE_NONE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Position tracking without orientation tracking?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											confidence  =  XRPose : : XR_TRACKING_CONFIDENCE_HIGH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// No tracking or 3DOF I guess..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_transform . origin  =  Vector3 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  confidence ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XRPose : : TrackingConfidence  OpenXRAPI : : transform_from_location ( const  XrSpaceLocation  & p_location ,  Transform3D  & r_transform )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  _transform_from_location ( p_location ,  r_transform ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XRPose : : TrackingConfidence  OpenXRAPI : : transform_from_location ( const  XrHandJointLocationEXT  & p_location ,  Transform3D  & r_transform )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  _transform_from_location ( p_location ,  r_transform ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 07:33:03 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : parse_velocities ( const  XrSpaceVelocity  & p_velocity ,  Vector3  & r_linear_velocity ,  Vector3  & r_angular_velocity )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( p_velocity . velocityFlags  &  XR_SPACE_VELOCITY_LINEAR_VALID_BIT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrVector3f  linear_velocity  =  p_velocity . linearVelocity ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_linear_velocity  =  Vector3 ( linear_velocity . x ,  linear_velocity . y ,  linear_velocity . z ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_linear_velocity  =  Vector3 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_velocity . velocityFlags  &  XR_SPACE_VELOCITY_ANGULAR_VALID_BIT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrVector3f  angular_velocity  =  p_velocity . angularVelocity ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_angular_velocity  =  Vector3 ( angular_velocity . x ,  angular_velocity . y ,  angular_velocity . z ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										r_angular_velocity  =  Vector3 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : xr_result ( XrResult  p_result ,  const  char  * p_format ,  const  Array  & p_args )  const  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_SUCCEEDED ( p_result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-06-21 11:21:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									char  resultString [ XR_MAX_RESULT_STRING_SIZE ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									xrResultToString ( instance ,  p_result ,  resultString ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									print_error ( String ( " OpenXR  " )  +  String ( p_format ) . format ( p_args )  +  String ( "  [ " )  +  String ( resultString )  +  String ( " ] " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrPath  OpenXRAPI : : get_xr_path ( const  String  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  XR_NULL_PATH ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_path . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// This isn't necesairily an issue, so silently return a null path.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrPath  path  =  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrStringToPath ( instance ,  p_path . utf8 ( ) . get_data ( ) ,  & path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to get path for  " ,  p_path ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  path ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-12 20:25:43 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : get_xr_path_name ( const  XrPath  & p_path )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  String ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uint32_t  size  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									char  path_name [ XR_MAX_PATH_LENGTH ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrPathToString ( instance ,  p_path ,  XR_MAX_PATH_LENGTH ,  & size ,  path_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_V_MSG ( String ( ) ,  " OpenXR: failed to get name for a path! [ "  +  get_error_string ( result )  +  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  String ( path_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_tracker_rid ( XrPath  p_path )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & tracker_rid  :  tracker_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Tracker  * tracker  =  tracker_owner . get_or_null ( tracker_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( tracker  & &  tracker - > toplevel_path  = =  p_path )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  tracker_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								RID  OpenXRAPI : : find_tracker ( const  String  & p_name )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & tracker_rid  :  tracker_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Tracker  * tracker  =  tracker_owner . get_or_null ( tracker_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( tracker  & &  tracker - > name  = =  p_name )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  tracker_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : tracker_create ( const  String  & p_name )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  RID ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  new_tracker ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									new_tracker . name  =  p_name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									new_tracker . toplevel_path  =  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									new_tracker . active_profile_rid  =  RID ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									new_tracker . toplevel_path  =  get_xr_path ( p_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( new_tracker . toplevel_path  = =  XR_NULL_PATH ,  RID ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  tracker_owner . make_rid ( new_tracker ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : tracker_get_name ( RID  p_tracker )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_tracker . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  String ( " None " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  String ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  tracker - > name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : tracker_check_profile ( RID  p_tracker ,  XrSession  p_session )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_session  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_session  =  session ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( tracker - > toplevel_path  = =  XR_NULL_PATH )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// no path, how was this even created?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrInteractionProfileState  profile_state  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_INTERACTION_PROFILE_STATE ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_NULL_PATH  // interactionProfile
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetCurrentInteractionProfile ( p_session ,  tracker - > toplevel_path ,  & profile_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: Failed to get interaction profile for " ,  itos ( tracker - > toplevel_path ) ,  " [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrPath  new_profile  =  profile_state . interactionProfile ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrPath  was_profile  =  get_interaction_profile_path ( tracker - > active_profile_rid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( was_profile  ! =  new_profile )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										tracker - > active_profile_rid  =  get_interaction_profile_rid ( new_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( xr_interface )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											xr_interface - > tracker_profile_changed ( p_tracker ,  tracker - > active_profile_rid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : tracker_free ( RID  p_tracker )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( tracker ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// there is nothing to free here
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									tracker_owner . free ( p_tracker ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : action_set_create ( const  String  & p_name ,  const  String  & p_localized_name ,  const  int  p_priority )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ActionSet  action_set ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									action_set . name  =  p_name ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									action_set . is_attached  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// create our action set...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionSetCreateInfo  action_set_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTION_SET_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" " ,  // actionSetName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" " ,  // localizedActionSetName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t ( p_priority )  // priority
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									copy_string_to_char_buffer ( p_name ,  action_set_info . actionSetName ,  XR_MAX_ACTION_SET_NAME_SIZE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									copy_string_to_char_buffer ( p_localized_name ,  action_set_info . localizedActionSetName ,  XR_MAX_LOCALIZED_ACTION_SET_NAME_SIZE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrCreateActionSet ( instance ,  & action_set_info ,  & action_set . handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to create action set  " ,  p_name ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_object_name ( XR_OBJECT_TYPE_ACTION_SET ,  uint64_t ( action_set . handle ) ,  p_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  action_set_owner . make_rid ( action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : find_action_set ( const  String  & p_name )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & action_set_rid  :  action_set_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ActionSet  * action_set  =  action_set_owner . get_or_null ( action_set_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( action_set  & &  action_set - > name  = =  p_name )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  action_set_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : action_set_get_name ( RID  p_action_set )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_action_set . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  String ( " None " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action_set ,  String ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  action_set - > name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrActionSet  OpenXRAPI : : action_set_get_handle ( RID  p_action_set )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_action_set . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action_set ,  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  action_set - > handle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : attach_action_sets ( const  Vector < RID >  & p_action_sets )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Vector < XrActionSet >  action_handles ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									action_handles . resize ( p_action_sets . size ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  p_action_sets . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_sets [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_NULL_V ( action_set ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( action_set - > is_attached )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action_handles . set ( i ,  action_set - > handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// So according to the docs, once we attach our action set to our session it becomes read only..
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/xrAttachSessionActionSets.html
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSessionActionSetsAttachInfo  attach_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										( uint32_t ) p_action_sets . size ( ) ,  // countActionSets,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action_handles . ptr ( )  // actionSets
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrAttachSessionActionSets ( session ,  & attach_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to attach action sets! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-09 21:40:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  p_action_sets . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_sets [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ERR_FAIL_NULL_V ( action_set ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action_set - > is_attached  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* For debugging:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									print_verbose ( " Attached set  "  +  action_set - > name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									List < RID >  action_rids ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									action_owner . get_owned_list ( & action_rids ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  action_rids . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Action  *  action  =  action_owner . get_or_null ( action_rids [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( action  & &  action - > action_set_rid  = =  p_action_set )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_verbose ( "  - Action  "  +  action - > name  +  " :  "  +  OpenXRUtil : : get_action_type_name ( action - > action_type ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for  ( int  j  =  0 ;  j  <  action - > trackers . size ( ) ;  j + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Tracker  *  tracker  =  tracker_owner . get_or_null ( action - > trackers [ j ] . tracker_rid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( tracker )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													print_verbose ( "     -  "  +  tracker - > name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : action_set_free ( RID  p_action_set )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( action_set - > handle  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroyActionSet ( action_set - > handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									action_set_owner . free ( p_action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_action_rid ( XrAction  p_action )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & action_rid  :  action_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Action  * action  =  action_owner . get_or_null ( action_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( action  & &  action - > handle  = =  p_action )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  action_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-26 12:57:26 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : find_action ( const  String  & p_name ,  const  RID  & p_action_set )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & action_rid  :  action_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Action  * action  =  action_owner . get_or_null ( action_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( action  & &  action - > name  = =  p_name  & &  ( p_action_set . is_null ( )  | |  action - > action_set_rid  = =  p_action_set ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  action_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : 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 )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  action ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									action . name  =  p_name ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ActionSet  * action_set  =  action_set_owner . get_or_null ( p_action_set ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action_set ,  RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action_set - > handle  = =  XR_NULL_HANDLE ,  RID ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									action . action_set_rid  =  p_action_set ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									switch  ( p_action_type )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  OpenXRAction : : OPENXR_ACTION_BOOL : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action . action_type  =  XR_ACTION_TYPE_BOOLEAN_INPUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  OpenXRAction : : OPENXR_ACTION_FLOAT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action . action_type  =  XR_ACTION_TYPE_FLOAT_INPUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  OpenXRAction : : OPENXR_ACTION_VECTOR2 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action . action_type  =  XR_ACTION_TYPE_VECTOR2F_INPUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  OpenXRAction : : OPENXR_ACTION_POSE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action . action_type  =  XR_ACTION_TYPE_POSE_INPUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										case  OpenXRAction : : OPENXR_ACTION_HAPTIC : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action . action_type  =  XR_ACTION_TYPE_VIBRATION_OUTPUT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ERR_FAIL_V ( RID ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector < XrPath >  toplevel_paths ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  p_trackers . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Tracker  * tracker  =  tracker_owner . get_or_null ( p_trackers [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( tracker  ! =  nullptr  & &  tracker - > toplevel_path  ! =  XR_NULL_PATH )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ActionTracker  action_tracker  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												p_trackers [ i ] ,  // tracker
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												XR_NULL_HANDLE ,  // space
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												false  // was_location_valid
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											action . trackers . push_back ( action_tracker ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											toplevel_paths . push_back ( tracker - > toplevel_path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionCreateInfo  action_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTION_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" " ,  // actionName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action . action_type ,  // actionType
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t ( toplevel_paths . size ( ) ) ,  // countSubactionPaths
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										toplevel_paths . ptr ( ) ,  // subactionPaths
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										" "  // localizedActionName
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									copy_string_to_char_buffer ( p_name ,  action_info . actionName ,  XR_MAX_ACTION_NAME_SIZE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									copy_string_to_char_buffer ( p_localized_name ,  action_info . localizedActionName ,  XR_MAX_LOCALIZED_ACTION_NAME_SIZE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrCreateAction ( action_set - > handle ,  & action_info ,  & action . handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to create action  " ,  p_name ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-05 17:25:28 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									set_object_name ( XR_OBJECT_TYPE_ACTION ,  uint64_t ( action . handle ) ,  p_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  action_owner . make_rid ( action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : action_get_name ( RID  p_action )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_action . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  String ( " None " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  String ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  action - > name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XrAction  OpenXRAPI : : action_get_handle ( RID  p_action )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_action . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XR_NULL_HANDLE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  XR_NULL_HANDLE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  action - > handle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : action_free ( RID  p_action )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( action - > handle  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										xrDestroyAction ( action - > handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									action_owner . free ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : get_interaction_profile_rid ( XrPath  p_path )  {  
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( const  RID  & ip_rid  :  interaction_profile_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( ip_rid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ip  & &  ip - > path  = =  p_path )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-21 21:23:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  ip_rid ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								XrPath  OpenXRAPI : : get_interaction_profile_path ( RID  p_interaction_profile )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_interaction_profile . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( ip ,  XR_NULL_PATH ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ip - > path ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								RID  OpenXRAPI : : interaction_profile_create ( const  String  & p_name )  {  
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! is_interaction_profile_supported ( p_name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-23 13:20:12 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// The extension enabling this path must not be active, we will silently skip this interaction profile
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									InteractionProfile  new_interaction_profile ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrStringToPath ( instance ,  p_name . utf8 ( ) . get_data ( ) ,  & new_interaction_profile . path ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to get path for  " ,  p_name ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RID ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RID  existing_ip  =  get_interaction_profile_rid ( new_interaction_profile . path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( existing_ip . is_valid ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  existing_ip ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									new_interaction_profile . name  =  p_name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  interaction_profile_owner . make_rid ( new_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								String  OpenXRAPI : : interaction_profile_get_name ( RID  p_interaction_profile )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( p_interaction_profile . is_null ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  String ( " None " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( ip ,  String ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ip - > name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : interaction_profile_clear_bindings ( RID  p_interaction_profile )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( ip ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ip - > bindings . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								int  OpenXRAPI : : interaction_profile_add_binding ( RID  p_interaction_profile ,  RID  p_action ,  const  String  & p_path )  {  
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( ip ,  - 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! interaction_profile_supports_io_path ( ip - > name ,  p_path ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-11-12 01:59:22 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrActionSuggestedBinding  binding ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action  = =  nullptr  | |  action - > handle  = =  XR_NULL_HANDLE ,  - 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									binding . action  =  action - > handle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrStringToPath ( instance ,  p_path . utf8 ( ) . get_data ( ) ,  & binding . binding ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to get path for  " ,  p_path ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ip - > bindings . push_back ( binding ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ip - > bindings . size ( )  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : interaction_profile_add_modifier ( RID  p_interaction_profile ,  const  PackedByteArray  & p_modifier )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( ip ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! p_modifier . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Add it to our stack.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ip - > modifiers . push_back ( p_modifier ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : interaction_profile_suggest_bindings ( RID  p_interaction_profile )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( instance  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( ip ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									void  * next  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Note, extensions should only add binding modifiers if they are supported, else this may fail.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrBindingModificationsKHR  binding_modifiers ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector < const  XrBindingModificationBaseHeaderKHR  * >  modifiers ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! ip - > modifiers . is_empty ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( const  PackedByteArray  & modifier  :  ip - > modifiers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  XrBindingModificationBaseHeaderKHR  * ptr  =  ( const  XrBindingModificationBaseHeaderKHR  * ) modifier . ptr ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											modifiers . push_back ( ptr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										binding_modifiers . type  =  XR_TYPE_BINDING_MODIFICATIONS_KHR ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										binding_modifiers . next  =  next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										binding_modifiers . bindingModificationCount  =  modifiers . size ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										binding_modifiers . bindingModifications  =  modifiers . ptr ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										next  =  & binding_modifiers ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									const  XrInteractionProfileSuggestedBinding  suggested_bindings  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING ,  // type
 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										next ,  // next
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ip - > path ,  // interactionProfile
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t ( ip - > bindings . size ( ) ) ,  // countSuggestedBindings
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ip - > bindings . ptr ( )  // suggestedBindings
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrSuggestInteractionProfileBindings ( instance ,  & suggested_bindings ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( result  = =  XR_ERROR_PATH_UNSUPPORTED )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// this is fine, not all runtimes support all devices.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( " OpenXR Interaction profile  "  +  ip - > name  +  "  is not supported on this runtime " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to suggest bindings for  " ,  ip - > name ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// reporting is enough...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* For debugging:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									print_verbose ( " Suggested bindings for  "  +  ip - > name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  ip - > bindings . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t  strlen ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										char  path [ XR_MAX_PATH_LENGTH ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										String  action_name  =  action_get_name ( get_action_rid ( ip - > bindings [ i ] . action ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrResult  result  =  xrPathToString ( instance ,  ip - > bindings [ i ] . binding ,  XR_MAX_PATH_LENGTH ,  & strlen ,  path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR: failed to retrieve bindings for  " ,  action_name ,  " ! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_verbose ( "  -  "  +  action_name  +  "  =>  "  +  String ( path ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : interaction_profile_free ( RID  p_interaction_profile )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InteractionProfile  * ip  =  interaction_profile_owner . get_or_null ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL ( ip ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ip - > bindings . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-18 10:14:21 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ip - > modifiers . clear ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									interaction_profile_owner . free ( p_interaction_profile ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-26 17:02:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : sync_action_sets ( const  Vector < RID >  & p_active_sets )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Vector < XrActiveActionSet >  active_sets ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( int  i  =  0 ;  i  <  p_active_sets . size ( ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ActionSet  * action_set  =  action_set_owner . get_or_null ( p_active_sets [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( action_set  & &  action_set - > handle  ! =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XrActiveActionSet  aset ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											aset . actionSet  =  action_set - > handle ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											aset . subactionPath  =  XR_NULL_PATH ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											active_sets . push_back ( aset ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-19 13:21:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( active_sets . is_empty ( ) ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionsSyncInfo  sync_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTIONS_SYNC_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										uint32_t ( active_sets . size ( ) ) ,  // countActiveActionSets
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										active_sets . ptr ( )  // activeActionSets
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrSyncActions ( session ,  & sync_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-06-17 17:36:38 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ERR_FAIL_V_MSG ( false ,  " OpenXR: failed to sync active action sets! [ "  +  get_error_string ( result )  +  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( interaction_profile_changed )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Just in case, see if we already have active trackers...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( const  RID  & tracker  :  tracker_owner . get_owned_list ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											tracker_check_profile ( tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										interaction_profile_changed  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-08-12 20:25:43 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( OpenXRExtensionWrapper  * wrapper  :  registered_extension_wrappers )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										wrapper - > on_sync_actions ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : get_action_bool ( RID  p_action ,  RID  p_tracker )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action - > action_type  ! =  XR_ACTION_TYPE_BOOLEAN_INPUT ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateGetInfo  get_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTION_STATE_GET_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action - > handle ,  // action
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										tracker - > toplevel_path  // subactionPath
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateBoolean  result_state ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . type  =  XR_TYPE_ACTION_STATE_BOOLEAN , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . next  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetActionStateBoolean ( session ,  & get_info ,  & result_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: couldn't get action boolean! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result_state . isActive  & &  result_state . currentState ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								float  OpenXRAPI : : get_action_float ( RID  p_action ,  RID  p_tracker )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  0.0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  0.0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  0.0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action - > action_type  ! =  XR_ACTION_TYPE_FLOAT_INPUT ,  0.0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateGetInfo  get_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTION_STATE_GET_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action - > handle ,  // action
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										tracker - > toplevel_path  // subactionPath
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateFloat  result_state ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . type  =  XR_TYPE_ACTION_STATE_FLOAT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . next  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetActionStateFloat ( session ,  & get_info ,  & result_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: couldn't get action float! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result_state . isActive  ?  result_state . currentState  :  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Vector2  OpenXRAPI : : get_action_vector2 ( RID  p_action ,  RID  p_tracker )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  Vector2 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  Vector2 ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  Vector2 ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action - > action_type  ! =  XR_ACTION_TYPE_VECTOR2F_INPUT ,  Vector2 ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateGetInfo  get_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_ACTION_STATE_GET_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action - > handle ,  // action
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										tracker - > toplevel_path  // subactionPath
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrActionStateVector2f  result_state ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . type  =  XR_TYPE_ACTION_STATE_VECTOR2F , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result_state . next  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrGetActionStateVector2f ( session ,  & get_info ,  & result_state ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: couldn't get action vector2! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  result_state . isActive  ?  Vector2 ( result_state . currentState . x ,  result_state . currentState . y )  :  Vector2 ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-06-14 07:33:03 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								XRPose : : TrackingConfidence  OpenXRAPI : : get_action_pose ( RID  p_action ,  RID  p_tracker ,  Transform3D  & r_transform ,  Vector3  & r_linear_velocity ,  Vector3  & r_angular_velocity )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  XRPose : : XR_TRACKING_CONFIDENCE_NONE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  XRPose : : XR_TRACKING_CONFIDENCE_NONE ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  XRPose : : XR_TRACKING_CONFIDENCE_NONE ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action - > action_type  ! =  XR_ACTION_TYPE_POSE_INPUT ,  XRPose : : XR_TRACKING_CONFIDENCE_NONE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// print_verbose("Checking " + action->name + " => " + tracker->name + " (" + itos(tracker->toplevel_path) + ")");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									uint64_t  index  =  0xFFFFFFFF ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									uint64_t  size  =  uint64_t ( action - > trackers . size ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									for  ( uint64_t  i  =  0 ;  i  <  size  & &  index  = =  0xFFFFFFFF ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( action - > trackers [ i ] . tracker_rid  = =  p_tracker )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											index  =  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( index  = =  0xFFFFFFFF )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// couldn't find it?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 18:58:24 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrTime  display_time  =  get_predicted_display_time ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( display_time  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( action - > trackers [ index ] . space  = =  XR_NULL_HANDLE )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										// if this is a pose we need to define spaces
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrActionSpaceCreateInfo  action_space_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											XR_TYPE_ACTION_SPACE_CREATE_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											action - > handle ,  // action
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											tracker - > toplevel_path ,  // subactionPath
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{  0.0 ,  0.0 ,  0.0 ,  1.0  } ,  // orientation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													{  0.0 ,  0.0 ,  0.0  }  // position
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  // poseInActionSpace
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrSpace  space ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XrResult  result  =  xrCreateActionSpace ( session ,  & action_space_info ,  & space ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											print_line ( " OpenXR: couldn't create action space! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										action - > trackers . ptrw ( ) [ index ] . space  =  space ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpaceVelocity  velocity  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SPACE_VELOCITY ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // velocityFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  } ,  // linearVelocity
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{  0.0 ,  0.0 ,  0.0  }  // angularVelocity
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrSpaceLocation  location  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_SPACE_LOCATION ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										& velocity ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										0 ,  // locationFlags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{  0.0 ,  0.0 ,  0.0 ,  0.0  } ,  // orientation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{  0.0 ,  0.0 ,  0.0  }  // position
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  // pose
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									XrResult  result  =  xrLocateSpace ( action - > trackers [ index ] . space ,  play_space ,  display_time ,  & location ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to locate space! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  XRPose : : XR_TRACKING_CONFIDENCE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XRPose : : TrackingConfidence  confidence  =  transform_from_location ( location ,  r_transform ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									parse_velocities ( velocity ,  r_linear_velocity ,  r_angular_velocity ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  confidence ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : trigger_haptic_pulse ( RID  p_action ,  RID  p_tracker ,  float  p_frequency ,  float  p_amplitude ,  XrDuration  p_duration_ns )  {  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( session  = =  XR_NULL_HANDLE ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Action  * action  =  action_owner . get_or_null ( p_action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( action ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Tracker  * tracker  =  tracker_owner . get_or_null ( p_tracker ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_NULL_V ( tracker ,  false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! running )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_FAIL_COND_V ( action - > action_type  ! =  XR_ACTION_TYPE_VIBRATION_OUTPUT ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrHapticActionInfo  action_info  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_HAPTIC_ACTION_INFO ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										action - > handle ,  // action
 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-05 21:09:21 +11:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										tracker - > toplevel_path  // subactionPath
 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrHapticVibration  vibration  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										XR_TYPE_HAPTIC_VIBRATION ,  // type
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										nullptr ,  // next
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_duration_ns ,  // duration
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_frequency ,  // frequency
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										p_amplitude ,  // amplitude
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XrResult  result  =  xrApplyHapticFeedback ( session ,  & action_info ,  ( const  XrHapticBaseHeader  * ) & vibration ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( XR_FAILED ( result ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										print_line ( " OpenXR: failed to apply haptic feedback! [ " ,  get_error_string ( result ) ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : register_composition_layer_provider ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot register OpenXR composition layer providers while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									composition_layer_providers . append ( p_extension ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : unregister_composition_layer_provider ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot unregister OpenXR composition layer providers while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-13 16:39:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									composition_layer_providers . erase ( p_extension ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-26 09:04:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : register_projection_views_extension ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot register OpenXR projection views extensions while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									projection_views_extensions . append ( p_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : unregister_projection_views_extension ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot unregister OpenXR projection views extensions while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-12-10 13:40:47 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									projection_views_extensions . erase ( p_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  OpenXRAPI : : register_frame_info_extension ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot register OpenXR frame info extensions while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									frame_info_extensions . append ( p_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : unregister_frame_info_extension ( OpenXRExtensionWrapper  * p_extension )  {  
						 
					
						
							
								
									
										
										
										
											2025-08-11 15:44:10 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ERR_FAIL_COND_MSG ( running ,  " Cannot unregister OpenXR frame info extensions while the session is running. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-27 10:42:05 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									frame_info_extensions . erase ( p_extension ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  Vector < XrEnvironmentBlendMode >  OpenXRAPI : : get_supported_environment_blend_modes ( )  {  
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_environment_blend_modes ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bool  OpenXRAPI : : is_environment_blend_mode_supported ( XrEnvironmentBlendMode  p_blend_mode )  const  {  
						 
					
						
							
								
									
										
										
										
											2024-12-18 17:22:37 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  supported_environment_blend_modes . has ( p_blend_mode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  OpenXRAPI : : set_environment_blend_mode ( XrEnvironmentBlendMode  p_blend_mode )  {  
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( emulate_environment_blend_mode_alpha_blend  & &  p_blend_mode  = =  XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										requested_environment_blend_mode  =  XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										environment_blend_mode  =  XR_ENVIRONMENT_BLEND_MODE_OPAQUE ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set_render_environment_blend_mode ( environment_blend_mode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-18 09:53:39 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// We allow setting this when not initialized and will check if it is supported when initializing.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// After OpenXR is initialized we verify we're setting a supported blend mode.
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									else  if  ( ! is_initialized ( )  | |  is_environment_blend_mode_supported ( p_blend_mode ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										requested_environment_blend_mode  =  p_blend_mode ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										environment_blend_mode  =  p_blend_mode ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-11 14:39:11 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set_render_environment_blend_mode ( environment_blend_mode ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-12 12:39:48 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-02-02 09:14:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  OpenXRAPI : : set_emulate_environment_blend_mode_alpha_blend ( bool  p_enabled )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									emulate_environment_blend_mode_alpha_blend  =  p_enabled ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								OpenXRAPI : : OpenXRAlphaBlendModeSupport  OpenXRAPI : : is_environment_blend_mode_alpha_blend_supported ( )  {  
						 
					
						
							
								
									
										
										
										
											2025-02-26 17:35:03 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( emulate_environment_blend_mode_alpha_blend )  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  OPENXR_ALPHA_BLEND_MODE_SUPPORT_EMULATING ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-26 17:35:03 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  ( is_environment_blend_mode_supported ( XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-25 14:07:50 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}