glpp::core::object::framebuffer_t class

class for creating and managing framebuffers in OpenGL

framebuffer_t is a storage class for OpenGL framebuffers, that creates, owns and manages framebuffers objects. Framebuffers can be used to render to textures or copy rendered frames to cpu memory.

Public static functions

static void bind_default_framebuffer(framebuffer_target_t target = framebuffer_target_t::read_and_write)
bind default framebuffer

Constructors, destructors, conversion operators

framebuffer_t(size_t width, size_t height)
constructor
framebuffer_t(std::initializer_list<std::pair<const texture_t&, attachment_t>> list) explicit
constructor
framebuffer_t(const framebuffer_t& cpy) deleted
copy constructor
framebuffer_t(framebuffer_t&& mov) defaulted
move constructor

Public functions

void attach(const texture_t& texture, attachment_t attatchment)
attatch texture to framebuffer
void bind(framebuffer_target_t target = framebuffer_target_t::read_and_write)
bind framebuffer
auto height() const -> size_t
get height
auto operator=(const framebuffer_t& cpy) -> framebuffer_t& deleted
copy assignment operator
auto operator=(framebuffer_t&& mov) -> framebuffer_t& defaulted
move assignment operator
template<class T = glm::vec3>
auto pixel_read(size_t x = 0, size_t y = 0) const -> image_t<T>
template<class T = glm::vec3>
auto pixel_read(size_t x, size_t y, size_t width, size_t height) const -> image_t<T>
auto width() const -> size_t
get width

Function documentation

static void glpp::core::object::framebuffer_t::bind_default_framebuffer(framebuffer_target_t target = framebuffer_target_t::read_and_write)

bind default framebuffer

Parameters
target [in] target that shall be bound

Make default framebuffer active. If write or read_and_write is passed as target, following draw calls will be rendered to the screen.

glpp::core::object::framebuffer_t::framebuffer_t(size_t width, size_t height)

constructor

Parameters
width [in] width of framebuffer in pixels
height [in] height of framebuffer in pixels

Create an empty framebuffer with no texture attatchments.

glpp::core::object::framebuffer_t::framebuffer_t(std::initializer_list<std::pair<const texture_t&, attachment_t>> list) explicit

constructor

Parameters
list [in] list of texture attatchments

Create an empty framebuffer with a list of texture attatchents. The width and height of the framebuffer is deduced from the textures that shall be attatched. All textures must have the same width and height.

glpp::core::object::framebuffer_t::framebuffer_t(const framebuffer_t& cpy) deleted

copy constructor

Framebuffer objects are not copy-constructible.

glpp::core::object::framebuffer_t::framebuffer_t(framebuffer_t&& mov) defaulted

move constructor

Framebuffer objects are move-constructible. Constructs a framebuffer_t object using contents of mov. After move the mov object is in an invalid state. All access other then destruction and reassignment will be undefined behaviour.

void glpp::core::object::framebuffer_t::attach(const texture_t& texture, attachment_t attatchment)

attatch texture to framebuffer

Parameters
texture [in] texture object that shall be attatched
attatchment [in] channel which shall be rendered to texture

This functions will attatch a texture object to the framebuffer. Following rendering to this framebuffer will render the contents of the specified attatchment into the texture object. Width and height of the attatched texture must match the width and height of the framebuffer.

void glpp::core::object::framebuffer_t::bind(framebuffer_target_t target = framebuffer_target_t::read_and_write)

bind framebuffer

Parameters
target [in] target hint

Bind framebuffer to OpenGL context. If write or read_and_write is used as target, all following draw calls will be rendered into this framebuffer object or into assigned texture objects.

size_t glpp::core::object::framebuffer_t::height() const

get height

Returns height of framebuffer in pixels

framebuffer_t& glpp::core::object::framebuffer_t::operator=(const framebuffer_t& cpy) deleted

copy assignment operator

Framebuffer objects are not copy-assignable.

framebuffer_t& glpp::core::object::framebuffer_t::operator=(framebuffer_t&& mov) defaulted

move assignment operator

Framebuffer objects are move-assignable. Constructs a framebuffer_t object using contents of mov. After move the mov object is in an invalid state. All access other then destruction and reassignment will be undefined behaviour.

template<class T = glm::vec3>
image_t<T> glpp::core::object::framebuffer_t::pixel_read(size_t x = 0, size_t y = 0) const

Parameters
x [in] left border of rendered screen
y [in] bottom border of rendered screen

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function will copy a subimage of the framebuffer into cpu memory. [x, y] are the left and top border. The subimage will be widht and height pixels wide. x+widht must be smaller or equal to the widht of the framebuffer. y+height must be smaller or equal to the height of the framebuffer.

template<class T = glm::vec3>
image_t<T> glpp::core::object::framebuffer_t::pixel_read(size_t x, size_t y, size_t width, size_t height) const

Parameters
x [in] left border of rendered screen
y [in] bottom border of rendered screen
width [in] width of rendered screen
height [in] height of rendered screen

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function will copy a subimage of the framebuffer into cpu memory. [x, y] are the left and top border. The subimage will be widht and height pixels wide. x+widht must be smaller or equal to the widht of the framebuffer. y+height must be smaller or equal to the height of the framebuffer.

size_t glpp::core::object::framebuffer_t::width() const

get width

Returns width of framebuffer in pixels