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