Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfFramebufferObject.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __glfFramebufferObject_hh__
26 #define __glfFramebufferObject_hh__
27 
28 #include "glfTexture.hh"
29 #include "glfRenderbuffer.hh"
30 #include "glfRenderTarget.hh"
31 #include "glfException.hh"
32 #include <vector>
33 
34 namespace BIAS {
35 
36  /**
37  * \brief Framebuffer object.
38  * \ingroup g_openglframework
39  * \author jkollmann
40  */
41  class BIASOpenGLFramework_EXPORT glfFramebufferObject : public glfRenderTarget {
42  public:
45 
46  /**
47  * Creates the framebuffer object. Before it can be used, you must
48  * attach one or several textures and check glfFramebufferObject::IsComplete.
49  */
50  void Create();
51 
52  /**
53  * Attaches a texture to an attachment point which can be
54  * - GL_COLOR_ATTACHMENT0_EXT .. GL_COLOR_ATTACHMENT<MAX_COLOR_ATTACH>_EXT
55  * - GL_DEPTH_ATTACHMENT_EXT
56  * - GL_STENCIL_ATTACHMENT_EXT
57  *
58  * If the texture is a cube map, then cubeMapSide must be one of the following
59  * values:
60  * GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
61  * GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
62  * GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
63  *
64  */
65  void AttachTexture(const glfTexture& texture,
66  GLenum attachmentPoint,
67  int attachedMipMapLevel = 0,
68  int zSlice = 0,
69  GLenum cubeMapSide = 0);
70 
71  /**
72  * Attaches a renderbuffer to the framebuffer object.
73  * See glfFramebufferObject::AttachTexture for valid attachment points.
74  */
75  void AttachRenderbuffer(const glfRenderbuffer& renderbuffer,
76  GLenum attachmentPoint);
77 
78  /**
79  * Removes an attachment from the framebuffer object.
80  */
81  void ReleaseAttachment(GLenum attachmentPoint);
82 
83  void SetDrawBuffers(const std::vector<GLenum>& drawbuffers);
84  void ResetDrawBuffers();
85 
86  /**
87  * Checks whether the framebuffer object is supported in its current state.
88  * If not, an exception is thrown. This method should be called before the
89  * framebuffer object is used as a render target.
90  */
91  void CheckComplete() const;
92 
93  // glfRenderTarget interface
94  virtual void Bind() const;
95 
96  static GLint MaxRenderTargets();
97 
98  /**
99  * Blits the attachments from source to target, requires EXT_framebuffer_blit extension.
100  * Copied content is only the color attachment.
101  * \param source is the source of the blit operation, i.e. the content copied.
102  * \param target is the target of the blit operation.
103  * \param colorFilter is either GL_LINEAR or GL_NEAREST.
104  **/
105  static void BlitColorBuffer(glfFramebufferObject* source, glfFramebufferObject* target,
106  GLenum colorFilter);
107 
108  /**
109  * Blits the attachments from source to target, requires EXT_framebuffer_blit extension.
110  * \param source is the source of the blit operation, i.e. the content copied.
111  * \param target is the target of the blit operation.
112  * \param bufferMask is the mask identifying the buffers that are copied,
113  * and can consists of GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT and GL_STENCIL_BUFFER_BIT.
114  * \attention the filter operation applied is GL_NEAREST.
115  **/
116  static void Blit(glfFramebufferObject* source,
117  glfFramebufferObject* target,
118  GLbitfield bufferMask);
119 
120  void GetSize(GLint& width, GLint& height);
121 
122 
123  private:
124  /**
125  * Blits the attachments from source to target, requires EXT_framebuffer_blit extension.
126  * \param source is the source of the blit operation, i.e. the content copied.
127  * \param target is the target of the blit operation.
128  * \param bufferMask is the mask identifying the buffers that are copied,
129  * and can consists of GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT and GL_STENCIL_BUFFER_BIT.
130  * \param colorFilter is either GL_LINEAR or GL_NEAREST, GL_LINEAR is only possible with GL_COLOR_BUFFER_BIT.
131  **/
132  static void Blit_(glfFramebufferObject* source,
133  glfFramebufferObject* target,
134  GLbitfield bufferMask,
135  GLenum colorFilter);
136  GLuint id_;
137  /** Defines the number of set draw buffers for multiple render targets**/
138  GLsizei numSimultaneousDrawBuffers_;
139  GLenum* listOfSimultaneousDrawBuffers_;
140  bool FramebufferCreated_;
141 
142  /** An intuitive assignment operator should generate a copy, as long as nobody is willing to implement
143  * the generation of a copy in gl controlled memory this operator cannot be used.
144  */
145  glfFramebufferObject& operator=(const glfFramebufferObject& fbb);
146 
147  /** An intuitive copy constructor should generate a copy, as long as nobody is willing to implement
148  * the generation of a copy in gl controlled memory this constructor cannot be used.
149  */
151 
152 
153  };
154 
155 } // namespace BIAS
156 
157 #endif // __glfFramebufferObject_hh__
Base class for textures.
Definition: glfTexture.hh:42
Interface for render targets.
The renderbuffer.