FBO.hh 3.88 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

Jan Möbius's avatar
Jan Möbius committed
24
#include <ACG/Config/ACGDefines.hh>
Jan Möbius's avatar
Jan Möbius committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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.
*/
42
class ACGDLLEXPORT FBO
Jan Möbius's avatar
Jan Möbius committed
43
44
{
public:
45
46
  
  // fbo_ braucht initialen Wert.
Jan Möbius's avatar
Jan Möbius committed
47
  /// Default constructor
48
  FBO();
Jan Möbius's avatar
Jan Möbius committed
49
50
51
52
53
54
  
  /// Destructor
  ~FBO();
  
  /// function to generate the framebuffer object
  void init();
55

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

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

62
63
64
65
66
67
68
69
  /// 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);

70

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

74
75
76
  /// 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
77
78
79
80
81
  /// 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 );
82
83
84
85
86
87
88
89

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

  /// return opengl id
  GLuint getFboID();

  /// resize function (if textures created by this class)
90
91
92
93
94
95
96
  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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  
  /// 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_;

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

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

    // GL_TEXTURE_2D, GL_TEXTURE_2D_MULTISAMPLE..
    GLenum target;

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

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

  /// 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
147
148
149
150
151
152
153
154
155
};


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