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