Skip to content

Class FrameBuffer

ClassList > FrameBuffer

OpenGL framebuffer wrapper with multi-target and dynamic resize support. More...

  • #include <FrameBuffer.h>

Public Attributes

Type Name
std::vector< Texture > fb_tex_list
Textures for color attachments.
std::optional< RenderBuffer > renderBuffer
Optional depth/stencil renderbuffer.

Public Functions

Type Name
void AppendTexture (const Texture & _tex, FBType _type)
Appends a new texture attachment.
void BindFrameBuffer () const
Binds this framebuffer for rendering.
void BindFrameBufferTex (int count=0, ...) const
Binds multiple framebuffer textures for shader sampling (variadic).
void BindFrameBufferTex (const std::vector< FBType > & _tars) const
Binds multiple framebuffer textures for shader sampling (vector).
void BindFrameBufferTex (FBType tar, GLuint slot) const
Binds a single framebuffer texture to a shader slot.
void BindFrameBufferTexR (FBType tar, GLuint slot) const
Binds a single framebuffer texture for reading.
FrameBuffer ()
Default constructor (empty framebuffer).
FrameBuffer (FBType type, GLuint attach=0)
Constructs a single-target framebuffer.
FrameBuffer (int count, ...)
Constructs a multi-target framebuffer (compile-time list).
FrameBuffer (const std::vector< FBType > & _tars)
Constructs a multi-target framebuffer (runtime list).
FrameBuffer (Texture && _depth)
Constructs a depth-only framebuffer.
FrameBuffer (const FrameBuffer & fb)
Copy constructor. Performs a GPU-side deep copy.
FrameBuffer (FrameBuffer && fb) noexcept
Move constructor (transfers ownership).
GLuint GetAttachmentLoc (FBType type) const
Returns attachment location for a given type.
size_t GetFBCount () const
Returns number of color attachments.
GLuint GetFBTextureID (FBType type) const
Returns OpenGL texture ID for a given type.
Texture * GetFBTexturePtr (FBType type) const
Returns pointer to texture for a given type.
GLuint GetFrameBufferID () const
Returns OpenGL framebuffer object ID.
glm::vec2 GetFrameBufferSize () const
Returns framebuffer dimensions.
glm::vec2 GetSize () const
Returns current framebuffer dimensions.
void LinkTexture (const Texture & _tex)
Links an existing texture to this framebuffer.
FBPixel ReadPix (GLuint x, GLuint y, FBType type) const
Reads a pixel from the specified attachment.
void Resize (const glm::vec2 & size, bool all=false)
Resizes all or selected attachments.
void Resize (GLuint w, GLuint h, bool all=false)
Resizes all or selected attachments.
void UnbindFrameBufferTex () const
Unbinds all framebuffer textures.
void UnbindFrameBufferTexR (FBType tar, GLuint slot) const
Unbinds a framebuffer texture from reading.
FrameBuffer & operator= (const FrameBuffer & fb)
Copy assignment operator.
FrameBuffer & operator= (FrameBuffer && fb) noexcept
Move assignment operator.
~FrameBuffer ()
Destructor. Releases all OpenGL resources.

Public Static Functions

Type Name
void UnbindFrameBuffer ()
Unbinds the current framebuffer (binds default FBO 0).

Detailed Description

FrameBuffer encapsulates OpenGL FBO with multiple color attachments and optional depth buffer. Supports deferred rendering by binding multiple targets simultaneously.

Features: * Multiple color attachments (up to GL_MAX_COLOR_ATTACHMENTS) * Optional depth/stencil via RenderBuffer * Dynamic resizing of all attachments * Texture binding for shader sampling * Pixel readback for picking

Note:

Thread-safety: Not thread-safe. Must be used from OpenGL context thread.

Note:

Ownership: Owns OpenGL FBO and textures. Cleans up in destructor.

Public Attributes Documentation

variable fb_tex_list

Textures for color attachments.

std::vector<Texture> FrameBuffer::fb_tex_list;


variable renderBuffer

Optional depth/stencil renderbuffer.

std::optional<RenderBuffer> FrameBuffer::renderBuffer;


Public Functions Documentation

function AppendTexture

Appends a new texture attachment.

void FrameBuffer::AppendTexture (
    const Texture & _tex,
    FBType _type
) 

Parameters:

  • _tex Texture to append
  • _type FBType for this attachment

function BindFrameBuffer

Binds this framebuffer for rendering.

void FrameBuffer::BindFrameBuffer () const

Note:

Subsequent draw calls render to this FBO


function BindFrameBufferTex [1/3]

Binds multiple framebuffer textures for shader sampling (variadic).

void FrameBuffer::BindFrameBufferTex (
    int count=0,
    ...
) const

Parameters:

  • count Number of FBType arguments
  • ... Variadic FBType arguments

function BindFrameBufferTex [2/3]

Binds multiple framebuffer textures for shader sampling (vector).

void FrameBuffer::BindFrameBufferTex (
    const std::vector< FBType > & _tars
) const

Parameters:

  • _tars Vector of FBType to bind

function BindFrameBufferTex [3/3]

Binds a single framebuffer texture to a shader slot.

void FrameBuffer::BindFrameBufferTex (
    FBType tar,
    GLuint slot
) const

Parameters:

  • tar FBType to bind
  • slot Texture unit (GL_TEXTURE0 + slot)

function BindFrameBufferTexR

