pub struct PathEncoder<'a> { /* private fields */ }Expand description
Encoder for path segments.
Implementations§
Source§impl<'a> PathEncoder<'a>
impl<'a> PathEncoder<'a>
Sourcepub fn new(
tags: &'a mut Vec<PathTag>,
data: &'a mut Vec<u32>,
n_segments: &'a mut u32,
n_paths: &'a mut u32,
is_fill: bool,
) -> Self
pub fn new( tags: &'a mut Vec<PathTag>, data: &'a mut Vec<u32>, n_segments: &'a mut u32, n_paths: &'a mut u32, is_fill: bool, ) -> Self
Creates a new path encoder for the specified path tags and data.
If is_fill is true, ensures that all subpaths are closed. Otherwise, the path is treated
as a stroke and an additional “stroke cap marker” segment is inserted at the end of every
subpath.
§Stroke Encoding
Every subpath within a stroked path is terminated with a “stroke cap marker” segment. This segment tells the GPU stroker whether to draw a cap or a join based on the topology of the path:
-
This marker segment is encoded as a
quad-to(2 additional points) for an open path and aline-to(1 additional point) for a closed path. An open path gets drawn with a start and end cap. A closed path gets drawn with a single join in place of the caps where the subpath’s start and end control points meet. -
The marker segment tells the GPU flattening stage how to render caps and joins while processing each path segment in parallel. All subpaths end with the marker segment which is the only segment that has the
SUBPATH_END_BITset to 1.The algorithm is as follows:
-
If a GPU thread is processing a regular segment (i.e.
SUBPATH_END_BITis 0), it outputs the offset curves for the segment. If the segment is immediately followed by the marker segment, then the same thread draws an end cap if the subpath is open (i.e. the marker is a quad-to) or a join if the subpath is closed (i.e. the marker is a line-to) using the tangent encoded in the marker segment. If the segment is immediately followed by another regular segment, then the thread draws a join using the start tangent of the neighboring segment. -
If a GPU thread is processing the marker segment (i.e.
SUBPATH_END_BITis 1), then it draws a start cap using the information encoded in the segment IF the subpath is open (i.e. the marker is a quad-to). If the subpath is closed (i.e. the marker is a line-to), the thread draws nothing.
-
Sourcepub fn cubic_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
pub fn cubic_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
Encodes a cubic bezier.
Sourcepub fn path_elements(&mut self, path: impl Iterator<Item = PathEl>)
pub fn path_elements(&mut self, path: impl Iterator<Item = PathEl>)
Encodes a path iterator
Sourcepub fn finish(self, insert_path_marker: bool) -> u32
pub fn finish(self, insert_path_marker: bool) -> u32
Completes path encoding and returns the actual number of encoded segments.
If insert_path_marker is true, encodes the PathTag::PATH tag to signify
the end of a complete path object. Setting this to false allows encoding
multiple paths with differing transforms for a single draw object.