using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace T3.Core.Resource.Dds;
///
/// Specifies data for initializing a subresource.
///
[StructLayout(LayoutKind.Sequential)]
public readonly struct D3D11SubResourceData : IEquatable
{
///
/// The initialization data.
///
private readonly Array data;
///
/// The distance (in bytes) from the beginning of one line of a texture to the next line.
///
private readonly uint pitch;
///
/// The distance (in bytes) from the beginning of one depth level to the next.
///
private readonly uint slicePitch;
///
/// Initializes a new instance of the struct.
///
/// The initialization data.
/// The distance (in bytes) from the beginning of one line of a texture to the next line.
public D3D11SubResourceData(Array data, uint pitch)
{
this.data = data;
this.pitch = pitch;
slicePitch = 0;
}
///
/// Initializes a new instance of the struct.
///
/// The initialization data.
/// The distance (in bytes) from the beginning of one line of a texture to the next line.
/// The distance (in bytes) from the beginning of one depth level to the next.
public D3D11SubResourceData(Array data, uint pitch, uint slicePitch)
{
this.data = data;
this.pitch = pitch;
this.slicePitch = slicePitch;
}
///
/// Gets the initialization data.
///
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Reviewed")]
public Array Data { get { return data; } }
///
/// Gets the distance (in bytes) from the beginning of one line of a texture to the next line.
///
public uint Pitch { get { return pitch; } }
///
/// Gets the distance (in bytes) from the beginning of one depth level to the next.
///
public uint SlicePitch { get { return slicePitch; } }
///
/// Compares two objects. The result specifies whether the values of the two objects are equal.
///
/// The left to compare.
/// The right to compare.
/// true if the values of left and right are equal; otherwise, false.
public static bool operator ==(D3D11SubResourceData left, D3D11SubResourceData right)
{
return left.Equals(right);
}
///
/// Compares two objects. The result specifies whether the values of the two objects are unequal.
///
/// The left to compare.
/// The right to compare.
/// true if the values of left and right differ; otherwise, false.
public static bool operator !=(D3D11SubResourceData left, D3D11SubResourceData right)
{
return !(left == right);
}
///
/// Determines whether the specified object is equal to the current object.
///
/// The object to compare with the current object.
/// true if the specified object is equal to the current object; otherwise, false.
public override bool Equals(object obj)
{
if (!(obj is D3D11SubResourceData))
{
return false;
}
return Equals((D3D11SubResourceData)obj);
}
///
/// Determines whether the specified object is equal to the current object.
///
/// The object to compare with the current object.
/// true if the specified object is equal to the current object; otherwise, false.
public bool Equals(D3D11SubResourceData other)
{
return data == other.data
&& pitch == other.pitch
&& slicePitch == other.slicePitch;
}
///
/// Returns the hash code for this instance.
///
/// A 32-bit signed integer that is the hash code for this instance.
public override int GetHashCode()
{
return new
{
data,
pitch,
slicePitch
}
.GetHashCode();
}
}