GlobeEngine
FrameBufferObject.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_FrameBufferObject_h
10 #define GlobeEngine_FrameBufferObject_h
11 
12 #include "OpenGL_Includes.h"
13 #include "RenderBufferObject.h"
14 #include "Common.h"
15 #include "Texture.h"
16 #include <vector>
17 #include <memory>
18 
19 namespace ge {
21  {
22  public:
23  enum FBOTYPE { NORMAL=0,
29 
30  public:
32  virtual ~FrameBufferObject();
33 
34  void clear();
35  void setupFrameBuffer(vmml::Vector2i _size);
36  void resizeFrameBuffer(vmml::Vector2i _size);
37  /*
38  * standard channel amount is 3:
39  * FragColor vec4, FragDepth float, FragIDInfo vec4
40  */
41  void createBasicBuffersAndColorBuffers(vmml::Vector2i _size, int _channels);
42  void createBasicBufferSetup(vmml::Vector2i _size);
43  void createDepthBuffer(vmml::Vector2i _size);
44  void createStencilBuffer(vmml::Vector2i _size, int _channels = 3);
45 
46  /* Create a (more standard) G-Buffer. Texture formats are choosen more
47  * conservatively, so we don't blow full 32-bit RGBA textures on every-
48  * thing. The current setup uses:
49  *
50  * - RGB8_Ax for (diffuse) color; A unused?
51  * - DEPTH32 for depth
52  * - RG16F for normals (*)
53  *
54  * (*) We could use RG16F and just reconstruct the Z component of the
55  * normal, or use RGB10_A2 (which also needs a bit manual work due to
56  * not being signed-normalized).
57  */
58  void createGBuffer(vmml::Vector2i _size);
59  void createGBufferWithIDLayer(vmml::Vector2i _size);
60 
62 
63  void bind();
64  void release();
65 
66  //void foo(const shared_ptr<T>& p)
67  const std::shared_ptr<TextureHandle> getColorTexture(GLint _index) const;
68 
69  void getOpenGLError(std::string _input);
70 
71  /*
72  * picking funtions:
73  */
74  GLubyte* getPickingResult(int _x, int _y, int _w, int _h, GLint _layer = 2);
75  GLfloat* getPickingResultf(int _x, int _y, int _w, int _h, GLint _layer = 2);
76 
77  /*
78  * export framebuffer:
79  */
80  void saveFramebufferToFile(std::string _filePath);
81 
82  /*
83  * release current framebuffer and bind to the given framebuffer ID.
84  * @param _id - if nothing is set, the OpenGL Standard buffer is
85  * set to 0.
86  */
89  void setStandardFramebufferID(int _id);
90 
91  int getWidth() const;
92  int getHeight() const;
93 
94  void printMaximumSizes();
95 
96  protected:
97  void setSize(int _width, int _height);
99  void setupTextureChannels();
100  void attachColorChannels();
101  /* Texture channel handling */
102  //void addTextureChannel(ge::Texture::eTEXTURE_TYPES _prop, std::string _name = "");
103  void addTextureChannel(ge::TextureProperties2D _prop, std::string _name = "");
104  void createBasicLayerSetup();
105  void attachTextureToFramebuffer(GLenum _attachement,GLenum _textarget, GLuint _texHandle, GLint _level);
106  void callDrawBuffers();
107  void checkFramebufferStatus();
108  void setupRenderBuffer(GLenum _internalFormat, GLenum _assignedAttachement);
109  void deleteMemory();
110  void deletePickbuffer();
112  void retrievePickResult(int _x, int _y, int _w, int _h, GLint _layer, GLenum _format, GLenum _type);
113 
115  GLuint fboId;
116  GLuint sboId;
117 
118  GLenum* colorBuffers;
119 
120  //std::vector< ge::Texture::eTEXTURE_TYPES > layertypes;
121  std::vector< ge::TextureProperties2D > layertypes;
122  //std::vector< std::shared_ptr<Texture> > colorMaps;
123  std::vector< std::shared_ptr<ge::TextureHandle> > colorMaps;
124 
125  //Texture depthMap;
126  //ge::Texture stencilMap;
128 
129  GLsizei width;
130  GLsizei height;
131 
132  /* last pick result */
133  union {
134  GLvoid* notype;
135  GLfloat* alpha;
136  GLubyte* rgba;
137  } pickdata;
138 
140  };
141 }
142 #endif
void setupFrameBuffer(vmml::Vector2i _size)
Definition: FrameBufferObject.cpp:68
void release()
Definition: FrameBufferObject.cpp:318
void deleteFrameBufferHandle()
Definition: FrameBufferObject.cpp:251
void setSize(int _width, int _height)
Definition: FrameBufferObject.cpp:360
FBOTYPE
Definition: FrameBufferObject.h:23
union ge::FrameBufferObject::@0 pickdata
void getOpenGLError(std::string _input)
Definition: FrameBufferObject.cpp:384
void saveFramebufferToFile(std::string _filePath)
Definition: FrameBufferObject.cpp:268
void deleteMemory()
Definition: FrameBufferObject.cpp:42
void createStencilBuffer(vmml::Vector2i _size, int _channels=3)
Definition: FrameBufferObject.cpp:94
Definition: FrameBufferObject.h:26
Definition: FrameBufferObject.h:23
GLsizei height
Definition: FrameBufferObject.h:130
void resizeFrameBuffer(vmml::Vector2i _size)
void addLayerType(ge::TextureProperties2D _prop)
Definition: FrameBufferObject.cpp:157
GLuint sboId
Definition: FrameBufferObject.h:116
void retrievePickResult(int _x, int _y, int _w, int _h, GLint _layer, GLenum _format, GLenum _type)
Definition: FrameBufferObject.cpp:230
GLvoid * notype
Definition: FrameBufferObject.h:134
GLenum * colorBuffers
Definition: FrameBufferObject.h:118
Definition: FrameBufferObject.h:20
int getHeight() const
Definition: FrameBufferObject.cpp:369
FrameBufferObject()
Definition: FrameBufferObject.cpp:16
GLfloat * alpha
Definition: FrameBufferObject.h:135
void attachTextureToFramebuffer(GLenum _attachement, GLenum _textarget, GLuint _texHandle, GLint _level)
Definition: FrameBufferObject.cpp:261
void setStandardFramebufferID(int _id)
Definition: FrameBufferObject.cpp:333
void deletePickbuffer()
Definition: FrameBufferObject.cpp:47
void createGBuffer(vmml::Vector2i _size)
Definition: FrameBufferObject.cpp:115
RenderBufferObject rbo
Definition: FrameBufferObject.h:114
int getStandardFramebufferID()
Definition: FrameBufferObject.cpp:338
GLfloat * getPickingResultf(int _x, int _y, int _w, int _h, GLint _layer=2)
Definition: FrameBufferObject.cpp:222
Definition: RenderBufferObject.h:16
void createBasicBuffersAndColorBuffers(vmml::Vector2i _size, int _channels)
Definition: FrameBufferObject.cpp:59
std::vector< ge::TextureProperties2D > layertypes
Definition: FrameBufferObject.h:121
const std::shared_ptr< TextureHandle > getColorTexture(GLint _index) const
Definition: FrameBufferObject.cpp:205
GLubyte * getPickingResult(int _x, int _y, int _w, int _h, GLint _layer=2)
Definition: FrameBufferObject.cpp:214
void checkFramebufferStatus()
Definition: FrameBufferObject.cpp:342
int lookupStandardFramebufferID()
Definition: FrameBufferObject.cpp:326
std::vector< std::shared_ptr< ge::TextureHandle > > colorMaps
Definition: FrameBufferObject.h:123
GLsizei width
Definition: FrameBufferObject.h:129
ge::DepthMap2Drgba stencilMap
Definition: FrameBufferObject.h:127
GLuint fboId
Definition: FrameBufferObject.h:115
Definition: FrameBufferObject.h:28
void createBasicLayerSetup()
Definition: FrameBufferObject.cpp:148
void createGBufferWithIDLayer(vmml::Vector2i _size)
Definition: FrameBufferObject.cpp:129
virtual ~FrameBufferObject()
Definition: FrameBufferObject.cpp:23
void createBasicBufferSetup(vmml::Vector2i _size)
Definition: FrameBufferObject.cpp:55
Definition: FrameBufferObject.h:24
void attachColorChannels()
Definition: FrameBufferObject.cpp:195
void addTextureChannel(ge::TextureProperties2D _prop, std::string _name="")
Definition: FrameBufferObject.cpp:165
int getWidth() const
Definition: FrameBufferObject.cpp:365
Definition: AvalancheTrainingSimulationEngine.h:28
void printMaximumSizes()
Definition: FrameBufferObject.cpp:373
void bind()
Definition: FrameBufferObject.cpp:313
void setupTextureChannels()
Definition: FrameBufferObject.cpp:188
void createFrameBufferHandle()
Definition: FrameBufferObject.cpp:245
int standardFBOid
Definition: FrameBufferObject.h:139
void createDepthBuffer(vmml::Vector2i _size)
Definition: FrameBufferObject.cpp:78
Definition: Texture.h:221
void callDrawBuffers()
Definition: FrameBufferObject.cpp:256
void setupRenderBuffer(GLenum _internalFormat, GLenum _assignedAttachement)
Definition: FrameBufferObject.cpp:142
Definition: FrameBufferObject.h:25
GLubyte * rgba
Definition: FrameBufferObject.h:136
Definition: FrameBufferObject.h:27
void clear()
Definition: FrameBufferObject.cpp:30