Rename parameters in Texture2D<T> copy APIs

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-12 02:38:29 +01:00
1 親 29944625e0
コミット 9a2d5bdced
3ファイル変更
+154 -154

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

+94 -94
ファイルの表示
@@ -16,15 +16,15 @@ public static class Texture2DExtensions
/// Reads the contents of the current <see cref="Texture2D{T}"/> instance and returns an array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <returns>A <typeparamref name="T"/> array with the contents of the current texture.</returns>
[Pure]
public static T[,] ToArray<T>(this Texture2D<T> texture)
public static T[,] ToArray<T>(this Texture2D<T> source)
where T : unmanaged
{
T[,] data = new T[texture.Height, texture.Width];
T[,] data = new T[source.Height, source.Width];
texture.CopyTo(data);
source.CopyTo(data);
return data;
}
@@ -33,102 +33,102 @@ public static class Texture2DExtensions
/// Reads the contents of the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[,] destination)
public static void CopyTo<T>(this Texture2D<T> source, T[,] destination)
where T : unmanaged
{
Guard.IsEqualTo(destination.GetLength(0), texture.Height, nameof(destination));
Guard.IsEqualTo(destination.GetLength(1), texture.Width, nameof(destination));
Guard.IsEqualTo(destination.GetLength(0), source.Height, nameof(destination));
Guard.IsEqualTo(destination.GetLength(1), source.Width, nameof(destination));
texture.CopyTo(ref destination[0, 0], destination.Length, 0, 0, texture.Width, texture.Height);
source.CopyTo(ref destination[0, 0], destination.Length, 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination)
public static void CopyTo<T>(this Texture2D<T> source, T[] destination)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(), 0, 0, texture.Width, texture.Height);
source.CopyTo(destination.AsSpan(), 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="x">The horizontal range of items to copy.</param>
/// <param name="y">The vertical range of items to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, Range x, Range y)
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, Range x, Range y)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(), x, y);
source.CopyTo(destination.AsSpan(), x, y);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int x, int y, int width, int height)
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(), x, y, width, height);
source.CopyTo(destination.AsSpan(), sourceOffsetX, sourceOffsetY, width, height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset)
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(offset), 0, 0, texture.Width, texture.Height);
source.CopyTo(destination.AsSpan(destinationOffset), 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="x">The horizontal range of items to copy.</param>
/// <param name="y">The vertical range of items to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset, Range x, Range y)
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset, Range x, Range y)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(offset), x, y);
source.CopyTo(destination.AsSpan(destinationOffset), x, y);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target array.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input array to write data to.</param>
/// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, T[] destination, int offset, int x, int y, int width, int height)
public static void CopyTo<T>(this Texture2D<T> source, T[] destination, int destinationOffset, int sourceOffsetX, int sourceOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyTo(destination.AsSpan(offset), x, y, width, height);
source.CopyTo(destination.AsSpan(destinationOffset), sourceOffsetX, sourceOffsetY, width, height);
}
/// <summary>
@@ -136,162 +136,162 @@ public static class Texture2DExtensions
/// The input data will be read from the start of the texture.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> texture, Span<T> destination)
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination)
where T : unmanaged
{
texture.CopyTo(destination, 0, 0, texture.Width, texture.Height);
source.CopyTo(destination, 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
/// <param name="x">The horizontal range of items to copy.</param>
/// <param name="y">The vertical range of items to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, Span<T> destination, Range x, Range y)
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination, Range x, Range y)
where T : unmanaged
{
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
var (offsetX, width) = x.GetOffsetAndLength(source.Width);
var (offsetY, height) = y.GetOffsetAndLength(source.Height);
texture.CopyTo(destination, offsetX, offsetY, width, height);
source.CopyTo(destination, offsetX, offsetY, width, height);
}
/// <summary>
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, Span<T> destination, int x, int y, int width, int height)
public static void CopyTo<T>(this Texture2D<T> source, Span<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, width, height);
source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, width, height);
}
/// <summary>
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
public static void CopyTo<T>(this Texture2D<T> texture, ReadBackTexture2D<T> destination)
public static void CopyTo<T>(this Texture2D<T> source, ReadBackTexture2D<T> destination)
where T : unmanaged
{
texture.CopyTo(destination, 0, 0, 0, 0, texture.Width, texture.Height);
source.CopyTo(destination, 0, 0, 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of a <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="Texture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
public static void CopyTo<T>(this Texture2D<T> texture, ReadBackTexture2D<T> destination, int x, int y, int width, int height)
public static void CopyTo<T>(this Texture2D<T> source, ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyTo(destination, 0, 0, x, y, width, height);
source.CopyTo(destination, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
public static unsafe void CopyFrom<T>(this Texture2D<T> texture, T[,] source)
public static unsafe void CopyFrom<T>(this Texture2D<T> destination, T[,] source)
where T : unmanaged
{
Guard.IsEqualTo(source.GetLength(0), texture.Height, nameof(source));
Guard.IsEqualTo(source.GetLength(1), texture.Width, nameof(source));
Guard.IsEqualTo(source.GetLength(0), destination.Height, nameof(source));
Guard.IsEqualTo(source.GetLength(1), destination.Width, nameof(source));
texture.CopyFrom(ref source[0, 0], source.Length, 0, 0, texture.Width, texture.Height);
destination.CopyFrom(ref source[0, 0], source.Length, 0, 0, destination.Width, destination.Height);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source)
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source)
where T : unmanaged
{
texture.CopyFrom(source.AsSpan(), 0, 0, texture.Width, texture.Height);
destination.CopyFrom(source.AsSpan(), 0, 0, destination.Width, destination.Height);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
/// <param name="x">The horizontal range of items to write.</param>
/// <param name="y">The vertical range of items to write.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, Range x, Range y)
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, Range x, Range y)
where T : unmanaged
{
texture.CopyFrom(source.AsSpan(), x, y);
destination.CopyFrom(source.AsSpan(), x, y);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int x, int y, int width, int height)
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int destinationOffsetX, int destinationOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyFrom(source.AsSpan(), x, y, width, height);
destination.CopyFrom(source.AsSpan(), destinationOffsetX, destinationOffsetY, width, height);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="x">The horizontal range of items to write.</param>
/// <param name="y">The vertical range of items to write.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int offset, Range x, Range y)
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int sourceOffset, Range x, Range y)
where T : unmanaged
{
texture.CopyFrom(source.AsSpan(offset), x, y);
destination.CopyFrom(source.AsSpan(sourceOffset), x, y);
}
/// <summary>
/// Writes the contents of a given <typeparamref name="T"/> array to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <typeparamref name="T"/> array to read data from.</param>
/// <param name="offset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="sourceOffset">The starting offset within <paramref name="source"/> to read data from.</param>
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, T[] source, int offset, int x, int y, int width, int height)
public static void CopyFrom<T>(this Texture2D<T> destination, T[] source, int sourceOffset, int destinationOffsetX, int destinationOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyFrom(source.AsSpan(offset), x, y, width, height);
destination.CopyFrom(source.AsSpan(sourceOffset), destinationOffsetX, destinationOffsetY, width, height);
}
/// <summary>
@@ -299,45 +299,45 @@ public static class Texture2DExtensions
/// The input data will be written to the start of the texture, and all input items will be copied.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, ReadOnlySpan<T> source)
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source)
where T : unmanaged
{
texture.CopyFrom(source, 0, 0, texture.Width, texture.Height);
destination.CopyFrom(source, 0, 0, destination.Width, destination.Height);
}
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
/// <param name="x">The horizontal range of items to write.</param>
/// <param name="y">The vertical range of items to write.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, ReadOnlySpan<T> source, Range x, Range y)
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source, Range x, Range y)
where T : unmanaged
{
var (offsetX, width) = x.GetOffsetAndLength(texture.Width);
var (offsetY, height) = y.GetOffsetAndLength(texture.Height);
var (offsetX, width) = x.GetOffsetAndLength(destination.Width);
var (offsetY, height) = y.GetOffsetAndLength(destination.Height);
texture.CopyFrom(source, offsetX, offsetY, width, height);
destination.CopyFrom(source, offsetX, offsetY, width, height);
}
/// <summary>
/// Writes the contents of a given <see cref="ReadOnlySpan{T}"/> to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="source">The input <see cref="ReadOnlySpan{T}"/> to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
public static void CopyFrom<T>(this Texture2D<T> texture, ReadOnlySpan<T> source, int x, int y, int width, int height)
public static void CopyFrom<T>(this Texture2D<T> destination, ReadOnlySpan<T> source, int destinationOffsetX, int destinationOffsetY, int width, int height)
where T : unmanaged
{
texture.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, x, y, width, height);
destination.CopyFrom(ref MemoryMarshal.GetReference(source), source.Length, destinationOffsetX, destinationOffsetY, width, height);
}
/// <summary>
+8 -8
ファイルの表示
@@ -11,27 +11,27 @@ public static class UploadTexture2DExtensions
/// Reads the contents of a <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
public static void CopyTo<T>(this UploadTexture2D<T> texture, Texture2D<T> destination)
public static void CopyTo<T>(this UploadTexture2D<T> source, Texture2D<T> destination)
where T : unmanaged
{
destination.CopyFrom(texture, 0, 0, 0, 0, texture.Width, texture.Height);
destination.CopyFrom(source, 0, 0, 0, 0, source.Width, source.Height);
}
/// <summary>
/// Reads the contents of a <see cref="UploadTexture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items stored on the texture.</typeparam>
/// <param name="texture">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
/// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
public static void CopyTo<T>(this UploadTexture2D<T> texture, Texture2D<T> destination, int x, int y, int width, int height)
public static void CopyTo<T>(this UploadTexture2D<T> source, Texture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int width, int height)
where T : unmanaged
{
destination.CopyFrom(texture, x, y, 0, 0, width, height);
destination.CopyFrom(source, sourceOffsetX, sourceOffsetY, 0, 0, width, height);
}
}
+52 -52
ファイルの表示
@@ -147,22 +147,22 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
/// </summary>
/// <param name="destination">The target memory area to write data to.</param>
/// <param name="size">The size of the target memory area to write data to.</param>
/// <param name="x">The horizontal offset in the source texture.</param>
/// <param name="y">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
internal void CopyTo(ref T destination, int size, int x, int y, int width, int height)
internal void CopyTo(ref T destination, int size, int sourceOffsetX, int sourceOffsetY, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(x, 0, Width, nameof(x));
Guard.IsInRange(y, 0, Height, nameof(y));
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
@@ -195,8 +195,8 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
destinationY: 0,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
sourceX: (uint)x,
sourceY: (uint)y,
sourceX: (uint)sourceOffsetX,
sourceY: (uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
@@ -227,13 +227,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
/// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="ReadBackTexture2D{T}"/> instance.
/// </summary>
/// <param name="destination">The target <see cref="ReadBackTexture2D{T}"/> instance to write data to.</param>
/// <param name="destinationX">The horizontal offset within <paramref name="destination"/>.</param>
/// <param name="destinationY">The vertical offset within <paramref name="destination"/>.</param>
/// <param name="sourceX">The horizontal offset in the source texture.</param>
/// <param name="sourceY">The vertical offset in the source texture.</param>
/// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
/// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
/// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param>
/// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param>
/// <param name="width">The width of the memory area to copy.</param>
/// <param name="height">The height of the memory area to copy.</param>
internal void CopyTo(ReadBackTexture2D<T> destination, int destinationX, int destinationY, int sourceX, int sourceY, int width, int height)
internal void CopyTo(ReadBackTexture2D<T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
@@ -242,18 +242,18 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
destination.ThrowIfDeviceMismatch(GraphicsDevice);
destination.ThrowIfDisposed();
Guard.IsInRange(destinationX, 0, destination.Width, nameof(destinationX));
Guard.IsInRange(destinationY, 0, destination.Height, nameof(destinationY));
Guard.IsInRange(sourceX, 0, Width, nameof(sourceX));
Guard.IsInRange(sourceY, 0, Height, nameof(sourceY));
Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX));
Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY));
Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX));
Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY));
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height));
Guard.IsBetweenOrEqualTo(destinationX + width, 1, destination.Width, nameof(destinationX));
Guard.IsBetweenOrEqualTo(destinationY + height, 1, destination.Height, nameof(destinationY));
Guard.IsLessThanOrEqualTo(sourceX + width, Width, nameof(sourceX));
Guard.IsLessThanOrEqualTo(sourceY + height, Height, nameof(sourceY));
Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX));
Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY));
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX));
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY));
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
@@ -267,12 +267,12 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: destination.D3D12Resource,
d3D12PlacedSubresourceFootprintDestination,
(uint)destinationX,
(uint)destinationY,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: D3D12Resource,
(uint)sourceX,
(uint)sourceY,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,
@@ -292,22 +292,22 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
/// </summary>
/// <param name="source">The input memory area to read data from.</param>
/// <param name="size">The size of the memory area to read data from.</param>
/// <param name="x">The horizontal offset in the destination texture.</param>
/// <param name="y">The vertical offset in the destination texture.</param>
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
internal void CopyFrom(ref T source, int size, int x, int y, int width, int height)
internal void CopyFrom(ref T source, int size, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
ThrowIfDisposed();
Guard.IsInRange(x, 0, Width, nameof(x));
Guard.IsInRange(y, 0, Height, nameof(y));
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsLessThanOrEqualTo(x + width, Width, nameof(x));
Guard.IsLessThanOrEqualTo(y + height, Height, nameof(y));
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
Guard.IsGreaterThanOrEqualTo(size, (nint)width * height, nameof(size));
GraphicsDevice.D3D12Device->GetCopyableFootprint(
@@ -346,8 +346,8 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
destinationX: (uint)x,
destinationY: (uint)y,
destinationX: (uint)destinationOffsetX,
destinationY: (uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: d3D12Resource.Get(),
&d3D12PlacedSubresourceFootprintSource,
@@ -370,13 +370,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
/// Writes the contents of a given <see cref="UploadTexture2D{T}"/> instance to a specified area of the current <see cref="Texture2D{T}"/> instance.
/// </summary>
/// <param name="source">The input <see cref="UploadTexture2D{T}"/> instance to read data from.</param>
/// <param name="sourceX">The horizontal offset within <paramref name="source"/>.</param>
/// <param name="sourceY">The vertical offset within <paramref name="source"/>.</param>
/// <param name="destinationX">The horizontal offset in the destination texture.</param>
/// <param name="destinationY">The vertical offset in the destination texture.</param>
/// <param name="sourceOffsetX">The horizontal offset within <paramref name="source"/>.</param>
/// <param name="sourceOffsetY">The vertical offset within <paramref name="source"/>.</param>
/// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
/// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
/// <param name="width">The width of the memory area to write to.</param>
/// <param name="height">The height of the memory area to write to.</param>
internal void CopyFrom(UploadTexture2D<T> source, int sourceX, int sourceY, int destinationX, int destinationY, int width, int height)
internal void CopyFrom(UploadTexture2D<T> source, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height)
{
GraphicsDevice.ThrowIfDisposed();
@@ -385,18 +385,18 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
source.ThrowIfDeviceMismatch(GraphicsDevice);
source.ThrowIfDisposed();
Guard.IsInRange(sourceX, 0, source.Width, nameof(sourceX));
Guard.IsInRange(sourceY, 0, source.Height, nameof(sourceY));
Guard.IsInRange(destinationX, 0, Width, nameof(destinationX));
Guard.IsInRange(destinationY, 0, Height, nameof(destinationY));
Guard.IsInRange(sourceOffsetX, 0, source.Width, nameof(sourceOffsetX));
Guard.IsInRange(sourceOffsetY, 0, source.Height, nameof(sourceOffsetY));
Guard.IsInRange(destinationOffsetX, 0, Width, nameof(destinationOffsetX));
Guard.IsInRange(destinationOffsetY, 0, Height, nameof(destinationOffsetY));
Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height));
Guard.IsBetweenOrEqualTo(width, 1, source.Width, nameof(width));
Guard.IsBetweenOrEqualTo(height, 1, source.Height, nameof(height));
Guard.IsLessThanOrEqualTo(sourceX + width, source.Width, nameof(sourceX));
Guard.IsLessThanOrEqualTo(sourceY + height, source.Height, nameof(sourceY));
Guard.IsLessThanOrEqualTo(destinationX + width, Width, nameof(destinationX));
Guard.IsLessThanOrEqualTo(destinationY + height, Height, nameof(destinationY));
Guard.IsLessThanOrEqualTo(sourceOffsetX + width, source.Width, nameof(sourceOffsetX));
Guard.IsLessThanOrEqualTo(sourceOffsetY + height, source.Height, nameof(sourceOffsetY));
Guard.IsLessThanOrEqualTo(destinationOffsetX + width, Width, nameof(destinationOffsetX));
Guard.IsLessThanOrEqualTo(destinationOffsetY + height, Height, nameof(destinationOffsetY));
using CommandList copyCommandList = new(GraphicsDevice, this.d3D12CommandListType);
@@ -409,13 +409,13 @@ public unsafe abstract class Texture2D<T> : NativeObject, GraphicsResourceHelper
{
copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion(
d3D12ResourceDestination: D3D12Resource,
(uint)destinationX,
(uint)destinationY,
(uint)destinationOffsetX,
(uint)destinationOffsetY,
destinationZ: 0,
d3D12ResourceSource: source.D3D12Resource,
d3D12PlacedSubresourceFootprintSource,
(uint)sourceX,
(uint)sourceY,
(uint)sourceOffsetX,
(uint)sourceOffsetY,
sourceZ: 0,
(uint)width,
(uint)height,