using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.XR.ARSubsystems
{
///
/// Contains a native texture object and includes various metadata about the texture.
///
[StructLayout(LayoutKind.Sequential)]
public struct XRTextureDescriptor : IEquatable
{
///
/// A pointer to the native texture object.
///
///
/// A pointer to the native texture object.
///
public IntPtr nativeTexture
{
get { return m_NativeTexture; }
private set { m_NativeTexture = value; }
}
IntPtr m_NativeTexture;
///
/// Specifies the width dimension of the native texture object.
///
///
/// The width of the native texture object.
///
public int width
{
get { return m_Width; }
private set { m_Width = value; }
}
int m_Width;
///
/// Specifies the height dimension of the native texture object.
///
///
/// The height of the native texture object.
///
public int height
{
get { return m_Height; }
private set { m_Height = value; }
}
int m_Height;
///
/// Specifies the number of mipmap levels in the native texture object.
///
///
/// The number of mipmap levels in the native texture object.
///
public int mipmapCount
{
get { return m_MipmapCount; }
private set { m_MipmapCount = value; }
}
int m_MipmapCount;
///
/// Specifies the texture format of the native texture object.
///
///
/// The format of the native texture object.
///
public TextureFormat format
{
get { return m_Format; }
private set { m_Format = value; }
}
TextureFormat m_Format;
///
/// Specifies the unique shader property name ID for the material shader texture.
///
///
/// The unique shader property name ID for the material shader texture.
///
///
/// Use the static method Shader.PropertyToID(string name) to get the unique identifier.
///
public int propertyNameId
{
get { return m_PropertyNameId; }
private set { m_PropertyNameId = value; }
}
int m_PropertyNameId;
///
/// Determines whether the texture data references a valid texture object with positive width and height.
///
///
/// true if the texture data references a valid texture object with positive width and height.
/// Otherwise, false.
///
public bool valid
{
get { return (m_NativeTexture != IntPtr.Zero) && (m_Width > 0) && (m_Height > 0); }
}
///
/// This specifies the depth dimension of the native texture. For a 3D texture, depth is greater than zero.
/// For any other kind of valid texture, depth is one.
///
///
/// The depth dimension of the native texture object.
///
public int depth
{
get => m_Depth;
private set => m_Depth = value;
}
int m_Depth;
///
/// Specifies the [texture dimension](https://docs.unity3d.com/ScriptReference/Rendering.TextureDimension.html) of the native texture object.
///
///
/// The texture dimension of the native texture object.
///
public TextureDimension dimension
{
get => m_Dimension;
private set => m_Dimension = value;
}
TextureDimension m_Dimension;
///
/// Determines whether the given texture descriptor has identical texture metadata (dimension, mipmap count,
/// and format).
///
/// The given texture descriptor with which to compare.
///
/// true if the texture metadata (dimension, mipmap count, and format) are identical between the
/// current and other texture descriptors. Otherwise, false.
///
public bool hasIdenticalTextureMetadata(XRTextureDescriptor other)
{
return
m_Width.Equals(other.m_Width) &&
m_Height.Equals(other.m_Height) &&
m_Depth.Equals(other.m_Depth) &&
m_Dimension == other.m_Dimension &&
m_MipmapCount.Equals(other.m_MipmapCount) &&
(m_Format == other.m_Format);
}
///
/// Reset the texture descriptor back to default values.
///
public void Reset()
{
m_NativeTexture = IntPtr.Zero;
m_Width = 0;
m_Height = 0;
m_Depth = 0;
m_Dimension = (TextureDimension)0;
m_MipmapCount = 0;
m_Format = (TextureFormat)0;
m_PropertyNameId = 0;
}
///
/// Tests for equality.
///
/// The other to compare against.
/// `True` if every field in is equal to this , otherwise `false`.
public bool Equals(XRTextureDescriptor other)
{
return
hasIdenticalTextureMetadata(other) &&
m_PropertyNameId.Equals(other.m_PropertyNameId) &&
(m_NativeTexture == other.m_NativeTexture);
}
///
/// Tests for equality.
///
/// The `object` to compare against.
/// `True` if is of type and
/// also returns `true`; otherwise `false`.
public override bool Equals(System.Object obj)
{
return ((obj is XRTextureDescriptor) && Equals((XRTextureDescriptor)obj));
}
///
/// Tests for equality. Same as .
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// `True` if is equal to , otherwise `false`.
public static bool operator ==(XRTextureDescriptor lhs, XRTextureDescriptor rhs)
{
return lhs.Equals(rhs);
}
///
/// Tests for inequality. Same as `!`.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// `True` if is not equal to , otherwise `false`.
public static bool operator !=(XRTextureDescriptor lhs, XRTextureDescriptor rhs)
{
return !lhs.Equals(rhs);
}
///
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
///
/// A hash code generated from this object's fields.
public override int GetHashCode()
{
int hashCode = 486187739;
unchecked
{
hashCode = (hashCode * 486187739) + m_NativeTexture.GetHashCode();
hashCode = (hashCode * 486187739) + m_Width.GetHashCode();
hashCode = (hashCode * 486187739) + m_Height.GetHashCode();
hashCode = (hashCode * 486187739) + m_Depth.GetHashCode();
hashCode = (hashCode * 486187739) + ((int)m_Dimension).GetHashCode();
hashCode = (hashCode * 486187739) + m_MipmapCount.GetHashCode();
hashCode = (hashCode * 486187739) + ((int)m_Format).GetHashCode();
hashCode = (hashCode * 486187739) + m_PropertyNameId.GetHashCode();
}
return hashCode;
}
///
/// Generates a string suitable for debugging purposes.
///
/// A string suitable for debug logging.
public override string ToString()
{
return $"0x{m_NativeTexture.ToString("X16")} {m_Width.ToString()}x{ m_Height.ToString()}"+
$"x{m_Depth.ToString()}-{m_MipmapCount.ToString()} dimension:{m_Dimension.ToString()}"+
$" format:{m_Format.ToString()} propertyNameId:{m_PropertyNameId.ToString()}";
}
}
}