Skip to main content

PlottingOpenGL::BatchLineStore

PlottingOpenGL::BatchLineStore

#include <BatchLineStore.hpp>

Public Functions

Name
BatchLineStore()
~BatchLineStore()
BatchLineStore(BatchLineStore const & ) =delete
BatchLineStore & operator=(BatchLineStore const & ) =delete
bool initialize()
Create GPU buffer objects.
void cleanup()
Release all GPU resources.
bool isInitialized() const
Whether GPU buffers have been successfully created.
void upload(CorePlotting::LineBatchData const & batch)
Full re-upload of batch data to GPU (and update CPU mirror).
void updateVisibilityMask(std::vector< std::uint32_t > const & mask)
Update only the visibility mask (CPU + GPU).
void updateSelectionMask(std::vector< std::uint32_t > const & mask)
Update only the selection mask (CPU + GPU).
std::uint32_t segmentsBufferId() const
std::uint32_t visibilityBufferId() const
std::uint32_t selectionMaskBufferId() const
std::uint32_t intersectionResultsBufferId() const
std::uint32_t intersectionCountBufferId() const
std::uint32_t numSegments() const
std::uint32_t numLines() const
CorePlotting::LineBatchData const & cpuData() const
CPU-side data mirror (for CpuLineBatchIntersector or direct queries).
void bindForCompute() const
Bind all SSBOs needed by the compute shader to their binding points.
void bindForRender() const
Bind all SSBOs needed by the rendering shader to their binding points.
void resetIntersectionCount()
Reset the intersection count atomic counter to zero (call before dispatch).

Public Attributes

Name
std::uint32_t RESULTS_CAPACITY
Maximum number of intersection results the results buffer can hold.

Public Functions Documentation

function BatchLineStore

BatchLineStore()

function ~BatchLineStore

~BatchLineStore()

function BatchLineStore

BatchLineStore(
    BatchLineStore const & 
) =delete

function operator=

BatchLineStore & operator=(
    BatchLineStore const & 
) =delete

function initialize

bool initialize()

Create GPU buffer objects.

Call from initializeGL() with a current GL 4.3+ context. Returns false if buffer creation fails or no context is available. On macOS / GL < 4.3, returns false — CPU data is still usable.

function cleanup

void cleanup()

Release all GPU resources.

Safe to call even if initialize() was never called or failed.

function isInitialized

inline bool isInitialized() const

Whether GPU buffers have been successfully created.

function upload

void upload(
    CorePlotting::LineBatchData const & batch
)

Full re-upload of batch data to GPU (and update CPU mirror).

Parameters:

  • batch The new batch data

Precondition:

  • A valid OpenGL context must be current on the calling thread when isInitialized() == true (enforcement: none) [CRITICAL] — SSBO allocate() calls raw GL; GLSSBOBuffer docs state all methods require a current context. If !isInitialized(), upload() returns before touching the GPU, so no context is needed.
  • batch.line_ids.size() == batch.segments.size() / 4 (one line_id per segment) (enforcement: none) [CRITICAL] — packSegments() accesses line_ids[seg] for every seg in [0, numSegments()) with no bounds check; if line_ids is shorter, this is an out-of-bounds vector read (UB / potential crash).
  • batch.segments.size() % 4 == 0 (each segment must be a complete {x1, y1, x2, y2} quad) (enforcement: none) [IMPORTANT] — numSegments() = segments.size() / 4 truncates; a trailing partial segment is silently ignored at pack time.
  • batch.segments.size() * sizeof(float) <= INT_MAX (narrowing cast to int for SSBO allocate()) (enforcement: none) [LOW]

Postcondition:

  • m_cpu_data == batch (CPU mirror is always updated).
  • If isInitialized(): all SSBOs reflect the new batch data and the intersection count SSBO has been reset to zero.

The segments are packed into the 5-float-per-segment format expected by the compute shader (x1, y1, x2, y2, line_id_as_bits).

CPU mirror is always updated, regardless of whether initialize() has been called or succeeded. This allows the CpuLineBatchIntersector and other CPU-side consumers to query the data even on platforms where GPU buffers are unavailable (e.g., macOS / OpenGL < 4.3).

