aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Gpu/Image/FormatInfo.cs
blob: 8a9f37bb0b041964e34a8a132f4b179e5c3aa90a (plain) (blame)
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
using Ryujinx.Graphics.GAL;

namespace Ryujinx.Graphics.Gpu.Image
{
    /// <summary>
    /// Represents texture format information.
    /// </summary>
    readonly struct FormatInfo
    {
        /// <summary>
        /// A default, generic RGBA8 texture format.
        /// </summary>
        public static FormatInfo Default { get; } = new(Format.R8G8B8A8Unorm, 1, 1, 4, 4);

        /// <summary>
        /// The format of the texture data.
        /// </summary>
        public Format Format { get; }

        /// <summary>
        /// The block width for compressed formats.
        /// </summary>
        /// <remarks>
        /// Must be 1 for non-compressed formats.
        /// </remarks>
        public int BlockWidth { get; }

        /// <summary>
        /// The block height for compressed formats.
        /// </summary>
        /// <remarks>
        /// Must be 1 for non-compressed formats.
        /// </remarks>
        public int BlockHeight { get; }

        /// <summary>
        /// The number of bytes occupied by a single pixel in memory of the texture data.
        /// </summary>
        public int BytesPerPixel { get; }

        /// <summary>
        /// The maximum number of components this format has defined (in RGBA order).
        /// </summary>
        public int Components { get; }

        /// <summary>
        /// Whenever or not the texture format is a compressed format. Determined from block size.
        /// </summary>
        public bool IsCompressed => (BlockWidth | BlockHeight) != 1;

        /// <summary>
        /// Constructs the texture format info structure.
        /// </summary>
        /// <param name="format">The format of the texture data</param>
        /// <param name="blockWidth">The block width for compressed formats. Must be 1 for non-compressed formats</param>
        /// <param name="blockHeight">The block height for compressed formats. Must be 1 for non-compressed formats</param>
        /// <param name="bytesPerPixel">The number of bytes occupied by a single pixel in memory of the texture data</param>
        public FormatInfo(
            Format format,
            int blockWidth,
            int blockHeight,
            int bytesPerPixel,
            int components)
        {
            Format = format;
            BlockWidth = blockWidth;
            BlockHeight = blockHeight;
            BytesPerPixel = bytesPerPixel;
            Components = components;
        }
    }
}