using System; using System.IO; 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 Lazy> RustyMetal = new(static () => LoadTexture()); static void Main() { // Prepare the mapping of available samples to choose from (string ShaderName, Win32Application Application)[] samples = new[] { (nameof(HelloWorld), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(FourColorGradient), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(ColorfulInfinity), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(FractalTiling), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(TwoTiledTruchet), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(MengerJourney), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(Octagrams), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(ProteanClouds), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(ExtrudedTruchetPattern), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(PyramidPattern), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(TriangleGridContouring), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), (nameof(ContouredLayers), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds, RustyMetal.Value))), (nameof(TerracedHills), Win32ApplicationFactory.Create(static time => new((float)time.TotalSeconds))), }; int index; do { Console.Clear(); Console.WriteLine("Available samples:"); Console.WriteLine(); for (int i = 0; i < samples.Length; i++) { Console.WriteLine($"{i}: {samples[i].ShaderName}"); } 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].ShaderName}..."); _ = Win32ApplicationRunner.Run(samples[index].Application, "ComputeSharp.SwapChain", samples[index].ShaderName); } } 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(AppContext.BaseDirectory, "Textures", $"{name}.png"); return GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename); } }