Added R16 pixel type

このコミットが含まれているのは:
Sergio Pedri committed 2021-01-04 23:39:12 +01:00
1 親 92bc95b028
コミット 1ac1f6afdd
7ファイル変更
+87 -5

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

+81
ファイルの表示
@@ -0,0 +1,81 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp
{
/// <summary>
/// Packed pixel type containing a single 16-bit unsigned normalized channel value.
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 0, 0, 0] in vector form.
/// </para>
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct R16 : IEquatable<R16>, IUnorm<float>, IUnorm<double>
{
/// <summary>
/// The red component.
/// </summary>
public ushort R;
/// <summary>
/// Initializes a new instance of the <see cref="R16"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
public R16(ushort r)
{
R = r;
}
/// <summary>
/// Gets or sets the packed representation of the <see cref="R16"/> struct.
/// </summary>
public ushort PackedValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => Unsafe.As<R16, ushort>(ref Unsafe.AsRef(this));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => Unsafe.As<R16, ushort>(ref this) = value;
}
/// <summary>
/// Compares two <see cref="R16"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(R16 left, R16 right) => left.Equals(right);
/// <summary>
/// Compares two <see cref="R16"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="R16"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="R16"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(R16 left, R16 right) => !left.Equals(right);
/// <inheritdoc/>
public override readonly bool Equals(object obj) => obj is R16 R16 && Equals(R16);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(R16 other) => PackedValue.Equals(other.PackedValue);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly int GetHashCode() => PackedValue.GetHashCode();
/// <inheritdoc/>
public override readonly string ToString() => $"{nameof(R16)}({this.R})";
}
}
+1 -1
ファイルの表示
@@ -31,7 +31,7 @@ namespace ComputeSharp
}
/// <summary>
/// Gets or sets the packed representation of the Rgba32 struct.
/// Gets or sets the packed representation of the <see cref="R8"/> struct.
/// </summary>
public byte PackedValue
{
+1 -1
ファイルの表示
@@ -39,7 +39,7 @@ namespace ComputeSharp
}
/// <summary>
/// Gets or sets the packed representation of the Rg16 struct.
/// Gets or sets the packed representation of the <see cref="Rg16"/> struct.
/// </summary>
public ushort PackedValue
{
+1 -1
ファイルの表示
@@ -39,7 +39,7 @@ namespace ComputeSharp
}
/// <summary>
/// Gets or sets the packed representation of the Rg32 struct.
/// Gets or sets the packed representation of the <see cref="Rg32"/> struct.
/// </summary>
public uint PackedValue
{
+1 -1
ファイルの表示
@@ -71,7 +71,7 @@ namespace ComputeSharp
}
/// <summary>
/// Gets or sets the packed representation of the Rgba32 struct.
/// Gets or sets the packed representation of the <see cref="Rgba32"/> struct.
/// </summary>
public uint PackedValue
{
+1 -1
ファイルの表示
@@ -71,7 +71,7 @@ namespace ComputeSharp
}
/// <summary>
/// Gets or sets the packed representation of the Rgba64 struct.
/// Gets or sets the packed representation of the <see cref="Rgba64"/> struct.
/// </summary>
public ulong PackedValue
{
+1
ファイルの表示
@@ -42,6 +42,7 @@ namespace ComputeSharp.Graphics.Helpers
else if (typeof(T) == typeof(Rgba32)) return DXGI_FORMAT_R8G8B8A8_UNORM;
else if (typeof(T) == typeof(Rgba64)) return DXGI_FORMAT_R16G16B16A16_UNORM;
else if (typeof(T) == typeof(R8)) return DXGI_FORMAT_R8_UNORM;
else if (typeof(T) == typeof(R16)) return DXGI_FORMAT_R16_UNORM;
else if (typeof(T) == typeof(Rg16)) return DXGI_FORMAT_R8G8_UNORM;
else if (typeof(T) == typeof(Rg32)) return DXGI_FORMAT_R16G16_UNORM;
else return ThrowHelper.ThrowArgumentException<DXGI_FORMAT>("Invalid texture type");