Move shared logic between UWP/WinUI 3 samples to shared project
このコミットが含まれているのは:
1 親
d9fa15a880
コミット
a7e3213fd8
20ファイル変更
+86
-283
検索条件に一致するファイルはありません
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>751bb05b-563d-4b3a-94c6-15e2d79d35ea</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>ComputeSharp.SwapChain.Core.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\ComputeShader.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>751bb05b-563d-4b3a-94c6-15e2d79d35ea</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,23 @@
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#else
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace ComputeSharp.SwapChain.Core.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// A class with some static converters for resolution scale settings.
|
||||
/// </summary>
|
||||
public static class ResolutionScaleConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a resolution scale to a formatted string.
|
||||
/// </summary>
|
||||
/// <param name="value">The input resolution scale (in percentage).</param>
|
||||
/// <returns>A formatted percentage string for <paramref name="value"/>.</returns>
|
||||
public static string ConvertPercentageToFormattedString(int value)
|
||||
{
|
||||
return $"{value}%";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a percentage value to a scaled value in the [0, 1] range.
|
||||
/// </summary>
|
||||
/// <param name="value">The input percentage value to scale.</param>
|
||||
/// <returns>The input percentage scaled to the [0, 1] range.</returns>
|
||||
public static double ConvertPercentageToScale(int value)
|
||||
{
|
||||
return value / 100.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.Uwp;
|
||||
#else
|
||||
using ComputeSharp.WinUI;
|
||||
#endif
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A model for a compute shader.
|
||||
/// </summary>
|
||||
/// <remarks>This can be converted to a record when bindings are fixed, see notes in the XAML code.</remarks>
|
||||
public sealed class ComputeShader : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ComputeShader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
public ComputeShader(string name, IShaderRunner shaderRunner)
|
||||
{
|
||||
Name = name;
|
||||
ShaderRunner = shaderRunner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the shader.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IShaderRunner"/> instance to execute.
|
||||
/// </summary>
|
||||
public IShaderRunner ShaderRunner { get; }
|
||||
|
||||
private bool isSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the current shader is selected.
|
||||
/// </summary>
|
||||
public bool IsSelected
|
||||
{
|
||||
get => this.isSelected;
|
||||
set => SetProperty(ref this.isSelected, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.Uwp;
|
||||
#else
|
||||
using ComputeSharp.WinUI;
|
||||
#endif
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
|
||||
/// <summary>
|
||||
/// A specialized <see cref="IShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// </summary>
|
||||
public sealed class ContouredLayersRunner : IShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture for <c>\Textures\RustyMetal.png</c>.
|
||||
/// </summary>
|
||||
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan)
|
||||
{
|
||||
if (this.texture is null)
|
||||
{
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
|
||||
|
||||
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
|
||||
}
|
||||
|
||||
Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ComputeSharp.SwapChain.Core.Models;
|
||||
using ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
using ComputeSharp.SwapChain.Shaders;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.Uwp;
|
||||
#else
|
||||
using ComputeSharp.WinUI;
|
||||
#endif
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// The viewmodel for for a view that allows users to select shaders and customize settings.
|
||||
/// </summary>
|
||||
public sealed class MainViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MainViewModel"/> instance.
|
||||
/// </summary>
|
||||
public MainViewModel()
|
||||
{
|
||||
this.isDynamicResolutionEnabled = true;
|
||||
this.selectedResolutionScale = 100;
|
||||
this.selectedComputeShader = ComputeShaderOptions[0];
|
||||
this.selectedComputeShader.IsSelected = true;
|
||||
|
||||
SetResolutionScaleCommand = new RelayCommand<int>(SetResolutionScale);
|
||||
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available resolution scaling options (as percentage values).
|
||||
/// </summary>
|
||||
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
|
||||
|
||||
private bool isDynamicResolutionEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the dynamic resolution is enabled.
|
||||
/// </summary>
|
||||
public bool IsDynamicResolutionEnabled
|
||||
{
|
||||
get => this.isDynamicResolutionEnabled;
|
||||
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
|
||||
}
|
||||
|
||||
private int selectedResolutionScale;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected resolution scale setting (as percentage valaue).
|
||||
/// </summary>
|
||||
public int SelectedResolutionScale
|
||||
{
|
||||
get => this.selectedResolutionScale;
|
||||
private set => SetProperty(ref this.selectedResolutionScale, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command that sets <see cref="SelectedResolutionScale"/>.
|
||||
/// </summary>
|
||||
public IRelayCommand SetResolutionScaleCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="SelectedResolutionScale"/>.
|
||||
/// </summary>
|
||||
private void SetResolutionScale(int resolutionScale)
|
||||
{
|
||||
SelectedResolutionScale = resolutionScale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of available compute shader.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
|
||||
{
|
||||
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
|
||||
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
|
||||
new("Menger Journey", new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds))),
|
||||
new("Octagrams", new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds))),
|
||||
new("Protean clouds", new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds))),
|
||||
new("Two tiled truchet", new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds))),
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
|
||||
new("Contoured layers", new ContouredLayersRunner())
|
||||
};
|
||||
|
||||
private ComputeShader selectedComputeShader;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected compute shader.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする