pub struct WebGl2ChartBackend { /* private fields */ }Expand description
The WebGL2 rendering backend for the chart.
This is the GPU fallback for browsers that do not expose WebGPU. It replays the same display list as the WebGPU backend and the Canvas2D backend, so the picture it produces is the same; only the plumbing differs.
§Performance
The display list is retained between frames, and the backend takes advantage of that in two ways.
The first is caching: the backend fingerprints the display list and only re-tessellates and re-uploads when the fingerprint changes. An unchanged chart therefore costs no vertex work at all — the GPU buffers are simply drawn again.
The second is batching: every shape in the display list ends up in one vertex buffer, in paint order, and is drawn with a handful of draw calls. A steady-state frame of an ordinary chart issues two or three draw calls, and none of them crosses the JavaScript boundary more than a handful of times, because the vertex data is uploaded in one go rather than one vertex at a time.
Implementations§
Source§impl WebGl2ChartBackend
Inherent implementation of WebGl2ChartBackend.
impl WebGl2ChartBackend
Inherent implementation of WebGl2ChartBackend.
Sourcepub fn is_supported() -> bool
pub fn is_supported() -> bool
Returns true when the host can give out a WebGL2 context.
The check opens a throw-away canvas and asks it for a context, so it costs one context creation. It is cheap enough to run while the backend is being picked, and it never throws.
§Returns
bool- A boolean.
Sourcepub fn create(canvas: &HtmlCanvasElement) -> Option<Self>
pub fn create(canvas: &HtmlCanvasElement) -> Option<Self>
Creates a backend around the given canvas.
Returns None when the canvas cannot give out a WebGL2 context —
in practice, when the canvas already has a WebGPU context, or when
the browser has no WebGL2 at all — and when the shaders cannot be
built. The factory then falls back to the Canvas2D backend.
§Arguments
&HtmlCanvasElement- Shared reference to aHtmlCanvasElement.
§Returns
Option<Self>-Some(...)on success,Noneotherwise.
Sourcepub fn canvas(&self) -> &HtmlCanvasElement
pub fn canvas(&self) -> &HtmlCanvasElement
Sourcepub fn draw_call_count(&self) -> usize
pub fn draw_call_count(&self) -> usize
Returns the number of draw calls the last frame used.
The number is a debugging aid: it is the number of batches the last frame was split into, which is what a chart with no images and no clip paths reports as one.
§Returns
usize- A non-negative integer.
Trait Implementations§
Source§impl ChartBackend for WebGl2ChartBackend
Implements ChartBackend for WebGl2ChartBackend.
impl ChartBackend for WebGl2ChartBackend
Implements ChartBackend for WebGl2ChartBackend.
Source§fn kind(&self) -> BackendKind
fn kind(&self) -> BackendKind
Source§fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
Implements the render operation on WebGl2ChartBackend.
§Arguments
&DisplayList- Shared reference to aDisplayList.&mut TextShaper- Mutable reference to aTextShaper(mutated in place).
Source§fn dispose(&mut self)
fn dispose(&mut self)
Implements the dispose operation on WebGl2ChartBackend.
Source§impl Drop for WebGl2ChartBackend
Implements Drop for WebGl2ChartBackend.
impl Drop for WebGl2ChartBackend
Implements Drop for WebGl2ChartBackend.