From f523906cc823eeb5f4bb0d9e6dbaa6401b3a59a7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 17 Jan 2022 11:36:00 +0100 Subject: [PATCH] Add APIs to load UploadTexture2D from images --- .../GraphicsDeviceExtensions.Resources.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs index c235c555..09e50274 100644 --- a/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs +++ b/src/ComputeSharp/Graphics/Extensions/GraphicsDeviceExtensions.Resources.cs @@ -1173,4 +1173,60 @@ public static partial class GraphicsDeviceExtensions return texture; } + + /// + /// Loads a new upload 2D texture with the contents of the specified file. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The filename of the image file to load and decode into the texture. + /// A instance with the contents of the specified file. + public static UploadTexture2D LoadUploadTexture2D(this GraphicsDevice device, string filename) + where T : unmanaged + { + Guard.IsNotNull(filename, nameof(filename)); + + return device.LoadUploadTexture2D(filename.AsSpan()); + } + + /// + /// Loads a new upload 2D texture with the contents of the specified file. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The filename of the image file to load and decode into the texture. + /// A instance with the contents of the specified file. + public static UploadTexture2D LoadUploadTexture2D(this GraphicsDevice device, ReadOnlySpan filename) + where T : unmanaged + { + return WICHelper.Instance.LoadTexture(device, filename); + } + + /// + /// Loads a new upload 2D texture with the contents of the specified file. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The buffer with the image data to load and decode into the texture. + /// A instance with the contents of the specified file. + public static UploadTexture2D LoadUploadTexture2D(this GraphicsDevice device, ReadOnlySpan span) + where T : unmanaged + { + return WICHelper.Instance.LoadTexture(device, span); + } + + /// + /// Loads a new upload 2D texture with the contents of the specified file. + /// + /// The type of items to store in the texture. + /// The instance to use to allocate the texture. + /// The stream with the image data to load and decode into the texture. + /// A instance with the contents of the specified file. + public static UploadTexture2D LoadUploadTexture2D(this GraphicsDevice device, Stream stream) + where T : unmanaged + { + Guard.IsNotNull(stream, nameof(stream)); + + return WICHelper.Instance.LoadTexture(device, stream); + } }