Add texture load/save overloads with string parameter

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-16 21:21:59 +01:00
1 親 fcc99d20aa
コミット f3eb04e4b7
5ファイル変更
+223 -23

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

+37
ファイルの表示
@@ -3,6 +3,7 @@ using System.Diagnostics.Contracts;
using ComputeSharp.__Internals;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Resources;
using Microsoft.Toolkit.Diagnostics;
#pragma warning disable CS0618
@@ -1070,6 +1071,24 @@ public static partial class GraphicsDeviceExtensions
return new(device, width, height, depth, allocationMode);
}
/// <summary>
/// Loads a new readonly 2D texture with the contents of the specified file.
/// </summary>
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="filename">The filename of the image file to load and decode into the texture.</param>
/// <returns>A <see cref="ReadOnlyTexture2D{T, TPixel}"/> instance with the contents of the specified file.</returns>
[Pure]
public static ReadOnlyTexture2D<T, TPixel> LoadReadOnlyTexture2D<T, TPixel>(this GraphicsDevice device, string filename)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
Guard.IsNotNull(filename, nameof(filename));
return device.LoadReadOnlyTexture2D<T, TPixel>(filename.AsSpan());
}
/// <summary>
/// Loads a new readonly 2D texture with the contents of the specified file.
/// </summary>
@@ -1114,6 +1133,24 @@ public static partial class GraphicsDeviceExtensions
return texture;
}
/// <summary>
/// Loads a new writeable 2D texture with the contents of the specified file.
/// </summary>
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
/// <typeparam name="TPixel">The type of pixels used on the GPU side.</typeparam>
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
/// <param name="filename">The filename of the image file to load and decode into the texture.</param>
/// <returns>A <see cref="ReadWriteTexture2D{T, TPixel}"/> instance with the contents of the specified file.</returns>
[Pure]
public static ReadWriteTexture2D<T, TPixel> LoadReadWriteTexture2D<T, TPixel>(this GraphicsDevice device, string filename)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
Guard.IsNotNull(filename, nameof(filename));
return device.LoadReadWriteTexture2D<T, TPixel>(filename.AsSpan());
}
/// <summary>
/// Loads a new writeable 2D texture with the contents of the specified file.
/// </summary>
+15
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Resources;
using Microsoft.Toolkit.Diagnostics;
namespace ComputeSharp;
@@ -55,6 +56,20 @@ public static class ReadBackTexture2DExtensions
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
}
/// <summary>
/// Saves a texture to a specified file.
/// </summary>
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
/// <param name="texture">The texture to save to an image.</param>
/// <param name="filename">The filename of the image file to save.</param>
public static void Save<T>(this ReadBackTexture2D<T> texture, string filename)
where T : unmanaged
{
Guard.IsNotNull(filename, nameof(filename));
WICHelper.Instance.SaveTexture(texture.View, filename.AsSpan());
}
/// <summary>
/// Saves a texture to a specified file.
/// </summary>
+14
ファイルの表示
@@ -535,6 +535,20 @@ public static class Texture2DExtensions
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, destinationOffsetX, destinationOffsetY, width, height);
}
/// <summary>
/// Saves a texture to a specified file.
/// </summary>
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
/// <param name="texture">The texture to save to an image.</param>
/// <param name="filename">The filename of the image file to save.</param>
public static void Save<T>(this Texture2D<T> texture, string filename)
where T : unmanaged
{
Guard.IsNotNull(filename, nameof(filename));
texture.Save(filename.AsSpan());
}
/// <summary>
/// Saves a texture to a specified file.
/// </summary>