static public bool BeginSession(IntPtr sessionHandle) { if (SRDProjectSettings.IsRunWithoutSRDisplayMode()) { return(true); } if (sessionHandle == IntPtr.Zero) { return(false); } SrdXrResult xrResult = SRDCorePlugin.BeginSession(sessionHandle); if (xrResult == SrdXrResult.SUCCESS) { SRDCorePlugin.SetGraphicsAPI(sessionHandle, SystemInfo.graphicsDeviceType); SRDCorePlugin.SetColorSpaceSettings(sessionHandle, QualitySettings.desiredColorSpace); return(true); } var errorToMessage = new Dictionary <SrdXrResult, string>() { { SrdXrResult.ERROR_USB_NOT_CONNECTED, SRDHelper.SRDMessages.DeviceConnectionError }, { SrdXrResult.ERROR_DEVICE_NOT_FOUND, SRDHelper.SRDMessages.DeviceNotFoundError }, { SrdXrResult.ERROR_SESSION_RUNNING, SRDHelper.SRDMessages.AppConflictionError }, { SrdXrResult.ERROR_USB_3_NOT_CONNECTED, SRDHelper.SRDMessages.USB3ConnectionError }, }; var msg = errorToMessage.ContainsKey(xrResult) ? errorToMessage[xrResult] : string.Format("Fail to begin seesion {0}", xrResult); SRDHelper.PopupMessageAndForceToTerminate(msg); return(false); }
public bool RegisterSourceStereoTextures(Texture renderTextureL, Texture renderTextureR) { if ((renderTextureL == null) || (renderTextureR == null)) { Debug.LogError("RenderTextures are not set. Set renderTextures with RenderStereoComposition function"); return(false); } var width = SRDSettings.DeviceInfo.ScreenRect.Width; var height = SRDSettings.DeviceInfo.ScreenRect.Height; _textureForPassThrough = renderTextureL; _leftTextureData.texture = renderTextureL.GetNativeTexturePtr(); _rightTextureData.texture = renderTextureR.GetNativeTexturePtr(); if (_outTexture == null) { _outTexture = new RenderTexture(width, height, depth: 24, RenderTextureFormat.ARGB32); _outTexture.filterMode = FilterMode.Point; _outTexture.Create(); _outTextureData.texture = _outTexture.GetNativeTexturePtr(); } _leftTextureData.width = _rightTextureData.width = _outTextureData.width = (uint)width; _leftTextureData.height = _rightTextureData.height = _outTextureData.height = (uint)height; SRDCorePlugin.GenerateTextureAndShaders(SRDSessionHandler.SessionHandle, ref _leftTextureData, ref _rightTextureData, ref _outTextureData); return(true); }
static public bool CreateSession(out IntPtr sessionHandle) { SRDCorePlugin.ShowNativeLog(); if (SRDProjectSettings.IsRunWithoutSRDisplayMode()) { sessionHandle = IntPtr.Zero; return(true); } SrdXrResult xrResult = SRDCorePlugin.CreateSession(out sessionHandle); if (xrResult == SrdXrResult.SUCCESS) { return(true); } var errorToMessage = new Dictionary <SrdXrResult, string>() { { SrdXrResult.ERROR_DISPLAY_NOT_FOUND, SRDHelper.SRDMessages.DisplayConnectionError }, { SrdXrResult.ERROR_FORM_FACTOR_UNAVAILABLE, SRDHelper.SRDMessages.DisplayConnectionError }, { SrdXrResult.ERROR_RUNTIME_NOT_FOUND, SRDHelper.SRDMessages.DLLNotFoundError }, }; // Should be set all possible message to the dict var msg = errorToMessage.ContainsKey(xrResult) ? errorToMessage[xrResult] : string.Format("Fail to create seesion {0}", xrResult); SRDHelper.PopupMessageAndForceToTerminate(msg); if (DestroySession(sessionHandle)) { sessionHandle = IntPtr.Zero; } return(false); }
static public bool EndSession(IntPtr sessionHandle) { if (sessionHandle == IntPtr.Zero) { return(false); } SrdXrResult xrResult = SRDCorePlugin.EndSession(sessionHandle); return(xrResult == SrdXrResult.SUCCESS); }
public void RenderStereoComposition(bool IsSRRenderingActive) { RenderTexture backBuffer = null; if (IsSRRenderingActive) { SRDCorePlugin.EndFrame(SRDSessionHandler.SessionHandle, false, true); Graphics.Blit(_outTexture, backBuffer); } else { Graphics.Blit(_textureForPassThrough, backBuffer); } }
public static SrdXrResult CreateSession(out IntPtr session) { var devices = new SrdXrDeviceInfo[1]; var resultED = SRDCorePlugin.EnumerateDevices(devices, (uint)devices.Length); SrdXrSessionCreateInfo info; { info.platform_id = SrdXrPlatformId.PLATFORM_ID_SRD; info.coordinate_system = SrdXrCoordinateSystem.COORDINATE_SYSTEM_LEFT_Y_UP_Z_FORWARD; info.coordinate_unit = SrdXrCoordinateUnit.COORDINATE_UNIT_METER; info.device = devices[0]; } var resultCS = XRRuntimeAPI.CreateSession(ref info, out session); return((resultED != SrdXrResult.SUCCESS) ? resultED : resultCS); }
private SRDSessionHandler() { var isLinked = SRDCorePlugin.LinkXrLibraryWin64(); if (!isLinked && _isLibraryLinked) { SRDHelper.PopupMessageAndForceToTerminate(SRDHelper.SRDMessages.DLLNotFoundError); _isLibraryLinked = false; return; } _isLibraryLinked = isLinked; _prevState = SrdXrSessionState.SESSION_STATE_MAX_ENUM; _srdSubsystems = new List <ISRDSubsystem>(); }
public SrdXrResult GetCurrentProjMatrices(float nearClip, float farClip, out EyeProjectionMatrices projMatrices) { projMatrices = (_prevProjMatrix != null) ? _prevProjMatrix : SRDFaceTracker.CreateDefaultProjMatrices(); var leftMatrix = projMatrices.LeftMatrix; var rightMatrix = projMatrices.RightMatrix; var xrResult = SRDCorePlugin.GetProjectionMatrix(SRDSessionHandler.SessionHandle, nearClip, farClip, out leftMatrix, out rightMatrix); projMatrices = new EyeProjectionMatrices(leftMatrix, rightMatrix); if (xrResult == SrdXrResult.ERROR_HANDLE_INVALID || xrResult == SrdXrResult.ERROR_SESSION_NOT_RUNNING) { projMatrices = SRDFaceTracker.CreateDefaultProjMatrices(); } _prevProjMatrix = projMatrices; return(xrResult); }
public SrdXrResult GetCurrentFacePose(out FacePose facePose) { facePose = (_prevFacePose != null) ? _prevFacePose : SRDFaceTracker.CreateDefaultFacePose().GetTransformedBy(_currentOrigin); var headPose = facePose.HeadPose; var eyePoseL = facePose.EyePoseL; var eyePoseR = facePose.EyePoseR; var xrResult = SRDCorePlugin.GetFacePose(SRDSessionHandler.SessionHandle, out headPose, out eyePoseL, out eyePoseR); facePose = (new FacePose(headPose, eyePoseL, eyePoseR)).GetTransformedBy(_currentOrigin); if (xrResult == SrdXrResult.ERROR_HANDLE_INVALID || xrResult == SrdXrResult.ERROR_SESSION_NOT_RUNNING) { facePose = SRDFaceTracker.CreateDefaultFacePose().GetTransformedBy(_currentOrigin); } _prevFacePose = facePose; return(xrResult); }
public static bool GetSRDScreenRect(out SRDSettings.ScreenRect screenRect) { var size = SRDCorePlugin.CountDevices(); if (size == 0) { screenRect = new SRDSettings.ScreenRect(); return(false); } SrdXrDeviceInfo[] devices = { new SrdXrDeviceInfo(), }; SRDCorePlugin.EnumerateDevices(devices, 1); var target = devices[0].target_monitor_rectangle; var width = target.right - target.left; var height = target.bottom - target.top; screenRect = new SRDSettings.ScreenRect(target.left, target.top, width, height); return(true); }
public void PollEvent() { SrdXrEventDataBuffer data; while (SRDCorePlugin.PollEvent(_sessionHandle, out data) == SrdXrResult.SUCCESS) { if ((_prevState == SrdXrSessionState.SESSION_STATE_MAX_ENUM) || (data.state != _prevState)) { if (OnSessionStateChangedEvent != null) { OnSessionStateChangedEvent.Invoke(_prevState, data.state); } _prevState = data.state; } if (data.state == SrdXrSessionState.SESSION_STATE_LOSS_PENDING) { SrdXrDeviceState device_state; var result = SRDCorePlugin.GetDeviceState(_sessionHandle, out device_state); var msg = ""; if (result != SrdXrResult.SUCCESS) { msg = string.Format("Fail to get DeviceInfo: {0}", result); } else { if (device_state.connection_state == SrdXrDeviceConnectionState.DEVICE_NOT_CONNECTED) { msg += SRDHelper.SRDMessages.DeviceInterruptionError + " "; } if (device_state.power_state == SrdXrDevicePowerState.DEVICE_POWER_OFF) { msg += SRDHelper.SRDMessages.DeviceNotFoundError; } } SRDHelper.PopupMessageAndForceToTerminate(msg); } } }
static public bool DestroySession(IntPtr sessionHandle) { SrdXrResult xrResult = SRDCorePlugin.DestroySession(out sessionHandle); return(xrResult == SrdXrResult.SUCCESS); }
public void UpdateState(Transform srdWorldOrigin) { _currentOrigin = srdWorldOrigin; SRDCorePlugin.BeginFrame(SRDSessionHandler.SessionHandle, callInMainThread: true, callinRenderThread: true); }
/// <summary> /// An api to show/remove the CameraWindow /// </summary> /// <param name="isOn">The flag to show the CameraWindow. If this is true, the CameraWindow will open. If this is false, the CameraWindow will close.</param> /// <returns>Success or not.</returns> public bool ShowCameraWindow(bool isOn) { var res = SRDCorePlugin.ShowCameraWindow(SRDSessionHandler.SessionHandle, isOn); return(SrdXrResult.SUCCESS == res); }