mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Added ability to define colors at UV coordinates along a path (#4353)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> I had to make a couple types not Copy because closures, but it should'nt be a massive deal. I tried my best to make the API change as non breaking as possible. Anywhere a PathStroke is used, you can just use a normal Stroke instead. As mentioned above, the bezier paths couldn't be copy anymore, but IMO that's a minor caveat. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use epaint::*;
|
||||
use epaint::{tessellator::Path, *};
|
||||
|
||||
fn single_dashed_lines(c: &mut Criterion) {
|
||||
c.bench_function("single_dashed_lines", move |b| {
|
||||
@@ -72,10 +72,166 @@ fn tessellate_circles(c: &mut Criterion) {
|
||||
});
|
||||
}
|
||||
|
||||
fn thick_line_solid(c: &mut Criterion) {
|
||||
c.bench_function("thick_solid_line", move |b| {
|
||||
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(1.5, &Stroke::new(2.0, Color32::RED).into(), &mut mesh);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thick_large_line_solid(c: &mut Criterion) {
|
||||
c.bench_function("thick_large_solid_line", move |b| {
|
||||
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(1.5, &Stroke::new(2.0, Color32::RED).into(), &mut mesh);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thin_line_solid(c: &mut Criterion) {
|
||||
c.bench_function("thin_solid_line", move |b| {
|
||||
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(1.5, &Stroke::new(0.5, Color32::RED).into(), &mut mesh);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thin_large_line_solid(c: &mut Criterion) {
|
||||
c.bench_function("thin_large_solid_line", move |b| {
|
||||
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(1.5, &Stroke::new(0.5, Color32::RED).into(), &mut mesh);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thick_line_uv(c: &mut Criterion) {
|
||||
c.bench_function("thick_uv_line", move |b| {
|
||||
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(
|
||||
1.5,
|
||||
&PathStroke::new_uv(2.0, |_, p| {
|
||||
black_box(p * 2.0);
|
||||
Color32::RED
|
||||
}),
|
||||
&mut mesh,
|
||||
);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thick_large_line_uv(c: &mut Criterion) {
|
||||
c.bench_function("thick_large_uv_line", move |b| {
|
||||
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(
|
||||
1.5,
|
||||
&PathStroke::new_uv(2.0, |_, p| {
|
||||
black_box(p * 2.0);
|
||||
Color32::RED
|
||||
}),
|
||||
&mut mesh,
|
||||
);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thin_line_uv(c: &mut Criterion) {
|
||||
c.bench_function("thin_uv_line", move |b| {
|
||||
let line = [pos2(0.0, 0.0), pos2(50.0, 0.0), pos2(100.0, 1.0)];
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(
|
||||
1.5,
|
||||
&PathStroke::new_uv(2.0, |_, p| {
|
||||
black_box(p * 2.0);
|
||||
Color32::RED
|
||||
}),
|
||||
&mut mesh,
|
||||
);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn thin_large_line_uv(c: &mut Criterion) {
|
||||
c.bench_function("thin_large_uv_line", move |b| {
|
||||
let line = (0..1000).map(|i| pos2(i as f32, 10.0)).collect::<Vec<_>>();
|
||||
let mut path = Path::default();
|
||||
path.add_open_points(&line);
|
||||
|
||||
b.iter(|| {
|
||||
let mut mesh = Mesh::default();
|
||||
path.stroke_closed(
|
||||
1.5,
|
||||
&PathStroke::new_uv(2.0, |_, p| {
|
||||
black_box(p * 2.0);
|
||||
Color32::RED
|
||||
}),
|
||||
&mut mesh,
|
||||
);
|
||||
|
||||
black_box(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
single_dashed_lines,
|
||||
many_dashed_lines,
|
||||
tessellate_circles
|
||||
tessellate_circles,
|
||||
thick_line_solid,
|
||||
thick_large_line_solid,
|
||||
thin_line_solid,
|
||||
thin_large_line_solid,
|
||||
thick_line_uv,
|
||||
thick_large_line_uv,
|
||||
thin_line_uv,
|
||||
thin_large_line_uv
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
||||
Reference in New Issue
Block a user