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 Framebuffer objects can be used to perform offscreen rendering. The most
27 common application is rendering to a texture, which can then be used for
28 fullscreen shader effects.
30 A framebuffer consist of a number of logical buffers, such as color and depth
31 buffers. Textures can be attached to the logical buffers. At least one image
32 must be attached for the framebuffer to be usable.
34 Requires the GL_EXT_framebuffer_object extension. The blit functions require
35 the GL_EXT_framebuffer_blit extension.
37 class Framebuffer: public FramebufferBackend
39 friend FramebufferBackend;
49 void set(Texture &, unsigned, int);
54 std::vector<Attachment> attachments;
57 mutable unsigned dirty;
61 /** Creates an empty framebuffer. Format must be set before textures can
65 /** Creates a framebuffer and sets its format to a single attachment. */
66 Framebuffer(FrameAttachment);
68 /** Creates a framebuffer and sets its format. */
69 Framebuffer(const FrameFormat &);
75 /** Sets the format of the framebuffer. Once the format is set, it can't
77 void set_format(const FrameFormat &);
79 const FrameFormat &get_format() const { return format; }
81 unsigned get_width() const { return width; }
82 unsigned get_height() const { return height; }
87 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
90 /** Attaches a texture to the framebuffer. Only the attachment point
91 portion of attch is considered; pixel format is ignored. The framebuffer
92 must have a format and the format of the texture must match that defined
93 in the framebuffer for this attachment point. */
94 void attach(FrameAttachment attch, Texture2D &tex, unsigned level = 0);
96 void attach(FrameAttachment attch, Texture2DMultisample &tex);
97 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
98 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
99 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
100 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
101 void detach(FrameAttachment attch);
103 void resize(const WindowView &);
105 /** Ensures that the framebuffer is complete, throwing an exception if it
107 void require_complete() const;
109 void refresh() const { if(dirty) update(); }
111 using FramebufferBackend::set_debug_name;
113 static Framebuffer &system();
126 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }