// Token: 0x06005F5A RID: 24410 RVA: 0x00217CD0 File Offset: 0x002160D0 private IEnumerator RenderLoop() { while (Application.isPlaying) { yield return(this.waitForEndOfFrame); if (!SteamVR_Render.pauseRendering) { CVRCompositor compositor = OpenVR.Compositor; if (compositor != null) { if (!compositor.CanRenderScene()) { continue; } compositor.SetTrackingSpace(this.trackingSpace); } SteamVR_Overlay overlay = SteamVR_Overlay.instance; if (overlay != null) { overlay.UpdateOverlay(); } this.RenderExternalCamera(); } } yield break; }
/// <summary> /// Submits the VR view to the screen. /// </summary> public void Submit() { VREvent_t evt = new VREvent_t(); while (VR.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t)))) { // No need to do anything here! } TrackedDevicePose_t[] rposes = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount]; TrackedDevicePose_t[] gposes = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount]; EVRCompositorError merr = Compositor.WaitGetPoses(rposes, gposes); if (rposes[OpenVR.k_unTrackedDeviceIndex_Hmd].bPoseIsValid) { HmdMatrix34_t tmat = rposes[OpenVR.k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking; headMat = new Matrix4(tmat.m0, tmat.m1, tmat.m2, tmat.m3, tmat.m4, tmat.m5, tmat.m6, tmat.m7, tmat.m8, tmat.m9, tmat.m10, tmat.m11, 0, 0, 0, 1); headMat.Transpose(); HeadMatRot = headMat * Matrix4.CreateRotationX((float)(Math.PI * 0.5)); headMat = headMat * Matrix4.CreateRotationX((float)(Math.PI * 0.5)); headMat = headMat.ClearTranslation() * Matrix4.CreateTranslation(headMat.ExtractTranslation() * VRScale); headMat.Invert(); } if (merr != EVRCompositorError.None) { SysConsole.Output(OutputType.WARNING, "Posing error: " + merr); } Left = GetController(true); Right = GetController(false); if (!Compositor.CanRenderScene()) { SysConsole.Output(OutputType.WARNING, "Can't render VR scene!"); } Texture_t left = new Texture_t() { eColorSpace = EColorSpace.Auto, eType = EGraphicsAPIConvention.API_OpenGL, handle = new IntPtr(TheClient.Engine3D.MainView.CurrentFBOTexture) }; VRTextureBounds_t bounds = new VRTextureBounds_t() { uMin = 0f, uMax = 0.5f, vMin = 0f, vMax = 1f }; EVRCompositorError lerr = Compositor.Submit(EVREye.Eye_Left, ref left, ref bounds, EVRSubmitFlags.Submit_Default); if (lerr != EVRCompositorError.None) { SysConsole.Output(OutputType.WARNING, "Left eye error: " + lerr); } Texture_t right = new Texture_t() { eColorSpace = EColorSpace.Auto, eType = EGraphicsAPIConvention.API_OpenGL, handle = new IntPtr(TheClient.Engine3D.MainView.CurrentFBOTexture) }; VRTextureBounds_t rbounds = new VRTextureBounds_t() { uMin = 0.5f, uMax = 1f, vMin = 0f, vMax = 1f }; EVRCompositorError rerr = Compositor.Submit(EVREye.Eye_Right, ref right, ref rbounds, EVRSubmitFlags.Submit_Default); if (rerr != EVRCompositorError.None) { SysConsole.Output(OutputType.WARNING, "Right eye error: " + rerr); } }
private void setup() { //init VR System and check for errors var error = EVRInitError.None; vrSystem = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Scene); if ((int)error != (int)EVRInitError.None) { log("KerbalVrPlugin started."); } else { err(error.ToString()); } //rendervalues ######################################################### // Setup render values uint w = 0, h = 0; vrSystem.GetRecommendedRenderTargetSize(ref w, ref h); float sceneWidth = (float)w; float sceneHeight = (float)h; float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f; vrSystem.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom); float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f; vrSystem.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom); Vector2 tanHalfFov = new Vector2(Mathf.Max(-l_left, l_right, -r_left, r_right), Mathf.Max(-l_top, l_bottom, -r_top, r_bottom)); //Setup rendertextures hmdLeftEyeTexture = new Texture_t(); hmdLeftEyeTexture.eColorSpace = EColorSpace.Auto; hmdRightEyeTexture = new Texture_t(); hmdRightEyeTexture.eColorSpace = EColorSpace.Auto; //select Texture Type depending on RenderAPI (Currently only DirectX11 is tested) switch (SystemInfo.graphicsDeviceType) { case UnityEngine.Rendering.GraphicsDeviceType.OpenGL2: log("OpenGL2"); hmdLeftEyeTexture.eType = ETextureType.OpenGL; hmdRightEyeTexture.eType = ETextureType.OpenGL; break; case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore: log("OpenCore"); hmdLeftEyeTexture.eType = ETextureType.OpenGL; hmdRightEyeTexture.eType = ETextureType.OpenGL; break; case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2: log("OpenGLES2"); hmdLeftEyeTexture.eType = ETextureType.OpenGL; hmdRightEyeTexture.eType = ETextureType.OpenGL; break; case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3: log("OpenGLES3"); hmdLeftEyeTexture.eType = ETextureType.OpenGL; hmdRightEyeTexture.eType = ETextureType.OpenGL; break; case UnityEngine.Rendering.GraphicsDeviceType.Direct3D9: log("Direct3D9"); warn("DirectX 9 mode not Supported! There be Dragons!"); hmdLeftEyeTexture.eType = ETextureType.DirectX; hmdRightEyeTexture.eType = ETextureType.DirectX; break; case UnityEngine.Rendering.GraphicsDeviceType.Direct3D11: log("Direct3D11"); hmdLeftEyeTexture.eType = ETextureType.DirectX; hmdRightEyeTexture.eType = ETextureType.DirectX; break; case UnityEngine.Rendering.GraphicsDeviceType.Direct3D12: log("Direct3D12"); warn("DirectX 12 mode not implemented! There be Dragons!"); hmdLeftEyeTexture.eType = ETextureType.DirectX12; hmdRightEyeTexture.eType = ETextureType.DirectX12; break; default: throw (new Exception(SystemInfo.graphicsDeviceType.ToString() + " not supported")); } vrCompositor = OpenVR.Compositor; if (!vrCompositor.CanRenderScene()) { err("can not render scene"); } }