GLS
1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
|
Class encapsulating an OpenGL framebuffer object. More...
#include <framebuffer.hpp>
Public Member Functions | |
GLuint | name () const |
Retrieve the OpenGL name of this framebuffer. More... | |
void | bind () |
Bind this framebuffer to the GL_FRAMEBUFFER target. More... | |
void | attach_texture (GLenum attachment, GLenum textarget, const texture< GL_TEXTURE_CUBE_MAP > &the_texture, GLint level) |
Attach a non-array cubemap to the given attachment. More... | |
template<GLenum Target> | |
void | attach_texture (GLenum attachment, const texture< Target > &the_texture, GLint level) |
Attach a texture to the given attachment. More... | |
template<GLenum Target> | |
void | attach_texture_layer (GLenum attachment, const texture< Target > &the_texture, GLint level, GLint layer) |
Attach a texture layer to the given attachment. More... | |
void | detach_texture (GLenum attachment) |
Clear a texture attachment. More... | |
void | add_renderbuffer (GLenum attachment, renderbuffer &&the_renderbuffer) |
Attach a renderbuffer to the given attachment. More... | |
void | remove_renderbuffer (GLenum attachment) |
Clear a renderbuffer attachment. More... | |
GLenum | status () |
Check the status of the framebuffer. More... | |
bool | complete () |
Check if the framebuffer is complete. More... | |
Static Public Member Functions | |
static void | unbind () |
Unbind the framebuffer currently bound to the GL_FRAMEBUFFER target. More... | |
Class encapsulating an OpenGL framebuffer object.
A gls::framebuffer is an object that encapsulates an OpenGL framebuffer object.
Like all objects in GLS, the underlying name is generated at object construction and deleted at destruction. This can be retrieved with name().
WARNING: Unlike other OpenGL objects, framebuffer objects are not shareable between contexts. As such, a gls::framebuffer object is only valid for use within the context where it was constructed. No checks are made to ensure it is used properly. If strange behaviour occurs, be sure to check the reported OpenGL errors in a debug configuration and assure you are not transferring the gls::framebuffer between contexts.
Framebuffer objects are the primary way of rendering to an offscreen surface on hardware that supports it. By default, i.e. when 0 is bound to GL_FRAMEBUFFER all draw commands affect the default framebuffer, typically the back buffer in double buffered applications. To draw to a framebuffer object instead, it has to be bound. All draw commands that are issued while it is bound will affect the framebuffer and its attachments. Once you want to draw to the back buffer once again, simply unbind the framebuffer.
The framebuffer attachments represent surfaces on which draw commands will have an affect. The depth attachment will have depth values written to it while the colour attachments will have colour values written to it and so on. The storage for these attachments comes either from standard texture objects or, since texture objects cannot store non-colour values, renderbuffer objects. The gls::framebuffer object will take ownership of any gls::renderbuffer objects that are attached to it. After all draw commands affecting the framebuffer have completed, one can use the attached texture objects much like one would use any other texture object. Just beware of feedback loops.
After assembling a framebuffer from its attachments and before rendering to it, it is always a good idea to check whether it is complete. This can be done simply by calling complete(). If it is incomplete, calling status() will return the reason for its incompleteness.
To render to a gls::framebuffer, simply call bind(). It will bind the gls::framebuffer to the GL_FRAMEBUFFER binding and replace any previously bound to that target. To clear the GL_FRAMEBUFFER binding and render to the back buffer again, call unbind().
Example usage:
GLuint name | ( | ) | const |
Retrieve the OpenGL name of this framebuffer.
void bind | ( | ) |
Bind this framebuffer to the GL_FRAMEBUFFER target.
If you want to bind this framebuffer to a target other than GL_FRAMEBUFFER, you can always do this manually with:
|
static |
Unbind the framebuffer currently bound to the GL_FRAMEBUFFER target.
If you want to unbind a framebuffer that is bound to a target other than GL_FRAMEBUFFER, you can always do this manually with:
void attach_texture | ( | GLenum | attachment, |
GLenum | textarget, | ||
const texture< GL_TEXTURE_CUBE_MAP > & | the_texture, | ||
GLint | level | ||
) |
Attach a non-array cubemap to the given attachment.
attachment | Attachment to attach to |
textarget | Cubemap texture target (GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, etc.) |
the_texture | The cubemap texture to attach |
level | Level of the cubemap texture to attach |
void attach_texture | ( | GLenum | attachment, |
const texture< Target > & | the_texture, | ||
GLint | level | ||
) |
Attach a texture to the given attachment.
attachment | Attachment to attach to |
the_texture | The texture to attach |
level | Level of the texture to attach |
void attach_texture_layer | ( | GLenum | attachment, |
const texture< Target > & | the_texture, | ||
GLint | level, | ||
GLint | layer | ||
) |
Attach a texture layer to the given attachment.
attachment | Attachment to attach to |
the_texture | The texture to attach |
level | Level of the texture to attach |
layer | Layer of the texture to attach |
void detach_texture | ( | GLenum | attachment | ) |
Clear a texture attachment.
attachment | Attachment to detach a texture from |
void add_renderbuffer | ( | GLenum | attachment, |
renderbuffer && | the_renderbuffer | ||
) |
Attach a renderbuffer to the given attachment.
Note: This method requires that you transfer ownership (i.e. std::move or equivalent) of the renderbuffer to the framebuffer. It will be destroyed either when the attachment is cleared or the gls::framebuffer is destroyed.
attachment | Attachment to attach to |
the_renderbuffer | The renderbuffer to attach |
void remove_renderbuffer | ( | GLenum | attachment | ) |
Clear a renderbuffer attachment.
attachment | Attachment to detach a renderbuffer from |
GLenum status | ( | ) |
Check the status of the framebuffer.
bool complete | ( | ) |
Check if the framebuffer is complete.