Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FBO.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 //=============================================================================
43 //
44 // CLASS FBO
45 //
46 // Author: Dominik Sibbing <sibbing@cs.rwth-aachen.de>
47 //
48 // Version: $Revision: 1$
49 // Date: $Date: 2008$
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_FBO_HH
55 #define ACG_FBO_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 #include <iostream>
61 #include <cstdlib>
62 #include <map>
63 #include <vector>
64 
65 #include <ACG/Config/ACGDefines.hh>
66 #include <ACG/GL/gl.hh>
67 
68 //== FORWARDDECLARATIONS ======================================================
69 
70 //== NAMESPACES ===============================================================
71 
72 namespace ACG {
73 
74 //== CLASS DEFINITION =========================================================
75 
76 
83 class ACGDLLEXPORT FBO
84 {
85 public:
86 
87  // fbo_ braucht initialen Wert.
89  FBO();
90 
92  ~FBO();
93 
95  void init();
96 
98  void del();
99 
102  GLsizei setMultisampling(GLsizei _samples, GLboolean _fixedsamplelocations = GL_TRUE);
103 
105  GLsizei getMultisamplingCount() const {return samples_;}
106 
108  void attachTexture( GLenum _attachment,
109  GLuint _texture,
110  GLuint _level = 0);
111 
113  void attachTexture2D( GLenum _attachment,
114  GLsizei _width, GLsizei _height,
115  GLuint _internalFmt, GLenum _format,
116  GLint _wrapMode = GL_CLAMP,
117  GLint _minFilter = GL_NEAREST,
118  GLint _magFilter = GL_NEAREST);
119 
120 
122  void attachTexture2D( GLenum _attachment, GLuint _texture, GLenum _target = GL_TEXTURE_2D );
123 
125  void attachTexture2DDepth( GLsizei _width, GLsizei _height, GLuint _internalFmt = GL_DEPTH_COMPONENT32, GLenum _format = GL_DEPTH_COMPONENT );
126 
128  void attachTexture2DStencil(GLsizei _width, GLsizei _height);
129 
132  void attachTexture3D( GLenum _attachment,
133  GLsizei _width, GLsizei _height, GLsizei _depth,
134  GLuint _internalFmt, GLenum _format,
135  GLint _wrapMode = GL_CLAMP,
136  GLint _minFilter = GL_NEAREST,
137  GLint _magFilter = GL_NEAREST);
138 
140  void addDepthBuffer( GLuint _width, GLuint _height );
141 
143  void addStencilBuffer( GLuint _width, GLuint _height );
144 
146  void addDepthStencilBuffer( GLuint _width, GLuint _height );
147 
149  GLuint getAttachment( GLenum _attachment );
150 
152  GLuint getInternalFormat( GLenum _attachment );
153 
155  GLuint getFboID();
156 
158  void resize(GLsizei _width, GLsizei _height, bool _forceResize = false);
159 
161  GLsizei width() const {return width_;}
162 
164  GLsizei height() const {return height_;}
165 
167  ACG::Vec2i size() const {return ACG::Vec2i(width_, height_);}
168 
170  bool bind();
171 
173  void unbind();
174 
176  bool checkFramebufferStatus();
177 
178 private:
179 
181  GLuint fbo_;
182 
184  GLuint depthbuffer_;
185 
188 
191  {
192  RenderTexture();
193 
194  // opengl buf id
195  GLuint id;
196 
197  // GL_TEXTURE_2D, GL_TEXTURE_2D_MULTISAMPLE..
198  GLenum target;
199 
200  GLenum internalFormat, format, gltype;
201 
202  // tex dimension
203  ACG::Vec3i dim;
204 
205  // common sampler params
206  GLint wrapMode,
207  minFilter,
208  magFilter;
209 
210  // created by FBO class
211  bool owner;
212  };
213 
214  typedef std::map<GLenum, RenderTexture> AttachmentList;
215  AttachmentList attachments_; // key: attachment index, value: RenderTexture
216 
217 
219  GLsizei width_, height_;
220 
222  GLsizei samples_;
223 
226 
227 
229  GLuint prevFbo_;
230  GLuint prevDrawBuffer_;
231 };
232 
233 
234 //=============================================================================
235 } // namespace ACG
236 //=============================================================================
237 #endif // ACG_FBO_HH defined
238 //=============================================================================
239 
GLsizei width_
width and height of render textures
Definition: FBO.hh:219
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
VectorT< signed int, 2 > Vec2i
Definition: VectorT.hh:104
GLsizei samples_
sample count if multisampling
Definition: FBO.hh:222
GLsizei width() const
get width of fbo texture
Definition: FBO.hh:161
Definition: FBO.hh:83
GLsizei getMultisamplingCount() const
get number of samples
Definition: FBO.hh:105
attached textures
Definition: FBO.hh:190
GLuint fbo_
handle of frame buffer object
Definition: FBO.hh:181
GLuint prevFbo_
handle of previously bound fbo
Definition: FBO.hh:229
GLboolean fixedsamplelocation_
enable fixed sample location if multisampling
Definition: FBO.hh:225
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Definition: bindT.hh:106
GLuint stencilbuffer_
stencilbuffer
Definition: FBO.hh:187
GLuint depthbuffer_
depthbuffer
Definition: FBO.hh:184
GLsizei height() const
get height of fbo texture
Definition: FBO.hh:164
ACG::Vec2i size() const
get width and height of fbo texture
Definition: FBO.hh:167