using System;
using ComputeSharp.Descriptors;
using TerraFX.Interop.Windows;
namespace ComputeSharp.SwapChain.Backend;
///
/// A factory type that renders an animated shader on a swapchain on a target .
///
/// The shader type to render.
///
/// The main point of this type is to hide the complexity of from the non-NativeAOT sample.
///
internal static class Win32ApplicationFactory
where T : struct, IComputeShader, IComputeShaderDescriptor
{
///
/// The instance used to create shaders to run.
///
private static Func? shaderFactory;
///
/// Creates a new from the specified factory.
///
/// The instance used to create shaders to run.
/// A instance to use.
public static unsafe Win32Application Create(Func shaderFactory)
{
Win32ApplicationFactory.shaderFactory = shaderFactory;
return new(&ShaderCallback);
}
///
/// The callback function to draw a single frame.
///
/// The input instance to draw on.
/// The time for the current frame.
private static void ShaderCallback(IReadWriteNormalizedTexture2D texture, TimeSpan time)
{
texture.GraphicsDevice.ForEach(texture, shaderFactory!(time));
}
}