1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
6 #include "frameformat.h"
7 #include "texturecube.h"
8 #include <msp/gl/extensions/arb_geometry_shader4.h>
9 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
10 #include <msp/gl/extensions/ext_framebuffer_object.h>
11 #include <msp/gl/extensions/nv_fbo_color_attachments.h>
18 class Texture2DMultisample;
22 class framebuffer_incomplete: public std::runtime_error
25 framebuffer_incomplete(const std::string &);
26 virtual ~framebuffer_incomplete() throw() { }
30 Framebuffer objects can be used to perform offscreen rendering. The most
31 common application is rendering to a texture, which can then be used for
32 fullscreen shader effects.
34 A framebuffer consist of a number of logical buffers, such as color and depth
35 buffers. Textures can be attached to the logical buffers. At least one image
36 must be attached for the framebuffer to be usable.
38 Requires the GL_EXT_framebuffer_object extension. The blit functions require
39 the GL_EXT_framebuffer_blit extension.
43 friend class Commands;
44 friend class PipelineState;
54 void set(Texture &, unsigned, int);
60 std::vector<Attachment> attachments;
63 mutable unsigned status;
64 mutable unsigned dirty;
66 Framebuffer(unsigned);
68 /** Creates an empty framebuffer. Format must be set before textures can
72 /** Creates a framebuffer and sets its format to a single attachment. */
73 Framebuffer(FrameAttachment);
75 /** Creates a framebuffer and sets its format. */
76 Framebuffer(const FrameFormat &);
83 /** Sets the format of the framebuffer. Once the format is set, it can't
85 void set_format(const FrameFormat &);
87 const FrameFormat &get_format() const { return format; }
89 unsigned get_width() const { return width; }
90 unsigned get_height() const { return height; }
95 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
98 /** Attaches a texture to the framebuffer. Only the attachment point
99 portion of attch is considered; pixel format is ignored. The framebuffer
100 must have a format and the format of the texture must match that defined
101 in the framebuffer for this attachment point. */
102 void attach(FrameAttachment attch, Texture2D &tex, unsigned level = 0);
104 void attach(FrameAttachment attch, Texture2DMultisample &tex);
105 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
106 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
107 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
108 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
109 void detach(FrameAttachment attch);
111 void resize(const WindowView &);
113 /** Ensures that the framebuffer is complete, throwing an exception if it
115 void require_complete() const;
117 void refresh() const { if(dirty) update(); }
119 void set_debug_name(const std::string &);
121 static Framebuffer &system();
134 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }