| 204 | } |
| 205 | |
| 206 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_Create(ovrSession* pSession, ovrGraphicsLuid* pLuid) |
| 207 | { |
| 208 | REV_TRACE(ovr_Create); |
| 209 | |
| 210 | if (!pSession) |
| 211 | return ovrError_InvalidParameter; |
| 212 | |
| 213 | *pSession = nullptr; |
| 214 | |
| 215 | // Initialize the opaque pointer with our own OpenVR-specific struct |
| 216 | g_Sessions.emplace_back(); |
| 217 | |
| 218 | // Get the LUID for the OpenVR adapter |
| 219 | uint64_t adapter; |
| 220 | vr::VRSystem()->GetOutputDevice(&adapter, vr::TextureType_DirectX); |
| 221 | if (adapter) |
| 222 | { |
| 223 | // Copy the LUID into the structure |
| 224 | static_assert(sizeof(adapter) == sizeof(ovrGraphicsLuid), |
| 225 | "The adapter LUID needs to fit in ovrGraphicsLuid"); |
| 226 | if (pLuid) |
| 227 | memcpy(pLuid, &adapter, sizeof(ovrGraphicsLuid)); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | // Fall-back to the default adapter |
| 232 | IDXGIFactory1* pFactory = nullptr; |
| 233 | if (FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))) |
| 234 | return ovrError_RuntimeException; |
| 235 | |
| 236 | IDXGIAdapter1* pAdapter = nullptr; |
| 237 | if (FAILED(pFactory->EnumAdapters1(0, &pAdapter))) |
| 238 | return ovrError_RuntimeException; |
| 239 | |
| 240 | DXGI_ADAPTER_DESC1 desc; |
| 241 | if (FAILED(pAdapter->GetDesc1(&desc))) |
| 242 | return ovrError_RuntimeException; |
| 243 | |
| 244 | // Copy the LUID into the structure |
| 245 | static_assert(sizeof(desc.AdapterLuid) == sizeof(ovrGraphicsLuid), |
| 246 | "The adapter LUID needs to fit in ovrGraphicsLuid"); |
| 247 | if (pLuid) |
| 248 | memcpy(pLuid, &desc.AdapterLuid, sizeof(ovrGraphicsLuid)); |
| 249 | } |
| 250 | |
| 251 | // Oculus games expect a seated tracking space by default |
| 252 | vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseSeated); |
| 253 | |
| 254 | *pSession = &g_Sessions.back(); |
| 255 | return ovrSuccess; |
| 256 | } |
| 257 | |
| 258 | OVR_PUBLIC_FUNCTION(void) ovr_Destroy(ovrSession session) |
| 259 | { |
nothing calls this directly
no outgoing calls
no test coverage detected