Skip to main content

RenderTarget Class

Represents a destination for rendering operations, such as a window's framebuffer. More...

Declaration

class helios::rendering::RenderTarget { ... }

Public Constructors Index

RenderTarget ()=default

Default constructor. More...

RenderTarget (std::shared_ptr< helios::rendering::Viewport > viewport, unsigned int width=0, unsigned int height=0)

Constructs a RenderTarget with an initial viewport and dimensions. More...

Public Member Functions Index

std::shared_ptr< helios::rendering::Viewport >addViewport (std::shared_ptr< helios::rendering::Viewport > viewport)

Adds a viewport to this render target and establishes a parent-child relationship. More...

std::span< const std::shared_ptr< helios::rendering::Viewport > >viewports () noexcept

Returns a read-only view of all viewports owned by this RenderTarget. More...

voidsetSize (unsigned int width, unsigned int height) noexcept

Resizes this RenderTarget to the specified dimensions and propagates the change to every viewport. More...

unsigned intwidth () const noexcept

Gets the width of the render target. More...

unsigned intheight () const noexcept

Gets the height of the render target. More...

Private Member Attributes Index

unsigned intwidth_ = 0

The width of the render target in pixels. More...

unsigned intheight_ = 0

The height of the render target in pixels. More...

helios::rendering::ViewportKeyviewportKey_ {}

Passkey instance to authorize `Viewport::setRenderTarget`. More...

std::vector< std::shared_ptr< helios::rendering::Viewport > >viewports_

A list of viewports owned by this render target. More...

Description

Represents a destination for rendering operations, such as a window's framebuffer.

A RenderTarget encapsulates a buffer (e.g., the default framebuffer or an off-screen texture) into which a scene can be rendered. It manages one or more `Viewport` objects, which define specific rectangular areas within the target.

When the RenderTarget is resized, it notifies all its associated viewports so they can update their states accordingly (e.g., camera aspect ratio).

Todo

This implementation currently represents only the **default framebuffer**. Future extensions should allow it to represent arbitrary framebuffer objects (FBOs), using indices.

See Also

glGenFramebuffers

Definition at line 33 of file RenderTarget.ixx.

Public Constructors

RenderTarget()

helios::rendering::RenderTarget::RenderTarget ()
default

Default constructor.

Definition at line 61 of file RenderTarget.ixx.

RenderTarget()

helios::rendering::RenderTarget::RenderTarget (std::shared_ptr< helios::rendering::Viewport > viewport, unsigned int width=0, unsigned int height=0)
inline explicit

Constructs a RenderTarget with an initial viewport and dimensions.

Parameters
viewport

The default viewport for this RenderTarget. The viewport defines the rectangular area where the image is drawn.

width

The initial width of the render target in pixels.

height

The initial height of the render target in pixels.

Exceptions
std::invalid_argument

if viewport is a nullptr.

See Also

addViewport()

Definition at line 75 of file RenderTarget.ixx.

75 explicit RenderTarget(
76 std::shared_ptr<helios::rendering::Viewport> viewport,
77 unsigned int width = 0,
78 unsigned int height = 0)
79 : width_(width),
80 height_(height) {
81 if (!viewport) {
82 throw std::invalid_argument("Constructor received a null shared pointer");
83 }
84
85 addViewport(std::move(viewport));
86 }

References addViewport, height and width.

Public Member Functions

addViewport()

std::shared_ptr< helios::rendering::Viewport > helios::rendering::RenderTarget::addViewport (std::shared_ptr< helios::rendering::Viewport > viewport)
inline

Adds a viewport to this render target and establishes a parent-child relationship.

Makes sure the viewport is informed about any possible bounds updates by calling onRenderTargetResize afterwards.

Parameters
viewport

A shared pointer to the `Viewport` to be added.

Returns

The newly added viewport as a shared pointer.

Exceptions
std::invalid_argument

