]> git.tdb.fi Git - libs/gl.git/blob - source/framebuffer.h
Add class Renderable
[libs/gl.git] / source / framebuffer.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_FRAMEBUFFER_H_
9 #define MSP_GL_FRAMEBUFFER_H_
10
11 #include <GL/gl.h>
12 #include "types.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Renderbuffer;
18 class Texture2D;
19
20 enum FramebufferAttachment
21 {
22         COLOR_ATTACHMENT0  = GL_COLOR_ATTACHMENT0_EXT,
23         COLOR_ATTACHMENT1  = GL_COLOR_ATTACHMENT1_EXT,
24         COLOR_ATTACHMENT2  = GL_COLOR_ATTACHMENT2_EXT,
25         COLOR_ATTACHMENT3  = GL_COLOR_ATTACHMENT3_EXT,
26         DEPTH_ATTACHMENT   = GL_DEPTH_ATTACHMENT_EXT,
27         STENCIL_ATTACHMENT = GL_STENCIL_ATTACHMENT_EXT
28 };
29
30 enum FramebufferStatus
31 {
32         FRAMEBUFFER_INCOMPLETE_ATTACHMENT         = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT,
33         FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT,
34         FRAMEBUFFER_INCOMPLETE_DIMENSIONS         = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT,
35         FRAMEBUFFER_INCOMPLETE_FORMATS            = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT,
36         FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER        = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT,
37         FRAMEBUFFER_INCOMPLETE_READ_BUFFER        = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT,
38         FRAMEBUFFER_UNSUPPORTED                   = GL_FRAMEBUFFER_UNSUPPORTED_EXT,
39         FRAMEBUFFER_COMPLETE                      = GL_FRAMEBUFFER_COMPLETE_EXT
40 };
41
42 /**
43 Framebuffer objects can be used to perform offscreen rendering.  The most
44 common application is rendering to a texture, which can then be used for
45 fullscreen shader effects.
46
47 A framebuffer consist of a number of logical buffers, such as color and depth
48 buffers.  Renderbuffers and Textures can be attached to the logical buffers.  At
49 least one image must be attached for the framebuffer to be usable.
50
51 Requires the GL_EXT_framebuffer_object extension.
52 */
53 class Framebuffer
54 {
55 private:
56         uint id;
57
58         static const Framebuffer *current;
59
60 public:
61         Framebuffer();
62         ~Framebuffer();
63
64         void bind() const;
65
66         void attach(FramebufferAttachment attch, Renderbuffer &rbuf);
67         void attach(FramebufferAttachment attch, Texture2D &tex, int level);
68
69         /**
70         Checks the completeness status of the framebuffer.  Returns
71         FRAMEBUFFER_COMPLETE if the framebuffer is complate and can be rendered to,
72         or one of the error status codes otherwise.
73         */
74         FramebufferStatus check_status() const;
75
76         static void unbind();
77 private:
78         void maybe_bind() const;
79 };
80
81 } // namespace GL
82 } // namespace Msp
83
84 #endif