Skip to content

Commit

Permalink
Adding WaitFrameSync to overlay loop and real pose timing
Browse files Browse the repository at this point in the history
  • Loading branch information
zite committed Jul 18, 2024
1 parent 7d5b854 commit 0a2d3c1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
24 changes: 23 additions & 1 deletion Providers/Input/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,33 @@ void OpenVRInputProvider::GfxThread_UpdateDevices()

if ( UserProjectSettings::GetInitializationType() == vr::VRApplication_Overlay )
{
if ( OpenVRSystem::Get().GetOverlay() == nullptr )
{
XR_TRACE( "[OpenVR] [ERROR] OpenVRSystem::Get().GetOverlay() returned nullptr.\n" );
return;
}

overlayError = OpenVRSystem::Get().GetOverlay()->WaitFrameSync(100);
if ( overlayError != vr::EVROverlayError::VROverlayError_None )
{
XR_TRACE( "[OpenVR] [ERROR] Overlay()->WaitFrameSync IVROverlay WaitFrameSync error: %d\n", overlayError );
return;
}

float last_vsync_time;
OpenVRSystem::Get().GetSystem()->GetTimeSinceLastVsync(&last_vsync_time, nullptr);

OpenVRSystem::Get().GetSystem()->GetDeviceToAbsoluteTrackingPose( vr::TrackingUniverseStanding, 0.0f, trackedDevicesCurrent, vr::k_unMaxTrackedDeviceCount );
OpenVRSystem::Get().GetSystem()->GetDeviceToAbsoluteTrackingPose( vr::TrackingUniverseStanding, 0.011f, trackedDevicesFuture, vr::k_unMaxTrackedDeviceCount );
OpenVRSystem::Get().GetSystem()->GetDeviceToAbsoluteTrackingPose( vr::TrackingUniverseStanding, last_vsync_time, trackedDevicesFuture, vr::k_unMaxTrackedDeviceCount );
}
else
{
if ( OpenVRSystem::Get().GetCompositor() == nullptr )
{
XR_TRACE( "[OpenVR] [ERROR] OpenVRSystem::Get().GetCompositor() returned nullptr.\n" );
return;
}

OpenVRSystem::Get().GetCompositor()->WaitGetPoses( trackedDevicesCurrent, vr::k_unMaxTrackedDeviceCount, trackedDevicesFuture, vr::k_unMaxTrackedDeviceCount );
}

Expand Down
1 change: 1 addition & 0 deletions Providers/Input/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class OpenVRInputProvider : public Singleton<OpenVRInputProvider>
static int trackerFeatureIndices[static_cast< int >( TrackerFeature::Total )];
static const int kUnityXRInputUpdateTypeCount = 2;
bool m_Started = false;
vr::EVROverlayError overlayError = vr::EVROverlayError::VROverlayError_None;

struct OpenVRDevice
{
Expand Down
15 changes: 12 additions & 3 deletions Providers/OpenVRSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ OpenVRSystem::OpenVRSystem() :
m_FrameIndex( 0 ),
m_VRSystem( nullptr ),
m_VRCompositor( nullptr ),
m_VROverlay( nullptr ),
initError( vr::VRInitError_None ),
tickCallback( nullptr )
{
Expand Down Expand Up @@ -60,20 +61,28 @@ bool OpenVRSystem::Initialize()
return false;
}

vr::IVRCompositor *vrCompositor = StartVRCompositor();
vr::IVRCompositor * vrCompositor = (vr::IVRCompositor*)vr::VR_GetGenericInterface(vr::IVRCompositor_Version, &initError);
if ( initError != vr::VRInitError_None )
{
std::string errorName = vr::VR_GetVRInitErrorAsSymbol( initError );
XR_TRACE( ( "[OpenVR] [ERROR] VR_GetGenericInterface IVRCompositor initError: " + errorName + "\n" ).c_str() );
return false;
}

vr::IVROverlay* vrOverlay = (vr::IVROverlay*)vr::VR_GetGenericInterface(vr::IVROverlay_Version, &initError);
if ( initError != vr::VRInitError_None )
{
std::string errorName = vr::VR_GetVRInitErrorAsSymbol( initError );
XR_TRACE( ( "[OpenVR] [ERROR] VR_Init initError: " + errorName + "\n" ).c_str() );
XR_TRACE( ( "[OpenVR] [ERROR] VR_GetGenericInterface IVROverlay initError: " + errorName + "\n" ).c_str() );
return false;
}

m_VRSystem = vrSystem;
m_VRCompositor = vrCompositor;
m_VROverlay = vrOverlay;
}

XR_TRACE( "[OpenVR] is initialized\n" );
XR_TRACE( "[OpenVR] initialized successfully. Runtime: %s\n", m_VRSystem->GetRuntimeVersion() );
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Providers/OpenVRSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OpenVRSystem : public Singleton<OpenVRSystem>

vr::IVRSystem *GetSystem() { return m_VRSystem; }
vr::IVRCompositor *GetCompositor() { return m_VRCompositor; }
vr::IVROverlay* GetOverlay() { return m_VROverlay; }

void SetTickCallback( TickCallback newTickCallback ) { tickCallback = newTickCallback; }

Expand All @@ -46,6 +47,7 @@ class OpenVRSystem : public Singleton<OpenVRSystem>
// OpenVR interfaces
vr::IVRSystem *m_VRSystem;
vr::IVRCompositor *m_VRCompositor;
vr::IVROverlay* m_VROverlay;

vr::EVRInitError initError;

Expand Down

0 comments on commit 0a2d3c1

Please sign in to comment.