Class LinesProxyBase

Inheritance Relationships

Base Type

Derived Type

Class Documentation

class LinesProxyBase : public mrpt::opengl::RenderableProxy

Specialization for proxies that render lines/wireframes.

This provides common functionality for all line-based rendering, including vertex, color, and line parameter management.

Lines of (effective) width 1 pixel are drawn as GL_LINES with the DefaultShaderID::WIREFRAME shader. Wider lines are drawn with DefaultShaderID::WIREFRAME_THICK: one screen-aligned quad per segment, made in the vertex shader by an instanced draw that reads both endpoints from the same vertex buffers (glLineWidth() > 1 is not available in OpenGL core profile, OpenGL ES, or WebGL).

See also

mrpt::viz::VisualObjectParams_Lines

Subclassed by mrpt::opengl::LinesProxy

Public Functions

LinesProxyBase() = default
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 data version of the source object changes (mrpt::viz::CVisualObject::dataVersion()). 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)

inline 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 bool castsShadows() const override

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:

m_castShadows by default, which follows mrpt::viz::CVisualObject::castShadows() of the object and its parents.

inline virtual const char *typeName() const override

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

float effectiveLineWidth() const

The width in pixels the lines are drawn with: like glLineWidth(), widths of aliased lines are rounded to whole pixels, and anti-aliased lines keep fractional widths. Never less than 1.

inline bool drawsThickLines() const

Whether lines are drawn as quads (WIREFRAME_THICK): when their width rounds to 2 pixels or more. Thinner anti-aliased lines (e.g. the default 1.3 of grid planes) keep the GL_LINES path.

Protected Attributes

Buffer m_vertexBuffer = {Buffer::Type::Vertex}

Vertex buffer (line endpoints)

Buffer m_colorBuffer = {Buffer::Type::Vertex}

Color buffer (per-vertex colors)

VertexArrayObject m_vao

Vertex Array Object for GL_LINES (thin lines)

VertexArrayObject m_vaoThick

Vertex Array Object for instanced quads (thick lines): the same buffers, with both endpoints of each segment as per-instance attributes.

size_t m_vertexCount = 0

Number of vertices (lines have 2 vertices each)

float m_lineWidth = 1.0f

Line width, in pixels, as set in the source object

bool m_antiAliasing = false

Anti-aliasing enabled

bool m_hasColorBuffer = false

If false, all vertices have m_baseColor

mrpt::img::TColor m_baseColor = {0xff, 0xff, 0xff, 0xff}