Skip to main content

euv_chart/backend/webgl/
enum.rs

1use super::*;
2
3/// How the fragment stage shades one vertex.
4///
5/// The kind travels with the vertex instead of being a uniform, because
6/// the chart puts fills, strokes, labels, and images into one buffer and
7/// draws them in the order the display list asks for. A per-vertex kind
8/// is what makes that possible: the whole frame is one draw call, and
9/// the paint order is the order of the triangles.
10#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
11pub enum WebGl2VertexKind {
12    /// A flat-coloured triangle: a fill, a stroke, an area strip, or a
13    /// label background.
14    ///
15    /// The colour is the one the vertex carries.
16    #[default]
17    Solid,
18    /// A glyph quad, read from the glyph atlas.
19    ///
20    /// The atlas holds white glyphs, so only the coverage the texture
21    /// carries is used and the colour comes from the vertex.
22    Text,
23    /// A triangle painted with a gradient.
24    ///
25    /// The colour comes from the ramp row the vertex names, and the
26    /// vertex's own alpha scales it.
27    Gradient,
28    /// An image quad, read from the image itself.
29    ///
30    /// Unlike a glyph, an image carries its own colour, so the texture
31    /// is multiplied by the vertex's colour.
32    Image,
33}
34
35/// Which texture a batch samples.
36///
37/// The chart draws in batches: a batch is a run of consecutive triangles
38/// that share a texture and a clip rectangle, and therefore cost exactly
39/// one draw call. Splitting the frame by texture is the only split the
40/// backend needs, because the glyph atlas and the images cannot be
41/// sampled from one binding.
42#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
43pub enum WebGl2BatchKind {
44    /// The batch samples the glyph atlas.
45    #[default]
46    Atlas,
47    /// The batch samples an image element.
48    Image,
49}
50
51/// A gradient the frame uses.
52///
53/// Gradients are rare compared to plain colours, so they are collected
54/// into a table instead of being baked into the vertices: every shape
55/// that uses the same gradient points at the same row of the ramp
56/// texture.
57#[derive(Clone)]
58pub(crate) enum WebGl2Gradient {
59    /// A linear gradient, running from one point to another.
60    Linear(LinearGradient),
61    /// A radial gradient, running from a centre outwards.
62    Radial(RadialGradient),
63}