using System; using System.Text; using UnityEngine.XR.ARFoundation.InternalUtils; namespace UnityEngine.XR.ARFoundation { /// /// Represents an external texture on the GPU. /// public readonly struct ARExternalTexture : IEquatable { /// /// The external texture. /// /// /// This texture may only exist on the GPU. Refer to your provider documentation for more information. /// /// If this is a GPU texture, to use the texture on the CPU, you must read it back from /// the GPU using [Texture2D.ReadPixels](xref:UnityEngine.Texture2D.ReadPixels(UnityEngine.Rect,System.Int32,System.Int32,System.Boolean)). /// public Texture texture { get; } /// /// ID of the shader property associated with this texture. /// /// public int propertyId { get; } /// /// Constructor. /// /// The texture. /// The texture's property ID. public ARExternalTexture(Texture texture, int propertyId) { this.texture = texture; this.propertyId = propertyId; } internal ARExternalTexture(IUpdatableTexture updatableTexture) { texture = updatableTexture.texture; propertyId = updatableTexture.descriptor.propertyNameId; } /// /// Indicates whether the current object is equal to another object of the same type. Textures are compared /// using reference equality. /// /// An object to compare with this object. /// if the current object is equal to . /// Otherwise, . public bool Equals(ARExternalTexture other) => ReferenceEquals(texture, other.texture) && propertyId == other.propertyId; /// /// Indicates whether the current object is equal to another object of the same type. Textures are compared /// using reference equality. /// /// An object to compare with this object. /// if the current object is equal to . /// Otherwise, . public override bool Equals(object obj) => obj is ARExternalTexture other && Equals(other); /// /// Serves as the default hash function. /// /// A hash code for the current object. public override int GetHashCode() => HashCode.Combine(texture, propertyId); /// /// Tests for equality. Equivalent to . /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// if is equal to . /// Otherwise, . public static bool operator ==(ARExternalTexture lhs, ARExternalTexture rhs) => Equals(lhs, rhs); /// /// Tests for inequality. Equivalent to `!`. /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// if is not equal to . /// Otherwise, . public static bool operator !=(ARExternalTexture lhs, ARExternalTexture rhs) => !Equals(lhs, rhs); /// /// Returns a string that represents the current object. /// /// The string. public override string ToString() { var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine($" propertyId: {propertyId},"); sb.AppendLine($" texture: {texture.ToDebugString()}"); sb.Append("}"); return sb.ToString(); } } }