]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/frameformat.h
Redesign framebuffer attachment management
[libs/gl.git] / source / core / frameformat.h
diff --git a/source/core/frameformat.h b/source/core/frameformat.h
new file mode 100644 (file)
index 0000000..45ea919
--- /dev/null
@@ -0,0 +1,84 @@
+#ifndef MSP_GL_FRAMEFORMAT_H_
+#define MSP_GL_FRAMEFORMAT_H_
+
+#include <msp/core/inttypes.h>
+#include "pixelformat.h"
+
+namespace Msp {
+namespace GL {
+
+/**
+Describes a single attachment of a framebuffer.  The values are bitfields laid
+as follows:
+
+nnnn nn__ fsss _ccc
+      │   │  │    └╴Number of components
+      │   │  └─────╴Size of one component
+      │   └────────╴Floating-point flag
+      └────────────╴Attachment index
+
+This information is presented for internal documentation purposes only; it is
+inadvisable for programs to rely on it.
+*/
+enum FrameAttachment
+{
+       COLOR_ATTACHMENT = 0x0014,
+       DEPTH_ATTACHMENT = 0xF8C1,
+       STENCIL_ATTACHMENT = 0xFC11
+};
+
+/**
+Describes the complete format of a framebuffer.  It can hold multiple
+attachments (currently up to seven) as well as a sample count.
+*/
+class FrameFormat
+{
+private:
+       enum { MAX_ATTACHMENTS = 7 };
+
+       UInt8 count;
+       UInt8 samples;
+       UInt16 attachments[MAX_ATTACHMENTS];
+
+public:
+       FrameFormat();
+       FrameFormat(FrameAttachment);
+
+       FrameFormat operator,(FrameAttachment) const;
+       FrameFormat operator,(PixelFormat) const;
+       FrameFormat operator,(unsigned) const;
+
+       FrameFormat &set_samples(unsigned);
+       unsigned get_samples() const { return samples; }
+
+       unsigned size() const { return count; }
+       bool empty() const { return !count; }
+       const UInt16 *begin() const { return attachments; }
+       const UInt16 *end() const { return attachments+count; }
+       int index(FrameAttachment) const;
+};
+
+inline FrameFormat operator,(FrameAttachment fa1, FrameAttachment fa2)
+{ return (FrameFormat(fa1), fa2); }
+
+FrameAttachment make_typed_attachment(FrameAttachment, PixelFormat);
+
+inline FrameAttachment operator,(FrameAttachment fa, PixelFormat pf)
+{ return make_typed_attachment(fa, pf); }
+
+FrameAttachment make_indexed_attachment(FrameAttachment, unsigned);
+
+inline FrameAttachment operator,(FrameAttachment fa, unsigned i)
+{ return make_indexed_attachment(fa, i); }
+
+inline unsigned get_attach_point(UInt16 fa)
+{ return fa>>10; }
+
+PixelFormat get_attachment_pixelformat(UInt16);
+
+GLenum get_gl_attachment(FrameAttachment);
+
+} // namespace GL
+} // namespace Msp
+
+#endif