1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
7 #include "texturecube.h"
8 #include <msp/gl/extensions/ext_framebuffer_object.h>
17 enum FramebufferAttachment
19 COLOR_ATTACHMENT0 = GL_COLOR_ATTACHMENT0,
20 COLOR_ATTACHMENT1 = GL_COLOR_ATTACHMENT1,
21 COLOR_ATTACHMENT2 = GL_COLOR_ATTACHMENT2,
22 COLOR_ATTACHMENT3 = GL_COLOR_ATTACHMENT3,
23 DEPTH_ATTACHMENT = GL_DEPTH_ATTACHMENT,
24 STENCIL_ATTACHMENT = GL_STENCIL_ATTACHMENT
27 enum FramebufferStatus
29 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
30 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
31 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT,
32 FRAMEBUFFER_INCOMPLETE_FORMATS = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT,
33 FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER,
34 FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER,
35 FRAMEBUFFER_UNSUPPORTED = GL_FRAMEBUFFER_UNSUPPORTED,
36 FRAMEBUFFER_COMPLETE = GL_FRAMEBUFFER_COMPLETE
41 COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT,
42 DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT,
43 STENCIL_BUFFER_BIT = GL_STENCIL_BUFFER_BIT,
44 ACCUM_BUFFER_BIT = GL_ACCUM_BUFFER_BIT
50 FRONT_LEFT = GL_FRONT_LEFT,
51 FRONT_RIGHT = GL_FRONT_RIGHT,
52 BACK_LEFT = GL_BACK_LEFT,
53 BACK_RIGHT = GL_BACK_RIGHT,
58 FRONT_AND_BACK = GL_FRONT_AND_BACK
61 class framebuffer_incomplete: public std::runtime_error
64 framebuffer_incomplete(FramebufferStatus);
65 virtual ~framebuffer_incomplete() throw() { }
69 Framebuffer objects can be used to perform offscreen rendering. The most
70 common application is rendering to a texture, which can then be used for
71 fullscreen shader effects.
73 A framebuffer consist of a number of logical buffers, such as color and depth
74 buffers. Renderbuffers and Textures can be attached to the logical buffers. At
75 least one image must be attached for the framebuffer to be usable.
77 Requires the GL_EXT_framebuffer_object extension. The blit functions require
78 the GL_EXT_framebuffer_blit extension.
80 class Framebuffer: public Bindable<Framebuffer>
85 FramebufferAttachment attachment;
95 Attachment(FramebufferAttachment);
96 void set(Renderbuffer &);
97 void set(Texture &, GLenum, unsigned);
102 std::vector<Attachment> attachments;
105 mutable unsigned dirty;
107 Framebuffer(unsigned);
112 unsigned get_width() const { return width; }
113 unsigned get_height() const { return height; }
116 void update_attachment(unsigned) const;
118 unsigned get_attachment_index(FramebufferAttachment);
120 void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
121 void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level = 0);
122 void attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
123 void detach(FramebufferAttachment attch);
125 /** Checks the completeness of the framebuffer. Returns
126 FRAMEBUFFER_COMPLETE if the framebuffer is complete and can be rendered to,
127 or one of the error status codes otherwise. */
128 FramebufferStatus check_status() const;
130 /** Ensures that the framebuffer is complete, throwing an exception if it
132 void require_complete() const;
134 void clear(BufferBits);
136 /** Blits a region from another framebuffer into this one. If the source
137 and destination regions have different dimensions, the contents will be
138 stretched. If filter is true, linear interpolation will be used, otherwise
139 no interpolation is done. */
140 void blit_from(const Framebuffer &other, int sx0, int sy0, int sx1, int sy1,
141 int dx0, int dy0, int dx1, int dy1, BufferBits bits, bool filter);
143 /** Blits a region from another framebuffer into this one, retaining its
145 void blit_from(const Framebuffer & other, int sx, int sy,
146 unsigned wd, unsigned ht, int dx, int dy, BufferBits bits);
148 /** Blits the entire contents of another framebuffer into this one. */
149 void blit_from(const Framebuffer &other, BufferBits bits, bool filter);
153 static const Framebuffer *current();
154 static void unbind();
156 static Framebuffer &system();
159 inline BufferBits operator|(BufferBits a, BufferBits b)
160 { return static_cast<BufferBits>(static_cast<int>(a)|static_cast<int>(b)); }