using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using ComputeSharp.SwapChain.Backend;
using ComputeSharp.SwapChain.Shaders;
namespace ComputeSharp.SwapChain;
class Program
{
///
/// A texture for \Textures\RustyMetal.png.
///
private static readonly IReadOnlyNormalizedTexture2D RustyMetal = LoadTexture();
///
/// The mapping of available samples to choose from.
///
private static readonly Win32Application[] Samples = new Win32Application[]
{
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds)),
new SwapChainApplication(static time => new((float)time.TotalSeconds, RustyMetal))
};
static void Main()
{
int index;
do
{
Console.Clear();
Console.WriteLine("Available samples:");
Console.WriteLine();
for (int i = 0; i < Samples.Length; i++)
{
Console.WriteLine($"{i}: {Samples[i].GetType().GenericTypeArguments[0].Name}");
}
Console.WriteLine($"{Samples.Length}+: Exit (Use Escape, 'Q', or Alt + F4 to exit a sample once chosen)");
Console.WriteLine();
do
{
Console.Write("Enter the index of the sample to run: ");
}
while (!int.TryParse(Console.ReadLine(), out index));
if (index >= 0 && index < Samples.Length)
{
Console.WriteLine();
Console.WriteLine($"Starting {Samples[index].GetType().GenericTypeArguments[0].Name}...");
Win32ApplicationRunner.Run(Samples[index]);
}
}
while (index >= 0 && index < Samples.Length);
}
///
/// Allocates a new instance with the specified texture data.
///
/// The name of the texture to load.
/// A texture with the data from the image at the specified name.
private static ReadOnlyTexture2D LoadTexture([CallerMemberName] string name = null!)
{
string filename = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Textures", $"{name}.png");
return GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename);
}
}