Class CompiledViewport

Nested Relationships

Nested Types

Class Documentation

class CompiledViewport

A compiled, GPU-ready representation of a mrpt::viz::Viewport.

This class is the rendering engine for a single viewport. It maintains:

  • Compiled proxies for all renderable objects in the viewport

  • Camera state and projection matrices

  • Lighting parameters

  • Special rendering modes (image view, cloned view, etc.)

  • Shadow mapping framebuffers (if enabled)

Key features:

  • Normal 3D rendering: Standard scene with objects, camera, lighting

  • Image view mode: Efficient rendering of 2D images (for video streams)

  • Cloned viewports: Share objects/camera from another viewport

  • Shadow mapping: Two-pass rendering for directional shadows

  • Frustum culling: Automatically skips objects outside camera view

The viewport can operate in several modes:

  1. Normal: Renders its own objects with its own camera

  2. Image view: Displays a textured quad (for images/video)

  3. Cloned objects: Renders objects from another viewport

  4. Cloned camera: Uses camera from another viewport

Viewport Configuration

void updateFromVizViewport(const mrpt::viz::Viewport &vizVp)

Synchronizes this compiled viewport with its source viz::Viewport.

Copies all configuration: camera, lights, rendering options, viewport bounds, special modes, etc.

This is called automatically by CompiledScene during compilation.

Parameters:

vizVp – The source viewport. A non-owning pointer is kept to allow writing back the rendered viewport size for get3DRayForPixelCoord().

inline const std::string &getName() const

Returns the viewport name

Special Rendering Modes

void setImageViewMode(RenderableProxy::Ptr imageProxy)

Enables/disables image view mode.

When enabled, the viewport displays a single textured quad instead of 3D objects. Used for efficient video/image display.

Parameters:

imageProxy – The textured quad proxy (created from CTexturedPlane)

void clearImageViewMode()

Disables image view mode, returns to normal 3D rendering

inline bool isImageViewMode() const

Returns true if viewport is in image view mode

void setCloneMode(const std::string &clonedViewportName, bool cloneCamera = false)

Sets this viewport to clone objects from another viewport.

Parameters:
  • clonedViewportName – Name of viewport to clone from

  • cloneCamera – If true, also clone camera settings

void clearCloneMode()

Disables cloning

inline bool isCloningObjects() const

Returns true if this viewport clones objects from another

inline bool isCloningCamera() const

Returns true if this viewport clones camera from another

inline const std::string &getClonedViewportName() const

Returns name of cloned viewport, or empty if not cloning

Shadow Mapping

void enableShadows(bool enabled, unsigned int shadowMapSizeX = 4096, unsigned int shadowMapSizeY = 4096)

Enables/disables shadow casting for this viewport.

Parameters:
  • enabled – Enable shadow rendering

  • shadowMapSizeX – Shadow map texture width (default 4096)

  • shadowMapSizeY – Shadow map texture height (default 4096)

inline bool areShadowsEnabled() const

Returns true if shadow casting is enabled

Proxy Management

void addProxy(const RenderableProxy::Ptr &proxy, const std::shared_ptr<mrpt::viz::CVisualObject> &sourceObj)

Adds a renderable proxy to this viewport.

Parameters:
  • proxy – The GPU-side representation of an object

  • sourceObj – The original viz object (tracked via weak_ptr)

size_t cleanupOrphanedProxies()

Removes proxies whose source objects have been deleted.

Returns:

Number of orphaned proxies removed

void updateProxiesForObject(const std::weak_ptr<mrpt::viz::CVisualObject> &weakObj, const mrpt::viz::CVisualObject *sourceObj, const mrpt::math::CMatrixFloat44 &modelMatrix, bool effectiveVisible = true)

Updates all proxies for a given source object (buffers + model matrix). Called by CompiledScene::updateDirtyObjects().

void removeProxy(const RenderableProxy::Ptr &proxy)

Removes a proxy from this viewport

void clearProxies()

Removes all proxies

inline size_t getProxyCount() const

Number of proxies in this viewport

inline const std::vector<RenderableProxy::Ptr> &getProxies() const

Access to the list of proxies (used by cloned viewports)

Rendering

void render(int renderWidth, int renderHeight, int renderOffsetX, int renderOffsetY, ShaderProgramManager &shaderManager, const CompiledViewport *sourceViewport = nullptr)

Renders this viewport.

This handles:

  • Viewport positioning and clipping

  • Background color clearing

  • Shadow map rendering (if enabled)

  • Normal scene rendering

  • Image view rendering (if in image mode)

  • Text overlay rendering

  • Viewport border rendering

Parameters:
  • renderWidth – Full window width in pixels

  • renderHeight – Full window height in pixels

  • renderOffsetX – X offset for multi-window rendering

  • renderOffsetY – Y offset for multi-window rendering

  • shaderManagerShader program manager for binding programs

  • sourceViewport – For cloned viewports, the source viewport whose proxies should be rendered. nullptr for normal viewports.

State Updates

bool updateIfNeeded()

Checks if viewport configuration has changed and updates if needed.

This monitors changes in:

  • Camera position/orientation

  • Lighting parameters

  • Viewport dimensions

Returns:

true if any updates were performed

bool hasPendingUpdates() const

Returns true if there are pending configuration changes

inline void forceMatrixUpdate()

Forces regeneration of all projection/view matrices

Camera and Matrices

void updateCamera(const mrpt::viz::CCamera &camera)

Updates camera state from a viz::CCamera

inline const TRenderMatrices &getRenderMatrices() const

Returns current render matrices (projection, view, etc.)

inline TRenderMatrices &getRenderMatrices()

Direct access to render matrices (for manual manipulation)

Configuration Access

void setViewportBounds(double x, double y, double width, double height)

Viewport position and size (normalized or pixel coordinates)

void getViewportBounds(double &x, double &y, double &width, double &height) const
void setClipPlanes(float nearPlane, float farPlane)

Set near/far clip planes

void getClipPlanes(float &nearPlane, float &farPlane) const
inline void setBackgroundColor(const mrpt::img::TColorf &color)

Set background color

inline const mrpt::img::TColorf &getBackgroundColor() const
inline void setTransparent(bool transparent)

Set transparent rendering (doesn’t clear color buffer)

inline bool isTransparent() const
void setBorder(unsigned int width, const mrpt::img::TColor &color)

Set viewport border

inline unsigned int getBorderWidth() const
inline const mrpt::img::TColor &getBorderColor() const
inline void setVisible(bool visible)

Set viewport visibility

inline bool isVisible() const
inline mrpt::viz::TLightParameters &lightParameters()

Access lighting parameters

inline const mrpt::viz::TLightParameters &lightParameters() const
inline const ViewportRenderStats &lastRenderStats() const

Last rendering statistics

inline void flipVerticalProjection(bool flipEnabled)

Flip vertically at projection level (useful for FBO rendering)

inline bool flipVerticalProjection() const

Flip vertically at projection level (useful for FBO rendering)

Public Types

using Ptr = std::shared_ptr<CompiledViewport>

Public Functions

explicit CompiledViewport(const std::string &name)

Constructor.

Parameters:

name – Viewport name (must match the name in viz::Viewport)

~CompiledViewport()
CompiledViewport(const CompiledViewport&) = delete
CompiledViewport &operator=(const CompiledViewport&) = delete
CompiledViewport(CompiledViewport&&) = delete
CompiledViewport &operator=(CompiledViewport&&) = delete