SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
6.1 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace UnityEngine.XR.ARSubsystems
  5. {
  6. /// <summary>
  7. /// Encapsulates a native texture object and includes various metadata about the texture.
  8. /// </summary>
  9. [StructLayout(LayoutKind.Sequential)]
  10. public struct XRTextureDescriptor : IEquatable<XRTextureDescriptor>
  11. {
  12. /// <summary>
  13. /// A pointer to the native texture object.
  14. /// </summary>
  15. /// <value>
  16. /// A pointer to the native texture object.
  17. /// </value>
  18. public IntPtr nativeTexture
  19. {
  20. get { return m_NativeTexture; }
  21. private set { m_NativeTexture = value; }
  22. }
  23. IntPtr m_NativeTexture;
  24. /// <summary>
  25. /// Specifies the width dimension of the native texture object.
  26. /// </summary>
  27. /// <value>
  28. /// The width of the native texture object.
  29. /// </value>
  30. public int width
  31. {
  32. get { return m_Width; }
  33. private set { m_Width = value; }
  34. }
  35. int m_Width;
  36. /// <summary>
  37. /// Specifies the height dimension of the native texture object.
  38. /// </summary>
  39. /// <value>
  40. /// The height of the native texture object.
  41. /// </value>
  42. public int height
  43. {
  44. get { return m_Height; }
  45. private set { m_Height = value; }
  46. }
  47. int m_Height;
  48. /// <summary>
  49. /// Specifies the number of mipmap levels in the native texture object.
  50. /// </summary>
  51. /// <value>
  52. /// The number of mipmap levels in the native texture object.
  53. /// </value>
  54. public int mipmapCount
  55. {
  56. get { return m_MipmapCount; }
  57. private set { m_MipmapCount = value; }
  58. }
  59. int m_MipmapCount;
  60. /// <summary>
  61. /// Specifies the texture format of the native texture object.
  62. /// </summary>
  63. /// <value>
  64. /// The format of the native texture object.
  65. /// </value>
  66. public TextureFormat format
  67. {
  68. get { return m_Format; }
  69. private set { m_Format = value; }
  70. }
  71. TextureFormat m_Format;
  72. /// <summary>
  73. /// Specifies the unique shader property name ID for the material shader texture.
  74. /// </summary>
  75. /// <value>
  76. /// The unique shader property name ID for the material shader texture.
  77. /// </value>
  78. /// <remarks>
  79. /// Use the static method <c>Shader.PropertyToID(string name)</c> to get the unique identifier.
  80. /// </remarks>
  81. public int propertyNameId
  82. {
  83. get { return m_PropertyNameId; }
  84. private set { m_PropertyNameId = value; }
  85. }
  86. int m_PropertyNameId;
  87. /// <summary>
  88. /// Determines whether the texture data references a valid texture object with positive width and height.
  89. /// </summary>
  90. /// <value>
  91. /// <c>true</c> if the texture data references a valid texture object with positive width and height.
  92. /// Otherwise, <c>false</c>.
  93. /// </value>
  94. public bool valid
  95. {
  96. get { return (m_NativeTexture != IntPtr.Zero) && (m_Width > 0) && (m_Height > 0); }
  97. }
  98. /// <summary>
  99. /// Determines whether the given texture descriptor has identical texture metadata (dimension, mipmap count,
  100. /// and format).
  101. /// </summary>
  102. /// <param name="other">The given texture descriptor with which to compare.</param>
  103. /// <returns>
  104. /// <c>true</c> if the texture metadata (dimension, mipmap count, and format) are identical between the
  105. /// current and other texture descriptors. Otherwise, <c>false</c>.
  106. /// </returns>
  107. public bool hasIdenticalTextureMetadata(XRTextureDescriptor other)
  108. {
  109. return
  110. m_Width.Equals(other.m_Width) &&
  111. m_Height.Equals(other.m_Height) &&
  112. m_MipmapCount.Equals(other.m_MipmapCount) &&
  113. (m_Format == other.m_Format);
  114. }
  115. /// <summary>
  116. /// Reset the texture descriptor back to default values.
  117. /// </summary>
  118. public void Reset()
  119. {
  120. m_NativeTexture = IntPtr.Zero;
  121. m_Width = 0;
  122. m_Height = 0;
  123. m_MipmapCount = 0;
  124. m_Format = (TextureFormat)0;
  125. m_PropertyNameId = 0;
  126. }
  127. public bool Equals(XRTextureDescriptor other)
  128. {
  129. return
  130. hasIdenticalTextureMetadata(other) &&
  131. m_PropertyNameId.Equals(other.m_PropertyNameId) &&
  132. (m_NativeTexture == other.m_NativeTexture);
  133. }
  134. public override bool Equals(System.Object obj)
  135. {
  136. return ((obj is XRTextureDescriptor) && Equals((XRTextureDescriptor)obj));
  137. }
  138. public static bool operator ==(XRTextureDescriptor lhs, XRTextureDescriptor rhs)
  139. {
  140. return lhs.Equals(rhs);
  141. }
  142. public static bool operator !=(XRTextureDescriptor lhs, XRTextureDescriptor rhs)
  143. {
  144. return !lhs.Equals(rhs);
  145. }
  146. public override int GetHashCode()
  147. {
  148. int hashCode = 486187739;
  149. unchecked
  150. {
  151. hashCode = (hashCode * 486187739) + m_NativeTexture.GetHashCode();
  152. hashCode = (hashCode * 486187739) + m_Width.GetHashCode();
  153. hashCode = (hashCode * 486187739) + m_Height.GetHashCode();
  154. hashCode = (hashCode * 486187739) + m_MipmapCount.GetHashCode();
  155. hashCode = (hashCode * 486187739) + ((int)m_Format).GetHashCode();
  156. hashCode = (hashCode * 486187739) + m_PropertyNameId.GetHashCode();
  157. }
  158. return hashCode;
  159. }
  160. public override string ToString()
  161. {
  162. return string.Format("0x{0} {1}x{2}-{3} format:{4} propertyNameId:{5}", m_NativeTexture.ToString("X16"),
  163. m_Width.ToString(), m_Height.ToString(), m_MipmapCount.ToString(),
  164. m_Format.ToString(), m_PropertyNameId.ToString());
  165. }
  166. }
  167. }