/// <summary> /// Captures the resolution texture. /// </summary> IEnumerator CaptureResolutionTextureCoroutine(ScreenshotResolution resolution, CaptureMode captureMode, int antiAliasing, ColorFormat colorFormat, bool recomputeAlphaMask) { if (!resolution.IsValid()) { yield break; } // Delegate call onResolutionUpdateStartDelegate(resolution); // Init texture m_ScreenshotTexture = GetOrCreateTexture(resolution, colorFormat, captureMode == CaptureMode.FIXED_GAMEVIEW ? true : false); if (captureMode == CaptureMode.GAMEVIEW_RESIZING) { // Force screen size change GameViewController.SetGameViewSize(m_ScreenshotTexture.width, m_ScreenshotTexture.height); yield return(new WaitForEndOfFrame()); // Force wait if (!Application.isPlaying) { // Useless texture update in editor mode when game is not running, // that takes some computational times to be sure that the UI is updated at least one time before the capture if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_ScreenshotTexture)); } else { CopyScreenToTexture(m_ScreenshotTexture); } } // Force screen size change, again // Particularly needed for special effects using several frame to compute their effects, like temporal anti aliasing for (int i = 0; i < m_GameViewResizingWaitingFrames; ++i) { GameViewController.SetGameViewSize(m_ScreenshotTexture.width, m_ScreenshotTexture.height); yield return(new WaitForEndOfFrame()); } // Delegate call to notify screen is resized onResolutionScreenResizedDelegate(resolution); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_ScreenshotTexture)); } else { CopyScreenToTexture(m_ScreenshotTexture); } } else if (captureMode == CaptureMode.RENDER_TO_TEXTURE) { // Do not need to wait anything, just capture the cameras RenderTexture renderTexture = GetOrCreateRenderTexture(resolution, antiAliasing); RenderCamerasToTexture(m_Cameras, m_ScreenshotTexture, renderTexture); } else if (captureMode == CaptureMode.FIXED_GAMEVIEW) { // Wait for the end of rendering yield return(new WaitForEndOfFrame()); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_ScreenshotTexture)); } else { CopyScreenToTexture(m_ScreenshotTexture); } } // Alpha mask if (colorFormat == ColorFormat.RGBA && recomputeAlphaMask) { // Capture the screen content yield return(StartCoroutine(RecomputeAlphaMask(resolution, m_Cameras, captureMode))); } // Delegate call onResolutionUpdateEndDelegate(resolution); }
/// <summary> /// Captures the resolution texture. /// </summary> IEnumerator CaptureResolutionTextureCoroutine(ScreenshotResolution resolution, CaptureMode captureMode, int antiAliasing, ColorFormat colorFormat, bool recomputeAlphaMask) { if (!resolution.IsValid()) { yield break; } // Delegate call onResolutionUpdateStartDelegate(resolution); // Init texture m_Texture = GetOrCreateTexture(resolution, colorFormat, captureMode == CaptureMode.FIXED_GAMEVIEW ? true : false); if (captureMode == CaptureMode.GAMEVIEW_RESIZING) { // Debug.Log ("Resize "); // Force screen size change GameViewController.SetGameViewSize(m_Texture.width, m_Texture.height); yield return(new WaitForEndOfFrame()); // Force wait if (!Application.isPlaying) { // Useless texture update in editor mode when game is not running, // that takes some computational times to be sure that the UI is updated at least one time before the capture if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } } // Delegate call to notify screen is resized onResolutionScreenResizedDelegate(resolution); // Wait several frames // Particularly needed for special effects using several frame to compute their effects, like temporal anti aliasing if (m_GameViewResizingWaitingMode == GameViewResizingWaitingMode.FRAMES || !Application.isPlaying) { for (int i = 0; i < m_GameViewResizingWaitingFrames; ++i) { // Debug.Log ("Wait " + i); GameViewController.SetGameViewSize(m_Texture.width, m_Texture.height); yield return(new WaitForEndOfFrame()); // Debug.Log ("Wait " + i + " end"); } } else { #if (UNITY_5_4_OR_NEWER) yield return(new WaitForSecondsRealtime(m_GameViewResizingWaitingTime)); #else if (Time.timeScale > 0f) { yield return(new WaitForSeconds(m_GameViewResizingWaitingTime)); } #endif yield return(new WaitForEndOfFrame()); } // Debug.Log ("Capture"); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } // Debug.Log ("End Capture"); } else if (captureMode == CaptureMode.RENDER_TO_TEXTURE) { // Wait for the end of rendering yield return(new WaitForEndOfFrame()); /* #if UNITY_EDITOR * if (Application.isPlaying) { * yield return new WaitForEndOfFrame (); * } else { * // We need to force a gameview repaint * Vector2 current = GameViewController.GetCurrentGameViewSize (); * GameViewController.SetGameViewSize ((int)current.x, (int)current.y); * yield return new WaitForEndOfFrame (); * } #endif */ // Do not need to wait anything, just capture the cameras RenderTexture renderTexture = GetOrCreateRenderTexture(resolution, antiAliasing); RenderCamerasToTexture(m_Cameras, m_Texture, renderTexture); } else if (captureMode == CaptureMode.FIXED_GAMEVIEW) { // Wait for the end of rendering yield return(new WaitForEndOfFrame()); // Capture the screen content if (MultiDisplayUtils.IsMultiDisplay()) { yield return(MultiDisplayCopyRenderBufferToTextureCoroutine(m_Texture)); } else { CopyScreenToTexture(m_Texture); } } // Alpha mask if (colorFormat == ColorFormat.RGBA && recomputeAlphaMask) { // Capture the screen content yield return(StartCoroutine(RecomputeAlphaMask(resolution, m_Cameras, captureMode))); } // Delegate call onResolutionUpdateEndDelegate(resolution); }