@@ -533,6 +533,13 @@ bool init(const Init& _init)
533533 , TextureFormat::Unknown
534534 , TextureFormat::UnknownDepth
535535 );
536+
537+ #if BX_PLATFORM_VISIONOS
538+ m_deviceAnchor = ar_device_anchor_create ();
539+ m_worldTracking = ar_world_tracking_provider_create (ar_world_tracking_configuration_create ());
540+ m_arSession = ar_session_create ();
541+ ar_session_run (m_arSession, ar_data_providers_create_with_data_providers (m_worldTracking, nil ));
542+ #endif
536543 m_numWindows = 1 ;
537544
538545#if BX_PLATFORM_VISIONOS
@@ -908,6 +915,13 @@ void shutdown()
908915 MTL_RELEASE (m_vertexDescriptor);
909916 MTL_RELEASE (m_textureDescriptor);
910917 MTL_RELEASE (m_samplerDescriptor);
918+
919+ #if BX_PLATFORM_VISIONOS
920+ ar_session_stop (m_arSession);
921+ MTL_RELEASE (m_arSession);
922+ MTL_RELEASE (m_worldTracking);
923+ MTL_RELEASE (m_deviceAnchor);
924+ #endif
911925
912926 m_mainFrameBuffer.destroy ();
913927
@@ -1454,6 +1468,19 @@ bool isDeviceRemoved() override
14541468 return false ;
14551469 }
14561470
1471+ #if BX_PLATFORM_VISIONOS
1472+ void createPoseForTiming (cp_frame_timing_t timing, ar_world_tracking_provider_t world_tracking)
1473+ {
1474+ cp_time_t presentationTime = cp_frame_timing_get_presentation_time (timing);
1475+ CFTimeInterval queryTime = cp_time_to_cf_time_interval (presentationTime);
1476+ ar_device_anchor_query_status_t status = ar_world_tracking_provider_query_device_anchor_at_timestamp (world_tracking, queryTime, m_deviceAnchor);
1477+ if (status != ar_device_anchor_query_status_success)
1478+ {
1479+ BX_WARN (false , " Device anchor query failed." )
1480+ }
1481+ }
1482+ #endif
1483+
14571484 void flip () override
14581485 {
14591486 if (NULL == m_commandBuffer)
@@ -1472,6 +1499,12 @@ void flip() override
14721499 if (NULL != frameBuffer.m_swapChain ->m_drawable )
14731500 {
14741501#if BX_PLATFORM_VISIONOS
1502+ if (m_worldTracking != NULL )
1503+ {
1504+ auto timingInfo = cp_drawable_get_frame_timing (frameBuffer.m_swapChain ->m_drawable );
1505+ createPoseForTiming (timingInfo, m_worldTracking);
1506+ cp_drawable_set_device_anchor (frameBuffer.m_swapChain ->m_drawable , m_deviceAnchor);
1507+ }
14751508 cp_drawable_encode_present (frameBuffer.m_swapChain ->m_drawable , m_commandBuffer);
14761509 cp_frame_end_submission (frameBuffer.m_swapChain ->m_frame );
14771510#else
@@ -2708,6 +2741,11 @@ void endEncoding()
27082741 Resolution m_resolution;
27092742 void * m_capture;
27102743 uint32_t m_captureSize;
2744+ #if BX_PLATFORM_VISIONOS
2745+ ar_session_t m_arSession;
2746+ ar_world_tracking_provider_t m_worldTracking;
2747+ ar_device_anchor_t m_deviceAnchor;
2748+ #endif
27112749
27122750 // descriptors
27132751 RenderPipelineDescriptor m_renderPipelineDescriptor;
0 commit comments