1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
6 #include "frameformat.h"
7 #include "texturecube.h"
13 class Texture2DMultisample;
17 class framebuffer_incomplete: public std::runtime_error
20 framebuffer_incomplete(const std::string &);
21 virtual ~framebuffer_incomplete() throw() { }
25 Framebuffer objects can be used to perform offscreen rendering. The most
26 common application is rendering to a texture, which can then be used for
27 fullscreen shader effects.
29 A framebuffer consist of a number of logical buffers, such as color and depth
30 buffers. Textures can be attached to the logical buffers. At least one image
31 must be attached for the framebuffer to be usable.
33 Requires the GL_EXT_framebuffer_object extension. The blit functions require
34 the GL_EXT_framebuffer_blit extension.
38 friend class Commands;
39 friend class PipelineState;
49 void set(Texture &, unsigned, int);
55 std::vector<Attachment> attachments;
58 mutable unsigned status;
59 mutable unsigned dirty;
61 Framebuffer(unsigned);
63 /** Creates an empty framebuffer. Format must be set before textures can
67 /** Creates a framebuffer and sets its format to a single attachment. */
68 Framebuffer(FrameAttachment);
70 /** Creates a framebuffer and sets its format. */
71 Framebuffer(const FrameFormat &);
78 /** Sets the format of the framebuffer. Once the format is set, it can't
80 void set_format(const FrameFormat &);
82 const FrameFormat &get_format() const { return format; }
84 unsigned get_width() const { return width; }
85 unsigned get_height() const { return height; }
90 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
93 /** Attaches a texture to the framebuffer. Only the attachment point
94 portion of attch is considered; pixel format is ignored. The framebuffer
95 must have a format and the format of the texture must match that defined
96 in the framebuffer for this attachment point. */
97 void attach(FrameAttachment attch, Texture2D &tex, unsigned level = 0);
99 void attach(FrameAttachment attch, Texture2DMultisample &tex);
100 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
101 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
102 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
103 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
104 void detach(FrameAttachment attch);
106 void resize(const WindowView &);
108 /** Ensures that the framebuffer is complete, throwing an exception if it
110 void require_complete() const;
112 void refresh() const { if(dirty) update(); }
114 void set_debug_name(const std::string &);
116 static Framebuffer &system();
129 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }