Add ID2D1ShaderRunner and D2D1ShaderRunner<T>
このコミットが含まれているのは:
1 親
1ec2dad382
コミット
ffd3b79aed
3ファイル変更
+69
検索条件に一致するファイルはありません
@@ -16,6 +16,8 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.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\Runners\ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ShaderRunnerViewModel.cs" />
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.D2D1;
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a shader runner to be used with a Win2D <see cref="CanvasAnimatedControl"/>.
|
||||
/// </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);
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする