Switch D2D1 UWP/WinUI samples to use CanvasEffect
This replaces the ID2D1ShaderRunner interface in the sample apps
このコミットが含まれているのは:
1 親
2578cf3028
コミット
a291685aff
12ファイル変更
+219
-166
検索条件に一致するファイルはありません
+1
-2
@@ -17,8 +17,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Enums\RenderingMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\DebugAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\ID2D1ShaderRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\D2D1ShaderRunner{T}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\PixelShaderEffect.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\D2D1ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.SwapChain.Core.Shaders;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
@@ -28,9 +29,9 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
|
||||
private CanvasAnimatedControl? canvasAnimatedControl;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1ShaderRunner"/> instance currently in use, if any.
|
||||
/// The <see cref="PixelShaderEffect"/> instance currently in use, if any.
|
||||
/// </summary>
|
||||
private volatile ID2D1ShaderRunner? shaderRunner;
|
||||
private volatile PixelShaderEffect? pixelShaderEffect;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1AnimatedPixelShaderPanel"/> instance.
|
||||
@@ -56,7 +57,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
|
||||
private void D2D1AnimatedPixelShaderPanel_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (this.canvasAnimatedControl is { } canvasAnimatedControl &&
|
||||
ShaderRunner is not null &&
|
||||
PixelShaderEffect is not null &&
|
||||
!IsPaused)
|
||||
{
|
||||
canvasAnimatedControl.Paused = false;
|
||||
@@ -75,43 +76,50 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
|
||||
/// <summary>
|
||||
/// Draws a new frame on the wrapped <see cref="CanvasAnimatedControl"/> instance.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="ID2D1ShaderRunner.Execute"/>
|
||||
/// <param name="sender">The source <see cref="ICanvasAnimatedControl"/> instance.</param>
|
||||
/// <param name="args">The <see cref="CanvasAnimatedDrawEventArgs"/> object to perform drawing with.</param>
|
||||
private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
|
||||
{
|
||||
this.shaderRunner?.Execute(sender, args);
|
||||
// Set the effect properties
|
||||
this.pixelShaderEffect!.ElapsedTime = args.Timing.TotalTime;
|
||||
this.pixelShaderEffect.ScreenWidth = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
|
||||
this.pixelShaderEffect.ScreenHeight = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
|
||||
|
||||
// Draw the effect
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ID2D1ShaderRunner"/> instance to use to render content.
|
||||
/// Gets or sets the <see cref="Core.Shaders.PixelShaderEffect"/> instance to use to render content.
|
||||
/// </summary>
|
||||
public ID2D1ShaderRunner? ShaderRunner
|
||||
public PixelShaderEffect? PixelShaderEffect
|
||||
{
|
||||
get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty);
|
||||
set => SetValue(ShaderRunnerProperty, value);
|
||||
get => (PixelShaderEffect?)GetValue(PixelShaderEffectProperty);
|
||||
set => SetValue(PixelShaderEffectProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DependencyProperty"/> backing <see cref="ShaderRunner"/>.
|
||||
/// The <see cref="DependencyProperty"/> backing <see cref="PixelShaderEffect"/>.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register(
|
||||
nameof(ShaderRunner),
|
||||
typeof(ID2D1ShaderRunner),
|
||||
public static readonly DependencyProperty PixelShaderEffectProperty = DependencyProperty.Register(
|
||||
nameof(PixelShaderEffect),
|
||||
typeof(PixelShaderEffect),
|
||||
typeof(D2D1AnimatedPixelShaderPanel),
|
||||
new PropertyMetadata(null, OnShaderRunnerPropertyChanged));
|
||||
new PropertyMetadata(null, OnPixelShaderEffectPropertyChanged));
|
||||
|
||||
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
|
||||
private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
private static void OnPixelShaderEffectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d;
|
||||
ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue;
|
||||
PixelShaderEffect? pixelShaderEffect = (PixelShaderEffect?)e.NewValue;
|
||||
|
||||
// Save the new shader runner for later (as the dependency property cannot be accessed by the render thread)
|
||||
@this.shaderRunner = shaderRunner;
|
||||
// Save the new pixel shader effect for later (as the dependency property cannot be accessed by the render thread)
|
||||
@this.pixelShaderEffect = pixelShaderEffect;
|
||||
|
||||
// Pause or start the render thread if a runner is available
|
||||
// Pause or start the render thread if an effect is available
|
||||
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
|
||||
{
|
||||
bool shouldRender = @this.IsLoaded && !@this.IsPaused && shaderRunner is not null;
|
||||
bool shouldRender = @this.IsLoaded && !@this.IsPaused && pixelShaderEffect is not null;
|
||||
|
||||
canvasAnimatedControl.Paused = !shouldRender;
|
||||
}
|
||||
@@ -143,7 +151,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
|
||||
|
||||
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
|
||||
{
|
||||
bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is not null;
|
||||
bool shouldRender = @this.IsLoaded && !isPaused && @this.PixelShaderEffect is not null;
|
||||
|
||||
canvasAnimatedControl.Paused = !shouldRender;
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.D2D1;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
#else
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
#endif
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// A simple <see cref="ID2D1ShaderRunner"/> implementation powered by a supplied shader type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
|
||||
public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner, IDisposable
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1,T2,T3TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
private readonly Func<TimeSpan, int, int, T> shaderFactory;
|
||||
|
||||
/// <summary>
|
||||
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
|
||||
/// </summary>
|
||||
private readonly PixelShaderEffect<T> pixelShaderEffect;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ShaderRunner{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.</param>
|
||||
public D2D1ShaderRunner(Func<TimeSpan, int, int, T> shaderFactory)
|
||||
{
|
||||
Guard.IsNotNull(shaderFactory);
|
||||
|
||||
this.shaderFactory = shaderFactory;
|
||||
this.pixelShaderEffect = new PixelShaderEffect<T>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
|
||||
{
|
||||
int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
|
||||
int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
|
||||
|
||||
// Set the constant buffer
|
||||
this.pixelShaderEffect.ConstantBuffer = this.shaderFactory(args.Timing.TotalTime, widthInPixels, heightInPixels);
|
||||
|
||||
// Draw the shader
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.pixelShaderEffect.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a shader runner to be used with a Win2D renderer.
|
||||
/// </summary>
|
||||
public interface ID2D1ShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a new frame on a target <see cref="ICanvasAnimatedControl"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="sender">The target <see cref="ICanvasAnimatedControl"/> instance.</param>
|
||||
/// <param name="args">The <see cref="CanvasAnimatedDrawEventArgs"/> instance to use to draw the new frame.</param>
|
||||
void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
#else
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
#endif
|
||||
using Microsoft.Graphics.Canvas;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// An base effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
public abstract class PixelShaderEffect : CanvasEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The current elapsed time.
|
||||
/// </summary>
|
||||
private TimeSpan elapsedTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen width in raw pixels.
|
||||
/// </summary>
|
||||
private int screenWidth;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen height in raw pixels.
|
||||
/// </summary>
|
||||
private int screenHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total elapsed time.
|
||||
/// </summary>
|
||||
public TimeSpan ElapsedTime
|
||||
{
|
||||
get => this.elapsedTime;
|
||||
set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the screen width in raw pixels.
|
||||
/// </summary>
|
||||
public int ScreenWidth
|
||||
{
|
||||
get => this.screenWidth;
|
||||
set => SetAndInvalidateEffectGraph(ref this.screenWidth, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the screen height in raw pixels.
|
||||
/// </summary>
|
||||
public int ScreenHeight
|
||||
{
|
||||
get => this.screenHeight;
|
||||
set => SetAndInvalidateEffectGraph(ref this.screenHeight, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
|
||||
public sealed class For<T> : PixelShaderEffect
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <typeparamref name="T"/> factory to use.
|
||||
/// </summary>
|
||||
private readonly Factory factory;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="PixelShaderEffect{T}"/> instance in use.
|
||||
/// </summary>
|
||||
private PixelShaderEffect<T>? effect;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public For(Factory factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override ICanvasImage BuildEffectGraph()
|
||||
{
|
||||
this.effect = new PixelShaderEffect<T>();
|
||||
|
||||
return this.effect;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void ConfigureEffectGraph()
|
||||
{
|
||||
this.effect!.ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
this.effect?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A factory of a given shader instance.
|
||||
/// </summary>
|
||||
/// <param name="elapsedTime">The total elapsed time.</param>
|
||||
/// <param name="screenWidth">The screen width in raw pixels.</param>
|
||||
/// <param name="screenHeight">The screen height in raw pixels.</param>
|
||||
/// <returns>A shader instance to render.</returns>
|
||||
public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight);
|
||||
}
|
||||
}
|
||||
+41
-41
@@ -9,7 +9,6 @@ using ComputeSharp.D2D1.WinUI;
|
||||
#endif
|
||||
using ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
#nullable enable
|
||||
@@ -17,9 +16,9 @@ using Windows.ApplicationModel;
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
|
||||
/// <summary>
|
||||
/// A specialized <see cref="ID2D1ShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// A specialized <see cref="PixelShaderEffect"/> for <see cref="ContouredLayers"/>.
|
||||
/// </summary>
|
||||
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable
|
||||
public sealed class D2D1ContouredLayersEffect : PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
|
||||
@@ -27,54 +26,55 @@ public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable
|
||||
private PixelShaderEffect<ContouredLayers>? pixelShaderEffect;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
|
||||
protected override unsafe ICanvasImage BuildEffectGraph()
|
||||
{
|
||||
if (this.pixelShaderEffect is null)
|
||||
{
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
|
||||
|
||||
// As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to
|
||||
// keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we
|
||||
// first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then
|
||||
// copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read
|
||||
// from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture.
|
||||
using ReadOnlyTexture2D<Rgba32, float4> readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
|
||||
using ReadBackTexture2D<Rgba32> readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D<Rgba32>(readOnlyTexture.Width, readOnlyTexture.Height);
|
||||
// As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to
|
||||
// keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we
|
||||
// first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then
|
||||
// copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read
|
||||
// from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture.
|
||||
using ReadOnlyTexture2D<Rgba32, float4> readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
|
||||
using ReadBackTexture2D<Rgba32> readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D<Rgba32>(readOnlyTexture.Width, readOnlyTexture.Height);
|
||||
|
||||
readOnlyTexture.CopyTo(readBackTexture);
|
||||
readOnlyTexture.CopyTo(readBackTexture);
|
||||
|
||||
// Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding.
|
||||
// That is, the area between the end of the data in the last row and the stride is not included.
|
||||
Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes);
|
||||
int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32));
|
||||
// Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding.
|
||||
// That is, the area between the end of the data in the last row and the stride is not included.
|
||||
Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes);
|
||||
int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32));
|
||||
|
||||
// Create the resource texture manager to use in the shader
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipLinear,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
|
||||
data: new ReadOnlySpan<byte>(dataBuffer, bufferSize),
|
||||
strides: stackalloc uint[] { (uint)strideInBytes });
|
||||
// Create the resource texture manager to use in the shader
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipLinear,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
|
||||
data: new ReadOnlySpan<byte>(dataBuffer, bufferSize),
|
||||
strides: stackalloc uint[] { (uint)strideInBytes });
|
||||
|
||||
// Create the new pixel shader effect
|
||||
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { ResourceTextureManagers = { [0] = resourceTextureManager } };
|
||||
}
|
||||
// Create the new pixel shader effect
|
||||
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { ResourceTextureManagers = { [0] = resourceTextureManager } };
|
||||
|
||||
int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
|
||||
int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
|
||||
|
||||
// Set the constant buffer
|
||||
this.pixelShaderEffect.ConstantBuffer = new ContouredLayers((float)args.Timing.TotalTime.TotalSeconds, new int2(widthInPixels, heightInPixels));
|
||||
|
||||
// Draw the shader
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
return this.pixelShaderEffect;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
protected override void ConfigureEffectGraph()
|
||||
{
|
||||
this.pixelShaderEffect?.Dispose();
|
||||
this.pixelShaderEffect!.ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
this.pixelShaderEffect?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,40 +95,40 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
new(
|
||||
nameof(ColorfulInfinity),
|
||||
new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(FractalTiling),
|
||||
new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(MengerJourney),
|
||||
new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(Octagrams),
|
||||
new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(ProteanClouds),
|
||||
new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(TwoTiledTruchet),
|
||||
new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(PyramidPattern),
|
||||
new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
nameof(TriangleGridContouring),
|
||||
new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersEffect()),
|
||||
new(
|
||||
nameof(TerracedHills),
|
||||
new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,12 +18,12 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
|
||||
/// </summary>
|
||||
/// <param name="shaderType">The name of the shader type to execute.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
/// <param name="d2D1ShaderRunner">The <see cref="ID2D1ShaderRunner"/> instance to execute.</param>
|
||||
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner)
|
||||
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
|
||||
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect)
|
||||
{
|
||||
ShaderType = shaderType;
|
||||
ShaderRunner = shaderRunner;
|
||||
D2D1ShaderRunner = d2D1ShaderRunner;
|
||||
PixelShaderEffect = pixelShaderEffect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,9 +37,9 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
|
||||
public IShaderRunner ShaderRunner { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID2D1ShaderRunner"/> instance to execute.
|
||||
/// Gets the <see cref="PixelShaderEffect"/> instance to execute.
|
||||
/// </summary>
|
||||
public ID2D1ShaderRunner D2D1ShaderRunner { get; }
|
||||
public PixelShaderEffect PixelShaderEffect { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the current shader is selected.
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
<controls:Case Value="{x:Bind enums:RenderingMode.Win2D}">
|
||||
|
||||
<!-- Win2D shader -->
|
||||
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.D2D1ShaderRunner, Mode=OneWay}" />
|
||||
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" PixelShaderEffect="{x:Bind ViewModel.SelectedComputeShader.PixelShaderEffect, Mode=OneWay}" />
|
||||
</controls:Case>
|
||||
</controls:SwitchPresenter>
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@
|
||||
<controls:Case Value="{x:Bind enums:RenderingMode.Win2D}">
|
||||
|
||||
<!-- Win2D shader -->
|
||||
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.D2D1ShaderRunner, Mode=OneWay}" />
|
||||
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" PixelShaderEffect="{x:Bind ViewModel.SelectedComputeShader.PixelShaderEffect, Mode=OneWay}" />
|
||||
</controls:Case>
|
||||
</controls:SwitchPresenter>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
@@ -65,6 +66,7 @@ unsafe partial class CanvasEffect
|
||||
/// </summary>
|
||||
/// <returns>The current <see cref="ICanvasImage"/> instance.</returns>
|
||||
/// <exception cref="ObjectDisposedException">Thrown if the current instance is disposed.</exception>
|
||||
[MemberNotNull(nameof(canvasImage))]
|
||||
private ICanvasImage GetCanvasImage()
|
||||
{
|
||||
lock (this.lockObject)
|
||||
|
||||
@@ -155,14 +155,6 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
|
||||
InvalidateEffectGraph(invalidationType);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes any disposable resources in the current instance.
|
||||
/// </summary>
|
||||
@@ -211,6 +203,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
|
||||
this.isDisposed = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the invalidation type to request when invoking <see cref="InvalidateEffectGraph"/> and related methods.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする