1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_H_
15 enum FramebufferAttachment
17 COLOR_ATTACHMENT0 = GL_COLOR_ATTACHMENT0_EXT,
18 COLOR_ATTACHMENT1 = GL_COLOR_ATTACHMENT1_EXT,
19 COLOR_ATTACHMENT2 = GL_COLOR_ATTACHMENT2_EXT,
20 COLOR_ATTACHMENT3 = GL_COLOR_ATTACHMENT3_EXT,
21 DEPTH_ATTACHMENT = GL_DEPTH_ATTACHMENT_EXT,
22 STENCIL_ATTACHMENT = GL_STENCIL_ATTACHMENT_EXT
25 enum FramebufferStatus
27 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT,
28 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT,
29 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT,
30 FRAMEBUFFER_INCOMPLETE_FORMATS = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT,
31 FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT,
32 FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT,
33 FRAMEBUFFER_UNSUPPORTED = GL_FRAMEBUFFER_UNSUPPORTED_EXT,
34 FRAMEBUFFER_COMPLETE = GL_FRAMEBUFFER_COMPLETE_EXT
39 COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT,
40 DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT,
41 STENCIL_BUFFER_BIT = GL_STENCIL_BUFFER_BIT,
42 ACCUM_BUFFER_BIT = GL_ACCUM_BUFFER_BIT
48 FRONT_LEFT = GL_FRONT_LEFT,
49 FRONT_RIGHT = GL_FRONT_RIGHT,
50 BACK_LEFT = GL_BACK_LEFT,
51 BACK_RIGHT = GL_BACK_RIGHT,
56 FRONT_AND_BACK = GL_FRONT_AND_BACK
60 Framebuffer objects can be used to perform offscreen rendering. The most
61 common application is rendering to a texture, which can then be used for
62 fullscreen shader effects.
64 A framebuffer consist of a number of logical buffers, such as color and depth
65 buffers. Renderbuffers and Textures can be attached to the logical buffers. At
66 least one image must be attached for the framebuffer to be usable.
68 Requires the GL_EXT_framebuffer_object extension.
70 class Framebuffer: public Bindable<Framebuffer>
75 FramebufferAttachment attachment;
84 Attachment(FramebufferAttachment);
85 void set(Renderbuffer &);
86 void set(Texture &, unsigned);
91 std::vector<Attachment> attachments;
94 mutable unsigned dirty;
96 Framebuffer(unsigned);
101 unsigned get_width() const { return width; }
102 unsigned get_height() const { return height; }
105 void update_attachment(unsigned) const;
108 void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
109 void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level = 0);
110 void detach(FramebufferAttachment attch);
113 Checks the completeness status of the framebuffer. Returns
114 FRAMEBUFFER_COMPLETE if the framebuffer is complate and can be rendered to,
115 or one of the error status codes otherwise.
117 FramebufferStatus check_status() const;
119 void clear(BufferBits);
120 void blit_from(const Framebuffer &, int, int, int, int, int, int, int, int, BufferBits, bool);
121 void blit_from(const Framebuffer &, int, int, unsigned, unsigned, int, int, BufferBits);
122 void blit_from(const Framebuffer &, BufferBits, bool);
126 static const Framebuffer *current();
127 static void unbind();
129 static Framebuffer &system();
131 unsigned get_attachment_index(FramebufferAttachment);
134 inline BufferBits operator|(BufferBits a, BufferBits b)
135 { return static_cast<BufferBits>(static_cast<int>(a)|static_cast<int>(b)); }