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.

104 lines
4.0 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. // Removing from summary of the configuration class because this has yet to be ported.
  6. // The camera image configuration affects the resolution of the image
  7. // returned by <see cref="XRCameraSubsystem.TryGetLatestImage(Experimental.XR.XRCameraSubsystem, out CameraImage)"/>.
  8. /// <summary>
  9. /// Contains information regarding the camera configuration. Different
  10. /// devices support different camera configurations. This includes
  11. /// the resolution of the image and may include framerate on some platforms.
  12. /// </summary>
  13. [StructLayout(LayoutKind.Sequential)]
  14. public struct XRCameraConfiguration : IEquatable<XRCameraConfiguration>
  15. {
  16. Vector2Int m_Resolution;
  17. int m_Framerate;
  18. /// <summary>
  19. /// The width of the camera resolution
  20. /// </summary>
  21. /// <value>
  22. /// The width, in pixels, of the camera resolution
  23. /// </value>
  24. public int width => m_Resolution.x;
  25. /// <summary>
  26. /// The height of the camera resolution
  27. /// </summary>
  28. /// <value>
  29. /// The height, in pixels, of the camera resolution
  30. /// </value>
  31. public int height => m_Resolution.y;
  32. /// <summary>
  33. /// The camera resolution.
  34. /// </summary>
  35. /// <value>
  36. /// The camera resolution in pixels.
  37. /// </value>
  38. public Vector2Int resolution => m_Resolution;
  39. /// <summary>
  40. /// The framerate, if this camera configuration specifies one.
  41. /// </summary>
  42. /// <value>
  43. /// The framerate, if this camera configuration specifies one. Otherwise, <c>null</c>.
  44. /// </value>
  45. /// <remarks>
  46. /// On some platforms, different resolutions may affect the available framerate.
  47. /// </remarks>
  48. public int? framerate => (m_Framerate > 0) ? new int?(m_Framerate) : new int?();
  49. /// <summary>
  50. /// Constructs a camera configuration with a framerate.
  51. /// </summary>
  52. /// <param name="resolution">The resolution of the camera image.</param>
  53. /// <param name="framerate">The camera framerate. Throws <c>ArgumentOutOfRangeException</c>
  54. /// if <paramref name="framerate"/> is less than or equal to zero.</param>
  55. internal XRCameraConfiguration(Vector2Int resolution, int framerate)
  56. {
  57. if (framerate <= 0)
  58. throw new ArgumentOutOfRangeException(
  59. string.Format("{0} is not a valid framerate; it must be greater than zero.", framerate));
  60. m_Resolution = resolution;
  61. m_Framerate = framerate;
  62. }
  63. /// <summary>
  64. /// Constructs a camera configuration without a framerate.
  65. /// </summary>
  66. /// <param name="resolution">The resolution of the camera image.</param>
  67. internal XRCameraConfiguration(Vector2Int resolution)
  68. {
  69. m_Resolution = resolution;
  70. m_Framerate = 0;
  71. }
  72. /// <summary>
  73. /// Converts the configuration to a string, suitable for debug logging.
  74. /// </summary>
  75. /// <returns></returns>
  76. public override string ToString() => $"{width}x{height}" + (framerate.HasValue ? $" at {framerate.Value} Hz" : "");
  77. public override int GetHashCode()
  78. {
  79. unchecked
  80. {
  81. var hash = m_Resolution.GetHashCode();
  82. return hash * 486187739 + framerate.GetHashCode();
  83. }
  84. }
  85. public override bool Equals(System.Object obj) => ((obj is XRCameraConfiguration) && Equals((XRCameraConfiguration)obj));
  86. public bool Equals(XRCameraConfiguration other) => (m_Resolution == other.m_Resolution) && (framerate == other.framerate);
  87. public static bool operator ==(XRCameraConfiguration lhs, XRCameraConfiguration rhs) => lhs.Equals(rhs);
  88. public static bool operator !=(XRCameraConfiguration lhs, XRCameraConfiguration rhs) => !lhs.Equals(rhs);
  89. }
  90. }