Class CompiledViewport
Defined in File CompiledViewport.h
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:
Normal: Renders its own objects with its own camera
Image view: Displays a textured quad (for images/video)
Cloned objects: Renders objects from another viewport
Cloned camera: Uses camera from another viewport
See also
CompiledScene, RenderableProxy, mrpt::viz::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().
-
void setSceneLights(const std::vector<mrpt::viz::TLight> &lights)
Sets the lights of the mrpt::viz::CLight objects in this viewport, in world coordinates, which are appended to those of the source viewport. This is called automatically by CompiledScene during compilation.
-
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 setCloneCameraFrom(const std::string &viewportName)
Makes this viewport use the camera of another one, while still rendering its own objects.
- Parameters:
viewportName – Name of the viewport whose camera is used
-
void clearCloneCamera()
Stops using the camera of another viewport
-
void clearCloneMode()
Disables cloning, of both objects and camera
-
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
-
inline const std::string &getCameraSourceViewportName() const
Returns the name of the viewport whose camera is used, or empty if the viewport has its own camera
Shadow Mapping
-
void enableShadows(bool enabled, unsigned int shadowMapSizeX = 2048, unsigned int shadowMapSizeY = 2048)
Enables/disables shadow casting for this viewport.
- Parameters:
enabled – Enable shadow rendering
shadowMapSizeX – Shadow map texture width (default 2048)
shadowMapSizeY – Shadow map texture height (default 2048)
-
inline bool areShadowsEnabled() const
Returns true if shadow casting is enabled
Proxy Management
-
void addProxy(const RenderableProxy::Ptr &proxy)
Adds a renderable proxy to this viewport. Its model matrix, visibility, etc. are kept up to date by the owner (CompiledScene).
- Parameters:
proxy – The GPU-side representation of an object
-
void removeProxy(const RenderableProxy::Ptr &proxy)
Removes a proxy from this viewport
-
void removeProxies(const std::vector<const RenderableProxy*> &proxies)
Removes a set of proxies from this viewport, in one pass.
-
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
shaderManager – Shader program manager for binding programs
sourceViewport – For cloned viewports, the source viewport whose proxies should be rendered. nullptr for normal viewports.
State Updates
-
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 setTransparent(bool transparent)
Set transparent rendering (doesn’t clear color buffer)
-
inline bool isTransparent() const
-
inline unsigned int getBorderWidth() 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