ファイル
ComputeSharp/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/ContouredLayersRunner.cs
T

43 行
1.2 KiB
C#

using System;
using System.IO;
using ComputeSharp.SwapChain.Shaders;
#if WINDOWS_UWP
using ComputeSharp.Uwp;
#else
using ComputeSharp.WinUI;
#endif
using Windows.ApplicationModel;
#nullable enable
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
/// <summary>
/// A specialized <see cref="IShaderRunner"/> for <see cref="ContouredLayers"/>.
/// </summary>
public sealed class ContouredLayersRunner : IShaderRunner
{
/// <summary>
/// A texture for <c>\Textures\RustyMetal.png</c>.
/// </summary>
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
/// <inheritdoc/>
public bool TryExecute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan, object? parameter)
{
if (this.texture is null ||
this.texture.GraphicsDevice != texture.GraphicsDevice)
{
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
this.texture?.Dispose();
this.texture = texture.GraphicsDevice.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
}
texture.GraphicsDevice.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
return true;
}
}