Skip to main content

PlottingOpenGL::PolyLineRenderer

PlottingOpenGL::PolyLineRenderer

Renders RenderablePolyLineBatch data using OpenGL 3.3+ compatible calls. More…

#include <PolyLineRenderer.hpp>

Inherits from PlottingOpenGL::IBatchRenderer

Public Functions

Name
PolyLineRenderer(std::string shader_base_path =““)
Construct a PolyLineRenderer with optional shader paths.
~PolyLineRenderer() override
virtual bool initialize() override
Initialize GPU resources (VAOs, VBOs, shaders).
virtual void cleanup() override
Release all GPU resources.
virtual bool isInitialized() const override
Check if the renderer has been successfully initialized.
virtual void render(glm::mat4 const & view_matrix, glm::mat4 const & projection_matrix) override
Render the current batch with the given View and Projection matrices.
virtual bool hasData() const override
Check if there is any data to render.
virtual void clearData() override
Clear all uploaded data (but keep GPU resources allocated).
void uploadData(CorePlotting::RenderablePolyLineBatch const & batch)
Upload a polyline batch to GPU memory.
void uploadBatches(std::span< CorePlotting::RenderablePolyLineBatch const > batches)
Upload multiple polyline batches to GPU memory in a single combined pass.
void setLineThickness(float thickness)
Set the line thickness for all lines in the batch.
bool isUsingShaderManager() const
Check if using ShaderManager (vs embedded fallback).
size_t getLastUploadedBytes() const
Number of bytes uploaded during the last upload call.
bool wasLastUploadIncremental() const
Whether the last upload was fulfilled via incremental sub-buffer updates.

Additional inherited members

Public Functions inherited from PlottingOpenGL::IBatchRenderer

Name
virtual ~IBatchRenderer() =default

Protected Functions inherited from PlottingOpenGL::IBatchRenderer

Name
IBatchRenderer() =default
IBatchRenderer(IBatchRenderer const & ) =delete
IBatchRenderer & operator=(IBatchRenderer const & ) =delete
IBatchRenderer(IBatchRenderer && ) =delete
IBatchRenderer & operator=(IBatchRenderer && ) =delete

Detailed Description

class PlottingOpenGL::PolyLineRenderer;

Renders RenderablePolyLineBatch data using OpenGL 3.3+ compatible calls.

See: CorePlotting::RenderablePolyLineBatch

This renderer is designed for the DataViewer use case: relatively few polylines (analog time series) that may have many vertices each.

Rendering Strategy:

  • Uses GL_LINE_STRIP for each polyline segment
  • Supports per-line colors (if provided) or a global batch color
  • Model matrix from the batch is combined with provided View/Projection

Shader Loading:

  • By default, uses ShaderManager with shaders from WhiskerToolbox/shaders/
  • Can fall back to embedded shaders if shader files are not available
  • Shader program name: “polyline_renderer”

For high-performance scenarios with 100,000+ short lines (e.g., raster plots), consider using a ComputePolyLineRenderer with SSBOs instead.

Vertex Format:

  • Position: vec2 (x, y) in world space
  • Color: vec4 (r, g, b, a) - either from uniform or vertex attribute

Public Functions Documentation

function PolyLineRenderer

explicit PolyLineRenderer(
    std::string shader_base_path =""
)

Construct a PolyLineRenderer with optional shader paths.

Parameters:

  • shader_base_path Base path to shader directory (e.g., “src/WhiskerToolbox/shaders/”) If empty, uses embedded fallback shaders.

function ~PolyLineRenderer

~PolyLineRenderer() override

function initialize

virtual bool initialize() override

Initialize GPU resources (VAOs, VBOs, shaders).

Return: true if initialization succeeded

Reimplements: PlottingOpenGL::IBatchRenderer::initialize

Must be called with a valid, current OpenGL context. Can be called multiple times (will reinitialize if needed).

function cleanup

virtual void cleanup() override

Release all GPU resources.

Reimplements: PlottingOpenGL::IBatchRenderer::cleanup

Should be called before the OpenGL context is destroyed. Safe to call even if initialize() was never called.

function isInitialized

virtual bool isInitialized() const override

Check if the renderer has been successfully initialized.

Reimplements: PlottingOpenGL::IBatchRenderer::isInitialized

function render

virtual void render(
    glm::mat4 const & view_matrix,
    glm::mat4 const & projection_matrix
) override

Render the current batch with the given View and Projection matrices.

Parameters:

  • view_matrix Global camera/view transformation
  • projection_matrix Projection to NDC

Reimplements: PlottingOpenGL::IBatchRenderer::render

The Model matrix is stored per-batch in the renderable data structure and will be combined with the provided VP matrices.

function hasData

virtual bool hasData() const override

Check if there is any data to render.

Return: true if the renderer has data uploaded and ready to draw

Reimplements: PlottingOpenGL::IBatchRenderer::hasData

function clearData

virtual void clearData() override

Clear all uploaded data (but keep GPU resources allocated).

Reimplements: PlottingOpenGL::IBatchRenderer::clearData

function uploadData

void uploadData(
    CorePlotting::RenderablePolyLineBatch const & batch
)

Upload a polyline batch to GPU memory.

Parameters:

  • batch The polyline batch to upload

Appends the batch’s vertex data to an internal combined buffer and uploads the data to the VBO via persistent buffer management (glBufferSubData). Batch metadata (topology, colors, model matrix) is stored CPU-side.

function uploadBatches

void uploadBatches(
    std::span< CorePlotting::RenderablePolyLineBatch const > batches
)

Upload multiple polyline batches to GPU memory in a single combined pass.

Parameters:

  • batches Span of batches to upload

Pre-allocates combined buffer memory and uploads all vertex data in a single GPU buffer write (using glBufferSubData when persistent capacity allows).

function setLineThickness

void setLineThickness(
    float thickness
)

Set the line thickness for all lines in the batch.

Parameters:

  • thickness Line width in pixels

Note: Line width support varies by OpenGL implementation and driver. Wide lines (> 1.0) may not be supported on all systems.

function isUsingShaderManager

inline bool isUsingShaderManager() const

Check if using ShaderManager (vs embedded fallback).

function getLastUploadedBytes

inline size_t getLastUploadedBytes() const

Number of bytes uploaded during the last upload call.

function wasLastUploadIncremental

inline bool wasLastUploadIncremental() const

Whether the last upload was fulfilled via incremental sub-buffer updates.


Updated on 2026-11-13 at 20:25:41 +0000