Fix scene animation rendering issue with game window is not selected tab

Fixes #170
This commit is contained in:
Wojtek Figat
2021-01-27 23:27:19 +01:00
parent b411539717
commit 876a728b41
3 changed files with 24 additions and 7 deletions

View File

@@ -430,7 +430,7 @@ namespace FlaxEditor.Windows.Assets
/// <summary> /// <summary>
/// Gets the original asset. Note: <see cref="AssetEditorWindowBase{T}.Asset"/> is the cloned asset for local editing. Use <see cref="SaveToOriginal"/> to apply changes to the original asset. /// Gets the original asset. Note: <see cref="AssetEditorWindowBase{T}.Asset"/> is the cloned asset for local editing. Use <see cref="SaveToOriginal"/> to apply changes to the original asset.
/// </summary> /// </summary>
public T OriginalAsset => (T)FlaxEngine.Content.GetAsset(_item.ID); public T OriginalAsset => (T)FlaxEngine.Content.Load(_item.ID);
/// <inheritdoc /> /// <inheritdoc />
protected ClonedAssetEditorWindowBase(Editor editor, AssetItem item) protected ClonedAssetEditorWindowBase(Editor editor, AssetItem item)

View File

@@ -277,6 +277,7 @@ namespace FlaxEditor.Windows.Assets
private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1]; private readonly StagingTexture[] _stagingTextures = new StagingTexture[FrameLatency + 1];
private RenderProgress _progress; private RenderProgress _progress;
private RenderEditorState _editorState; private RenderEditorState _editorState;
private GameWindow _gameWindow;
public RenderOptions Options => _options; public RenderOptions Options => _options;
@@ -373,6 +374,9 @@ namespace FlaxEditor.Windows.Assets
gameWin.Viewport.Task.PostRender += OnPostRender; gameWin.Viewport.Task.PostRender += OnPostRender;
if (!gameWin.Visible) if (!gameWin.Visible)
gameWin.Show(); gameWin.Show();
else if (!gameWin.IsFocused)
gameWin.Focus();
_gameWindow = gameWin;
_warmUpTimeLeft = _options.WarmUpTime; _warmUpTimeLeft = _options.WarmUpTime;
_animationFrame = 0; _animationFrame = 0;
var stagingTextureDesc = GPUTextureDescription.New2D(resolution.X, resolution.Y, gameWin.Viewport.Task.Output.Format, GPUTextureFlags.None); var stagingTextureDesc = GPUTextureDescription.New2D(resolution.X, resolution.Y, gameWin.Viewport.Task.Output.Format, GPUTextureFlags.None);
@@ -385,6 +389,12 @@ namespace FlaxEditor.Windows.Assets
_stagingTextures[i].TaskFrame = -1; _stagingTextures[i].TaskFrame = -1;
} }
_player.Play(); _player.Play();
if (!_player.IsPlaying)
{
Editor.LogError("Scene Animation Player failed to start playing.");
CancelRendering();
return;
}
if (_warmUpTimeLeft > 0.0f) if (_warmUpTimeLeft > 0.0f)
{ {
// Start warmup time // Start warmup time
@@ -438,8 +448,11 @@ namespace FlaxEditor.Windows.Assets
_stagingTextures[i].Texture.ReleaseGPU(); _stagingTextures[i].Texture.ReleaseGPU();
Object.Destroy(ref _stagingTextures[i].Texture); Object.Destroy(ref _stagingTextures[i].Texture);
} }
_progress.End(); if (_progress != null)
editor.ProgressReporting.UnregisterHandler(_progress); {
_progress.End();
editor.ProgressReporting.UnregisterHandler(_progress);
}
if (_editorState != null) if (_editorState != null)
{ {
editor.StateMachine.GoToState(editor.StateMachine.EditingSceneState); editor.StateMachine.GoToState(editor.StateMachine.EditingSceneState);
@@ -452,6 +465,7 @@ namespace FlaxEditor.Windows.Assets
gameWin.Viewport.BackgroundColor = Color.Transparent; gameWin.Viewport.BackgroundColor = Color.Transparent;
gameWin.Viewport.KeepAspectRatio = false; gameWin.Viewport.KeepAspectRatio = false;
gameWin.Viewport.Task.PostRender -= OnPostRender; gameWin.Viewport.Task.PostRender -= OnPostRender;
_gameWindow = null;
_isRendering = false; _isRendering = false;
_presenter.Panel.Enabled = true; _presenter.Panel.Enabled = true;
_presenter.BuildLayoutOnUpdate(); _presenter.BuildLayoutOnUpdate();
@@ -467,6 +481,11 @@ namespace FlaxEditor.Windows.Assets
{ {
// Render first frame // Render first frame
_player.Play(); _player.Play();
if (!_player.IsPlaying)
{
Editor.LogError("Scene Animation Player failed to start playing.");
CancelRendering();
}
_warmUpTimeLeft = -1; _warmUpTimeLeft = -1;
_state = States.Render; _state = States.Render;
} }
@@ -503,8 +522,7 @@ namespace FlaxEditor.Windows.Assets
private void OnPostRender(GPUContext context, RenderContext renderContext) private void OnPostRender(GPUContext context, RenderContext renderContext)
{ {
var gameWin = Editor.Instance.Windows.GameWin; var task = _gameWindow.Viewport.Task;
var task = gameWin.Viewport.Task;
var taskFrame = task.FrameCount; var taskFrame = task.FrameCount;
// Check all staging textures for finished GPU to CPU transfers // Check all staging textures for finished GPU to CPU transfers
@@ -540,7 +558,7 @@ namespace FlaxEditor.Windows.Assets
ref var stagingTexture = ref _stagingTextures[textureIdx]; ref var stagingTexture = ref _stagingTextures[textureIdx];
stagingTexture.AnimationFrame = _animationFrame; stagingTexture.AnimationFrame = _animationFrame;
stagingTexture.TaskFrame = taskFrame; stagingTexture.TaskFrame = taskFrame;
_options.VideoOutputFormat.RenderFrame(context, ref stagingTexture, _options, gameWin.Viewport.Task.Output); _options.VideoOutputFormat.RenderFrame(context, ref stagingTexture, _options, _gameWindow.Viewport.Task.Output);
// Now wait for the next animation frame to be updated // Now wait for the next animation frame to be updated
_state = States.Update; _state = States.Update;

View File

@@ -387,7 +387,6 @@ namespace FlaxEditor.Windows
} }
} }
// Prevent closing the game window tab during a play session // Prevent closing the game window tab during a play session
if (Editor.StateMachine.IsPlayMode && Editor.Options.Options.Input.CloseTab.Process(this, key)) if (Editor.StateMachine.IsPlayMode && Editor.Options.Options.Input.CloseTab.Process(this, key))
{ {