1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
6 #include "framebuffer_backend.h"
7 #include "frameformat.h"
9 #include "texturecube.h"
15 class Texture2DMultisample;
19 class framebuffer_incomplete: public std::runtime_error
22 framebuffer_incomplete(const std::string &);
23 virtual ~framebuffer_incomplete() throw() { }
27 Uses one or more textures as buffers to draw into. Framebuffers can contain
28 multiple color buffers to match multiple outputs from a fragment shader, but
29 only one depth and stencil buffer.
31 RenderTarget provides a higher-level interface which manages the textures as
32 well as the framebuffer itself.
34 class Framebuffer: public FramebufferBackend
36 friend FramebufferBackend;
45 void set(Texture &, unsigned, int);
50 std::vector<Attachment> attachments;
54 mutable unsigned dirty = 0;
58 /** Creates an empty framebuffer. Format must be set before textures can
62 /** Creates a framebuffer and sets its format to a single attachment. */
63 Framebuffer(FrameAttachment);
65 /** Creates a framebuffer and sets its format. */
66 Framebuffer(const FrameFormat &);
68 /** Sets the format of the framebuffer. Once the format is set, it can't
70 void set_format(const FrameFormat &);
72 const FrameFormat &get_format() const { return format; }
74 unsigned get_width() const { return width; }
75 unsigned get_height() const { return height; }
76 Rect get_rect() const { return Rect(0, 0, width, height); }
77 unsigned get_layers() const { return layers; }
82 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
85 /** Attaches a texture to the framebuffer. Only the attachment point
86 portion of attch is considered; pixel format is ignored. The framebuffer
87 must have a format and the format of the texture must match that defined
88 in the framebuffer for this attachment point. */
89 void attach(FrameAttachment attch, Texture2D &, unsigned level = 0);
91 void attach(FrameAttachment attch, Texture2DMultisample &);
93 /** Attaches a single layer from a 3-dimensional texture to the
95 void attach(FrameAttachment attch, Texture3D &, unsigned layer, unsigned level = 0);
97 void attach(FrameAttachment attch, TextureCube &, TextureCubeFace face, unsigned level = 0);
99 /** Attaches a layered texture to the framebuffer. Shaders can direct
100 output to a particular layer. */
101 void attach_layered(FrameAttachment attch, Texture3D &, unsigned level = 0);
103 void attach_layered(FrameAttachment attch, TextureCube &, unsigned level = 0);
104 void detach(FrameAttachment attch);
106 const Texture *get_attachment(FrameAttachment) const;
107 const Texture *get_attachment(unsigned) const;
109 /** Ensures that the framebuffer is complete, throwing an exception if it
111 void require_complete() const;
113 void refresh() const { if(dirty) update(); }
115 using FramebufferBackend::set_debug_name;
128 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }