![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/Framebuffer.h>
Wrapper class for OpenGL Framebuffer Objects (FBO). More...
Wrapper class for OpenGL Framebuffer Objects (FBO).
FBOs allow for using custom textures as framebuffer attachments so that you can render to them instead of rendering to the main screen.
To avoid confusion, GL::Framebuffer will synchronize the color attachment point Attachment::ColorI
with the fragment color location (location in glDrawBuffers()
array/fragment shader outputs). Thus, color attachment i
will always end up on draw buffer/fragment shader output location i
.
Example for rendering to texture:
the corresponding shader should be setup like this:
Public Types | |
enum class | Attachment { Color0 = 0x8CE0 , Color1 = 0x8CE1 , Color2 = 0x8CE2 , Color3 = 0x8CE3 , Color4 = 0x8CE4 , Color5 = 0x8CE5 , Color6 = 0x8CE6 , Color7 = 0x8CE7 , Depth = 0x8D00 , Stencil = 0x8D20 , DepthStencil = 0x821A } |
Enumeration of possible FBO attachment points. More... | |
Public Member Functions | |
Framebuffer () | |
Construct a new FBO. | |
~Framebuffer () | |
Destroy FBO. | |
void | bind () |
Bind FBO. | |
void | unbind () |
Unbind FBO, resets the bound FBO to 0. | |
bool | isBound () const |
Returns true if this framebuffer object is the current draw buffer. | |
StateGuard | guardedBind () |
Binds the FBO and returns a GlStateGuard to restore the FBO binding state before the call. | |
void | attach (Texture &texture, Attachment attachment, int mipmapLevel=0) |
Attach the given texture as a whole to this FBO. | |
void | attachLayer (Texture &texture, Attachment attachment, int layer, int mipmapLevel=0) |
Attach a single layer/slice of the given texture to this FBO. | |
void | attach (Texture &texture, int position=0) |
Convenience overload that auto-determines the position based on the texture's internal format. | |
void | detach (Attachment attachment) |
Detaches the texture at the given attachment point. | |
void | detachAll () |
Detaches all previously attached textures. | |
void | setDrawBuffers () |
Set draw buffers according to the attached color textures. | |
void | clearDrawBuffers () |
Clear draw buffers. | |
uint32_t | id () const |
Return the OpenGL name/id for the wrapped FBO. | |
Static Public Member Functions | |
static bool | isComplete () |
Check FBO status, will log the reason in case of errors and return false. | |
|
strong |
Enumeration of possible FBO attachment points.
Framebuffer | ( | ) |
Construct a new FBO.
std::runtime_error | if the corresponding OpenGL framebuffer object could not be created. |
void unbind | ( | ) |
Unbind FBO, resets the bound FBO to 0.
|
nodiscard |
Binds the FBO and returns a GlStateGuard to restore the FBO binding state before the call.
void attach | ( | Texture & | texture, |
Attachment | attachment, | ||
int | mipmapLevel = 0 ) |
Attach the given texture as a whole to this FBO.
texture | Texture to attach |
attachment | Attachment point |
mipmapLevel | Mipmap level of texture to attach |
void attachLayer | ( | Texture & | texture, |
Attachment | attachment, | ||
int | layer, | ||
int | mipmapLevel = 0 ) |
Attach a single layer/slice of the given texture to this FBO.
texture | Texture to attach, must be a 3D texture or an array texture. |
attachment | Attachment point |
layer | Layer/slice of texture to attach |
mipmapLevel | Mipmap level of texture to attach |
void attach | ( | Texture & | texture, |
int | position = 0 ) |
Convenience overload that auto-determines the position based on the texture's internal format.
texture | Texture to attach |
position | Ignored if texture has a depth or stencil format. Otherwise describes the index of the color attachment, i.e. attachment = (Color0 + position) . |