Add initial D2D1ContouredLayersRunner implementation
このコミットが含まれているのは:
1 親
162b46ed41
コミット
0deddde903
5ファイル変更
+95
-5
検索条件に一致するファイルはありません
@@ -18,6 +18,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\ID2D1ShaderRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\D2D1ShaderRunner{T}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\D2D1ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ShaderRunnerViewModel.cs" />
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.IO;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.D2D1;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
using ComputeSharp.SwapChain.Shaders.D2D1;
|
||||
#if WINDOWS_UWP
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
#else
|
||||
using ComputeSharp.WinUI;
|
||||
#endif
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
|
||||
/// <summary>
|
||||
/// A specialized <see cref="ID2D1ShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// </summary>
|
||||
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
|
||||
/// </summary>
|
||||
private PixelShaderEffect<ContouredLayers>? pixelShaderEffect;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
|
||||
{
|
||||
if (this.pixelShaderEffect is null)
|
||||
{
|
||||
D2D1ResourceTextureManager resourceTextureManager;
|
||||
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.1024x1024rgba32");
|
||||
|
||||
// Open a file to read from the file (we're doing synchronous IO here by design, doesn't really matter)
|
||||
using (FileStream fileStream = new(filename, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] pixelData = new byte[(int)fileStream.Length];
|
||||
int totalBytesRead = 0;
|
||||
|
||||
// Read the raw image data
|
||||
while (totalBytesRead < pixelData.Length)
|
||||
{
|
||||
int bytesRead = fileStream.Read(pixelData, 0, pixelData.Length);
|
||||
|
||||
Guard.IsGreaterThan(bytesRead, 0);
|
||||
|
||||
totalBytesRead += bytesRead;
|
||||
}
|
||||
|
||||
// Create the resource texture manager to use in the shader
|
||||
resourceTextureManager = new D2D1ResourceTextureManager(
|
||||
extents: stackalloc uint[] { 1024, 1024 },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipLinear,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror },
|
||||
data: pixelData,
|
||||
strides: stackalloc uint[] { (uint)(1024 * sizeof(Bgra32)) });
|
||||
}
|
||||
|
||||
// Create the new pixel shader effect
|
||||
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { ResourceTextureManagers = { [0] = resourceTextureManager } };
|
||||
}
|
||||
|
||||
int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round);
|
||||
int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round);
|
||||
|
||||
// Set the constant buffer
|
||||
this.pixelShaderEffect.ConstantBuffer = new ContouredLayers((float)args.Timing.TotalTime.TotalSeconds, new int2(widthInPixels, heightInPixels));
|
||||
|
||||
// Draw the shader
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
}
|
||||
}
|
||||
@@ -135,10 +135,7 @@ public sealed partial class MainViewModel : ObservableObject
|
||||
typeof(TriangleGridContouring),
|
||||
new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(
|
||||
typeof(ContouredLayers),
|
||||
new ContouredLayersRunner(),
|
||||
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.HelloWorld>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
|
||||
new(typeof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()),
|
||||
new(
|
||||
typeof(TerracedHills),
|
||||
new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds)),
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする