PlottingOpenGL::GlyphRenderer
PlottingOpenGL::GlyphRenderer
Renders RenderableGlyphBatch data using instanced rendering. More…
#include <GlyphRenderer.hpp>
Inherits from PlottingOpenGL::IBatchRenderer
Public Functions
| Name | |
|---|---|
| GlyphRenderer(std::string shader_base_path =““) Construct a GlyphRenderer with optional shader paths. |
|
| ~GlyphRenderer() 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::RenderableGlyphBatch const & batch) Upload a glyph batch to GPU memory. |
| void | setGlyphSize(float size) Set the glyph size in pixels (for point sprites) or world units. |
| bool | isUsingShaderManager() const Check if using ShaderManager (vs embedded fallback). |
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::GlyphRenderer;Renders RenderableGlyphBatch data using instanced rendering.
See: CorePlotting::RenderableGlyphBatch
This renderer is designed for event markers, raster plot ticks, and point data visualization. It uses GPU instancing to efficiently render thousands of identical glyphs at different positions.
Rendering Strategy:
- Uses instanced rendering (glDrawArraysInstanced)
- Each glyph type (circle, square, tick, top line, cross) has predefined CPU-side line or quad geometry
- Position and color can vary per instance
- Model matrix from the batch positions the entire batch in world space
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: “glyph_renderer”
Supported Glyph Types:
- Circle: Point primitive (GL_POINTS) with gl_PointSize
- Square: Quad rendered as two triangles
- Tick: Vertical line segment (local geometry along ±Y, scaled by batch.size)
- TopLine: Horizontal line segment (local geometry along ±X, scaled by batch.size)
- Cross: Two perpendicular line segments
Public Functions Documentation
function GlyphRenderer
explicit GlyphRenderer(
std::string shader_base_path =""
)Construct a GlyphRenderer 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 ~GlyphRenderer
~GlyphRenderer() overridefunction initialize
virtual bool initialize() overrideInitialize 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() overrideRelease 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 overrideCheck 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
) overrideRender 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 overrideCheck 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() overrideClear all uploaded data (but keep GPU resources allocated).
Reimplements: PlottingOpenGL::IBatchRenderer::clearData
function uploadData
void uploadData(
CorePlotting::RenderableGlyphBatch const & batch
)Upload a glyph batch to GPU memory.
Parameters:
- batch The glyph batch to upload
Precondition:
- initialize() must have been called and returned true before the first call (enforcement: runtime_check — early return if !m_initialized)
- A valid OpenGL context must be current on the calling thread when batch.glyph_type != GlyphType::Circle (enforcement: none) [IMPORTANT] — non-Circle types call m_geometry_vbo.allocate() immediately if the geometry type changed or no geometry exists; Circle glyphs defer all GL work to render(), so no context is required for them at this point.
- If batch.colors is non-empty, batch.colors.size() >= batch.positions.size() (enforcement: none) [IMPORTANT] — render() uploads batch.colors to the color VBO and then draws batch.positions.size() instances; if colors is shorter, the GPU reads uninitialized instance color data for the excess glyphs.
- batch.size > 0 (enforcement: none) [LOW] — passed directly to u_glyph_size / u_point_size uniforms in render(); zero or negative values produce invisible or degenerate glyphs.
Stores batch metadata (positions, colors, model matrix, glyph type) CPU-side. Instance VBO uploads (positions and colors) are deferred to render(), so there is no O(N²) re-upload cost from multiple uploadData calls.
For non-Circle glyph types, glyph geometry is created and immediately uploaded to the geometry VBO if the type has changed or no geometry exists. For Circle glyphs, no GPU work is done at uploadData time.
Each call appends a new batch — call clearData() between frames.
An empty batch.positions is handled gracefully (early return). An empty batch.colors causes a uniform white color array to be generated for all instances — no precondition is required for that field.
function setGlyphSize
void setGlyphSize(
float size
)Set the glyph size in pixels (for point sprites) or world units.
Parameters:
- size The size of each glyph
function isUsingShaderManager
inline bool isUsingShaderManager() constCheck if using ShaderManager (vs embedded fallback).
Updated on 2026-11-13 at 20:25:41 +0000