Add parameter to IShaderRunner

このコミットが含まれているのは:
Sergio Pedri committed 2022-01-02 20:32:40 +01:00
1 親 056e50d899
コミット 28a4ad3b48
4ファイル変更
+36 -10

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -23,7 +23,7 @@ public sealed class ContouredLayersRunner : IShaderRunner
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
/// <inheritdoc/>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan)
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter)
{
if (this.texture is null)
{
+1 -1
ファイルの表示
@@ -230,7 +230,7 @@ partial class SwapChainManager
/// <param name="time">The current time since the start of the application.</param>
private void OnUpdate(TimeSpan time)
{
this.shaderRunner!.Execute(this.texture!, time);
this.shaderRunner!.Execute(this.texture!, time, null);
}
/// <summary>
+2 -1
ファイルの表示
@@ -16,5 +16,6 @@ public interface IShaderRunner
/// </summary>
/// <param name="texture">The target texture to render the frame to.</param>
/// <param name="timespan">The timespan for the current frame.</param>
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan);
/// <param name="parameter">The input parameter for the frame being rendered.</param>
void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter);
}
+32 -7
ファイルの表示
@@ -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));
}
}
}