1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
6 #include "frameformat.h"
8 #include "texturecube.h"
9 #include <msp/gl/extensions/arb_geometry_shader4.h>
10 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
11 #include <msp/gl/extensions/ext_framebuffer_object.h>
12 #include <msp/gl/extensions/nv_fbo_color_attachments.h>
19 class Texture2DMultisample;
25 COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT,
26 DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT,
27 STENCIL_BUFFER_BIT = GL_STENCIL_BUFFER_BIT
30 class framebuffer_incomplete: public std::runtime_error
33 framebuffer_incomplete(const std::string &);
34 virtual ~framebuffer_incomplete() throw() { }
38 Framebuffer objects can be used to perform offscreen rendering. The most
39 common application is rendering to a texture, which can then be used for
40 fullscreen shader effects.
42 A framebuffer consist of a number of logical buffers, such as color and depth
43 buffers. Textures can be attached to the logical buffers. At least one image
44 must be attached for the framebuffer to be usable.
46 Requires the GL_EXT_framebuffer_object extension. The blit functions require
47 the GL_EXT_framebuffer_blit extension.
51 friend class Commands;
52 friend class PipelineState;
62 void set(Texture &, unsigned, int);
68 std::vector<Attachment> attachments;
71 mutable unsigned status;
72 mutable unsigned dirty;
74 Framebuffer(unsigned);
76 /** Creates an empty framebuffer. Format must be set before textures can
80 /** Creates a framebuffer and sets its format to a single attachment. */
81 Framebuffer(FrameAttachment);
83 /** Creates a framebuffer and sets its format. */
84 Framebuffer(const FrameFormat &);
91 /** Sets the format of the framebuffer. Once the format is set, it can't
93 void set_format(const FrameFormat &);
95 const FrameFormat &get_format() const { return format; }
97 unsigned get_width() const { return width; }
98 unsigned get_height() const { return height; }
103 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
106 /** Attaches a texture to the framebuffer. Only the attachment point
107 portion of attch is considered; pixel format is ignored. The framebuffer
108 must have a format and the format of the texture must match that defined
109 in the framebuffer for this attachment point. */
110 void attach(FrameAttachment attch, Texture2D &tex, unsigned level = 0);
112 void attach(FrameAttachment attch, Texture2DMultisample &tex);
113 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
114 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
115 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
116 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
117 void detach(FrameAttachment attch);
119 void resize(const WindowView &);
121 /** Ensures that the framebuffer is complete, throwing an exception if it
123 void require_complete() const;
125 void refresh() const { if(dirty) update(); }
127 void set_debug_name(const std::string &);
129 static Framebuffer &system();
142 ClearValue(): color(0.0f, 0.0f, 0.0f, 0.0f) { }
145 inline BufferBits operator|(BufferBits a, BufferBits b)
146 { return static_cast<BufferBits>(static_cast<int>(a)|static_cast<int>(b)); }