1 #ifndef MSP_GL_FRAMEBUFFER_H_
2 #define MSP_GL_FRAMEBUFFER_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>
22 enum FramebufferAttachment
24 COLOR_ATTACHMENT0 = GL_COLOR_ATTACHMENT0,
25 COLOR_ATTACHMENT1 = GL_COLOR_ATTACHMENT1,
26 COLOR_ATTACHMENT2 = GL_COLOR_ATTACHMENT2,
27 COLOR_ATTACHMENT3 = GL_COLOR_ATTACHMENT3,
28 DEPTH_ATTACHMENT = GL_DEPTH_ATTACHMENT,
29 STENCIL_ATTACHMENT = GL_STENCIL_ATTACHMENT
32 enum FramebufferStatus
34 FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
35 FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
36 FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT,
37 FRAMEBUFFER_INCOMPLETE_FORMATS = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT,
38 FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER,
39 FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER,
40 FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
41 FRAMEBUFFER_INCOMPLETE_LAYER_COUNT = GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB,
42 FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS,
43 FRAMEBUFFER_UNSUPPORTED = GL_FRAMEBUFFER_UNSUPPORTED,
44 FRAMEBUFFER_COMPLETE = GL_FRAMEBUFFER_COMPLETE
49 COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT,
50 DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT,
51 STENCIL_BUFFER_BIT = GL_STENCIL_BUFFER_BIT
54 class framebuffer_incomplete: public std::runtime_error
57 framebuffer_incomplete(FramebufferStatus);
58 virtual ~framebuffer_incomplete() throw() { }
62 Framebuffer objects can be used to perform offscreen rendering. The most
63 common application is rendering to a texture, which can then be used for
64 fullscreen shader effects.
66 A framebuffer consist of a number of logical buffers, such as color and depth
67 buffers. Renderbuffers and Textures can be attached to the logical buffers. At
68 least one image must be attached for the framebuffer to be usable.
70 Requires the GL_EXT_framebuffer_object extension. The blit functions require
71 the GL_EXT_framebuffer_blit extension.
78 FramebufferAttachment attachment;
88 Attachment(FramebufferAttachment);
89 void set(Renderbuffer &);
90 void set(Texture &, unsigned, int);
95 std::vector<Attachment> attachments;
98 mutable FramebufferStatus status;
99 mutable unsigned dirty;
101 Framebuffer(unsigned);
106 unsigned get_width() const { return width; }
107 unsigned get_height() const { return height; }
112 unsigned get_attachment_index(FramebufferAttachment);
113 void set_texture_attachment(FramebufferAttachment, Texture &, unsigned, int);
115 void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
116 void attach(FramebufferAttachment attch, Texture2D &tex, unsigned level = 0);
117 void attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level = 0);
118 void attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level = 0);
119 void attach_layered(FramebufferAttachment attch, Texture3D &tex, unsigned level = 0);
120 void attach_layered(FramebufferAttachment attch, TextureCube &tex, unsigned level = 0);
121 void detach(FramebufferAttachment attch);
123 void resize(const WindowView &);
125 /** Returns FRAMEBUFFER_COMPLETE if the framebuffer is complete and can be
126 rendered to, or one of the error status codes otherwise. */
127 FramebufferStatus get_status() const { return status; }
129 /** Ensures that the framebuffer is complete, throwing an exception if it
131 void require_complete() const;
133 void refresh() const { if(dirty) update(); }
135 unsigned get_id() const { return id; }
137 void set_debug_name(const std::string &);
139 static Framebuffer &system();
142 inline BufferBits operator|(BufferBits a, BufferBits b)
143 { return static_cast<BufferBits>(static_cast<int>(a)|static_cast<int>(b)); }