using System.Collections.Generic;
using ComputeSharp.SwapChain.Shaders;
using ComputeSharp.SwapChain.WinUI.Models;
using ComputeSharp.WinUI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ComputeSharp.SwapChain.WinUI.Shaders.Runners;
namespace ComputeSharp.SwapChain.WinUI.ViewModels
{
///
/// The viewmodel for for a view that allows users to select shaders and customize settings.
///
public sealed class MainViewModel : ObservableObject
{
///
/// Creates a new instance.
///
public MainViewModel()
{
this.isDynamicResolutionEnabled = true;
this.selectedResolutionScale = 100;
this.selectedComputeShader = ComputeShaderOptions[0];
this.selectedComputeShader.IsSelected = true;
SetResolutionScaleCommand = new RelayCommand(SetResolutionScale);
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
}
///
/// Gets the available resolution scaling options (as percentage values).
///
public IList ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
private bool isDynamicResolutionEnabled;
///
/// Gets or sets whether the dynamic resolution is enabled.
///
public bool IsDynamicResolutionEnabled
{
get => this.isDynamicResolutionEnabled;
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
}
private int selectedResolutionScale;
///
/// Gets the currently selected resolution scale setting (as percentage valaue).
///
public int SelectedResolutionScale
{
get => this.selectedResolutionScale;
private set => SetProperty(ref this.selectedResolutionScale, value);
}
///
/// Gets the command that sets .
///
public IRelayCommand SetResolutionScaleCommand { get; }
///
/// Sets .
///
private void SetResolutionScale(int resolutionScale)
{
SelectedResolutionScale = resolutionScale;
}
///
/// Gets the collection of available compute shader.
///
public IReadOnlyList ComputeShaderOptions { get; } = new ComputeShader[]
{
new("Colorful infinity", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Extruded truchet", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Fractal tiling", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Menger Journey", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Octagrams", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Protean clouds", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Two tiled truchet", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Pyramid pattern", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Triangle grid contouring", new ShaderRunner(static time => new((float)time.TotalSeconds))),
new("Contoured layers", new ContouredLayersRunner())
};
private ComputeShader selectedComputeShader;
///
/// Gets or sets the currently selected compute shader.
///
public ComputeShader SelectedComputeShader
{
get => this.selectedComputeShader;
set
{
this.selectedComputeShader.IsSelected = false;
if (SetProperty(ref this.selectedComputeShader, value) &&
value is not null)
{
value.IsSelected = true;
}
}
}
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;
}
}
}