From 255db239eaa0bf3075db7a84c2638839a3c0cebc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 2 May 2021 20:14:50 +0200 Subject: [PATCH] Fixed rendering pause feature, added sample option --- .../Converters/RenderingPauseConverter.cs | 20 ++++++++++++++ .../ViewModels/MainViewModel.cs | 27 +++++++++++++++++++ .../Views/MainWindow.xaml | 12 ++++++++- .../ComputeShaderPanel.Rendering.cs | 15 ++++++++--- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/RenderingPauseConverter.cs diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/RenderingPauseConverter.cs b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/RenderingPauseConverter.cs new file mode 100644 index 00000000..53493e7f --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/RenderingPauseConverter.cs @@ -0,0 +1,20 @@ +using Microsoft.UI.Xaml.Controls; + +namespace ComputeSharp.SwapChain.WinUI.Converters +{ + /// + /// A class with some static converters for rendering state. + /// + public static class RenderingPauseConverter + { + /// + /// Gets a symbol for an input rendering state. + /// + /// Whether or not the rendering is currently paaused. + /// A symbol representing the next action for the rendering. + public static Symbol ConvertPausedToSymbol(bool value) + { + return value ? Symbol.Play : Symbol.Pause; + } + } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs index 2ea85921..c71153fb 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs @@ -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); } /// @@ -70,5 +73,29 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels } } } + + private bool isRenderingPaused; + + /// + /// Gets or sets whether the rendering is currently paused. + /// + public bool IsRenderingPaused + { + get => this.isRenderingPaused; + set => SetProperty(ref this.isRenderingPaused, value); + } + + /// + /// Gets the command that toggles . + /// + public IRelayCommand ToggleRenderingPausedCommand { get; } + + /// + /// Toggles . + /// + private void ToggleRenderingPaused() + { + IsRenderingPaused = !IsRenderingPaused; + } } } diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index f4ba3099..8648baea 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -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}"/> + + +