Viewport Class
Represents a rectangular area within a RenderTarget where a scene is rendered. More...
Declaration
Public Constructors Index
| Viewport () noexcept | |
|
Constructs a Viewport with normalized bounds set to (0.0f, 0.0f, 1.0f, 1.0f) and z-index 0. More... | |
| Viewport (float x, float y, float width, float height, const helios::engine::core::data::ViewportId viewportId=helios::engine::core::data::ViewportId{helios::core::types::no_init}, const int zIndex=0) noexcept | |
|
Constructs a Viewport with specified normalized dimensions. More... | |
Public Member Functions Index
| const helios::rendering::RenderTarget * | renderTarget () const noexcept |
|
Gets the parent RenderTarget. More... | |
| helios::engine::core::data::ViewportId | viewportId () const noexcept |
|
Returns the unique identifier for this viewport. More... | |
| Viewport & | setCameraSceneNode (helios::scene::CameraSceneNode *cameraSceneNode) noexcept |
|
Assigns a camera scene node to this viewport. More... | |
| const helios::scene::CameraSceneNode * | cameraSceneNode () const noexcept |
|
Gets the camera scene node associated with this viewport. More... | |
| Viewport & | setRenderTarget (const helios::rendering::RenderTarget *renderTarget, ViewportKey key) noexcept |
|
Sets the parent RenderTarget for this viewport. More... | |
| const helios::math::vec4f & | bounds () const noexcept |
|
Gets the cached dimensions of the viewport. More... | |
| const helios::math::vec4f & | absoluteBounds () const noexcept |
|
Gets the cached absolute bounds of the viewport in pixels. More... | |
| ViewportSnapshot | snapshot () const noexcept |
|
Returns an immutable snapshot of this viewport's current state. More... | |
| void | setBounds (float x, float y, float width, float height) noexcept |
|
Sets the normalized bounds of the viewport. More... | |
| int | clearFlags () const noexcept |
|
Gets the clear flags for this viewport. More... | |
| const helios::math::vec4f & | clearColor () const noexcept |
|
Gets the color used for clearing the color buffer. More... | |
| Viewport & | setClearFlags (int clearFlags) noexcept |
|
Sets the clear flags for this viewport. More... | |
| Viewport & | setClearColor (const helios::math::vec4f &color) noexcept |
|
Specifies the RGBA values used when clearing color buffers. More... | |
| Viewport & | setZIndex (int zIndex) noexcept |
|
Sets the z-index that controls rendering order relative to sibling viewports. More... | |
| void | onRenderTargetResize (const unsigned int width, const unsigned int height) noexcept |
|
Notifies the viewport of a change in the parent RenderTarget's dimensions. More... | |
Private Member Functions Index
| void | updateCache () const noexcept |
|
Updates the cached dimensions vector if it is dirty. More... | |
| void | updateCamera (unsigned int renderTargetWidth, unsigned int renderTargetHeight) noexcept |
|
Updates this Viewport's CameraSceneNode and its associated Camera based on the dimension of the RenderTarget. More... | |
Private Member Attributes Index
| const helios::rendering::RenderTarget * | renderTarget_ = nullptr |
|
Pointer to the parent RenderTarget. More... | |
| int | clearFlags_ = std::to_underlying(ClearFlags::Color) |
|
Bitmask of buffers to clear. More... | |
| helios::math::vec4f | clearColor_ = helios::math::vec4f(0.0f, 0.0f, 0.0f, 1.0f) |
|
Color used when clearing the color buffer. Defaults to "black", i.e. no color at all. More... | |
| float | x_ = 0.0f |
|
The x-offset of the viewport, normalized to [0, 1]. More... | |
| float | y_ = 0.0f |
|
The y-offset of the viewport, normalized to [0, 1]. More... | |
| float | width_ = 1.0f |
|
The width of the viewport, normalized to [0, 1]. More... | |
| float | height_ = 1.0f |
|
The height of the viewport, normalized to [0, 1]. More... | |
| helios::math::vec2ui | renderTargetSize_ {} |
|
Size of the parent RenderTarget in pixels. More... | |
| helios::scene::CameraSceneNode * | cameraSceneNode_ = nullptr |
|
The cameraSceneNode associated as the main camera with this viewport. More... | |
| bool | needsUpdate_ = true |
|
Flag indicating if cached dimensions are dirty. More... | |
| helios::math::vec4f | bounds_ |
|
Cached dimensions [x, y, width, height]. More... | |
| int | zIndex_ = 0 |
|
The z-index for this viewport. More... | |
| const helios::engine::core::data::ViewportId | viewportId_ {helios::core::types::no_init} |
|
Unique identifier for this viewport. More... | |
| helios::math::vec4f | absoluteBounds_ {} |
|
Cached absolute bounds [x, y, width, height] in pixels. More... | |
| ViewportSnapshot | snapshot_ {} |
|
Cached viewport snapshot for efficient access. More... | |
Private Static Attributes Index
| static const helios::util::log::Logger & | logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE) |
Description
Represents a rectangular area within a RenderTarget where a scene is rendered.
A Viewport defines the 2D rectangle into which a 3D scene is projected. Its dimensions are specified in normalized coordinates relative to its parent `RenderTarget`. It is associated with a `CameraSceneNode`, which provides the view and projection matrices. The viewport automatically updates the CameraSceneNode associated camera's aspect ratio when its parent `RenderTarget` is resized.
Since a Viewport only stores normalized values for its location and dimensions relative to the owning RenderTarget, rendering APIs should query the size of the RenderTarget when a viewport is about to be rendered, allowing them to compute the final screen coordinates and dimensions correctly.
- See Also
- See Also
Definition at line 64 of file Viewport.ixx.
Public Constructors
Viewport()
| inline noexcept |
Constructs a Viewport with normalized bounds set to (0.0f, 0.0f, 1.0f, 1.0f) and z-index 0.
Definition at line 200 of file Viewport.ixx.
Referenced by setCameraSceneNode, setClearColor, setClearFlags, setRenderTarget and setZIndex.
Viewport()
| inline explicit noexcept |
Constructs a Viewport with specified normalized dimensions.
- Parameters
-
x The normalized horizontal offset [0, 1].
y The normalized vertical offset [0, 1].
width The normalized width [0, 1].
height The normalized height [0, 1].
zIndex The z-index that determines the rendering order.
Definition at line 213 of file Viewport.ixx.
References helios::core::types::no_init and viewportId.
Public Member Functions
absoluteBounds()
| inline nodiscard noexcept |
Gets the cached absolute bounds of the viewport in pixels.
- Returns
A const reference to a vec4f containing [x, y, width, height] in pixels.
Definition at line 305 of file Viewport.ixx.
bounds()
| inline nodiscard noexcept |
Gets the cached dimensions of the viewport.
- Returns
A const reference to a vec4f containing [x, y, width, height].
Definition at line 295 of file Viewport.ixx.
cameraSceneNode()
| inline nodiscard noexcept |
Gets the camera scene node associated with this viewport.
- Returns
A const pointer to the associated `CameraSceneNode`, or `nullptr` if none is set.
Definition at line 266 of file Viewport.ixx.
Referenced by helios::scene::Scene::createSnapshot and setCameraSceneNode.
clearColor()
| inline nodiscard noexcept |
Gets the color used for clearing the color buffer.
- Returns
A const reference to the clear color.
Definition at line 363 of file Viewport.ixx.
clearFlags()
| inline nodiscard noexcept |
Gets the clear flags for this viewport.
- Returns
An integer bitmask representing the `ClearFlags`.
Definition at line 354 of file Viewport.ixx.
Referenced by setClearFlags.
onRenderTargetResize()
| inline noexcept |
Notifies the viewport of a change in the parent RenderTarget's dimensions.
This method is called by the parent `RenderTarget` when it is resized. The viewport uses the new dimensions to calculate the correct aspect ratio for its associated camera.
- Parameters
-
width The new width of the RenderTarget in pixels.
height The new height of the RenderTarget in pixels.
- See Also
updateCamera()
Definition at line 417 of file Viewport.ixx.
renderTarget()
| inline nodiscard noexcept |
Gets the parent RenderTarget.
If the returned value is a nullptr, this Viewport is not owned by any RenderTarget.
- Returns
A const pointer to the parent RenderTarget, or `nullptr` if not set.
Definition at line 231 of file Viewport.ixx.
Referenced by setRenderTarget.
setBounds()
| inline noexcept |
Sets the normalized bounds of the viewport.
- Parameters
-
x The normalized horizontal offset [0, 1].
y The normalized vertical offset [0, 1].
width The normalized width [0, 1].
height The normalized height [0, 1].
Definition at line 333 of file Viewport.ixx.
setCameraSceneNode()
| inline noexcept |
Assigns a camera scene node to this viewport.
The viewport uses the associated camera's projection matrix and the node's computed view matrix for rendering. The camera's aspect ratio is automatically updated when the parent RenderTarget is resized.
- Parameters
-
cameraSceneNode A non-owning raw pointer to the `CameraSceneNode`. Must remain valid for the lifetime of this viewport.
- Returns
A reference to this viewport to allow fluent chaining.
Definition at line 256 of file Viewport.ixx.
References cameraSceneNode and Viewport.
setClearColor()
| inline noexcept |
Specifies the RGBA values used when clearing color buffers.
Values are automatically clamped to the range [0, 1].
- Parameters
-
color The color to use for clearing.
- Returns
A reference to this viewport to allow fluent chaining.
Definition at line 388 of file Viewport.ixx.
Reference Viewport.
setClearFlags()
| inline noexcept |
Sets the clear flags for this viewport.
- Parameters
-
clearFlags An integer bitmask created from `ClearFlags` enum values.
- Returns
A reference to this viewport to allow fluent chaining.
Definition at line 374 of file Viewport.ixx.
References clearFlags and Viewport.
setRenderTarget()
| inline noexcept |
Sets the parent RenderTarget for this viewport.
This function can only be called by classes that can construct a `ViewportKey`, effectively restricting its use to the `RenderTarget` class.
- Parameters
-
renderTarget A pointer to the parent RenderTarget.
key A `ViewportKey` instance, required for authorization.
- Returns
A reference to this viewport to allow fluent chaining.
- See Also
updateCamera()
- Todo
-
The Viewport should observe the RenderTarget for state changes (e.g., resize).
Definition at line 285 of file Viewport.ixx.
References renderTarget and Viewport.
setZIndex()
| inline noexcept |
Sets the z-index that controls rendering order relative to sibling viewports.
- Parameters
-
zIndex The new z-index value; higher values are rendered later.
- Returns
A reference to this viewport to allow fluent chaining.
Definition at line 400 of file Viewport.ixx.
Reference Viewport.
snapshot()
| inline nodiscard noexcept |
Returns an immutable snapshot of this viewport's current state.
The snapshot contains the viewport ID and both normalized and absolute bounds. Useful for passing viewport state to rendering systems without exposing the mutable Viewport object.
- Returns
A ViewportSnapshot containing the current viewport state.
Definition at line 319 of file Viewport.ixx.
viewportId()
| inline nodiscard noexcept |
Returns the unique identifier for this viewport.
- Returns
The ViewportId assigned to this viewport.
Definition at line 240 of file Viewport.ixx.
Referenced by Viewport.
Private Member Functions
updateCache()
| inline noexcept |
Updates the cached dimensions vector if it is dirty.
Definition at line 145 of file Viewport.ixx.
updateCamera()
| inline noexcept |
Updates this Viewport's CameraSceneNode and its associated Camera based on the dimension of the RenderTarget.
- Parameters
-
width The new width of the RenderTarget in pixels.
height The new height of the RenderTarget in pixels.
This method should be called internally whenever the dimensions of the owning RenderTarget change.
Definition at line 182 of file Viewport.ixx.
Private Member Attributes
absoluteBounds_
| mutable |
Cached absolute bounds [x, y, width, height] in pixels.
Definition at line 140 of file Viewport.ixx.
bounds_
| mutable |
Cached dimensions [x, y, width, height].
Definition at line 121 of file Viewport.ixx.
cameraSceneNode_
|
The cameraSceneNode associated as the main camera with this viewport.
Definition at line 111 of file Viewport.ixx.
clearColor_
|
Color used when clearing the color buffer. Defaults to "black", i.e. no color at all.
Definition at line 83 of file Viewport.ixx.
clearFlags_
|
Bitmask of buffers to clear.
Defaults to ClearFlags::Color.
Definition at line 78 of file Viewport.ixx.
height_
|
The height of the viewport, normalized to [0, 1].
Definition at line 101 of file Viewport.ixx.
needsUpdate_
| mutable |
Flag indicating if cached dimensions are dirty.
Definition at line 116 of file Viewport.ixx.
renderTarget_
|
Pointer to the parent RenderTarget.
Definition at line 71 of file Viewport.ixx.
renderTargetSize_
|
Size of the parent RenderTarget in pixels.
Definition at line 106 of file Viewport.ixx.
snapshot_
| mutable |
Cached viewport snapshot for efficient access.
Definition at line 171 of file Viewport.ixx.
viewportId_
|
Unique identifier for this viewport.
Definition at line 135 of file Viewport.ixx.
width_
|
The width of the viewport, normalized to [0, 1].
Definition at line 97 of file Viewport.ixx.
x_
|
The x-offset of the viewport, normalized to [0, 1].
Definition at line 88 of file Viewport.ixx.
y_
|
The y-offset of the viewport, normalized to [0, 1].
Definition at line 92 of file Viewport.ixx.
zIndex_
|
The z-index for this viewport.
The z-index represents the order the Viewport gets rendered. A higher z-index means that the viewport gets rendered after viewports with a lower z-index are rendered.
Definition at line 130 of file Viewport.ixx.
Private Static Attributes
logger_
| static |
Definition at line 65 of file Viewport.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.