Binds a single framebuffer texture for reading.

void FrameBuffer::BindFrameBufferTexR (
    FBType tar,
    GLuint slot
) const

Parameters:

  • tar FBType to bind
  • slot Texture unit

function FrameBuffer [1/7]

Default constructor (empty framebuffer).

FrameBuffer::FrameBuffer () 


function FrameBuffer [2/7]

Constructs a single-target framebuffer.

FrameBuffer::FrameBuffer (
    FBType type,
    GLuint attach=0
) 

Parameters:

  • type Framebuffer type for the single attachment
  • attach Attachment index (default: 0)

function FrameBuffer [3/7]

Constructs a multi-target framebuffer (compile-time list).

FrameBuffer::FrameBuffer (
    int count,
    ...
) 

Parameters:

  • count Number of framebuffer types
  • ... Variadic FBType arguments

function FrameBuffer [4/7]

Constructs a multi-target framebuffer (runtime list).

FrameBuffer::FrameBuffer (
    const std::vector< FBType > & _tars
) 

Parameters:

  • _tars Vector of FBType targets

function FrameBuffer [5/7]

Constructs a depth-only framebuffer.

FrameBuffer::FrameBuffer (
    Texture && _depth
) 

Parameters:

  • _depth Depth texture (moved into framebuffer)

function FrameBuffer [6/7]

Copy constructor. Performs a GPU-side deep copy.

FrameBuffer::FrameBuffer (
    const FrameBuffer & fb
) 

Allocates a new FBO and deep-copies all attached textures and the optional depth/stencil renderbuffer. The resulting FrameBuffer is fully independent of the source.

Parameters:

  • fb Source framebuffer.

function FrameBuffer [7/7]

Move constructor (transfers ownership).

FrameBuffer::FrameBuffer (
    FrameBuffer && fb
) noexcept

Parameters:

  • fb Source framebuffer (invalidated)

function GetAttachmentLoc

Returns attachment location for a given type.

inline GLuint FrameBuffer::GetAttachmentLoc (
    FBType type
) const

Parameters:

  • type FBType to query

Returns:

Attachment index


function GetFBCount

Returns number of color attachments.

inline size_t FrameBuffer::GetFBCount () const

Returns:

Attachment count


function GetFBTextureID

Returns OpenGL texture ID for a given type.

inline GLuint FrameBuffer::GetFBTextureID (
    FBType type
) const

Parameters:

  • type FBType to query

Returns:

Texture ID


function GetFBTexturePtr

Returns pointer to texture for a given type.

inline Texture * FrameBuffer::GetFBTexturePtr (
    FBType type
) const

Parameters:

  • type FBType to query

Returns:

Non-owning pointer to Texture


function GetFrameBufferID

Returns OpenGL framebuffer object ID.

inline GLuint FrameBuffer::GetFrameBufferID () const

Returns:

FBO ID


function GetFrameBufferSize

Returns framebuffer dimensions.

inline glm::vec2 FrameBuffer::GetFrameBufferSize () const

Returns:

Size (width, height)


function GetSize

Returns current framebuffer dimensions.

inline glm::vec2 FrameBuffer::GetSize () const

Returns:

Size (width, height)


function LinkTexture

Links an existing texture to this framebuffer.

void FrameBuffer::LinkTexture (
    const Texture & _tex
) 

Parameters:


function ReadPix

Reads a pixel from the specified attachment.

FBPixel FrameBuffer::ReadPix (
    GLuint x,
    GLuint y,
    FBType type
) const

Parameters:

  • x Pixel x coordinate
  • y Pixel y coordinate
  • type FBType to read from

Returns:

Pixel data (RGBA float)

Note:

Used for object picking via ID buffer


function Resize [1/2]

Resizes all or selected attachments.

void FrameBuffer::Resize (
    const glm::vec2 & size,
    bool all=false
) 

Parameters:

  • size New size (width, height)
  • all If true, resize all textures; otherwise only depth

function Resize [2/2]

Resizes all or selected attachments.

void FrameBuffer::Resize (
    GLuint w,
    GLuint h,
    bool all=false
) 

Parameters:

  • w New width in pixels
  • h New height in pixels
  • all If true, resize all textures; otherwise only depth

function UnbindFrameBufferTex

Unbinds all framebuffer textures.

void FrameBuffer::UnbindFrameBufferTex () const


function UnbindFrameBufferTexR

Unbinds a framebuffer texture from reading.

void FrameBuffer::UnbindFrameBufferTexR (
    FBType tar,
    GLuint slot
) const

Parameters:

  • tar FBType to unbind
  • slot Texture unit

function operator=

Copy assignment operator.

FrameBuffer & FrameBuffer::operator= (
    const FrameBuffer & fb
) 

Parameters:

  • fb Source framebuffer

Returns:

Reference to this


function operator=

Move assignment operator.

FrameBuffer & FrameBuffer::operator= (
    FrameBuffer && fb
) noexcept

Parameters:

  • fb Source framebuffer (invalidated)

Returns:

Reference to this


function ~FrameBuffer

Destructor. Releases all OpenGL resources.

FrameBuffer::~FrameBuffer () 


Public Static Functions Documentation

function UnbindFrameBuffer

Unbinds the current framebuffer (binds default FBO 0).

static void FrameBuffer::UnbindFrameBuffer () 



The documentation for this class was generated from the following file src/render/buffers/FrameBuffer.h