The canvas to render candles into. Should be sized/stacked by
the host beneath the chart's existing 2D layers. If getContext('webgl')
returns null the renderer disables itself (supported stays false).
Release every GL resource (buffers, program, shaders). Idempotent and safe when unsupported. After this the renderer must not be used again.
Build candle geometry for view and draw it. Uploads fresh positions/colors
(DYNAMIC_DRAW — they change every frame), sets the viewport + resolution
uniform, optionally clears, then issues one drawArrays(TRIANGLES, …) for
the whole frame. No-op when unsupported or when there are zero visible
vertices.
Update the cached drawable size (pixels). Call after the host resizes the
GL canvas so the next render uses the right gl.viewport and
pixel→clip resolution. No-op when unsupported.
OPTIONAL GPU-instanced renderer for the candle hot path. Draws ONLY the candle bodies + wicks via WebGL
TRIANGLES; axes, grid, legend, crosshair, and everything else stay on Canvas2D. It is not wired intoChartEngine/OHLCVChart— a host opts in explicitly, layering a WebGL canvas under the existing 2D layers, so this whole module tree-shakes to zero in the base bundle.The expensive geometry step (buildCandleVertices) is a pure function with no GL/DOM dependency, so it is fully unit-testable; this class is the thin GL wrapper around it.
Graceful degradation: if the browser can't give a
webglcontext (very old browser, blocked GPU) the constructor sets supported tofalseand never throws — a host checks the flag and falls back to the Canvas2D path.Example