MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / enable

Method enable

Engine/source/platform/input/openVR/openVRProvider.cpp:534–627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534bool OpenVRProvider::enable()
535{
536 mOpenVRNS = Namespace::find(StringTable->insert("OpenVR"));
537
538 disable();
539
540 // Load openvr runtime
541 vr::EVRInitError eError = vr::VRInitError_None;
542 mHMD = vr::VR_Init(&eError, vr::VRApplication_Scene);
543
544 dMemset(mDeviceClassChar, '\0', sizeof(mDeviceClassChar));
545
546 if (eError != vr::VRInitError_None)
547 {
548 mHMD = NULL;
549 char buf[1024];
550 sprintf_s(buf, sizeof(buf), "Unable to init VR runtime: %s", vr::VR_GetVRInitErrorAsEnglishDescription(eError));
551 Con::printf(buf);
552 return false;
553 }
554
555 dMemset(&mLUID, '\0', sizeof(mLUID));
556
557#ifdef TORQUE_OS_WIN32
558
559 // For windows we need to lookup the DXGI record for this and grab the LUID for the display adapter. We need the LUID since
560 // T3D uses EnumAdapters1 not EnumAdapters whereas openvr uses EnumAdapters.
561 int32_t AdapterIdx;
562 IDXGIAdapter* EnumAdapter;
563 IDXGIFactory1* DXGIFactory;
564 mHMD->GetDXGIOutputInfo(&AdapterIdx);
565 // Get the LUID of the device
566
567 HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&DXGIFactory));
568
569 if (FAILED(hr))
570 AssertFatal(false, "OpenVRProvider::enable -> CreateDXGIFactory1 call failure");
571
572 hr = DXGIFactory->EnumAdapters(AdapterIdx, &EnumAdapter);
573
574 if (FAILED(hr))
575 {
576 Con::warnf("VR: HMD device has an invalid adapter.");
577 }
578 else
579 {
580 DXGI_ADAPTER_DESC desc;
581 hr = EnumAdapter->GetDesc(&desc);
582 if (FAILED(hr))
583 {
584 Con::warnf("VR: HMD device has an invalid adapter.");
585 }
586 else
587 {
588 dMemcpy(&mLUID, &desc.AdapterLuid, sizeof(mLUID));
589 }
590 SAFE_RELEASE(EnumAdapter);
591 }

Callers 2

TESTFunction · 0.45
openVRProvider.cppFile · 0.45

Calls 9

printfFunction · 0.85
GetTrackedDeviceStringFunction · 0.85
findFunction · 0.50
dMemsetFunction · 0.50
warnfFunction · 0.50
dMemcpyFunction · 0.50
MatrixFClass · 0.50
insertMethod · 0.45
resetMethod · 0.45

Tested by 1

TESTFunction · 0.36