// This couroutine is called every frame. IEnumerator EndOfFrame() { while (true) { yield return(new WaitForEndOfFrame()); if (DisplayController.UseRenderManager && DisplayController.CheckDisplayStartup()) { // Issue a RenderEvent, which copies Unity RenderTextures to RenderManager buffers #if UNITY_5_2 || UNITY_5_3 GL.Clear(false, true, Camera.backgroundColor); GL.IssuePluginEvent(DisplayController.RenderManager.GetRenderEventFunction(), OsvrRenderManager.RENDER_EVENT); if (DisplayController.showDirectModePreview) { Camera.Render(); } #else Debug.LogError("GL.IssuePluginEvent failed. This version of Unity cannot support RenderManager."); DisplayController.UseRenderManager = false; #endif } //if we disabled the dummy camera, enable it here if (_disabledCamera) { Camera.enabled = true; _disabledCamera = false; } } }
// This couroutine is called every frame. IEnumerator EndOfFrame() { while (true) { yield return(new WaitForEndOfFrame()); if (DisplayController.UseRenderManager && DisplayController.CheckDisplayStartup()) { // Issue a RenderEvent, which copies Unity RenderTextures to RenderManager buffers #if UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 GL.Viewport(_emptyViewport); GL.Clear(false, true, Camera.backgroundColor); GL.IssuePluginEvent(DisplayController.RenderManager.GetRenderEventFunction(), OsvrRenderManager.RENDER_EVENT); if (DisplayController.showDirectModePreview) { Camera.Render(); } #else Debug.LogError("[OSVR-Unity] GL.IssuePluginEvent failed. This version of Unity cannot support RenderManager."); DisplayController.UseRenderManager = false; #endif } //if we disabled the dummy camera, enable it here if (_disabledCamera) { Camera.enabled = true; _disabledCamera = false; } //Sends queued-up commands in the driver's command buffer to the GPU. //only accessible in Unity 5.4+ API #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_7 || UNITY_4_6) GL.Flush(); #endif } }
// The main rendering loop, should be called late in the pipeline, i.e. from OnPreCull // Set our viewer and eye poses and render to each surface. void DoRendering() { // update poses once DisplayConfig is ready if (DisplayController.CheckDisplayStartup()) { if (_hmdConnectionError) { _hmdConnectionError = false; Debug.Log("[OSVR-Unity] HMD connection established. You can ignore previous error messages indicating Display Startup failure."); } // update the viewer's head pose // currently getting viewer pose from DisplayConfig always UpdateViewerHeadPose(GetViewerPose(ViewerIndex)); // each viewer updates its eye poses, viewports, projection matrices UpdateEyes(); } else { if (!_hmdConnectionError) { //report an error message once if the HMD is not connected //it can take a few frames to connect under normal operation, so inidcate when this error has been resolved _hmdConnectionError = true; Debug.LogError("[OSVR-Unity] Display Startup failed. Check HMD connection."); } } }
void Update() { if (!recentered) { if (_displayController != null && _displayController.CheckDisplayStartup() && _displayController.UseRenderManager) { _displayController.RenderManager.SetRoomRotationUsingHead(); recentered = true; } else if (_displayController != null && _displayController.CheckDisplayStartup() && !_displayController.UseRenderManager) { _clientKit.context.SetRoomRotationUsingHead(); recentered = true; } } }
// Culling determines which objects are visible to the camera. OnPreCull is called just before this process. // This gets called because we have a camera component, but we disable the camera here so it doesn't render. // We have the "dummy" camera so existing Unity game code can refer to a MainCamera object. // We update our viewer and eye transforms here because it is as late as possible before rendering happens. // OnPreRender is not called because we disable the camera here. void OnPreCull() { //leave the preview camera enabled if there is no display config _camera.enabled = !DisplayController.CheckDisplayStartup(); DoRendering(); // Flag that we disabled the camera _disabledCamera = true; }
// Culling determines which objects are visible to the camera. OnPreCull is called just before this process. // This gets called because we have a camera component, but we disable the camera here so it doesn't render. // We have the "dummy" camera so existing Unity game code can refer to a MainCamera object. // We update our viewer and eye transforms here because it is as late as possible before rendering happens. // OnPreRender is not called because we disable the camera here. void OnPreCull() { //leave the preview camera enabled if there is no display config _camera.enabled = !DisplayController.CheckDisplayStartup(); DoRendering(); //Sends queued-up commands in the driver's command buffer to the GPU. //only accessible in Unity 5.4+ API #if !(UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_7 || UNITY_4_6) GL.Flush(); #endif // Flag that we disabled the camera _disabledCamera = true; }
// Culling determines which objects are visible to the camera. OnPreCull is called just before this process. // This gets called because we have a camera component, but we disable the camera here so it doesn't render. // We have the "dummy" camera so existing Unity game code can refer to a MainCamera object. // We update our viewer and eye transforms here because it is as late as possible before rendering happens. // OnPreRender is not called because we disable the camera here. void OnPreCull() { if (!DisplayController.CheckDisplayStartup()) { //leave this preview camera enabled if there is no display config _camera.enabled = true; } else { // To save Render time, disable this camera here and re-enable after the frame // OR, in DirectMode, leave it on for "mirror" mode, although this is an expensive operation // The long-term solution is to provide a DirectMode preview window in RenderManager //@todo enable directmode preview in RenderManager _camera.enabled = DisplayController.UseRenderManager && DisplayController.showDirectModePreview; } DoRendering(); // Flag that we disabled the camera _disabledCamera = true; }
// The main rendering loop, should be called late in the pipeline, i.e. from OnPreCull // Set our viewer and eye poses and render to each surface. void DoRendering() { // update poses once DisplayConfig is ready if (DisplayController.CheckDisplayStartup()) { // update the viewer's head pose // @todo Get viewer pose from RenderManager if UseRenderManager = true // currently getting viewer pose from DisplayConfig always UpdateViewerHeadPose(GetViewerPose(ViewerIndex)); // each viewer updates its eye poses, viewports, projection matrices UpdateEyes(); } else { if (!DisplayController.CheckDisplayStartup()) { //@todo do something other than not show anything Debug.LogError("Display Startup failed. Check HMD connection."); } } }