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