-
Notifications
You must be signed in to change notification settings - Fork 65
/
dllmain.cpp
95 lines (70 loc) · 3.14 KB
/
dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "UnityInterfaces.h"
#include "CommonTypes.h"
#include "OpenVRSystem.h"
#include "Display/Display.h"
#include "Input/Input.h"
#include "ProviderInterface/IUnityXRPreInit.h"
#include "ProviderInterface/IUnityXRTrace.h"
#include "ProviderInterface/UnitySubsystemTypes.h"
#include "ProviderInterface/IUnityInterface.h"
static OpenVRProviderContext *s_pOpenVRProviderContext {};
UnitySubsystemErrorCode Load_Display( OpenVRProviderContext & );
UnitySubsystemErrorCode Load_Input( OpenVRProviderContext & );
IUnityXRTrace *s_pXRTrace = nullptr;
static bool ReportError( const char *subsystemProviderName, UnitySubsystemErrorCode err )
{
if ( err != kUnitySubsystemErrorCodeSuccess )
{
XR_TRACE_ERROR( s_pOpenVRProviderContext->trace, "[OpenVR] [Error] Error loading subsystem: %s (%d)\n", subsystemProviderName, err );
return true;
}
return false;
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
UnityPluginLoad( IUnityInterfaces *unityInterfaces )
{
// Setup interfaces
UnityInterfaces::Get().SetUnityInterfaces( unityInterfaces );
s_pXRTrace = (IUnityXRTrace * )unityInterfaces->GetInterface( UNITY_GET_INTERFACE_GUID( IUnityXRTrace ) );
// Setup provider context
s_pOpenVRProviderContext = new OpenVRProviderContext;
s_pOpenVRProviderContext->interfaces = unityInterfaces;
s_pOpenVRProviderContext->trace = (IUnityXRTrace * )unityInterfaces->GetInterface( UNITY_GET_INTERFACE_GUID( IUnityXRTrace ) );
XR_TRACE( "[OpenVR] Registering providers\n" );
RegisterDisplayLifecycleProvider( s_pOpenVRProviderContext );
RegisterInputLifecycleProvider( s_pOpenVRProviderContext );
}
static bool UNITY_INTERFACE_API GetPreInitFlags( void *userData, uint64_t *flags )
{
*flags = 0;
return true;
}
static bool UNITY_INTERFACE_API GetGraphicsAdapterId( void *userData, UnityXRPreInitRenderer renderer, uint64_t rendererData, uint64_t *adapterId )
{
if ( OpenVRSystem::Get().GetCompositor() )
{
return OpenVRSystem::Get().GetGraphicsAdapterId( userData, renderer, rendererData, adapterId );
}
return false;
}
static bool UNITY_INTERFACE_API GetVulkanInstanceExtensions( void *userData, uint32_t namesCapacityIn, uint32_t *namesCountOut, char *namesString )
{
return OpenVRSystem::Get().GetVulkanInstanceExtensions( userData, namesCapacityIn, namesCountOut, namesString );
}
static bool UNITY_INTERFACE_API GetVulkanDeviceExtensions( void *userData, uint32_t namesCapacityIn, uint32_t *namesCountOut, char *namesString )
{
return OpenVRSystem::Get().GetVulkanDeviceExtensions( userData, namesCapacityIn, namesCountOut, namesString );
}
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
XRSDKPreInit( IUnityInterfaces *interfaces )
{
IUnityXRPreInit *preInit = (IUnityXRPreInit * )interfaces->GetInterface( GetUnityInterfaceGUID<IUnityXRPreInit>() );
UnityXRPreInitProvider provider = { 0 };
provider.userData = nullptr;
provider.GetPreInitFlags = GetPreInitFlags;
provider.GetGraphicsAdapterId = GetGraphicsAdapterId;
provider.GetVulkanInstanceExtensions = GetVulkanInstanceExtensions;
provider.GetVulkanDeviceExtensions = GetVulkanDeviceExtensions;
preInit->RegisterPreInitProvider( &provider );
XR_TRACE( "XRPreInitProvider registered\n" );
}