if viewport is a nullptr, or if the viewport already has a parent RenderTarget.

Definition at line 101 of file RenderTarget.ixx.

101 std::shared_ptr<helios::rendering::Viewport> addViewport(
102 std::shared_ptr<helios::rendering::Viewport> viewport) {
103 if (!viewport) {
104 throw std::invalid_argument("addViewport() received a null shared pointer");
105 }
106
107 if (viewport->renderTarget()) {
108 throw std::invalid_argument("Viewport already belongs to a RenderTarget.");
109 }
110
111 viewport->setRenderTarget(&*this, viewportKey_);
112
113 // make sure viewport is initialized with the render target's size
114 viewport->onRenderTargetResize(width_, height_);
115
116 viewports_.emplace_back(viewport);
117
118 return viewport;
119 }

Referenced by RenderTarget.

height()

unsigned int helios::rendering::RenderTarget::height ()
inline nodiscard noexcept

Gets the height of the render target.

Returns

The height in pixels.

Definition at line 163 of file RenderTarget.ixx.

163 [[nodiscard]] unsigned int height() const noexcept {
164 return height_;
165 }

Referenced by helios::ext::opengl::rendering::OpenGLDevice::beginRenderPass, RenderTarget and setSize.

setSize()

void helios::rendering::RenderTarget::setSize (unsigned int width, unsigned int height)
inline noexcept

Resizes this RenderTarget to the specified dimensions and propagates the change to every viewport.

Parameters
width

The new width of the render target in pixels.

height

The new height of the render target in pixels.

Todo

A LayoutManager could be introduced to manage the arrangement of multiple viewports.

See Also

helios::rendering::Viewport::onRenderTargetResize()

Definition at line 140 of file RenderTarget.ixx.

140 void setSize(unsigned int width, unsigned int height) noexcept {
141 width_ = width;
142 height_ = height;
143
144 for (const auto& it : viewports_) {
145 it->onRenderTargetResize(width_, height_);
146 }
147 }

References height and width.

viewports()

std::span< const std::shared_ptr< helios::rendering::Viewport > > helios::rendering::RenderTarget::viewports ()
inline nodiscard noexcept

Returns a read-only view of all viewports owned by this RenderTarget.

Returns

A span of shared pointers to the viewports.

Definition at line 126 of file RenderTarget.ixx.

126 [[nodiscard]] std::span<const std::shared_ptr<helios::rendering::Viewport>> viewports() noexcept {
127 return viewports_;
128 }

width()

unsigned int helios::rendering::RenderTarget::width ()
inline nodiscard noexcept

Gets the width of the render target.

Returns

The width in pixels.

Definition at line 154 of file RenderTarget.ixx.

154 [[nodiscard]] unsigned int width() const noexcept {
155 return width_;
156 }

Referenced by helios::ext::opengl::rendering::OpenGLDevice::beginRenderPass, RenderTarget and setSize.

Private Member Attributes

height_

unsigned int helios::rendering::RenderTarget::height_ = 0

The height of the render target in pixels.

Definition at line 43 of file RenderTarget.ixx.

43 unsigned int height_ = 0;

viewportKey_

helios::rendering::ViewportKey helios::rendering::RenderTarget::viewportKey_ {}

Passkey instance to authorize `Viewport::setRenderTarget`.

Definition at line 48 of file RenderTarget.ixx.

viewports_

std::vector<std::shared_ptr<helios::rendering::Viewport> > helios::rendering::RenderTarget::viewports_

A list of viewports owned by this render target.

Todo

The list should be sorted after a meaningful key, like the viewport's z-Index.

Definition at line 55 of file RenderTarget.ixx.

55 std::vector<std::shared_ptr<helios::rendering::Viewport>> viewports_;

width_

unsigned int helios::rendering::RenderTarget::width_ = 0

The width of the render target in pixels.

Definition at line 38 of file RenderTarget.ixx.

38 unsigned int width_ = 0;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.