Lysa  0.0
Lysa 3D Engine
Viewport Class Reference

Detailed Description

Viewport orchestrates a self‑contained rendering context.

  • Own a root node (scene tree) and manage per‑frame scene instances.
  • Handle deferred add/remove of nodes and camera activation between frames.
  • Bridge input and per‑frame updates to the node tree (process/physics).
  • Provide a vireo::Viewport and scissors used by render passes.
  • Drive rendering of a Scene into color/depth render targets.

Notes:

  • Create with a ViewportConfiguration, then attach to a Window (friend).
  • Use setRootNode() to change the active scene tree.
  • Nodes can be added/removed immediately or deferred (async parameter).
  • activateCamera() schedules camera switching at a safe point.
  • Root node and per‑frame queues are protected by mutexes where needed.
  • Public mutators should be called from the main/render thread unless explicitly documented; async queues are processed on the frame boundary.

Public Member Functions

 Viewport (ViewportConfiguration &config)
 
void setRootNode (const std::shared_ptr< Node > &node)
 
auto isPaused () const
 
void setPaused (bool pause)
 
void activateCamera (const std::shared_ptr< Camera > &camera)
 
void addNode (const std::shared_ptr< Node > &node, bool async, bool attachToViewport)
 
void removeNode (const std::shared_ptr< Node > &node, bool async)
 
auto getAspectRatio () const
 
const auto & getViewport () const
 
void setViewport (const vireo::Viewport &viewport)
 
const auto & getScissors () const
 
void setScissors (const vireo::Rect &scissors)
 
auto & getWindow () const
 
void lockDeferredUpdate ()
 
void unlockDeferredUpdate ()
 
auto & getPhysicsScene () const
 
auto getDebugRenderer () const
 
auto getVectorRenderer ()
 
void update (const vireo::CommandList &commandList, uint32 frameIndex) const
 
void draw (vireo::CommandList &commandList, const Scene &scene, const std::shared_ptr< vireo::RenderTarget > &colorAttachment, const std::shared_ptr< vireo::RenderTarget > &depthAttachment, uint32 frameIndex) const
 
const auto & getConfiguration () const
 
auto getDisplayDebug () const
 
void setDisplayDebug (const bool displayDebug)
 
virtual ~Viewport ()
 
 Viewport (Viewport &) = delete
 
Viewport & operator= (Viewport &) = delete
 

Constructor & Destructor Documentation

Viewport ( ViewportConfiguration config)

Constructs a viewport with the provided configuration.

Parameters
configViewport configuration (dimensions, buffers, features).
virtual ~Viewport ( )
virtual
Viewport ( Viewport &  )
delete

Member Function Documentation

void activateCamera ( const std::shared_ptr< Camera > &  camera)

Schedules activation of the specified camera for the next frame. The camera must belong to the current scene.

Parameters
cameraCamera to activate.
void addNode ( const std::shared_ptr< Node > &  node,
bool  async,
bool  attachToViewport 
)

Adds a node to the current scene.

Parameters
nodeNode to add.
asyncIf true, queues the add for the next frame.
attachToViewportIf true, attaches the node under the viewport root.
void draw ( vireo::CommandList &  commandList,
const Scene scene,
const std::shared_ptr< vireo::RenderTarget > &  colorAttachment,
const std::shared_ptr< vireo::RenderTarget > &  depthAttachment,
uint32  frameIndex 
) const

Renders the provided Scene into the given color and depth attachments.

Parameters
commandListCommand buffer to record draw calls.
sceneScene to draw (camera, lights, instances).
colorAttachmentTarget color render surface.
depthAttachmentTarget depth render surface.
frameIndexIndex of the in‑flight frame.
auto getAspectRatio ( ) const
inline

Returns the aspect ratio (width/height) of the viewport.

const auto& getConfiguration ( ) const
inline

Returns the immutable configuration used to create this viewport.

auto getDebugRenderer ( ) const
inline

Returns the debug renderer (may be null).

auto getDisplayDebug ( ) const
inline

Returns true when debug overlays are enabled.

auto& getPhysicsScene ( ) const
inline

Returns the physics scene associated with this viewport.

const auto& getScissors ( ) const
inline

Returns the scissors rectangle applied to rendering.

auto getVectorRenderer ( )
inline

Returns the vector renderer (may be null).

const auto& getViewport ( ) const
inline

Returns the low‑level viewport definition (x, y, width, height, depth).

auto& getWindow ( ) const
inline

Returns the Window this viewport is attached to. Asserts if not attached.

auto isPaused ( ) const
inline

Returns whether the scene is currently paused. This controls Node processing with respect to ProcessMode.

Returns
True if paused, false otherwise.
void lockDeferredUpdate ( )
inline

Prevents processing of deferred add/remove updates for the next frames.

Viewport& operator= ( Viewport &  )
delete
void removeNode ( const std::shared_ptr< Node > &  node,
bool  async 
)

Removes a node from the current scene.

Parameters
nodeNode to remove.
asyncIf true, queues the removal for the next frame.
void setDisplayDebug ( const bool  displayDebug)
inline

Enables or disables debug overlays rendering.

void setPaused ( bool  pause)

Pauses or resumes the current scene.

Parameters
pauseNew state (true pauses, false resumes).
void setRootNode ( const std::shared_ptr< Node > &  node)

Changes the current scene root node.

The provided node must not have a parent; ownership is shared.

Parameters
nodeNew root node of the scene graph.
void setScissors ( const vireo::Rect &  scissors)
inline

Sets the scissors rectangle applied to rendering.

void setViewport ( const vireo::Viewport &  viewport)
inline

Sets the low‑level viewport definition.

void unlockDeferredUpdate ( )
inline

Allows processing of deferred add/remove updates again.

void update ( const vireo::CommandList &  commandList,
uint32  frameIndex 
) const

Updates the current frame (game state and scene) prior to rendering.

Friends And Related Function Documentation

Window
friend