@@ -540,6 +540,13 @@ bool init(const Init& _init)
540540 , TextureFormat::Unknown
541541 , TextureFormat::UnknownDepth
542542 );
543+
544+ #if BX_PLATFORM_VISIONOS
545+ m_deviceAnchor = ar_device_anchor_create ();
546+ m_worldTracking = ar_world_tracking_provider_create (ar_world_tracking_configuration_create ());
547+ m_arSession = ar_session_create ();
548+ ar_session_run (m_arSession, ar_data_providers_create_with_data_providers (m_worldTracking, nil ));
549+ #endif
543550 m_numWindows = 1 ;
544551
545552 #if BX_PLATFORM_VISIONOS
@@ -920,6 +927,13 @@ void shutdown()
920927 MTL_RELEASE (m_vertexDescriptor);
921928 MTL_RELEASE (m_textureDescriptor);
922929 MTL_RELEASE (m_samplerDescriptor);
930+
931+ #if BX_PLATFORM_VISIONOS
932+ ar_session_stop (m_arSession);
933+ MTL_RELEASE (m_arSession);
934+ MTL_RELEASE (m_worldTracking);
935+ MTL_RELEASE (m_deviceAnchor);
936+ #endif
923937
924938 m_mainFrameBuffer.destroy ();
925939
@@ -1465,6 +1479,19 @@ bool isDeviceRemoved() override
14651479 return false ;
14661480 }
14671481
1482+ #if BX_PLATFORM_VISIONOS
1483+ void createPoseForTiming (cp_frame_timing_t timing, ar_world_tracking_provider_t world_tracking)
1484+ {
1485+ cp_time_t presentationTime = cp_frame_timing_get_presentation_time (timing);
1486+ CFTimeInterval queryTime = cp_time_to_cf_time_interval (presentationTime);
1487+ ar_device_anchor_query_status_t status = ar_world_tracking_provider_query_device_anchor_at_timestamp (world_tracking, queryTime, m_deviceAnchor);
1488+ if (status != ar_device_anchor_query_status_success)
1489+ {
1490+ BX_WARN (false , " Device anchor query failed." )
1491+ }
1492+ }
1493+ #endif
1494+
14681495 void flip () override
14691496 {
14701497 if (NULL == m_commandBuffer)
@@ -1483,6 +1510,12 @@ void flip() override
14831510 if (NULL != frameBuffer.m_swapChain ->m_drawable )
14841511 {
14851512#if BX_PLATFORM_VISIONOS
1513+ if (m_worldTracking != NULL )
1514+ {
1515+ auto timingInfo = cp_drawable_get_frame_timing (frameBuffer.m_swapChain ->m_drawable );
1516+ createPoseForTiming (timingInfo, m_worldTracking);
1517+ cp_drawable_set_device_anchor (frameBuffer.m_swapChain ->m_drawable , m_deviceAnchor);
1518+ }
14861519 cp_drawable_encode_present (frameBuffer.m_swapChain ->m_drawable , m_commandBuffer);
14871520 cp_frame_end_submission (frameBuffer.m_swapChain ->m_frame );
14881521#else // BX_PLATFORM_VISIONOS
@@ -2719,6 +2752,11 @@ void endEncoding()
27192752 Resolution m_resolution;
27202753 void * m_capture;
27212754 uint32_t m_captureSize;
2755+ #if BX_PLATFORM_VISIONOS
2756+ ar_session_t m_arSession;
2757+ ar_world_tracking_provider_t m_worldTracking;
2758+ ar_device_anchor_t m_deviceAnchor;
2759+ #endif
27222760
27232761 // descriptors
27242762 RenderPipelineDescriptor m_renderPipelineDescriptor;
0 commit comments