GPU upload is skipped (returns early) if !isInitialized(). Empty visibility_mask, selection_mask, and line_ids are handled gracefully (0-byte SSBO allocation with nullptr).

function updateVisibilityMask

void updateVisibilityMask(
    std::vector< std::uint32_t > const & mask
)

Update only the visibility mask (CPU + GPU).

Parameters:

  • mask New per-line visibility values (1 = visible, 0 = hidden). Must have size == numLines().

Precondition:

  • upload() must have been called at least once before this function to establish the expected mask size in m_cpu_data.visibility_mask (enforcement: none) [IMPORTANT] — if upload() has not been called, m_cpu_data.visibility_mask.size() == 0; any non-empty mask will silently fail the size check and the update will be dropped with no indication of failure.
  • mask.size() == numLines() (enforcement: runtime_check — silent) — a size mismatch causes an unconditional silent early return; callers cannot distinguish a successful write from a dropped one.
  • A valid OpenGL context must be current on the calling thread when isInitialized() == true and mask is non-empty (enforcement: none) [CRITICAL] — m_visibility_ssbo.write() calls glBufferSubData with no context guard.
  • mask.size() * sizeof(uint32_t) <= INT_MAX (narrowing cast to int for m_visibility_ssbo.write()) (enforcement: none) [LOW]

Much cheaper than a full upload. Updates m_cpu_data.visibility_mask and (if initialized and non-empty) writes to the visibility SSBO via glBufferSubData without reallocating or touching any other buffer.

If the size check fails, the function returns silently — no error is reported and neither the CPU mirror nor the GPU buffer is updated.

function updateSelectionMask

void updateSelectionMask(
    std::vector< std::uint32_t > const & mask
)

Update only the selection mask (CPU + GPU).

Parameters:

  • mask New per-line selection values (1 = selected, 0 = not selected). Must have size == numLines().

See: updateVisibilityMask() for the equivalent visibility update.

Precondition:

  • upload() must have been called at least once before this function to establish the expected mask size in m_cpu_data.selection_mask (enforcement: none) [IMPORTANT] — if upload() has not been called, m_cpu_data.selection_mask.size() == 0; any non-empty mask will silently fail the size check and the update will be dropped with no indication of failure.
  • mask.size() == numLines() (enforcement: runtime_check — silent) — a size mismatch causes an unconditional silent early return; callers cannot distinguish a successful write from a dropped one.
  • A valid OpenGL context must be current on the calling thread when isInitialized() == true and mask is non-empty (enforcement: none) [CRITICAL] — m_selection_ssbo.write() calls glBufferSubData with no context guard.
  • mask.size() * sizeof(uint32_t) <= INT_MAX (narrowing cast to int for m_selection_ssbo.write()) (enforcement: none) [LOW]

Structurally identical to updateVisibilityMask() — same size check, same silent-failure pattern, same conditional SSBO write — operating on selection_mask / m_selection_ssbo instead of the visibility counterparts.

If the size check fails, the function returns silently — no error is reported and neither the CPU mirror nor the GPU buffer is updated.

function segmentsBufferId

inline std::uint32_t segmentsBufferId() const

function visibilityBufferId

inline std::uint32_t visibilityBufferId() const

function selectionMaskBufferId

inline std::uint32_t selectionMaskBufferId() const

function intersectionResultsBufferId

inline std::uint32_t intersectionResultsBufferId() const

function intersectionCountBufferId

inline std::uint32_t intersectionCountBufferId() const

function numSegments

inline std::uint32_t numSegments() const

function numLines

inline std::uint32_t numLines() const

function cpuData

inline CorePlotting::LineBatchData const & cpuData() const

CPU-side data mirror (for CpuLineBatchIntersector or direct queries).

function bindForCompute

void bindForCompute() const

Bind all SSBOs needed by the compute shader to their binding points.

function bindForRender

void bindForRender() const

Bind all SSBOs needed by the rendering shader to their binding points.

function resetIntersectionCount

void resetIntersectionCount()

Reset the intersection count atomic counter to zero (call before dispatch).

Public Attributes Documentation

variable RESULTS_CAPACITY

static std::uint32_t RESULTS_CAPACITY = 100000;

Maximum number of intersection results the results buffer can hold.


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