Tucano
0.1
A library for rapid prototyping with modern OpenGL and GLSL
|
A wrapper class for creating and using FBOs. More...
#include <framebuffer.hpp>
Public Member Functions | |
Framebuffer (int w, int h, int num_buffers=1, GLenum textype=GL_TEXTURE_2D, GLenum int_frm=GL_RGBA32F, GLenum frm=GL_RGBA, GLenum pix_type=GL_UNSIGNED_BYTE) | |
Framebuffer default constructor. More... | |
Framebuffer (void) | |
Framebuffer default empty constructor. More... | |
void | create (int w, int h, int num_attachs=1, int nsamples=1) |
Creates the framebuffer with specified parameters. More... | |
void | create (Eigen::Vector2i size, int num_attachs=1, int nsamples=1) |
int | bufferElements () const |
Returns the total number of data elements held by the framebuffer, in terms of red, green, blue and alpha components. Use this method if you need to allocate a buffer large enough to copy the framebuffer's contents. More... | |
int | depthBufferElements () const |
Returns the total number of depth data elements held by the framebuffer. Use this method if you need to allocate a buffer large enough to copy the framebuffer's depth contents. More... | |
GLuint | getTexID (int tex_id) |
Returns the id of the texture in given color attachment. More... | |
Texture * | getTexture (int tex_id) |
Returns a pointer to a texture (attachment). More... | |
GLenum | textureType (void) |
void | fillTexture (int attach_id, GLubyte *data) |
Fills a texture with given data in an array of Bytes. More... | |
void | fillTexture (int attach_id, GLfloat *data) |
Fill a texture with given data in an array of Floats. More... | |
virtual void | bind (void) |
Binds framebuffer object. More... | |
virtual void | bindRenderBuffer (GLuint attachID) |
Bind framebuffer object and set render buffer to given attachment. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1) |
Bind framebuffer object and set render buffer to 2 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2) |
Bind framebuffer object and set render buffer to 3 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2, GLuint attachID3) |
Bind framebuffer object and set render buffer to 4 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2, GLuint attachID3, GLuint attachID4) |
Bind framebuffer object and set render buffer to 5 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2, GLuint attachID3, GLuint attachID4, GLuint attachID5) |
Bind framebuffer object and set render buffer to 6 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2, GLuint attachID3, GLuint attachID4, GLuint attachID5, GLuint attachID6) |
Bind framebuffer object and set render buffer to 7 given attachments. More... | |
virtual void | bindRenderBuffers (GLuint attachID0, GLuint attachID1, GLuint attachID2, GLuint attachID3, GLuint attachID4, GLuint attachID5, GLuint attachID6, GLuint attachID7) |
Bind framebuffer object and set render buffer to 8 given attachments. More... | |
virtual void | bindRenderBuffers (GLsizei n, GLuint *buffers) |
Bind framebuffer object and set render buffer to given array of buffers. More... | |
virtual void | unbindFBO (void) |
Unbinds framebuffer object. More... | |
void | unbind (void) |
Unbinds fbo and all texture units in use. More... | |
void | blitTo (Framebuffer ©fbo, int source_attach=0, int dest_attach=0) |
Copy fbo attachment to another fbo with blit operation. More... | |
Eigen::Vector2i | getSize () const |
Returns the framebuffer's dimensions as a 2-component vector. More... | |
void | clearAttachments (Eigen::Vector4f clear_color=Eigen::Vector4f::Zero()) |
Clears all attachments with a given color. More... | |
void | clearAttachment (int attachment, Eigen::Vector4f clear_color=Eigen::Vector4f::Zero()) |
Clears a given attachments with a given color. More... | |
void | clearDepth (void) |
Clears the FBO depthbuffer. More... | |
void | bindAttachment (int attachment, int texture_unit) |
Binds a texture attachment to a given texture unit. More... | |
int | bindAttachment (int attachment) |
Binds a texture attachment to the first free unit. More... | |
void | unbindAttachments (void) |
Unbinds all texture attachments. More... | |
void | setInternalFormat (GLenum int_frm) |
Sets the internal format of the FBO's texture. More... | |
void | setInputFormat (GLenum in_format) |
Sets format to read data to the FBO. More... | |
void | setInputType (GLenum in_type) |
Sets data type for reading pixels to the FBO. More... | |
void | setTextureType (GLenum tex_type) |
Sets FBO texture type. More... | |
Eigen::Vector4f | readPixel (int attach, Eigen::Vector2i pos) |
Reads a pixel from a buffer and returns it as an Eigen vector. More... | |
void | readBuffer (int attach_id, GLfloat **pixels) |
Reads a GPU buffer and stores it in a CPU array of floats. More... | |
void | readBuffer (int attach_id, GLbyte **pixels) |
Reads a GPU buffer and stores it in a CPU array of unsigned bytes. More... | |
void | readBuffer (int attach_id, unsigned char **pixels) |
Reads a GPU buffer and stores it in a CPU array of unsigned char. More... | |
void | readBuffer (int attach_id, vector< unsigned char > &pixels) |
Reads a GPU buffer and stores it in a CPU vector of unsigned char. More... | |
void | readBuffer (int attach_id, vector< float > &pixels) |
Reads a GPU buffer and stores it in a CPU vector of float. More... | |
void | readDepthBuffer (vector< GLbyte > &depth_values) |
Reads the depth buffer and stores it in a CPU vector of GLbyte. More... | |
void | readDepthBuffer (vector< float > &depth_values) |
Reads the depth buffer and stores it in a CPU vector of float. More... | |
void | saveAsPPM (string filename, int attach=0) |
Saves the buffer to a PPM image. More... | |
void | printBuffer (int attach, Eigen::Vector4f exception=Eigen::Vector4f(0.0, 0.0, 0.0, 0.0)) |
Prints the content of a GPU. Usually used for debugging. More... | |
GLuint | getID (void) |
Returns the fbo ID. More... | |
Eigen::Vector2i | getDimensions (void) |
Returns the dimensions of the FBO. More... | |
int | getWidth (void) |
Returns the width of the FBO. More... | |
int | getHeight (void) |
Returns the height of the FBO. More... | |
int | getNumAttachments (void) |
Returns the number of attachments. More... | |
bool | isBinded (void) |
Returns wether the FBO is currently binded or not. More... | |
Protected Member Functions | |
virtual void | createFramebuffer (int viewportWidth, int viewportHeight, int numberOfTextures=1) |
Creates the framebuffer and the depthbuffer. More... | |
virtual void | createTexture (int attach_id) |
Generate the ith FBO texture as the ith color attachment. More... | |
Protected Attributes | |
GLuint | fbo_id |
The Framebuffer Object. More... | |
GLuint | depthbuffer_id |
The Depthbuffer Object. More... | |
std::vector< Texture > | fboTextures |
Array of textures attachments. More... | |
GLenum | texture_type |
Texture type for framebuffer attachments, default is GL_TEXTURE_2D. More... | |
Eigen::Vector2i | size |
Framebuffer dimensions. More... | |
GLenum | internal_format |
Internal format as defined by OpenGL (ex. GL_RGBA, GL_RGBA32F ...). More... | |
GLenum | pixel_type |
Pixel type (GL_FLOAT, GL_UNSIGNED_INT ...) More... | |
GLenum | format |
Format as defined by OpenGL (ex. GL_RGBA, GL_RGBA_INTEGER ...) More... | |
int | num_samples = 1 |
Number of samples (for multisampling) More... | |
bool | is_binded |
Flag to indicate if buffer is binded or not. More... | |
std::shared_ptr< GLuint > | fboID_sptr |
Shared pointer to fbo id. More... | |
std::shared_ptr< GLuint > | depthbufferID_sptr |
Shared pointer to depth buffer id. More... | |
A wrapper class for creating and using FBOs.
The Framebuffer class is responsible for framebuffer generation and storage. It holds many shortcut methods to bind, draw to buffer, read buffer for debug, etc...
|
inline |
Framebuffer default constructor.
Creates a framebuffer with the given size and number of buffers, as well as set all texture units as not used.
w | Width of the framebuffer texture object. |
h | Height of the framebuffer texture object. |
num_buffers | Number of textures that the framebuffer object will hold. |
textype | Type of the framebuffer texture object. |
int_frm | Internal format (default is GL_RGBA32F) |
frm | Format (default is GL_RGBA) |
pix_type | Texture pixel type (default is GL_FLOAT) |
|
inline |
Framebuffer default empty constructor.
|
inlinevirtual |
Binds framebuffer object.
|
inline |
Binds a texture attachment to a given texture unit.
attachment | Number of color attachment. |
texture_unit | Number of unit to bind texture. |
|
inline |
Binds a texture attachment to the first free unit.
attachment | Number of color attachment |
|
inlinevirtual |
Bind framebuffer object and set render buffer to given attachment.
attachID | The color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 2 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 3 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 4 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
attachID3 | The fourth color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 5 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
attachID3 | The fourth color attachment to be used for writing. |
attachID4 | The fifth color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 6 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
attachID3 | The fourth color attachment to be used for writing. |
attachID4 | The fifth color attachment to be used for writing. |
attachID5 | The sixth color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 7 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
attachID3 | The fourth color attachment to be used for writing. |
attachID4 | The fifth color attachment to be used for writing. |
attachID5 | The sixth color attachment to be used for writing. |
attachID6 | The seventh color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to 8 given attachments.
attachID0 | The first color attachment to be used for writing. |
attachID1 | The second color attachment to be used for writing. |
attachID2 | The third color attachment to be used for writing. |
attachID3 | The fourth color attachment to be used for writing. |
attachID4 | The fifth color attachment to be used for writing. |
attachID5 | The sixth color attachment to be used for writing. |
attachID6 | The seventh color attachment to be used for writing. |
attachID7 | The eigth color attachment to be used for writing. |
|
inlinevirtual |
Bind framebuffer object and set render buffer to given array of buffers.
n | Number of attachments to be used for writing. |
buffers | Array of attachments to be used for writing. |
|
inline |
Copy fbo attachment to another fbo with blit operation.
copyfbo | Pointer to destination FBO |
source_attach | Source attachment |
dest_attach | Destination attachment |
|
inline |
Returns the total number of data elements held by the framebuffer, in terms of red, green, blue and alpha components. Use this method if you need to allocate a buffer large enough to copy the framebuffer's contents.
|
inline |
Clears a given attachments with a given color.
attachment | Given texture attachment to be cleared. |
clear_color | Clear color (default is zero vector) |
|
inline |
Clears all attachments with a given color.
clear_color | Clear color (default is zero vector). |
|
inline |
Clears the FBO depthbuffer.
|
inline |
Creates the framebuffer with specified parameters.
w | Width of FBO. |
h | Height of FBO. |
num_attachs | Number of texture attachments to be created. |
num_samples | Number of samples, if more than 1 creates multisample texture. |
|
inline |
Overload of create method to use vector2i instead of width and height
|
inlineprotectedvirtual |
Creates the framebuffer and the depthbuffer.
The viewport width and height are needed in order to create the FBO. The number of texture attachments may be greater than one. Note, however, that all textures of the FBO must have the same size (unless it is a MipMap) and parameters.
viewportWidth | The current viewport width. |
viewportHeight | The current viewport height. |
numberOfTextures | Number of output attachments |
|
inlineprotectedvirtual |
Generate the ith FBO texture as the ith color attachment.
attach_id | Attachment holding the texture. |
|
inline |
Returns the total number of depth data elements held by the framebuffer. Use this method if you need to allocate a buffer large enough to copy the framebuffer's depth contents.
|
inline |
Fills a texture with given data in an array of Bytes.
attach_id | Attachment of texture to be filled. |
data | Pointer to the data. |
|
inline |
Fill a texture with given data in an array of Floats.
attach_id | Attachment of texture to be filled. |
data | Pointer to the data. |
|
inline |
Returns the dimensions of the FBO.
|
inline |
Returns the height of the FBO.
|
inline |
Returns the fbo ID.
|
inline |
Returns the number of attachments.
|
inline |
Returns the framebuffer's dimensions as a 2-component vector.
|
inline |
Returns the id of the texture in given color attachment.
tex_id | Position of the texture, as in the ith texture of the FBO. |
|
inline |
Returns a pointer to a texture (attachment).
tex_id | Position of the texture, as in the ith texture of the FBO. |
|
inline |
Returns the width of the FBO.
|
inline |
Returns wether the FBO is currently binded or not.
|
inline |
Prints the content of a GPU. Usually used for debugging.
Assumes each pixel has four GLfloat elements.
attach | Number of buffer to be read |
exception | Pixel value that should not be printed, usually the background. |
|
inline |
Reads a GPU buffer and stores it in a CPU array of floats.
Assumes each pixel has four GLfloat elements. If pixels
is not null, it is deallocated, then reallocated to ensure the array as large enough to store the framebuffer's contents.
attach_id | Buffer to be read, the id of the attachment. |
pixels | Pointer to array of pixels. |
|
inline |
Reads a GPU buffer and stores it in a CPU array of unsigned bytes.
Assumes each pixel has four GLBytes elements. If pixels
is not null, it is deallocated, then reallocated to ensure the array as large enough to store the framebuffer's contents.
attach_id | Buffer to be read, the id of the attachment |
pixels | Pointer to array of pixels. |
|
inline |
Reads a GPU buffer and stores it in a CPU array of unsigned char.
Assumes each pixel has four unsigned char elements. If pixels
is not null, it is deallocated, then reallocated to ensure the array as large enough to store the framebuffer's contents.
attach_id | Buffer to be read, the id of the attachment |
pixels | Pointer to array of pixels. |
|
inline |
Reads a GPU buffer and stores it in a CPU vector of unsigned char.
The vector is cleared prior to copying the framebuffer's contents.
Assumes each pixel has four unsigned char elements.
attach_id | Buffer to be read, the id of the attachment |
pixels | Vector of pixels. |
|
inline |
Reads a GPU buffer and stores it in a CPU vector of float.
The vector is cleared prior to copying the framebuffer's contents.
Assumes each pixel has four float elements.
attach_id | Buffer to be read, the id of the attachment. |
pixels | Vector of float pixels. |
|
inline |
Reads the depth buffer and stores it in a CPU vector of GLbyte.
depth_values | Vector of GLbyte pixels to receive depth values. |
|
inline |
Reads the depth buffer and stores it in a CPU vector of float.
depth_values | Vector of float pixels to receive depth values. |
|
inline |
Reads a pixel from a buffer and returns it as an Eigen vector.
Assumes that a pixel has four GLfloat elements.
attach | Buffer to be read, the id of the attachment. |
pos | Pixel position to be read. |
|
inline |
Saves the buffer to a PPM image.
filename | Output ppm filename |
attach | FBO attachment to save as image (default is 0) |
|
inline |
Sets format to read data to the FBO.
Default when created is GL_RGBA32F.
in_format | Given input data format. |
|
inline |
Sets data type for reading pixels to the FBO.
Default when created is GL_FLOAT.
in_type | Given input data type. |
|
inline |
Sets the internal format of the FBO's texture.
Default when created is GL_RGBA32F.
int_frm | Internal format. |
|
inline |
Sets FBO texture type.
Default when created is GL_TEXTURE_2D.
tex_type | Given input data type. |
|
inline |
|
inline |
Unbinds fbo and all texture units in use.
|
inline |
Unbinds all texture attachments.
|
inlinevirtual |
Unbinds framebuffer object.
|
protected |
The Depthbuffer Object.
|
protected |
Shared pointer to depth buffer id.
|
protected |
The Framebuffer Object.
|
protected |
Shared pointer to fbo id.
|
protected |
Array of textures attachments.
|
protected |
Format as defined by OpenGL (ex. GL_RGBA, GL_RGBA_INTEGER ...)
|
protected |
Internal format as defined by OpenGL (ex. GL_RGBA, GL_RGBA32F ...).
|
protected |
Flag to indicate if buffer is binded or not.
In operations where the buffer needs to be binded (such as read, clear, etc) it will be automatically binded and then unbided if flag is not currently binded, otherwise, if it was already binded, it will be left binded.
|
protected |
Number of samples (for multisampling)
|
protected |
Pixel type (GL_FLOAT, GL_UNSIGNED_INT ...)
|
protected |
Framebuffer dimensions.
|
protected |
Texture type for framebuffer attachments, default is GL_TEXTURE_2D.