Optimize tessellator: pass options by reference
This commit is contained in:
parent
2e83e36146
commit
d9db768180
2 changed files with 13 additions and 13 deletions
|
@ -152,12 +152,12 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open-ended.
|
/// Open-ended.
|
||||||
pub fn stroke_open(&self, stroke: Stroke, options: TessellationOptions, out: &mut Mesh) {
|
pub fn stroke_open(&self, stroke: Stroke, options: &TessellationOptions, out: &mut Mesh) {
|
||||||
stroke_path(&self.0, PathType::Open, stroke, options, out)
|
stroke_path(&self.0, PathType::Open, stroke, options, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A closed path (returning to the first point).
|
/// A closed path (returning to the first point).
|
||||||
pub fn stroke_closed(&self, stroke: Stroke, options: TessellationOptions, out: &mut Mesh) {
|
pub fn stroke_closed(&self, stroke: Stroke, options: &TessellationOptions, out: &mut Mesh) {
|
||||||
stroke_path(&self.0, PathType::Closed, stroke, options, out)
|
stroke_path(&self.0, PathType::Closed, stroke, options, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,14 +165,14 @@ impl Path {
|
||||||
&self,
|
&self,
|
||||||
path_type: PathType,
|
path_type: PathType,
|
||||||
stroke: Stroke,
|
stroke: Stroke,
|
||||||
options: TessellationOptions,
|
options: &TessellationOptions,
|
||||||
out: &mut Mesh,
|
out: &mut Mesh,
|
||||||
) {
|
) {
|
||||||
stroke_path(&self.0, path_type, stroke, options, out)
|
stroke_path(&self.0, path_type, stroke, options, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The path is taken to be closed (i.e. returning to the start again).
|
/// The path is taken to be closed (i.e. returning to the start again).
|
||||||
pub fn fill(&self, color: Color32, options: TessellationOptions, out: &mut Mesh) {
|
pub fn fill(&self, color: Color32, options: &TessellationOptions, out: &mut Mesh) {
|
||||||
fill_closed_path(&self.0, color, options, out)
|
fill_closed_path(&self.0, color, options, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ impl TessellationOptions {
|
||||||
fn fill_closed_path(
|
fn fill_closed_path(
|
||||||
path: &[PathPoint],
|
path: &[PathPoint],
|
||||||
color: Color32,
|
color: Color32,
|
||||||
options: TessellationOptions,
|
options: &TessellationOptions,
|
||||||
out: &mut Mesh,
|
out: &mut Mesh,
|
||||||
) {
|
) {
|
||||||
if color == Color32::TRANSPARENT {
|
if color == Color32::TRANSPARENT {
|
||||||
|
@ -356,7 +356,7 @@ fn stroke_path(
|
||||||
path: &[PathPoint],
|
path: &[PathPoint],
|
||||||
path_type: PathType,
|
path_type: PathType,
|
||||||
stroke: Stroke,
|
stroke: Stroke,
|
||||||
options: TessellationOptions,
|
options: &TessellationOptions,
|
||||||
out: &mut Mesh,
|
out: &mut Mesh,
|
||||||
) {
|
) {
|
||||||
if stroke.width <= 0.0 || stroke.color == Color32::TRANSPARENT {
|
if stroke.width <= 0.0 || stroke.color == Color32::TRANSPARENT {
|
||||||
|
@ -532,7 +532,7 @@ impl Tessellator {
|
||||||
/// many times, pass it a reference to the same `Path` to avoid excessive allocations.
|
/// many times, pass it a reference to the same `Path` to avoid excessive allocations.
|
||||||
pub fn tessellate_shape(&mut self, tex_size: [usize; 2], shape: Shape, out: &mut Mesh) {
|
pub fn tessellate_shape(&mut self, tex_size: [usize; 2], shape: Shape, out: &mut Mesh) {
|
||||||
let clip_rect = self.clip_rect;
|
let clip_rect = self.clip_rect;
|
||||||
let options = self.options;
|
let options = &self.options;
|
||||||
|
|
||||||
match shape {
|
match shape {
|
||||||
Shape::Noop => {}
|
Shape::Noop => {}
|
||||||
|
@ -640,14 +640,14 @@ impl Tessellator {
|
||||||
closed,
|
closed,
|
||||||
"You asked to fill a path that is not closed. That makes no sense."
|
"You asked to fill a path that is not closed. That makes no sense."
|
||||||
);
|
);
|
||||||
self.scratchpad_path.fill(fill, self.options, out);
|
self.scratchpad_path.fill(fill, &self.options, out);
|
||||||
}
|
}
|
||||||
let typ = if closed {
|
let typ = if closed {
|
||||||
PathType::Closed
|
PathType::Closed
|
||||||
} else {
|
} else {
|
||||||
PathType::Open
|
PathType::Open
|
||||||
};
|
};
|
||||||
self.scratchpad_path.stroke(typ, stroke, self.options, out);
|
self.scratchpad_path.stroke(typ, stroke, &self.options, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tessellate_rect(&mut self, rect: &RectShape, out: &mut Mesh) {
|
pub(crate) fn tessellate_rect(&mut self, rect: &RectShape, out: &mut Mesh) {
|
||||||
|
@ -676,8 +676,8 @@ impl Tessellator {
|
||||||
path.clear();
|
path.clear();
|
||||||
path::rounded_rectangle(&mut self.scratchpad_points, rect, corner_radius);
|
path::rounded_rectangle(&mut self.scratchpad_points, rect, corner_radius);
|
||||||
path.add_line_loop(&self.scratchpad_points);
|
path.add_line_loop(&self.scratchpad_points);
|
||||||
path.fill(fill, self.options, out);
|
path.fill(fill, &self.options, out);
|
||||||
path.stroke_closed(stroke, self.options, out);
|
path.stroke_closed(stroke, &self.options, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tessellate_text(&mut self, tex_size: [usize; 2], text_shape: TextShape, out: &mut Mesh) {
|
pub fn tessellate_text(&mut self, tex_size: [usize; 2], text_shape: TextShape, out: &mut Mesh) {
|
||||||
|
@ -768,7 +768,7 @@ impl Tessellator {
|
||||||
self.scratchpad_path
|
self.scratchpad_path
|
||||||
.add_line_segment([row_rect.left_bottom(), row_rect.right_bottom()]);
|
.add_line_segment([row_rect.left_bottom(), row_rect.right_bottom()]);
|
||||||
self.scratchpad_path
|
self.scratchpad_path
|
||||||
.stroke_open(underline, self.options, out);
|
.stroke_open(underline, &self.options, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,7 +567,7 @@ fn add_hline(fonts: &Fonts, [start, stop]: [Pos2; 2], stroke: Stroke, mesh: &mut
|
||||||
let options = crate::tessellator::TessellationOptions::from_pixels_per_point(
|
let options = crate::tessellator::TessellationOptions::from_pixels_per_point(
|
||||||
fonts.pixels_per_point(),
|
fonts.pixels_per_point(),
|
||||||
);
|
);
|
||||||
path.stroke_open(stroke, options, mesh);
|
path.stroke_open(stroke, &options, mesh);
|
||||||
} else {
|
} else {
|
||||||
// Thin lines often lost, so this is a bad idea
|
// Thin lines often lost, so this is a bad idea
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue