Add LoadReadOnlyTexture2D overload for Stream

このコミットが含まれているのは:
Sergio Pedri committed 2021-12-08 19:57:28 +01:00
1 親 b93a4a2a5b
コミット 770ed134bf
4ファイル変更
+208 -79

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

+49
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics.Contracts;
using System.IO;
using ComputeSharp.__Internals;
using ComputeSharp.Graphics.Helpers;
using ComputeSharp.Resources;
@@ -1133,6 +1134,30 @@ public static partial class GraphicsDeviceExtensions
return texture;
}
/// <summary>
/// Loads a new readonly 2D texture with the contents of the specified stream.
/// </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="stream">The stream with the image data 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, Stream stream)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
Guard.IsNotNull(stream, nameof(stream));
using UploadTexture2D<T> upload = WICHelper.Instance.LoadTexture<T>(device, stream);
ReadOnlyTexture2D<T, TPixel> texture = device.AllocateReadOnlyTexture2D<T, TPixel>(upload.Width, upload.Height);
upload.CopyTo(texture);
return texture;
}
/// <summary>
/// Loads a new writeable 2D texture with the contents of the specified file.
/// </summary>
@@ -1194,4 +1219,28 @@ public static partial class GraphicsDeviceExtensions
return texture;
}
/// <summary>
/// Loads a new writeable 2D texture with the contents of the specified stream.
/// </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="stream">The stream with the image data 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, Stream stream)
where T : unmanaged, IUnorm<TPixel>
where TPixel : unmanaged
{
Guard.IsNotNull(stream, nameof(stream));
using UploadTexture2D<T> upload = WICHelper.Instance.LoadTexture<T>(device, stream);
ReadWriteTexture2D<T, TPixel> texture = device.AllocateReadWriteTexture2D<T, TPixel>(upload.Width, upload.Height);
upload.CopyTo(texture);
return texture;
}
}