1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
5 #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;
24 COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT,
25 DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT,
26 STENCIL_BUFFER_BIT = GL_STENCIL_BUFFER_BIT
29 class framebuffer_incomplete: public std::runtime_error
32 framebuffer_incomplete(const std::string &);
33 virtual ~framebuffer_incomplete() throw() { }
37 Framebuffer objects can be used to perform offscreen rendering. The most
38 common application is rendering to a texture, which can then be used for
39 fullscreen shader effects.
41 A framebuffer consist of a number of logical buffers, such as color and depth
42 buffers. Textures can be attached to the logical buffers. At least one image
43 must be attached for the framebuffer to be usable.
45 Requires the GL_EXT_framebuffer_object extension. The blit functions require
46 the GL_EXT_framebuffer_blit extension.
50 friend class Commands;
51 friend class PipelineState;
61 void set(Texture &, unsigned, int);
67 std::vector<Attachment> attachments;
70 mutable unsigned status;
71 mutable unsigned dirty;
73 Framebuffer(unsigned);
75 /** Creates an empty framebuffer. Format must be set before textures can
79 /** Creates a framebuffer and sets its format to a single attachment. */
80 Framebuffer(FrameAttachment);
82 /** Creates a framebuffer and sets its format. */
83 Framebuffer(const FrameFormat &);
90 /** Sets the format of the framebuffer. Once the format is set, it can't
92 void set_format(const FrameFormat &);
94 const FrameFormat &get_format() const { return format; }
96 unsigned get_width() const { return width; }
97 unsigned get_height() const { return height; }
102 void set_attachment(FrameAttachment, Texture &, unsigned, int, unsigned);
105 /** Attaches a texture to the framebuffer. Only the attachment point
106 portion of attch is considered; pixel format is ignored. The framebuffer
107 must have a format and the format of the texture must match that defined
108 in the framebuffer for this attachment point. */
109 void attach(FrameAttachment attch, Texture2D &tex, unsigned level = 0);
111 void attach(FrameAttachment attch, Texture2DMultisample &tex);
112 void attach(FrameAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
113 void attach(FrameAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
114 void attach_layered(FrameAttachment attch, Texture3D &tex, unsigned level = 0);
115 void attach_layered(FrameAttachment attch, TextureCube &tex, unsigned level = 0);
116 void detach(FrameAttachment attch);
118 void resize(const WindowView &);
120 /** Ensures that the framebuffer is complete, throwing an exception if it
122 void require_complete() const;
124 void refresh() const { if(dirty) update(); }
126 void set_debug_name(const std::string &);
128 static Framebuffer &system();
131 inline BufferBits operator|(BufferBits a, BufferBits b)
132 { return static_cast<BufferBits>(static_cast<int>(a)|static_cast<int>(b)); }