Class TrianglesProxy
Defined in File TrianglesProxy.h
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public mrpt::opengl::TrianglesProxyBase(Class TrianglesProxyBase)
Class Documentation
-
class TrianglesProxy : public mrpt::opengl::TrianglesProxyBase
GPU-side proxy for rendering triangle meshes.
This proxy handles rendering of any CVisualObject that uses triangle-based shaders, such as:
CMesh
CBox
CSphere
CCylinder
Any object derived from VisualObjectParams_Triangles
The proxy manages:
Vertex buffer (3D triangle vertices)
Normal buffer (per-vertex normals for lighting)
Color buffer (per-vertex RGBA colors)
VAO for efficient attribute binding
Lighting and material parameters
Face culling modes
Triangle rendering features:
Phong lighting (ambient, diffuse, specular)
Per-vertex colors with optional lighting modulation
Face culling (FRONT, BACK, NONE)
Shadow casting (2-pass rendering)
Material properties (shininess)
Shader selection:
Normal rendering: TRIANGLES_LIGHT or TRIANGLES_NO_LIGHT
Shadow 1st pass: TRIANGLES_SHADOW_1ST (depth only)
Shadow 2nd pass: TRIANGLES_SHADOW_2ND (with shadow mapping)
Typical data flow:
compile(): Upload triangle vertices, normals, colors to GPU
updateBuffers(): Re-upload when mesh changes
render(): Draw triangles with appropriate shader every frame
RenderableProxy Interface Implementation
-
virtual void compile(const mrpt::viz::CVisualObject *sourceObj) override
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)
-
virtual void updateBuffers(const mrpt::viz::CVisualObject *sourceObj) override
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 override
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)
-
virtual std::vector<shader_id_t> requiredShaders() const override
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 const char *typeName() const override
Returns a human-readable type name for this proxy. Used for debugging and logging.