Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::render::Framebuffer Class Reference

#include <OxygenEngine/render/framebuffer.h>

Public Member Functions

 Framebuffer (const glm::ivec2 &dimensions)
 
 Framebuffer (const uint32_t width, const uint32_t height)
 
std::shared_ptr< TextureaddColorAttachment (const uint32_t attachment_level=0, const uint32_t internal_format=0, const uint32_t format=0, const uint32_t type=0, const uint32_t filter=0, const uint8_t max_mips=1)
 
void addDepthAttachment (const uint32_t format=0, const uint32_t type=0, const uint32_t filter=0)
 
void setDepthAttachment (std::shared_ptr< Texture > texture)
 
void setTextureAttachment (const uint32_t attachment_level, std::shared_ptr< Texture > texture, const int32_t mip_level=0)
 
void clearContents (const glm::vec4 &color=glm::vec4(0.f), const int &target=0)
 
void beginRender (const bool resize_viewport=true)
 
void endRender ()
 
 operator bool ()
 
const std::shared_ptr< Texture > & getColorAttachment (const uint32_t attachment_level) const
 
const std::shared_ptr< Texture > & getDepthAttachment () const
 
void blitFrom (const Framebuffer *src, const glm::ivec4 &src_bounds=glm::ivec4(0), const glm::ivec4 &target_bounds=glm::ivec4(0), const TargetBuffer &type=TargetBuffer::ALL, const uint8_t color_attachment_src=0, const uint8_t color_attachment_dest=0, const bool usefilter=false)
 
void blitTo (Framebuffer *target, const glm::ivec4 &src_bounds=glm::ivec4(0), const glm::ivec4 &target_bounds=glm::ivec4(0), const TargetBuffer &type=TargetBuffer::ALL, const uint8_t color_attachment_src=0, const uint8_t color_attachment_dest=0, const bool usefilter=false) const
 
void copyFrom (Framebuffer *source, const TargetBuffer &type=TargetBuffer::ALL)
 
void blitToDefault (const uint8_t color_attachment_src=0, const bool &usefilter=false) const
 
glm::ivec2 getDimensions () const noexcept
 

Detailed Description

Wrapper around framebuffer operations

Example usage:

Framebuffer fb(800, 600);
fb.addColorAttachment(0);
fb.addDepthAttachment();
// Ensure framebuffer is valid
assert(fb);
fb.beginRender();
// Clear color and depth buffers (example, set the background to grey)
fb.clearContents(glm::vec4(glm::vec3(0.5), 1.0));
// Your other OpenGL render calls
...
fb.endRender();
Definition framebuffer.h:43

Member Function Documentation

◆ addColorAttachment()

std::shared_ptr< Texture > oe::render::Framebuffer::addColorAttachment ( const uint32_t  attachment_level = 0,
const uint32_t  internal_format = 0,
const uint32_t  format = 0,
const uint32_t  type = 0,
const uint32_t  filter = 0,
const uint8_t  max_mips = 1 
)

Generate a color texture to the framebuffer

Parameters
attachment_levelthe attachment level to use

◆ addDepthAttachment()

void oe::render::Framebuffer::addDepthAttachment ( const uint32_t  format = 0,
const uint32_t  type = 0,
const uint32_t  filter = 0 
)

Generate a depth attachment to the framebuffer

Note
If no parameters provided, a renderbuffer will be generated instead a texture (the rbo is more optimized but you won't be able to sample it)

◆ beginRender()

void oe::render::Framebuffer::beginRender ( const bool  resize_viewport = true)

Begin rendering operations on this framebuffer

◆ blitFrom()

void oe::render::Framebuffer::blitFrom ( const Framebuffer src,
const glm::ivec4 &  src_bounds = glm::ivec4(0),
const glm::ivec4 &  target_bounds = glm::ivec4(0),
const TargetBuffer &  type = TargetBuffer::ALL,
const uint8_t  color_attachment_src = 0,
const uint8_t  color_attachment_dest = 0,
const bool  usefilter = false 
)

Copy a portion of a framebuffer to this one

Parameters
srcsource framebuffer to get blit data
src_boundsblit source bounds (from src)
target_boundsblit target bounds (on this one)
typea TargetBuffer target to copy
color_attachment_srcIf type contains the color buffer, src attachment layer to fetch
color_attachment_destIf type contains the color buffer, this framebuffer attachment layer to write
usefilterIf bounds are not the same size, do we need to use a linear filter

◆ blitTo()

void oe::render::Framebuffer::blitTo ( Framebuffer target,
const glm::ivec4 &  src_bounds = glm::ivec4(0),
const glm::ivec4 &  target_bounds = glm::ivec4(0),
const TargetBuffer &  type = TargetBuffer::ALL,
const uint8_t  color_attachment_src = 0,
const uint8_t  color_attachment_dest = 0,
const bool  usefilter = false 
) const

Copy a portion of this framebuffer to another one

Parameters
targettarget framebuffer to blit data
src_boundsblit source bounds (from this one)
target_boundsblit target bounds (on target)
typeTargetBuffer target to copy
color_attachment_srcIf type contains the color buffer, this attachment layer to fetch
color_attachment_destIf type contains the color buffer, target framebuffer attachment layer to write
usefilterIf bounds are not the same size, do we need to use a linear filter

◆ blitToDefault()

void oe::render::Framebuffer::blitToDefault ( const uint8_t  color_attachment_src = 0,
const bool &  usefilter = false 
) const

Handy function to copy this framebuffer to default framebuffer

Parameters
color_attachment_srcAttachment layer to fetch
usefilterIf bounds are not the same size, do we need to use a linear filter

◆ clearContents()

void oe::render::Framebuffer::clearContents ( const glm::vec4 &  color = glm::vec4(0.f),
const int &  target = 0 
)

Clear the framebuffer contents with a color

◆ copyFrom()

void oe::render::Framebuffer::copyFrom ( Framebuffer source,
const TargetBuffer &  type = TargetBuffer::ALL 
)
inline

Copy all contents from source

Parameters
sourceSource framebuffer to get blit data
typeTargetBuffer target to copy

◆ endRender()

void oe::render::Framebuffer::endRender ( )

End rendering operations on this framebuffer

◆ getColorAttachment()

const std::shared_ptr< Texture > & oe::render::Framebuffer::getColorAttachment ( const uint32_t  attachment_level) const
inline

Get the color attachment texture

Parameters
attachment_levelthe attachment level to fetch (if not multitexturing used, set it to 0)

◆ getDepthAttachment()

const std::shared_ptr< Texture > & oe::render::Framebuffer::getDepthAttachment ( ) const
inline

Get the depth attachment texture

Note
nullptr returned if the framebuffer doesn't have depth or depth created with a renderbuffer

◆ getDimensions()

glm::ivec2 oe::render::Framebuffer::getDimensions ( ) const
inlinenoexcept

Get Framebuffer dimensions

◆ operator bool()

oe::render::Framebuffer::operator bool ( )

Check if the framebuffer is valid

◆ setDepthAttachment()

void oe::render::Framebuffer::setDepthAttachment ( std::shared_ptr< Texture texture)

Add a existing texture as the depth framebuffer

◆ setTextureAttachment()

void oe::render::Framebuffer::setTextureAttachment ( const uint32_t  attachment_level,
std::shared_ptr< Texture texture,
const int32_t  mip_level = 0 
)

Add a existing texture to the framebuffer

Parameters
attachment_levelthe attachment level to use (if not multitexturing used, set it to 0)
texturethe texture to use
mip_levelMIP MAP level of texture

The documentation for this class was generated from the following file: