using System.Diagnostics.CodeAnalysis; using ComputeSharp.SwapChain.D2D1.Backend; using ComputeSharp.SwapChain.D2D1.Extensions; using ComputeSharp.SwapChain.Shaders.D2D1; using Windows.ApplicationModel.Core; using Windows.UI.Core; using Windows.UI.ViewManagement; namespace ComputeSharp.SwapChain.D2D1; /// /// A sample app rendering D2D shaders into a instance. /// public sealed partial class App : IFrameworkViewSource, IFrameworkView { /// /// The collection of available pixel shader effects. /// private static readonly PixelShaderEffect[] Effects = [ new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))) ]; /// /// The for the current app instance. /// private CoreApplicationView? applicationView; /// /// The used to display the app content. /// private CoreWindow? window; /// /// The currently selected effect (one of the items in ). /// private PixelShaderEffect selectedEffect = Effects[0]; /// /// The entry point for the application. /// public static void Main() { CoreApplication.Run(new App()); } /// public IFrameworkView CreateView() { return this; } /// [MemberNotNull(nameof(applicationView))] public void Initialize(CoreApplicationView applicationView) { this.applicationView = applicationView; } /// [MemberNotNull(nameof(window))] public void SetWindow(CoreWindow window) { this.window = window; } /// public void Load(string entryPoint) { } /// public void Run() { this.applicationView!.TitleBar.ExtendViewIntoTitleBar = true; ApplicationView.GetForCurrentView().TitleBar.StyleTitleBarForExtendedIntoViewMode(); // Switch the shader to use when pressing the number keys this.window!.CharacterReceived += (s, e) => { if (e.KeyCode is >= '1' and <= '9') { this.selectedEffect = Effects[(int)(e.KeyCode - '1')]; e.Handled = true; } }; CoreWindowApplication application = new(); application.Draw += (s, e) => { PixelShaderEffect effect = this.selectedEffect; // 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); }; CoreWindowApplicationRunner.Run(application, this.window); } /// public void Uninitialize() { } }