Switch Win2D WASDK sample to CLI style

このコミットが含まれているのは:
Sergio Pedri committed 2023-04-22 01:34:36 +02:00
1 親 2f72522bc3
コミット 27e7b0fa94
2ファイル変更
+62 -62

検索条件に一致するファイルはありません

+2 -2
ファイルの表示
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType Condition="'$(CI_RUNNER_SAMPLES_INTEGRATION_TESTS)' == 'true'">Exe</OutputType>
<OutputType Condition="'$(CI_RUNNER_SAMPLES_INTEGRATION_TESTS)' != 'true'">WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.22621</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64;ARM64</Platforms>
@@ -22,7 +23,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.1.0-preview1" />
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="all" />
<PackageReference Include="TerraFX.Interop.Windows" Version="10.0.22621.1" />
</ItemGroup>
+60 -60
ファイルの表示
@@ -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:
// - []
// - [<SHADER_NAME>]
if (args is [] or [_])
{
/// <summary>
/// The mapping of available samples to choose from.
/// </summary>
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<HelloWorld>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(ColorfulInfinity), new PixelShaderEffect.For<ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(FractalTiling), new PixelShaderEffect.For<FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(TwoTiledTruchet), new PixelShaderEffect.For<TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(MengerJourney), new PixelShaderEffect.For<MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(Octagrams), new PixelShaderEffect.For<Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(ProteanClouds), new PixelShaderEffect.For<ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(PyramidPattern), new PixelShaderEffect.For<PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(TriangleGridContouring), new PixelShaderEffect.For<TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
(nameof(TerracedHills), new PixelShaderEffect.For<TerracedHills>(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<HelloWorld>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"colorfulinfinity" => new PixelShaderEffect.For<ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"fractaltiling" => new PixelShaderEffect.For<FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"twotiledtruchet" => new PixelShaderEffect.For<TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"mengerjourney" => new PixelShaderEffect.For<MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"octagrams" => new PixelShaderEffect.For<Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"proteanclouds" => new PixelShaderEffect.For<ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"pyramidpattern" => new PixelShaderEffect.For<PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"trianglegridcontouring" => new PixelShaderEffect.For<TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
"terracedhills" => new PixelShaderEffect.For<TerracedHills>(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");
}
}
// 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;