]> git.tdb.fi Git - libs/gl.git/blob - source/core/frameformat.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / frameformat.h
1 #ifndef MSP_GL_FRAMEFORMAT_H_
2 #define MSP_GL_FRAMEFORMAT_H_
3
4 #include <cstdint>
5 #include "pixelformat.h"
6
7 namespace Msp {
8 namespace GL {
9
10 /**
11 Describes a single attachment of a framebuffer, including the type and index
12 of the attachment point and the format of the attached texture.
13
14 The values are bitfields laid as follows:
15
16 nnnn nn_f _sss rccc
17       │ │    │ │  └╴Number of components
18       │ │    │ └───╴Reverse order flag
19       │ │    └─────╴Size of one component
20       │ └──────────╴Floating-point flag
21       └────────────╴Attachment index
22
23 This information is presented for internal documentation purposes only; it is
24 inadvisable for applications to rely on it.
25 */
26 enum FrameAttachment: std::uint16_t
27 {
28         COLOR_ATTACHMENT = 0x0014,
29         DEPTH_ATTACHMENT = 0xF941,
30         STENCIL_ATTACHMENT = 0xFC11
31 };
32
33 /**
34 Describes the complete format of a framebuffer.  It can hold multiple
35 attachments (currently up to seven) as well as a sample count.
36 */
37 class FrameFormat
38 {
39 public:
40         static constexpr unsigned MAX_ATTACHMENTS = 7;
41
42 private:
43         std::uint8_t count = 0;
44         std::uint8_t samples = 0;
45         FrameAttachment attachments[MAX_ATTACHMENTS];
46
47 public:
48         FrameFormat() = default;
49         FrameFormat(FrameAttachment);
50
51         FrameFormat operator,(FrameAttachment) const;
52         FrameFormat operator,(PixelFormat) const;
53         FrameFormat operator,(unsigned) const;
54
55         FrameFormat &set_samples(unsigned);
56         unsigned get_samples() const { return samples; }
57
58         unsigned size() const { return count; }
59         bool empty() const { return !count; }
60         const FrameAttachment *begin() const { return attachments; }
61         const FrameAttachment *end() const { return attachments+count; }
62         int index(FrameAttachment) const;
63 };
64
65 inline FrameFormat operator,(FrameAttachment fa1, FrameAttachment fa2)
66 { return (FrameFormat(fa1), fa2); }
67
68 FrameAttachment make_typed_attachment(FrameAttachment, PixelFormat);
69
70 inline FrameAttachment operator,(FrameAttachment fa, PixelFormat pf)
71 { return make_typed_attachment(fa, pf); }
72
73 FrameAttachment make_indexed_attachment(FrameAttachment, unsigned);
74
75 inline FrameAttachment operator,(FrameAttachment fa, unsigned i)
76 { return make_indexed_attachment(fa, i); }
77
78 inline unsigned get_attach_point(FrameAttachment fa)
79 { return fa>>10; }
80
81 PixelFormat get_attachment_pixelformat(FrameAttachment);
82
83 } // namespace GL
84 } // namespace Msp
85
86 #include "frameformat_backend.h"
87
88 #endif