Vp::Framebuffer
A utility class for managing an OpenGL FrameBufferObject. More...
#include "Viewport/framebuffer/Framebuffer.h"
Inherits from std::enable_shared_from_this< Framebuffer >
Public Functions
Name | |
---|---|
Framebuffer * | createDefault(bool multisample, unsigned int samples, bool alpha)<br>Create a basic framebuffer with a single color attachment and a depth-stencil buffer. |
Framebuffer * | createDefault(int width, int height, bool multisample, unsigned int samples, bool alpha)<br>Create a basic framebuffer with a single color attachment and a depth-stencil buffer. |
Framebuffer()<br>Create an empty framebuffer. | |
Framebuffer(bool multisample, unsigned int samples)<br>Create an empty framebuffer. | |
Framebuffer(int width, int height)<br>Create an empty framebuffer. | |
Framebuffer(int width, int height, bool multisample, unsigned int samples)<br>Create an empty framebuffer. | |
~Framebuffer() | |
void | addColorAttachment(ColorAttachment colorAttachment)<br>Add a color attachment. |
void | bind() const<br>Binds the FBO. |
void | dispose()<br>Frees up all OpenGL resources used by the framebuffer. |
void | end(bool resolveMultisample =true)<br>Finalizes the FBO and unbinds it. |
ColorAttachment & | getColorAttachment(unsigned int index) |
GLuint | getColorTexture(unsigned int index =0, bool multisampled =false) const<br>Returns the id of the color texture. |
std::optional< DepthAttachment > & | getDepthAttachment() |
int | getHeight() const |
GLuint | getId() const |
std::weak_ptr< Framebuffer > | getResolvedFramebuffer()<br>If this framebuffer is multisampled this methods returns a weak pointer to the internal single sampled framebuffer that was used to resolve it. |
unsigned int | getSampleCount() const |
int | getWidth() const |
bool | isInitialized() const |
bool | isMultisampled() |
void | multisampleResolveColor(unsigned int colorAttachmentIndex)<br>The DEFAULT (0) frame buffer is bound after this call! |
void | multisampleResolveColors()<br>The DEFAULT (0) frame buffer is bound after this call! |
void | multisampleResolveDepth()<br>The DEFAULT (0) frame buffer is bound after this call! |
void | recreate()<br>Completely reinitializes the framebuffer. |
void | removeAllColorAttachments() |
void | removeDepthAttachment() |
void | setDepthAttachment(DepthAttachment depthAttachment)<br>Set a depth attachment. |
void | setDrawBuffers() |
void | setDrawBuffers(std::vector< unsigned int > indices) |
void | setMultisampled(bool multisample, unsigned int samples) |
void | start()<br>Binds the FBO, clears it and resizes glViewport. |
void | start(int width, int height)<br>Binds the FBO and resizes glViewport. |
void | update(int width, int height)<br>Ensure the fbo has the specified size. |
Detailed Description
class Vp::Framebuffer;
class Vp::Framebuffer;
A utility class for managing an OpenGL FrameBufferObject.
Usage:
- //Create fbo object
- fbo.start(); //The fbo is lazily initialized here if necessary
- //Render stuff
- fbo.end(); //The fbo is unbound by BINDING THE DEFAULT (0) FRAMEBUFFER!
- //Multisampling is resolved here unless fbo.end(false) is called
- //Get color texture using fbo.getColorTexture()
Supports multi sampled antialiasing (MSAA) which can be enabled in the constructor. When MSAA is enabled, the framebuffer creates a second intermediate framebuffer instance which is used to "resolve" the multisampled framebuffer into a regular one.
Multisampled framebuffers with multiple color attachments are also supported. In that case the intermediate framebuffer creates equivalent single-sampled color attachment(s) for each multisampled one.
Note that the framebuffer sampling settings overwrite any attachment settings as all attachments must have the same sample count and either be all multisampled or none.
After resolving multisampling the resolved framebuffer can be accessed using getResolvedFramebuffer() and further used.
Public Functions Documentation
function createDefault
static Framebuffer * createDefault(
bool multisample,
unsigned int samples,
bool alpha
)
static Framebuffer * createDefault(
bool multisample,
unsigned int samples,
bool alpha
)
Create a basic framebuffer with a single color attachment and a depth-stencil buffer.
Parameters:
- multisample Whether MSAA should be enabled
- samples Amount of MSAA samples
- alpha Whether the color buffer should have an alpha component
Return: Raw unmanaged pointer to the newly created Framebuffer.
function createDefault
static Framebuffer * createDefault(
int width,
int height,
bool multisample,
unsigned int samples,
bool alpha
)
static Framebuffer * createDefault(
int width,
int height,
bool multisample,
unsigned int samples,
bool alpha
)
Create a basic framebuffer with a single color attachment and a depth-stencil buffer.
Parameters:
- width Width of the framebuffer in pixels
- height Height of the framebuffer in pixels
- multisample Whether MSAA should be enabled
- samples Amount of MSAA samples
- alpha Whether the color buffer should have an alpha component
Return: Raw unmanaged pointer to the newly created Framebuffer.
function Framebuffer
Framebuffer()
Framebuffer()
Create an empty framebuffer.
function Framebuffer
Framebuffer(
bool multisample,
unsigned int samples
)
Framebuffer(
bool multisample,
unsigned int samples
)
Create an empty framebuffer.
Parameters:
- multisample Whether MSAA should be enabled
- samples Amount of MSAA samples
function Framebuffer
Framebuffer(
int width,
int height
)
Framebuffer(
int width,
int height
)
Create an empty framebuffer.
Parameters:
- width Width of the framebuffer in pixels
- height Height of the framebuffer in pixels
function Framebuffer
Framebuffer(
int width,
int height,
bool multisample,
unsigned int samples
)
Framebuffer(
int width,
int height,
bool multisample,
unsigned int samples
)
Create an empty framebuffer.
Parameters:
- width Width of the framebuffer in pixels
- height Height of the framebuffer in pixels
- multisample Whether MSAA should be enabled
- samples Amount of MSAA samples
function ~Framebuffer
~Framebuffer()
~Framebuffer()
function addColorAttachment
void addColorAttachment(
ColorAttachment colorAttachment
)
void addColorAttachment(
ColorAttachment colorAttachment
)
Add a color attachment.
Parameters:
- colorAttachment
Color attachment index is set to its current order in the color attachments list. Multisampling settings are synced with the framebuffer multisampling settings.
Note that color attachments are meant to be setup before using the framebuffer.
function bind
void bind() const
void bind() const
Binds the FBO.
function dispose
void dispose()
void dispose()
Frees up all OpenGL resources used by the framebuffer.
The framebuffer is considered uninitialized after this call.
function end
void end(
bool resolveMultisample =true
)
void end(
bool resolveMultisample =true
)
Finalizes the FBO and unbinds it.
Parameters:
- resolveMultisample If the fbo is multisampled and this argument is true this call resolves the multisampled buffer into an intermediate regular (single sampled) one. Whose color texture is then returned via getColorTexture(). Note that only the first (index 0) color attachment gets resolved by this call. To resolve multiple color buffers or the depth buffer you can use the multisampleResolveXXX() methods.
The DEFAULT (0) frame buffer is bound after this call!
function getColorAttachment
ColorAttachment & getColorAttachment(
unsigned int index
)
ColorAttachment & getColorAttachment(
unsigned int index
)
function getColorTexture
GLuint getColorTexture(
unsigned int index =0,
bool multisampled =false
) const
GLuint getColorTexture(
unsigned int index =0,
bool multisampled =false
) const
Returns the id of the color texture.
Parameters:
- index Optional index of the color attachment
- multisampled Optional flag specifying if the multisampled or resolved single sampled texture should be returned. If multisampling is disabled the single sampled texture will be always returned.
function getDepthAttachment
std::optional< DepthAttachment > & getDepthAttachment()
std::optional< DepthAttachment > & getDepthAttachment()
function getHeight
int getHeight() const
int getHeight() const
function getId
GLuint getId() const
GLuint getId() const
Return: The id of the Frame Buffer Object
function getResolvedFramebuffer
std::weak_ptr< Framebuffer > getResolvedFramebuffer()
std::weak_ptr< Framebuffer > getResolvedFramebuffer()
If this framebuffer is multisampled this methods returns a weak pointer to the internal single sampled framebuffer that was used to resolve it.
Otherwise it just returns a weak pointer to itself.
function getSampleCount
unsigned int getSampleCount() const
unsigned int getSampleCount() const
function getWidth
int getWidth() const
int getWidth() const
function isInitialized
bool isInitialized() const
bool isInitialized() const
function isMultisampled
bool isMultisampled()
bool isMultisampled()
function multisampleResolveColor
void multisampleResolveColor(
unsigned int colorAttachmentIndex
)
void multisampleResolveColor(
unsigned int colorAttachmentIndex
)
The DEFAULT (0) frame buffer is bound after this call!
function multisampleResolveColors
void multisampleResolveColors()
void multisampleResolveColors()
The DEFAULT (0) frame buffer is bound after this call!
function multisampleResolveDepth
void multisampleResolveDepth()
void multisampleResolveDepth()
The DEFAULT (0) frame buffer is bound after this call!
function recreate
void recreate()
void recreate()
Completely reinitializes the framebuffer.
All associated OpenGL resources are freed and can no longer be used. New resources are allocated.
function removeAllColorAttachments
void removeAllColorAttachments()
void removeAllColorAttachments()
function removeDepthAttachment
void removeDepthAttachment()
void removeDepthAttachment()
function setDepthAttachment
void setDepthAttachment(
DepthAttachment depthAttachment
)
void setDepthAttachment(
DepthAttachment depthAttachment
)
Set a depth attachment.
Parameters:
- depthAttachment
Multisampling settings are synced with the framebuffer multisampling settings.
function setDrawBuffers
void setDrawBuffers()
void setDrawBuffers()
function setDrawBuffers
void setDrawBuffers(
std::vector< unsigned int > indices
)
void setDrawBuffers(
std::vector< unsigned int > indices
)
function setMultisampled
void setMultisampled(
bool multisample,
unsigned int samples
)
void setMultisampled(
bool multisample,
unsigned int samples
)
function start
void start()
void start()
Binds the FBO, clears it and resizes glViewport.
The FBO is also initialised if necessary. Uses previously set width and height. **Don't forget to call glClear after this call!**glViewport is set to the fbo's dimensions.
function start
void start(
int width,
int height
)
void start(
int width,
int height
)
Binds the FBO and resizes glViewport.
The FBO is also initialised if necessary. **Don't forget to call glClear after this call!**glViewport is set to the fbo's dimensions.
function update
void update(
int width,
int height
)
void update(
int width,
int height
)
Ensure the fbo has the specified size.
Fbo is initialized and/or resized accordingly. Has no effect if fbo is already initialized and sized as requested.
Updated on 2024-11-06 at 20:16:53 +0000