Added extensions to allocate 2D textures
このコミットが含まれているのは:
1 親
70a8b095b0
コミット
eec3b22ebc
1ファイル変更
+172
@@ -203,6 +203,178 @@ namespace ComputeSharp
|
||||
return readWriteBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new readonly 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A zeroed <see cref="ReadOnlyTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new readonly 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadOnlyTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, T[] array, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return device.AllocateReadOnlyTexture2D(array, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new readonly 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadOnlyTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, T[] array, int offset, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return device.AllocateReadOnlyTexture2D<T>(array.AsSpan(offset), width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new readonly 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <returns>A read write <see cref="ReadOnlyTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, T[,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new readonly 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> with the data to copy on the allocated texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadOnlyTexture2D{T}"/> instance with the contents of the input span.</returns>
|
||||
[Pure]
|
||||
public static ReadOnlyTexture2D<T> AllocateReadOnlyTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadOnlyTexture2D<T> texture = new(device, width, height);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new writeable 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A zeroed <see cref="ReadWriteTexture2D{T}"/> instance of size [<paramref name="width"/>, <paramref name="height"/>].</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return new(device, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new writeable 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadWriteTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, T[] array, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return device.AllocateReadWriteTexture2D(array, width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new writeable 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadWriteTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, T[] array, int offset, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
return device.AllocateReadWriteTexture2D<T>(array.AsSpan(offset), width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new writeable 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="array">The input <typeparamref name="T"/> array with the data to copy on the allocated texture.</param>
|
||||
/// <returns>A read write <see cref="ReadWriteTexture2D{T}"/> instance with the contents of the input array.</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, T[,] array)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T> texture = new(device, array.GetLength(1), array.GetLength(0));
|
||||
|
||||
texture.SetData(array);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocates a new writeable 2D texture with the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of items to store in the texture.</typeparam>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> instance to use to allocate the texture.</param>
|
||||
/// <param name="span">The input <see cref="ReadOnlySpan{T}"/> with the data to copy on the allocated texture.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <returns>A <see cref="ReadWriteTexture2D{T}"/> instance with the contents of the input span.</returns>
|
||||
[Pure]
|
||||
public static ReadWriteTexture2D<T> AllocateReadWriteTexture2D<T>(this GraphicsDevice device, ReadOnlySpan<T> span, int width, int height)
|
||||
where T : unmanaged
|
||||
{
|
||||
ReadWriteTexture2D<T> texture = new(device, width, height);
|
||||
|
||||
texture.SetData(span);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiles and runs the input shader on a target <see cref="GraphicsDevice"/> instance, with the specified parameters.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする