Mesh data stream.
| 15 | /// Mesh data stream. |
| 16 | /// </summary> |
| 17 | public unsafe ref struct Stream |
| 18 | { |
| 19 | private Span<byte> _data; |
| 20 | private PixelFormat _format; |
| 21 | private int _stride, _count; |
| 22 | private readonly PixelFormatSampler _sampler; |
| 23 | |
| 24 | internal Stream(Span<byte> data, PixelFormat format, int stride, int count) |
| 25 | { |
| 26 | _data = data; |
| 27 | _stride = stride; |
| 28 | _count = count; |
| 29 | if (PixelFormatSampler.Get(format, out _sampler)) |
| 30 | { |
| 31 | _format = format; |
| 32 | } |
| 33 | else if (format != PixelFormat.Unknown) |
| 34 | { |
| 35 | Debug.LogError($"Unsupported pixel format '{format}' to sample vertex attribute."); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// <summary> |
| 40 | /// Gets the raw data block. |
| 41 | /// </summary> |
| 42 | public Span<byte> Data => _data; |
| 43 | |
| 44 | /// <summary> |
| 45 | /// Gets the format of the data. |
| 46 | /// </summary> |
| 47 | public PixelFormat Format => _format; |
| 48 | |
| 49 | /// <summary> |
| 50 | /// Gets the stride (in bytes) of the data. |
| 51 | /// </summary> |
| 52 | public int Stride => _stride; |
| 53 | |
| 54 | /// <summary> |
| 55 | /// Gets the count of the items in the stride. |
| 56 | /// </summary> |
| 57 | public int Count => _count; |
| 58 | |
| 59 | /// <summary> |
| 60 | /// Returns true if stream is valid. |
| 61 | /// </summary> |
| 62 | public bool IsValid => _format != PixelFormat.Unknown; |
| 63 | |
| 64 | /// <summary> |
| 65 | /// Checks if the stream can use <seealso cref="SetLinear"/> via a single memory copy. |
| 66 | /// </summary> |
| 67 | /// <param name="expectedFormat">Source data format.</param> |
| 68 | /// <returns>True if stream is linear and format matches expected input data.</returns> |
| 69 | public bool IsLinear(PixelFormat expectedFormat) |
| 70 | { |
| 71 | return _format == expectedFormat && _stride == PixelFormatExtensions.SizeInBytes(_format); |
| 72 | } |
| 73 | |
| 74 | /// <summary> |