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;
48 void set(Texture &, unsigned, int);
53 std::vector<Attachment> attachments;
56 mutable unsigned dirty;
60 /** Creates an empty framebuffer. Format must be set before textures can
64 /** Creates a framebuffer and sets its format to a single attachment. */
65 Framebuffer(FrameAttachment);
67 /** Creates a framebuffer and sets its format. */
68 Framebuffer(const FrameFormat &);
70 /** Sets the format of the framebuffer. Once the format is set, it can't
72 void set_format(const FrameFormat &);
74 const FrameFormat &get_format() const { return format; }
76 unsigned get_width() const { return width; }
77 unsigned get_height() const { return height; }
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 &tex, unsigned level = 0);
91 void attach(FrameAttachment attch, Texture2DMultisample &tex);
92 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
93 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
94 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
95 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
96 void detach(FrameAttachment attch);
98 void resize(const WindowView &);
100 /** Ensures that the framebuffer is complete, throwing an exception if it
102 void require_complete() const;
104 void refresh() const { if(dirty) update(); }
106 using FramebufferBackend::set_debug_name;
108 static Framebuffer &system();
121 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }