1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
6 #include "framebuffer_backend.h"
7 #include "frameformat.h"
8 #include "texturecube.h"
14 class Texture2DMultisample;
18 class framebuffer_incomplete: public std::runtime_error
21 framebuffer_incomplete(const std::string &);
22 virtual ~framebuffer_incomplete() throw() { }
26 Uses one or more textures as buffers to draw into. Framebuffers can contain
27 multiple color buffers to match multiple outputs from a fragment shader, but
28 only one depth and stencil buffer.
30 RenderTarget provides a higher-level interface which manages the textures as
31 well as the framebuffer itself.
33 class Framebuffer: public FramebufferBackend
35 friend FramebufferBackend;
44 void set(Texture &, unsigned, int);
49 std::vector<Attachment> attachments;
53 mutable unsigned dirty = 0;
57 /** Creates an empty framebuffer. Format must be set before textures can
61 /** Creates a framebuffer and sets its format to a single attachment. */
62 Framebuffer(FrameAttachment);
64 /** Creates a framebuffer and sets its format. */
65 Framebuffer(const FrameFormat &);
67 /** Sets the format of the framebuffer. Once the format is set, it can't
69 void set_format(const FrameFormat &);
71 const FrameFormat &get_format() const { return format; }
73 unsigned get_width() const { return width; }
74 unsigned get_height() const { return height; }
75 unsigned get_layers() const { return layers; }
80 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
83 /** Attaches a texture to the framebuffer. Only the attachment point
84 portion of attch is considered; pixel format is ignored. The framebuffer
85 must have a format and the format of the texture must match that defined
86 in the framebuffer for this attachment point. */
87 void attach(FrameAttachment attch, Texture2D &, unsigned level = 0);
89 void attach(FrameAttachment attch, Texture2DMultisample &);
91 /** Attaches a single layer from a 3-dimensional texture to the
93 void attach(FrameAttachment attch, Texture3D &, unsigned layer, unsigned level = 0);
95 void attach(FrameAttachment attch, TextureCube &, TextureCubeFace face, unsigned level = 0);
97 /** Attaches a layered texture to the framebuffer. Shaders can direct
98 output to a particular layer. */
99 void attach_layered(FrameAttachment attch, Texture3D &, unsigned level = 0);
101 void attach_layered(FrameAttachment attch, TextureCube &, unsigned level = 0);
102 void detach(FrameAttachment attch);
104 const Texture *get_attachment(FrameAttachment) const;
105 const Texture *get_attachment(unsigned) const;
107 /** Ensures that the framebuffer is complete, throwing an exception if it
109 void require_complete() const;
111 void refresh() const { if(dirty) update(); }
113 using FramebufferBackend::set_debug_name;
126 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }