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;
52 mutable unsigned dirty;
56 /** Creates an empty framebuffer. Format must be set before textures can
60 /** Creates a framebuffer and sets its format to a single attachment. */
61 Framebuffer(FrameAttachment);
63 /** Creates a framebuffer and sets its format. */
64 Framebuffer(const FrameFormat &);
66 /** Sets the format of the framebuffer. Once the format is set, it can't
68 void set_format(const FrameFormat &);
70 const FrameFormat &get_format() const { return format; }
72 unsigned get_width() const { return width; }
73 unsigned get_height() const { return height; }
78 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
81 /** Attaches a texture to the framebuffer. Only the attachment point
82 portion of attch is considered; pixel format is ignored. The framebuffer
83 must have a format and the format of the texture must match that defined
84 in the framebuffer for this attachment point. */
85 void attach(FrameAttachment attch, Texture2D &, unsigned level = 0);
87 void attach(FrameAttachment attch, Texture2DMultisample &);
89 /** Attaches a single layer from a 3-dimensional texture to the
91 void attach(FrameAttachment attch, Texture3D &, unsigned layer, unsigned level = 0);
93 void attach(FrameAttachment attch, TextureCube &, TextureCubeFace face, unsigned level = 0);
95 /** Attaches a layered texture to the framebuffer. Shaders can direct
96 output to a particular layer. */
97 void attach_layered(FrameAttachment attch, Texture3D &, unsigned level = 0);
99 void attach_layered(FrameAttachment attch, TextureCube &, unsigned level = 0);
100 void detach(FrameAttachment attch);
102 void resize(const WindowView &);
104 /** Ensures that the framebuffer is complete, throwing an exception if it
106 void require_complete() const;
108 void refresh() const { if(dirty) update(); }
110 using FramebufferBackend::set_debug_name;
112 static Framebuffer &system();
125 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }