Add parameter to IShaderRunner
このコミットが含まれているのは:
1 親
056e50d899
コミット
28a4ad3b48
4ファイル変更
+36
-10
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
#if WINDOWS_UWP
|
||||
namespace ComputeSharp.Uwp;
|
||||
@@ -14,9 +15,14 @@ public sealed class ShaderRunner<T> : IShaderRunner
|
||||
where T : struct, IPixelShader<Float4>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1, TResult}"/> instance used to create shaders to run.
|
||||
/// The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
private readonly Func<TimeSpan, T> shaderFactory;
|
||||
private readonly Func<TimeSpan, T>? shaderFactory;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1,T2,TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
private readonly Func<TimeSpan, object?, T>? statefulShaderFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderRunner{T}"/> instance that will create shader instances with
|
||||
@@ -25,21 +31,40 @@ public sealed class ShaderRunner<T> : IShaderRunner
|
||||
/// </summary>
|
||||
public ShaderRunner()
|
||||
{
|
||||
this.shaderFactory = static _ => default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderRunner{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1, T2, TResult}"/> instance used to create shaders to run.</param>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.</param>
|
||||
public ShaderRunner(Func<TimeSpan, T> shaderFactory)
|
||||
{
|
||||
Guard.IsNotNull(shaderFactory, nameof(shaderFactory));
|
||||
|
||||
this.shaderFactory = shaderFactory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ShaderRunner{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="shaderFactory">The <see cref="Func{T1,T2,TResult}"/> instance used to create shaders to run.</param>
|
||||
public ShaderRunner(Func<TimeSpan, object?, T> shaderFactory)
|
||||
{
|
||||
GraphicsDevice.Default.ForEach(texture, this.shaderFactory(time));
|
||||
Guard.IsNotNull(shaderFactory, nameof(shaderFactory));
|
||||
|
||||
this.statefulShaderFactory = shaderFactory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan time, object? parameter)
|
||||
{
|
||||
if (this.shaderFactory is Func<TimeSpan, T> shaderFactory)
|
||||
{
|
||||
GraphicsDevice.Default.ForEach(texture, this.shaderFactory(time));
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphicsDevice.Default.ForEach(texture, this.statefulShaderFactory!(time, parameter));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする