----------------------------------------------------------------------------- Purpose: This is called by vrserver after it receives a pointer back from HmdDriverFactory. You should do your resources allocations here (**not** in the constructor). -----------------------------------------------------------------------------
| 8 | // You should do your resources allocations here (**not** in the constructor). |
| 9 | //----------------------------------------------------------------------------- |
| 10 | vr::EVRInitError MyDeviceProvider::Init( vr::IVRDriverContext *pDriverContext ) |
| 11 | { |
| 12 | // We need to initialise our driver context to make calls to the server. |
| 13 | // OpenVR provides a macro to do this for us. |
| 14 | VR_INIT_SERVER_DRIVER_CONTEXT( pDriverContext ); |
| 15 | |
| 16 | // Let's add our controllers to the system. |
| 17 | // First, we need to actually instantiate our controller devices. |
| 18 | // We made the constructor take in a controller role, so let's pass their respective roles in. |
| 19 | my_left_controller_device_ = std::make_unique< MyControllerDeviceDriver >( vr::TrackedControllerRole_LeftHand ); |
| 20 | my_right_controller_device_ = std::make_unique< MyControllerDeviceDriver >( vr::TrackedControllerRole_RightHand ); |
| 21 | |
| 22 | // Now we need to tell vrserver about our controllers. |
| 23 | // The first argument is the serial number of the device, which must be unique across all devices. |
| 24 | // We get it from our driver settings when we instantiate, |
| 25 | // And can pass it out of the function with MyGetSerialNumber(). |
| 26 | // Let's add the left hand controller first (there isn't a specific order). |
| 27 | // make sure we actually managed to create the device. |
| 28 | // TrackedDeviceAdded returning true means we have had our device added to SteamVR. |
| 29 | if ( !vr::VRServerDriverHost()->TrackedDeviceAdded( my_left_controller_device_->MyGetSerialNumber().c_str(), vr::TrackedDeviceClass_Controller, my_left_controller_device_.get() ) ) |
| 30 | { |
| 31 | DriverLog( "Failed to create left controller device!" ); |
| 32 | // We failed? Return early. |
| 33 | return vr::VRInitError_Driver_Unknown; |
| 34 | } |
| 35 | |
| 36 | |
| 37 | // Now, the right hand |
| 38 | // Make sure we actually managed to create the device. |
| 39 | // TrackedDeviceAdded returning true means we have had our device added to SteamVR. |
| 40 | if ( !vr::VRServerDriverHost()->TrackedDeviceAdded( my_right_controller_device_->MyGetSerialNumber().c_str(), vr::TrackedDeviceClass_Controller, my_right_controller_device_.get() ) ) |
| 41 | { |
| 42 | DriverLog( "Failed to create right controller device!" ); |
| 43 | // We failed? Return early. |
| 44 | return vr::VRInitError_Driver_Unknown; |
| 45 | } |
| 46 | |
| 47 | return vr::VRInitError_None; |
| 48 | } |
| 49 | |
| 50 | //----------------------------------------------------------------------------- |
| 51 | // Purpose: Tells the runtime which version of the API we are targeting. |