Class RenderableProxy

Inheritance Relationships

Derived Types

Class Documentation

class RenderableProxy

Base class for GPU-side representations of mrpt::viz::CVisualObject instances.

This is the core abstraction that bridges the abstract scene graph (mrpt::viz) with the actual OpenGL rendering (mrpt::opengl).

Key responsibilities:

  • GPU Resource Management: Owns OpenGL buffers (VBOs, VAOs, textures)

  • Compilation: Translates abstract object data into GPU buffers

  • Incremental Updates: Efficiently updates only changed data

  • Rendering: Issues OpenGL draw calls using bound shaders

Design pattern: Each concrete CVisualObject type has a corresponding RenderableProxy:

Lifecycle:

  1. Created by CompiledScene during compilation

  2. compile() called once to upload initial data to GPU

  3. updateBuffers() called when source object changes (dirty flag)

  4. render() called every frame to draw

  5. Destroyed when source object deleted or scene recompiled

Thread safety:

  • All methods must be called from the OpenGL context thread

  • Source object access is read-only (via const pointers)

  • Source objects are tracked via weak_ptr in CompiledScene

Subclassed by mrpt::opengl::LinesProxyBase, mrpt::opengl::PointsProxyBase, mrpt::opengl::SkyBoxProxy, mrpt::opengl::TrianglesProxyBase

Core Rendering Interface

virtual void compile(const mrpt::viz::CVisualObject *sourceObj) = 0

Initial compilation: uploads object data to GPU.

This is called once when the proxy is first created. It should:

  • Create OpenGL buffers (VBOs, VAOs, textures)

  • Upload initial vertex/color/normal/texture data

  • Cache any frequently-used values

Note

Must be called from OpenGL context thread

Note

After this call, the proxy should be ready to render

Parameters:

sourceObj – The abstract viz object (read-only access)

inline virtual void updateBuffers(const mrpt::viz::CVisualObject *sourceObj)

Incremental update: refreshes GPU buffers with changed data.

This is called when the source object’s dirty flag is set (hasToUpdateBuffers() returns true). It should:

  • Re-upload only the changed data (vertices, colors, etc.)

  • Be as efficient as possible (don’t recompile everything)

Note

Must be called from OpenGL context thread

Note

Default implementation calls compile() - override for efficiency

Parameters:

sourceObj – The abstract viz object (read-only access)

virtual void render(const RenderContext &rc) const = 0

Renders this object using the provided context.

This is called every frame for visible objects. It should:

  • Bind appropriate buffers (VAO, VBO, textures)

  • Set shader uniforms (model matrix, material properties, etc.)

  • Issue draw calls (glDrawArrays, glDrawElements, etc.)

Note

Must be called from OpenGL context thread

Note

The shader program is already bound when this is called

Note

Common matrices (P, V, M) are already uploaded by CompiledViewport

Parameters:

rc – Rendering context (shader, matrices, lights)

Shader and Rendering Properties

virtual std::vector<shader_id_t> requiredShaders() const = 0

Returns the list of shader programs this object needs.

Most objects use a single shader, but some may use multiple (e.g., different shaders for shadow map pass vs. normal rendering).

Returns:

Vector of shader IDs, typically with 1 element

inline virtual bool castsShadows() const

Does this object cast shadows?

Used to determine if the object should be rendered during the shadow map generation pass (1st pass of shadow rendering).

Returns:

true if object casts shadows (default: true)

inline virtual bool cullEligible() const

Should this object be checked for frustum culling?

Some objects (like skyboxes) should never be culled even if their bounding box is outside the view frustum.

Returns:

true if eligible for culling (default: true)

Bounding Box (for Culling and Spatial Queries)

inline virtual mrpt::math::TBoundingBoxf getBoundingBoxLocal() const

Returns the object’s bounding box in local coordinates.

Used for frustum culling and spatial queries. The bounding box should be as tight as possible for efficient culling.

Note

This is in the object’s local frame, before applying pose transform

Returns:

Bounding box, or empty box if not applicable

inline mrpt::math::TBoundingBoxf getBoundingBox(const mrpt::poses::CPose3D &objPose) const

Returns the object’s bounding box in world coordinates.

This applies the object’s pose transformation to the local bbox.

Parameters:

objPose – The object’s SE(3) pose in world frame

Returns:

Transformed bounding box

Type Information

inline virtual const char *typeName() const

Returns a human-readable type name for this proxy. Used for debugging and logging.

Helper Methods for Derived Classes

static void uploadMatrix(const RenderContext &rc, const char *uniformName, const mrpt::math::CMatrixFloat44 &matrix)

Helper: uploads a 4x4 matrix as a uniform to the current shader.

Parameters:
  • rc – Render context with bound shader

  • uniformName – Name of the uniform variable in the shader

  • matrix – The 4x4 matrix to upload

static void uploadVector3(const RenderContext &rc, const char *uniformName, const mrpt::math::TVector3Df &v)

Helper: uploads a 3-component vector as a uniform.

Parameters:
  • rc – Render context with bound shader

  • uniformName – Name of the uniform variable

  • v – The 3D vector

static void uploadColor(const RenderContext &rc, const char *uniformName, const mrpt::img::TColorf &color)

Helper: uploads a color (4 floats) as a uniform.

Parameters:
  • rc – Render context with bound shader

  • uniformName – Name of the uniform variable

  • color – The color (RGBA in [0,1])

static void uploadFloat(const RenderContext &rc, const char *uniformName, float value)

Helper: uploads a float scalar as a uniform.

Parameters:
  • rc – Render context with bound shader

  • uniformName – Name of the uniform variable

  • value – The float value

static void uploadInt(const RenderContext &rc, const char *uniformName, int value)

Helper: uploads an integer as a uniform.

Parameters:
  • rc – Render context with bound shader

  • uniformName – Name of the uniform variable

  • value – The integer value

Public Types

using Ptr = std::shared_ptr<RenderableProxy>

Public Functions

RenderableProxy() = default
virtual ~RenderableProxy() = default
inline void setSourceObject(std::weak_ptr<mrpt::viz::CVisualObject> obj)

Sets the source object reference. Called by CompiledScene during compilation.

inline std::shared_ptr<mrpt::viz::CVisualObject> getSourceObject() const

Returns the source object, or nullptr if it has been deleted.

inline bool isSourceValid() const

Check if source object still exists

inline bool sourceNeedsUpdate() const

Check if source object has pending changes (dirty flag)

RenderableProxy(const RenderableProxy&) = delete
RenderableProxy &operator=(const RenderableProxy&) = delete
RenderableProxy(RenderableProxy&&) = default
RenderableProxy &operator=(RenderableProxy&&) = default

Public Members

mrpt::math::CMatrixFloat44 m_modelMatrix = mrpt::math::CMatrixFloat44::Identity()

Model matrix: object local frame -> world frame. Composed from the object’s pose (and parent container poses). Set during compilation by CompiledScene.

bool m_visible = true

Effective visibility (accounts for parent container visibility). Updated by CompiledScene during dirty-object updates.

Protected Attributes

std::weak_ptr<mrpt::viz::CVisualObject> m_sourceObject

Weak reference to the source viz object. Used to:

  • Check if source still exists (weak_ptr::expired())

  • Access source data during updateBuffers() if needed

  • Query dirty flags Set by CompiledScene during proxy creation.