Merge pull request #852 from Sergio0694/dev/core-uwp-sample
Add UWP CoreApplication sample
このコミットが含まれているのは:
24ファイル変更
+622
-9
検索条件に一致するファイルはありません
@@ -334,6 +334,21 @@ jobs:
|
||||
msbuild samples\ComputeSharp.SwapChain.WinUI\ComputeSharp.SwapChain.WinUI.csproj /restore -t:publish
|
||||
/p:Configuration=Release /p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}}
|
||||
|
||||
# Publish the D2D1 UWP (CoreApplication) sample app with NativeAOT
|
||||
- if: matrix.platform == 'x64'
|
||||
name: Publish ComputeSharp.SwapChain.D2D1.Uwp
|
||||
run: >
|
||||
msbuild samples\ComputeSharp.SwapChain.D2D1.Uwp\ComputeSharp.SwapChain.D2D1.Uwp.csproj /restore -t:publish
|
||||
/p:Configuration=Release /p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}}
|
||||
|
||||
# Publish the D2D1 UWP sample app again with NativeAOT, with Xbox support
|
||||
- if: matrix.platform == 'x64'
|
||||
name: Publish ComputeSharp.SwapChain.D2D1.Uwp (Xbox)
|
||||
run: >
|
||||
$env:EXPERIMENTAL_XBOX_SUPPORT='true';
|
||||
msbuild samples\ComputeSharp.SwapChain.D2D1.Uwp\ComputeSharp.SwapChain.D2D1.Uwp.csproj /restore -t:publish
|
||||
/p:Configuration=Release /p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}}
|
||||
|
||||
# Download the NuGet packages generated in the previous job and use them
|
||||
# to build and run the sample project referencing them. This is used as
|
||||
# a test to ensure the NuGet packages work in a consuming project.
|
||||
|
||||
@@ -176,6 +176,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.D2D1.UI", "src
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Uwp", "src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj", "{716DF19E-69BA-4A9C-9CA4-BFD196152F46}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SwapChain.D2D1.Uwp", "samples\ComputeSharp.SwapChain.D2D1.Uwp\ComputeSharp.SwapChain.D2D1.Uwp.csproj", "{9FBE070E-A210-4CEF-9F04-61C2B269C600}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -488,6 +490,18 @@ Global
|
||||
{716DF19E-69BA-4A9C-9CA4-BFD196152F46}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{716DF19E-69BA-4A9C-9CA4-BFD196152F46}.Release|x64.ActiveCfg = Release|x64
|
||||
{716DF19E-69BA-4A9C-9CA4-BFD196152F46}.Release|x64.Build.0 = Release|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|ARM64.Deploy.0 = Debug|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|x64.Build.0 = Debug|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|ARM64.Deploy.0 = Release|ARM64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|x64.ActiveCfg = Release|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|x64.Build.0 = Release|x64
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600}.Release|x64.Deploy.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -527,6 +541,7 @@ Global
|
||||
{B4F6A41C-AA9A-4302-92B3-AC64CF2E30F5} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104}
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
|
||||
{551EF4FB-F34F-412A-B3E6-E345797560ED} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
|
||||
{9FBE070E-A210-4CEF-9F04-61C2B269C600} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
|
||||
@@ -550,6 +565,7 @@ Global
|
||||
src\ComputeSharp.CodeFixing\ComputeSharp.CodeFixing.projitems*{9b4448b1-200f-4966-8a13-a508691b3003}*SharedItemsImports = 5
|
||||
src\ComputeSharp.Win32.D2D1\ComputeSharp.Win32.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13
|
||||
samples\ComputeSharp.SwapChain.Shaders.D2D1\ComputeSharp.SwapChain.Shaders.D2D1.projitems*{9ea5ae9d-c39a-4f43-b03e-0a848ea2558a}*SharedItemsImports = 5
|
||||
samples\ComputeSharp.SwapChain.Shaders.D2D1\ComputeSharp.SwapChain.Shaders.D2D1.projitems*{9fbe070e-a210-4cef-9f04-61c2b269c600}*SharedItemsImports = 5
|
||||
src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{a2a2171b-0baf-4a2a-bfb3-3357ef714bf0}*SharedItemsImports = 13
|
||||
src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{bd9e6556-357e-4c20-bfcd-fb131f9372fa}*SharedItemsImports = 5
|
||||
samples\ComputeSharp.SwapChain.Shaders\ComputeSharp.SwapChain.Shaders.projitems*{c12d7ace-98ed-4813-8118-6667c34f484f}*SharedItemsImports = 5
|
||||
|
||||
@@ -33,9 +33,9 @@ if (args is [] or [_])
|
||||
// If a shader is found, run it
|
||||
if (effect is not null)
|
||||
{
|
||||
Win32Application win32Application = new();
|
||||
Win32Application application = new();
|
||||
|
||||
win32Application.Draw += (_, e) =>
|
||||
application.Draw += (_, e) =>
|
||||
{
|
||||
// Set the effect properties
|
||||
effect.ElapsedTime = e.TotalTime;
|
||||
@@ -46,7 +46,7 @@ if (args is [] or [_])
|
||||
e.DrawingSession.DrawImage(effect);
|
||||
};
|
||||
|
||||
Win32ApplicationRunner.Run(win32Application, "ComputeSharp.D2D1");
|
||||
Win32ApplicationRunner.Run(application, "ComputeSharp.D2D1");
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// A sample app rendering D2D shaders into a <see cref="CoreWindow"/> instance.
|
||||
/// </summary>
|
||||
public sealed partial class App : IFrameworkViewSource, IFrameworkView
|
||||
{
|
||||
/// <summary>
|
||||
/// The collection of available pixel shader effects.
|
||||
/// </summary>
|
||||
private static readonly PixelShaderEffect[] Effects =
|
||||
[
|
||||
new PixelShaderEffect.For<ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))),
|
||||
new PixelShaderEffect.For<TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="CoreApplicationView"/> for the current app instance.
|
||||
/// </summary>
|
||||
private CoreApplicationView? applicationView;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="CoreWindow"/> used to display the app content.
|
||||
/// </summary>
|
||||
private CoreWindow? window;
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected effect (one of the items in <see cref="Effects"/>).
|
||||
/// </summary>
|
||||
private PixelShaderEffect selectedEffect = Effects[0];
|
||||
|
||||
/// <summary>
|
||||
/// The entry point for the application.
|
||||
/// </summary>
|
||||
public static void Main()
|
||||
{
|
||||
CoreApplication.Run(new App());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IFrameworkView CreateView()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MemberNotNull(nameof(applicationView))]
|
||||
public void Initialize(CoreApplicationView applicationView)
|
||||
{
|
||||
this.applicationView = applicationView;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MemberNotNull(nameof(window))]
|
||||
public void SetWindow(CoreWindow window)
|
||||
{
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Load(string entryPoint)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Uninitialize()
|
||||
{
|
||||
}
|
||||
}
|
||||
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 432 B |
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 8.3 KiB |
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 3.7 KiB |
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 1.7 KiB |
バイナリ
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 796 B |
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 2.0 KiB |
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 4.2 KiB |
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Windows.Graphics.Display;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace ComputeSharp.SwapChain.D2D1.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// A simple <see cref="CoreWindow"/> application handling a D2D swapchain.
|
||||
/// </summary>
|
||||
internal sealed class CoreWindowApplication
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="CanvasDevice"/> instance to use.
|
||||
/// </summary>
|
||||
private CanvasDevice? canvasDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="CanvasSwapChain"/> instance to use to render frames.
|
||||
/// </summary>
|
||||
private CanvasSwapChain? canvasSwapChain;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the window has been resized and requires the buffers to be updated.
|
||||
/// </summary>
|
||||
private volatile bool isResizePending;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen width in raw pixels.
|
||||
/// </summary>
|
||||
private uint screenWidth;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen height in raw pixels.
|
||||
/// </summary>
|
||||
private uint screenHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Raised whenever a draw operation can be performed.
|
||||
/// </summary>
|
||||
public event EventHandler<DrawEventArgs>? Draw;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the current application.
|
||||
/// </summary>
|
||||
/// <param name="window">The <see cref="CoreWindow"/> instance.</param>
|
||||
[MemberNotNull(nameof(canvasDevice))]
|
||||
[MemberNotNull(nameof(canvasSwapChain))]
|
||||
public unsafe void OnInitialize(CoreWindow window)
|
||||
{
|
||||
// Create a new canvas device, which will handle DX11/D2D initialization
|
||||
CanvasDevice canvasDevice = new();
|
||||
|
||||
// Create the swapchain for rendering (it is automatically tied to the window)
|
||||
CanvasSwapChain canvasSwapChain = CanvasSwapChain.CreateForCoreWindow(
|
||||
resourceCreator: canvasDevice,
|
||||
coreWindow: window,
|
||||
dpi: DisplayInformation.GetForCurrentView().LogicalDpi);
|
||||
|
||||
// Save the Win2D objects for later use
|
||||
this.canvasDevice = canvasDevice;
|
||||
this.canvasSwapChain = canvasSwapChain;
|
||||
|
||||
// Store the initial size of the screen
|
||||
this.screenWidth = canvasSwapChain.SizeInPixels.Width;
|
||||
this.screenHeight = canvasSwapChain.SizeInPixels.Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the current application.
|
||||
/// </summary>
|
||||
public void OnResize()
|
||||
{
|
||||
this.isResizePending = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the current application.
|
||||
/// </summary>
|
||||
/// <param name="time">The current time since the start of the application.</param>
|
||||
public void OnUpdate(TimeSpan time)
|
||||
{
|
||||
if (this.isResizePending)
|
||||
{
|
||||
// Resize the swapchain if needed (the size is calculated automatically)
|
||||
this.canvasSwapChain!.ResizeBuffers(0, 0);
|
||||
|
||||
BitmapSize bitmapSize = this.canvasSwapChain!.SizeInPixels;
|
||||
|
||||
this.screenWidth = bitmapSize.Width;
|
||||
this.screenHeight = bitmapSize.Height;
|
||||
|
||||
this.isResizePending = false;
|
||||
}
|
||||
|
||||
// Create the drawing session and invoke all registered draw handler
|
||||
using (CanvasDrawingSession canvasDrawingSession = this.canvasSwapChain!.CreateDrawingSession(default))
|
||||
{
|
||||
Draw?.Invoke(this, new DrawEventArgs
|
||||
{
|
||||
ScreenWidth = this.screenWidth,
|
||||
ScreenHeight = this.screenHeight,
|
||||
TotalTime = time,
|
||||
DrawingSession = canvasDrawingSession
|
||||
});
|
||||
}
|
||||
|
||||
// Wait for v-sync
|
||||
this.canvasSwapChain.WaitForVerticalBlank();
|
||||
|
||||
// Present the new frame
|
||||
this.canvasSwapChain.Present(syncInterval: 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Arguments for <see cref="Draw"/>.
|
||||
/// </summary>
|
||||
public sealed class DrawEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the screen width in raw pixels.
|
||||
/// </summary>
|
||||
public required uint ScreenWidth { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the screen height in raw pixels.
|
||||
/// </summary>
|
||||
public required uint ScreenHeight { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total time for the rendering loop.
|
||||
/// </summary>
|
||||
public required TimeSpan TotalTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CanvasDrawingSession"/> instance to use.
|
||||
/// </summary>
|
||||
public required CanvasDrawingSession DrawingSession { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace ComputeSharp.SwapChain.D2D1.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// A helper class to manage the creation and execution of <see cref="CoreWindow"/> applications.
|
||||
/// </summary>
|
||||
internal static class CoreWindowApplicationRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs a specified application and starts the main loop to update its state. This is the entry point for a given application,
|
||||
/// and it should be called as soon as the process is launched, excluding any other additional initialization needed.
|
||||
/// </summary>
|
||||
/// <param name="application">The input application instance to run.</param>
|
||||
/// <param name="window">The <see cref="CoreWindow"/> instance.</param>
|
||||
public static void Run(CoreWindowApplication application, CoreWindow window)
|
||||
{
|
||||
// Initialize the application
|
||||
application.OnInitialize(window);
|
||||
|
||||
// Setup the render thread that enables smooth resizing of the window
|
||||
Thread renderThread = new(static args =>
|
||||
{
|
||||
(CoreWindowApplication application, CancellationToken token) = ((CoreWindowApplication, CancellationToken))args!;
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
application.OnUpdate(stopwatch.Elapsed);
|
||||
}
|
||||
});
|
||||
|
||||
CancellationTokenSource tokenSource = new();
|
||||
|
||||
// Start the render thread before activating the window.
|
||||
// This allows the app to show up while already drawing.
|
||||
renderThread.Start((application, tokenSource.Token));
|
||||
|
||||
// Register a callback to monitor resize operations
|
||||
window.ResizeCompleted += (s, e) => application.OnResize();
|
||||
|
||||
// Activate the window
|
||||
window.Activate();
|
||||
|
||||
// Process any messages in the queue
|
||||
window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
|
||||
|
||||
tokenSource.Cancel();
|
||||
|
||||
// Wait for the render thread to stop before terminating
|
||||
renderThread.Join();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using ComputeSharp.D2D1;
|
||||
using ComputeSharp.D2D1.Descriptors;
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
|
||||
namespace ComputeSharp.SwapChain.D2D1.Backend;
|
||||
|
||||
/// <summary>
|
||||
/// An base effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
internal abstract partial class PixelShaderEffect : CanvasEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The current elapsed time.
|
||||
/// </summary>
|
||||
private TimeSpan elapsedTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen width in raw pixels.
|
||||
/// </summary>
|
||||
private int screenWidth;
|
||||
|
||||
/// <summary>
|
||||
/// The current screen height in raw pixels.
|
||||
/// </summary>
|
||||
private int screenHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total elapsed time.
|
||||
/// </summary>
|
||||
public TimeSpan ElapsedTime
|
||||
{
|
||||
get => this.elapsedTime;
|
||||
set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the screen width in raw pixels.
|
||||
/// </summary>
|
||||
public int ScreenWidth
|
||||
{
|
||||
get => this.screenWidth;
|
||||
set => SetAndInvalidateEffectGraph(ref this.screenWidth, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the screen height in raw pixels.
|
||||
/// </summary>
|
||||
public int ScreenHeight
|
||||
{
|
||||
get => this.screenHeight;
|
||||
set => SetAndInvalidateEffectGraph(ref this.screenHeight, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An effect for an animated pixel shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
|
||||
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
|
||||
public sealed partial class For<T>(For<T>.Factory factory) : PixelShaderEffect
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="PixelShaderEffect{T}"/> node in use.
|
||||
/// </summary>
|
||||
private static readonly CanvasEffectNode<PixelShaderEffect<T>> Effect = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void BuildEffectGraph(CanvasEffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.RegisterOutputNode(Effect, new PixelShaderEffect<T>());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph)
|
||||
{
|
||||
effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A factory of a given shader instance.
|
||||
/// </summary>
|
||||
/// <param name="elapsedTime">The total elapsed time.</param>
|
||||
/// <param name="screenWidth">The screen width in raw pixels.</param>
|
||||
/// <param name="screenHeight">The screen height in raw pixels.</param>
|
||||
/// <returns>A shader instance to render.</returns>
|
||||
public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
|
||||
<WindowsSdkPackageVersion>10.0.22621.45</WindowsSdkPackageVersion>
|
||||
<UseUwp>true</UseUwp>
|
||||
<UseUwpTools>true</UseUwpTools>
|
||||
<Platforms>x64;arm64</Platforms>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
<EnableXamlCompilerTargetsForUwpApps>false</EnableXamlCompilerTargetsForUwpApps>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- NativeAOT settings, and size saving options for unnecessary features (optimize for speed otherwise) -->
|
||||
<PropertyGroup>
|
||||
<PublishAot>true</PublishAot>
|
||||
<UseSystemResourceKeys>true</UseSystemResourceKeys>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<StackTraceSupport>false</StackTraceSupport>
|
||||
<OptimizationPreference>Speed</OptimizationPreference>
|
||||
<CsWinRTEnableDynamicObjectsSupport>false</CsWinRTEnableDynamicObjectsSupport>
|
||||
<CsWinRTUseExceptionResourceKeys>true</CsWinRTUseExceptionResourceKeys>
|
||||
<CsWinRTEnableDefaultCustomTypeMappings>false</CsWinRTEnableDefaultCustomTypeMappings>
|
||||
<CsWinRTEnableICustomPropertyProviderSupport>false</CsWinRTEnableICustomPropertyProviderSupport>
|
||||
<CsWinRTEnableIDynamicInterfaceCastableSupport>false</CsWinRTEnableIDynamicInterfaceCastableSupport>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
If experimental support for Xbox is enabled, link against 'WindowsApp.lib'.
|
||||
Additionally, set the AppContainer switch, as Xbox might be validating that.
|
||||
-->
|
||||
<ItemGroup Condition="'$(EXPERIMENTAL_XBOX_SUPPORT)' == 'true'">
|
||||
<LinkerArg Include="/APPCONTAINER /DEFAULTLIB:WindowsApp.lib WindowsApp.lib" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.3" />
|
||||
|
||||
<!--
|
||||
This sample does not need WebView2, but WinAppSDK is pulling it in as a transitive NuGet
|
||||
dependency. We can manually exclude all of its assets to avoid them being in the output.
|
||||
This also prevents the old projections from being referenced and triggering the generator.
|
||||
-->
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2739.15" IncludeAssets="none" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared projects for the D2D1 shaders -->
|
||||
<Import Project="..\ComputeSharp.SwapChain.Shaders.D2D1\ComputeSharp.SwapChain.Shaders.D2D1.projitems" Label="Shared" />
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
using Windows.UI;
|
||||
using Windows.UI.ViewManagement;
|
||||
|
||||
namespace ComputeSharp.SwapChain.D2D1.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for <see cref="ApplicationViewTitleBar"/>.
|
||||
/// </summary>
|
||||
internal static class ApplicationViewTitleBarExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Styles the title bar to look correctly when the view is expanded into it.
|
||||
/// </summary>
|
||||
/// <param name="titleBar">The input title bar.</param>
|
||||
public static void StyleTitleBarForExtendedIntoViewMode(this ApplicationViewTitleBar titleBar)
|
||||
{
|
||||
// Transparent colors
|
||||
titleBar.ForegroundColor = Colors.Transparent;
|
||||
titleBar.BackgroundColor = Colors.Transparent;
|
||||
titleBar.ButtonBackgroundColor = Colors.Transparent;
|
||||
titleBar.InactiveBackgroundColor = Colors.Transparent;
|
||||
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
||||
|
||||
// Theme aware colors
|
||||
titleBar.ButtonForegroundColor = Colors.White;
|
||||
titleBar.ButtonHoverForegroundColor = Colors.White;
|
||||
titleBar.ButtonPressedForegroundColor = Colors.White;
|
||||
titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0x20, 0xFF, 0xFF, 0xFF);
|
||||
titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0x40, 0xFF, 0xFF, 0xFF);
|
||||
titleBar.ButtonInactiveForegroundColor = Color.FromArgb(0xC0, 0xFF, 0xFF, 0xFF);
|
||||
titleBar.InactiveForegroundColor = Color.FromArgb(0xA0, 0xA0, 0xA0, 0xA0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
|
||||
IgnorableNamespaces="uap uap5 mp">
|
||||
|
||||
<Identity
|
||||
Name="b0b35275-65a6-4b18-96bf-8b79fb4bb0bf"
|
||||
Publisher="CN=Sergio"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="b0b35275-65a6-4b18-96bf-8b79fb4bb0bf" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
<Properties>
|
||||
<DisplayName>ComputeSharp Sample App (Core)</DisplayName>
|
||||
<PublisherDisplayName>Sergio Pedri</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="App"
|
||||
Executable="$targetnametoken$.exe"
|
||||
EntryPoint="ComputeSharp.SwapChain.D2D1.App">
|
||||
<uap:VisualElements
|
||||
DisplayName="ComputeSharp Sample App (Core)"
|
||||
Description="A sample app for ComputeSharp using CoreApplication and Win2D"
|
||||
BackgroundColor="#005491"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" uap5:Optional="true" BackgroundColor="transparent" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
</Package>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<Platform>ARM64</Platform>
|
||||
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
|
||||
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
|
||||
<PublishAot>true</PublishAot>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<Platform>x64</Platform>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
|
||||
<PublishAot>true</PublishAot>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<Platform>x86</Platform>
|
||||
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
|
||||
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
|
||||
<PublishAot>true</PublishAot>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"profiles": {
|
||||
"ComputeSharp.SwapChain.D2D1.Uwp": {
|
||||
"commandName": "MsixPackage"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22621.0" />
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22621.0" />
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
@@ -35,8 +34,8 @@
|
||||
BackgroundColor="#005491"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square71x71Logo="Assets\SmallTile.png" Square310x310Logo="Assets\LargeTile.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="transparent"/>
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square71x71Logo="Assets\SmallTile.png" Square310x310Logo="Assets\LargeTile.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="transparent"/>
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- https://go.microsoft.com/fwlink/?LinkID=208121 -->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- https://go.microsoft.com/fwlink/?LinkID=208121 -->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする