FBO.hh 3.84 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//=============================================================================
//
//  CLASS FBO
//
// Author:  Dominik Sibbing <sibbing@cs.rwth-aachen.de>
//
// Version: $Revision: 1$
// Date:    $Date: 2008$
//
//=============================================================================


#ifndef ACG_FBO_HH
#define ACG_FBO_HH


//== INCLUDES =================================================================

#include <iostream>
20
#include <cstdlib>
21
22
#include <map>
#include <vector>
Jan Möbius's avatar
Jan Möbius committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include <ACG/GL/gl.hh>

//== FORWARDDECLARATIONS ======================================================

//== NAMESPACES ===============================================================

namespace ACG {

//== CLASS DEFINITION =========================================================


/** \class FBO FBO.hh <ACG/.../FBO.hh>

    Brief Description.
  
    A more elaborate description follows.
*/
41
class ACGDLLEXPORT FBO
Jan Möbius's avatar
Jan Möbius committed
42
43
{
public:
44
45
  
  // fbo_ braucht initialen Wert.
Jan Möbius's avatar
Jan Möbius committed
46
  /// Default constructor
47
  FBO();
Jan Möbius's avatar
Jan Möbius committed
48
49
50
51
52
53
  
  /// Destructor
  ~FBO();
  
  /// function to generate the framebuffer object
  void init();
54

55
56
57
58
59
60
  /// enable/disable multisampling
  void setMultisampling(GLsizei _samples, GLboolean _fixedsamplelocations = GL_TRUE);

  /// get number of samples
  GLsizei getMultisamplingCount() const {return samples_;}

61
62
63
64
65
66
67
68
  /// function to attach a texture to fbo
  void attachTexture2D( GLenum _attachment,
    GLsizei _width, GLsizei _height, 
    GLuint _internalFmt, GLenum _format, 
    GLint _wrapMode = GL_CLAMP,
    GLint _minFilter = GL_NEAREST,
    GLint _magFilter = GL_NEAREST);

69

Jan Möbius's avatar
Jan Möbius committed
70
  /// function to attach a texture to fbo
71
  void attachTexture2D( GLenum _attachment, GLuint _texture, GLenum _target = GL_TEXTURE_2D );
Jan Möbius's avatar
Jan Möbius committed
72

73
74
75
  /// function to attach a depth-buffer texture to fbo (using GL_DEPTH_ATTACHMENT)
  void attachTexture2DDepth( GLsizei _width, GLsizei _height, GLuint _internalFmt = GL_DEPTH_COMPONENT32, GLenum _format = GL_DEPTH_COMPONENT );

Jan Möbius's avatar
Jan Möbius committed
76
77
78
79
80
  /// function to add a depth buffer to the fbo
  void addDepthBuffer( GLuint _width, GLuint _height );
  
  /// function to add a stencil buffer to the fbo
  void addStencilBuffer( GLuint _width, GLuint _height );
81
82
83
84
85
86
87
88

  /// return attached texture id
  GLuint getAttachment( GLenum _attachment );

  /// return opengl id
  GLuint getFboID();

  /// resize function (if textures created by this class)
89
90
91
92
93
94
95
  void resize(GLsizei _width, GLsizei _height, bool _forceResize = false);

  /// get width of fbo texture
  GLsizei width() const {return width_;}

  /// get height of fbo texture
  GLsizei height() const {return height_;}
Jan Möbius's avatar
Jan Möbius committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  
  /// bind the fbo and sets it as rendertarget
  bool bind();
  
  /// unbind fbo, go to normal rendering mode 
  void unbind();
  
  /// function to check the framebuffer status
  bool checkFramebufferStatus();

private:

  /// handle of frame buffer object
  GLuint fbo_;

  /// depthbuffer
  GLuint depthbuffer_;
  
  /// stencilbuffer
  GLuint stencilbuffer_;

117
  /// attached textures
118
119
  typedef std::map<GLenum, std::pair<GLuint, GLenum> > AttachmentList;
  AttachmentList attachments_; // key: attachment index,  value: <tex_id, target>
120
121
122

  struct RenderTexture
  {
123
    // opengl buf id
124
    GLuint id;
125
126
127
128

    // GL_TEXTURE_2D, GL_TEXTURE_2D_MULTISAMPLE..
    GLenum target;

129
130
131
132
133
134
135
    GLenum internalFormat, format;
  };
  /// textures created by this class
  std::vector<RenderTexture> internalTextures_;

  /// width and height of render textures
  GLsizei width_, height_;
136
137
138
139
140
141
142
143
144
145

  /// sample count if multisampling
  GLsizei samples_;

  /// enable fixed sample location if multisampling
  GLboolean fixedsamplelocation_;


  /// handle of previously bound fbo
  GLuint prevFbo_;
Jan Möbius's avatar
Jan Möbius committed
146
147
148
149
150
151
152
153
154
};


//=============================================================================
} // namespace ACG
//=============================================================================
#endif // ACG_FBO_HH defined
//=============================================================================