diff --git a/samples/ComputeSharp.SwapChain.D2D1/ComputeSharp.SwapChain.D2D1.csproj b/samples/ComputeSharp.SwapChain.D2D1/ComputeSharp.SwapChain.D2D1.csproj index 570bdc08..6a8139da 100644 --- a/samples/ComputeSharp.SwapChain.D2D1/ComputeSharp.SwapChain.D2D1.csproj +++ b/samples/ComputeSharp.SwapChain.D2D1/ComputeSharp.SwapChain.D2D1.csproj @@ -1,7 +1,8 @@ - Exe + Exe + WinExe net7.0-windows10.0.22621 app.manifest x64;ARM64 @@ -22,7 +23,6 @@ - diff --git a/samples/ComputeSharp.SwapChain.D2D1/Program.cs b/samples/ComputeSharp.SwapChain.D2D1/Program.cs index 7da94709..25467b03 100644 --- a/samples/ComputeSharp.SwapChain.D2D1/Program.cs +++ b/samples/ComputeSharp.SwapChain.D2D1/Program.cs @@ -1,74 +1,74 @@ using System; using ComputeSharp.SwapChain.D2D1.Backend; using ComputeSharp.SwapChain.Shaders.D2D1; +using TerraFX.Interop.Windows; -namespace ComputeSharp.SwapChain; - -class Program +// Accepted inputs: +// - [] +// - [] +if (args is [] or [_]) { - /// - /// The mapping of available samples to choose from. - /// - private static readonly (string ShaderName, PixelShaderEffect Effect)[] Samples = new (string, PixelShaderEffect)[] + // If there are no args, just run the default shader + if (args is not [string shaderName]) { - (nameof(HelloWorld), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(ColorfulInfinity), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(FractalTiling), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(TwoTiledTruchet), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(MengerJourney), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(Octagrams), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(ProteanClouds), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(PyramidPattern), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(TriangleGridContouring), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - (nameof(TerracedHills), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))) + shaderName = nameof(ColorfulInfinity); + } + + // Get the requested shader, if possible + PixelShaderEffect? effect = shaderName.ToLowerInvariant() switch + { + "helloworld" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "colorfulinfinity" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "fractaltiling" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "twotiledtruchet" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "mengerjourney" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "octagrams" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "proteanclouds" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "pyramidpattern" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "trianglegridcontouring" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + "terracedhills" => new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + _ => null }; - static void Main() + // If a shader is found, run it + if (effect is not null) { - int index; + Win32Application win32Application = new(); - do + win32Application.Draw += (_, e) => { - Console.Clear(); - Console.WriteLine("Available samples:"); - Console.WriteLine(); + // Set the effect properties + effect.ElapsedTime = e.TotalTime; + effect.ScreenWidth = (int)e.ScreenWidth; + effect.ScreenHeight = (int)e.ScreenHeight; - for (int i = 0; i < Samples.Length; i++) - { - Console.WriteLine($"{i}: {Samples[i].ShaderName}"); - } + // Draw the effect + e.DrawingSession.DrawImage(effect); + }; - 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}..."); - - Win32Application win32Application = new(); - PixelShaderEffect effect = Samples[index].Effect; - - win32Application.Draw += (_, e) => - { - // Set the effect properties - effect.ElapsedTime = e.TotalTime; - effect.ScreenWidth = (int)e.ScreenWidth; - effect.ScreenHeight = (int)e.ScreenHeight; - - // Draw the effect - e.DrawingSession.DrawImage(effect); - }; - - _ = Win32ApplicationRunner.Run(win32Application, "ComputeSharp.SwapChain.D2D1", Samples[index].ShaderName); - } - } - while (index >= 0 && index < Samples.Length); + return Win32ApplicationRunner.Run(win32Application, "ComputeSharp.D2D1", "ComputeSharp.D2D1"); } -} \ No newline at end of file + + // If no shader matches, check if help was requested + if (shaderName is "-h") + { + Console.WriteLine($""" + Available shaders: + + - {nameof(HelloWorld)} + - {nameof(ColorfulInfinity)} + - {nameof(FractalTiling)} + - {nameof(TwoTiledTruchet)} + - {nameof(MengerJourney)} + - {nameof(Octagrams)} + - {nameof(ProteanClouds)} + - {nameof(PyramidPattern)} + - {nameof(TriangleGridContouring)} + - {nameof(TerracedHills)} + """); + + return S.S_OK; + } +} + +return E.E_INVALIDARG; \ No newline at end of file