PlottingOpenGL::ComputeShaderIntersector
PlottingOpenGL::ComputeShaderIntersector
#include <ComputeShaderIntersector.hpp>
Inherits from CorePlotting::ILineBatchIntersector
Public Functions
| Name | |
|---|---|
| ComputeShaderIntersector(BatchLineStore & store) Construct a ComputeShaderIntersector backed by the given store. |
|
| ~ComputeShaderIntersector() override | |
| ComputeShaderIntersector(ComputeShaderIntersector const & ) =delete | |
| ComputeShaderIntersector & | operator=(ComputeShaderIntersector const & ) =delete |
| bool | initialize(std::string const & shader_resource_path =“:/shaders/line_intersection.comp”) Load and compile the compute shader program. |
| void | cleanup() |
| bool | isAvailable() const |
| virtual CorePlotting::LineIntersectionResult | intersect(CorePlotting::LineBatchData const & batch, CorePlotting::LineIntersectionQuery const & query) const override Find all lines whose segments intersect the query line. |
Additional inherited members
Public Functions inherited from CorePlotting::ILineBatchIntersector
| Name | |
|---|---|
| virtual | ~ILineBatchIntersector() =default |
Public Functions Documentation
function ComputeShaderIntersector
explicit ComputeShaderIntersector(
BatchLineStore & store
)Construct a ComputeShaderIntersector backed by the given store.
Parameters:
- store The BatchLineStore that owns the segment SSBOs. The store must outlive this intersector.
function ~ComputeShaderIntersector
~ComputeShaderIntersector() overridefunction ComputeShaderIntersector
ComputeShaderIntersector(
ComputeShaderIntersector const &
) =deletefunction operator=
ComputeShaderIntersector & operator=(
ComputeShaderIntersector const &
) =deletefunction initialize
bool initialize(
std::string const & shader_resource_path =":/shaders/line_intersection.comp"
)Load and compile the compute shader program.
Parameters:
- shader_resource_path Path to the .comp shader (file or Qt resource). Defaults to “:/shaders/line_intersection.comp”.
Return: true if the shader compiled and linked successfully.
Must be called with a current OpenGL 4.3+ context. Uses ShaderManager to manage the program lifetime per-context.
function cleanup
void cleanup()Release the shader program (managed by ShaderManager, so this is a no-op on the program itself, but resets internal state).
function isAvailable
inline bool isAvailable() constReturn: true if initialize() succeeded and the compute shader is usable.
function intersect
virtual CorePlotting::LineIntersectionResult intersect(
CorePlotting::LineBatchData const & batch,
CorePlotting::LineIntersectionQuery const & query
) const overrideFind all lines whose segments intersect the query line.
Parameters:
- batch (Ignored in GPU path; interface conformance only.)
- query The query line and transform parameters.
Return: Indices of intersected lines (0-based into LineBatchData::lines).
Note: The batch parameter is unused — segment data is read from the store’s SSBOs. The parameter exists to satisfy the interface. The CPU-side data from the store is used for result mapping.
Precondition:
- initialize() must have been called and returned true (enforcement: runtime_check — returns empty result if !m_initialized)
- A valid OpenGL context must be current on the calling thread (enforcement: none) [CRITICAL] — resetIntersectionCount(), dispatchBatched(), glMemoryBarrier(), glMapBufferRange() all issue raw GL calls. initialize() checks the context at setup time but does not re-check at call time.
- m_store.isInitialized() == true (enforcement: none) [IMPORTANT] — if the store’s SSBOs are not created, bindForCompute() silently no-ops, the compute shader runs with unbound SSBOs, and an empty result is returned with no error. The caller cannot distinguish “no intersections” from “store not ready”.
- m_store.upload() must have been called at least once (enforcement: runtime_check — silent, via cpu.empty() guard) — if no data has been uploaded, the function returns an empty result before dispatch. The CPU mirror check provides the guard, but gives no diagnostic to distinguish “no data” from “no hits”.
- query.start_ndc != query.end_ndc (query line must be non-degenerate) (enforcement: none) [LOW] — a zero-length query line is sent to the shader as-is and will produce no intersections (or undefined shader behaviour).
- query.tolerance > 0.0f (enforcement: none) [LOW] — zero or negative tolerance means no segment can be “within” the threshold; all queries return empty results silently.
- m_store must remain valid (not destroyed) for the lifetime of this intersector (enforcement: none — by construction contract on ctor)
Reimplements: CorePlotting::ILineBatchIntersector::intersect
Dispatches the compute shader in batches respecting hardware work-group limits, then reads back results via buffer mapping. The number of results is capped at BatchLineStore::RESULTS_CAPACITY.
Returns an empty result (not an error) if:
- !isAvailable() or the compute program is null
- The store’s CPU data is empty (no upload() has been called)
- GLFunctions::getExtra() returns null after dispatch
- The compute shader produces zero intersection hits
- m_store is not initialized (bindForCompute() silently no-ops)
Updated on 2026-11-13 at 20:25:41 +0000