Fixed rendering pause feature, added sample option

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-20 00:27:59 +01:00
1 親 2d89489e7f
コミット 255db239ea
4ファイル変更
+70 -4

検索条件に一致するファイルはありません

@@ -0,0 +1,20 @@
using Microsoft.UI.Xaml.Controls;
namespace ComputeSharp.SwapChain.WinUI.Converters
{
/// <summary>
/// A class with some static converters for rendering state.
/// </summary>
public static class RenderingPauseConverter
{
/// <summary>
/// Gets a symbol for an input rendering state.
/// </summary>
/// <param name="value">Whether or not the rendering is currently paaused.</param>
/// <returns>A symbol representing the next action for the rendering.</returns>
public static Symbol ConvertPausedToSymbol(bool value)
{
return value ? Symbol.Play : Symbol.Pause;
}
}
}
@@ -3,6 +3,7 @@ using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.WinUI;
using CommunityToolkit.Mvvm.ComponentModel;
using ComputeSharp.SwapChain.WinUI.Models;
using CommunityToolkit.Mvvm.Input;
namespace ComputeSharp.SwapChain.WinUI.ViewModels
{
@@ -19,6 +20,8 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
this.selectedResolutionScale = 100;
this.selectedComputeShader = ComputeShaderOptions[0];
this.selectedComputeShader.IsSelected = true;
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
}
/// <summary>
@@ -70,5 +73,29 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
}
}
}
private bool isRenderingPaused;
/// <summary>
/// Gets or sets whether the rendering is currently paused.
/// </summary>
public bool IsRenderingPaused
{
get => this.isRenderingPaused;
set => SetProperty(ref this.isRenderingPaused, value);
}
/// <summary>
/// Gets the command that toggles <see cref="IsRenderingPaused"/>.
/// </summary>
public IRelayCommand ToggleRenderingPausedCommand { get; }
/// <summary>
/// Toggles <see cref="IsRenderingPaused"/>.
/// </summary>
private void ToggleRenderingPaused()
{
IsRenderingPaused = !IsRenderingPaused;
}
}
}
+11 -1
ファイルの表示
@@ -24,7 +24,8 @@
x:Name="ShaderPanel"
Grid.Row="1"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"
ResolutionScale="{x:Bind ViewModel.SelectedResolutionScale, Mode=OneWay}"/>
ResolutionScale="{x:Bind ViewModel.SelectedResolutionScale, Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"/>
<!--Invisible title bar-->
<Rectangle
@@ -41,6 +42,15 @@
HorizontalAlignment="Right"
Margin="48">
<!--Shader pause button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Command="{x:Bind ViewModel.ToggleRenderingPausedCommand}">
<SymbolIcon Symbol="{x:Bind converters:RenderingPauseConverter.ConvertPausedToSymbol(ViewModel.IsRenderingPaused), Mode=OneWay}"/>
</Button>
<!--Shader selection button-->
<Button
Padding="20"
+12 -3
ファイルの表示
@@ -113,6 +113,11 @@ namespace ComputeSharp.WinUI
/// </summary>
private bool isCancellationRequested;
/// <summary>
/// The <see cref="Stopwatch"/> instance tracking time since the first rendered frame.
/// </summary>
private Stopwatch? renderTimer;
/// <summary>
/// Initializes the current application.
/// </summary>
@@ -375,12 +380,14 @@ namespace ComputeSharp.WinUI
static void ExecuteRenderLoop(ComputeShaderPanel @this)
{
Stopwatch
startStopwatch = Stopwatch.StartNew(),
startStopwatch = @this.renderTimer ??= new(),
frameStopwatch = Stopwatch.StartNew();
const long targetFrameTimeInTicksFor60fps = 166666;
@this.OnUpdate(startStopwatch.Elapsed);
@this.OnUpdate(TimeSpan.Zero);
startStopwatch.Start();
const long targetFrameTimeInTicksFor60fps = 166666;
while (!@this.isCancellationRequested)
{
@@ -391,6 +398,8 @@ namespace ComputeSharp.WinUI
@this.OnUpdate(startStopwatch.Elapsed);
}
}
startStopwatch.Stop();
}
this.isCancellationRequested = false;