Add new rendering mode setting to sample app
このコミットが含まれているのは:
1 親
0deddde903
コミット
9c7ecdb654
6ファイル変更
+80
-27
検索条件に一致するファイルはありません
+1
-1
@@ -11,9 +11,9 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Constants\Error.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Constants\Event.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\BoolConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Enums\RenderingMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\DebugAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\ID2D1ShaderRunner.cs" />
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace ComputeSharp.SwapChain.Core.Constants;
|
||||
/// </summary>
|
||||
public static class Event
|
||||
{
|
||||
public const string SelectedRenderingModeChanged = "[SETTINGS] SelectedRenderingMode";
|
||||
public const string IsVerticalSyncEnabledChanged = "[SETTINGS] IsVerticalSyncEnabled";
|
||||
public const string IsDynamicResolutionEnabledChanged = "[SETTINGS] IsDynamicResolutionEnabled";
|
||||
public const string SelectedResolutionScaleChanged = "[SETTINGS] SelectedResolutionScale";
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// A class with some static converters for <see cref="bool"/> values.
|
||||
/// </summary>
|
||||
public static class BoolConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Negates an input <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="bool"/> value to negate.</param>
|
||||
/// <returns>The negated value of <paramref name="value"/>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool Not(bool value)
|
||||
{
|
||||
return !value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace ComputeSharp.SwapChain.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the rendering mode being used.
|
||||
/// </summary>
|
||||
public enum RenderingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Render using DirectX 12 APIs.
|
||||
/// </summary>
|
||||
DirectX12,
|
||||
|
||||
/// <summary>
|
||||
/// Render using Win2D (ie. Direct2D behind the scenes).
|
||||
/// </summary>
|
||||
Win2D
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using CommunityToolkit.Diagnostics;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ComputeSharp.SwapChain.Core.Constants;
|
||||
using ComputeSharp.SwapChain.Core.Enums;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.Shaders;
|
||||
using ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
@@ -35,6 +36,7 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
Guard.IsNotNull(analyticsService);
|
||||
|
||||
this.analyticsService = analyticsService;
|
||||
this.selectedRenderingMode = RenderingMode.DirectX12;
|
||||
this.isVerticalSyncEnabled = true;
|
||||
this.isDynamicResolutionEnabled = true;
|
||||
this.selectedResolutionScale = 100;
|
||||
@@ -42,6 +44,25 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
this.selectedComputeShader.IsSelected = true;
|
||||
}
|
||||
|
||||
private RenderingMode selectedRenderingMode;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected rendering mode.
|
||||
/// </summary>
|
||||
public RenderingMode SelectedRenderingMode
|
||||
{
|
||||
get => this.selectedRenderingMode;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref this.selectedRenderingMode, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(IsResolutionScaleOptionEnabled));
|
||||
|
||||
this.analyticsService.Log(Event.SelectedRenderingModeChanged, (nameof(value), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available resolution scaling options (as percentage values).
|
||||
/// </summary>
|
||||
@@ -76,6 +97,8 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
{
|
||||
if (SetProperty(ref this.isDynamicResolutionEnabled, value))
|
||||
{
|
||||
OnPropertyChanged(nameof(IsResolutionScaleOptionEnabled));
|
||||
|
||||
this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value));
|
||||
}
|
||||
}
|
||||
@@ -98,6 +121,11 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the resolution scale can currently be expliclty set.
|
||||
/// </summary>
|
||||
public bool IsResolutionScaleOptionEnabled => SelectedRenderingMode == RenderingMode.DirectX12 && !IsDynamicResolutionEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of available compute shader.
|
||||
/// </summary>
|
||||
@@ -181,6 +209,15 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="SelectedRenderingMode"/>.
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void SetRenderingMode(RenderingMode renderingMode)
|
||||
{
|
||||
SelectedRenderingMode = renderingMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets <see cref="SelectedResolutionScale"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:computesharp="using:ComputeSharp.Uwp"
|
||||
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
|
||||
xmlns:converters="using:ComputeSharp.SwapChain.Core.Converters"
|
||||
xmlns:enums="using:ComputeSharp.SwapChain.Core.Enums"
|
||||
xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:ui="using:Microsoft.Toolkit.Uwp.UI"
|
||||
@@ -193,32 +194,49 @@
|
||||
<SymbolIcon Symbol="Setting" />
|
||||
<Button.Flyout>
|
||||
<MenuFlyout>
|
||||
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=TwoWay}" Text="Vertical sync" />
|
||||
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}" Text="Dynamic resolution" />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
|
||||
CommandParameter="{x:Bind enums:RenderingMode.DirectX12}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
|
||||
Text="DirectX 12" />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
|
||||
CommandParameter="{x:Bind enums:RenderingMode.Win2D}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.Win2D), Mode=OneWay}"
|
||||
Text="Win2D (Direct2D)" />
|
||||
<MenuFlyoutSeparator />
|
||||
<ToggleMenuFlyoutItem
|
||||
IsChecked="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=TwoWay}"
|
||||
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
|
||||
Text="Vertical sync" />
|
||||
<ToggleMenuFlyoutItem
|
||||
IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}"
|
||||
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
|
||||
Text="Dynamic resolution" />
|
||||
<MenuFlyoutSeparator />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
|
||||
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[0]}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[0]), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
|
||||
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[0])}" />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
|
||||
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[1]}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[1]), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
|
||||
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[1])}" />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
|
||||
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[2]}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[2]), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
|
||||
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[2])}" />
|
||||
<ToggleMenuFlyoutItem
|
||||
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
|
||||
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[3]}"
|
||||
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[3]), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind converters:BoolConverter.Not(ViewModel.IsDynamicResolutionEnabled), Mode=OneWay}"
|
||||
IsEnabled="{x:Bind ViewModel.IsResolutionScaleOptionEnabled, Mode=OneWay}"
|
||||
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[3])}" />
|
||||
</MenuFlyout>
|
||||
</Button.Flyout>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする