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