mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 07:23:13 -04:00
Wrap tesselated output in struct ClippedMesh(Rect, Mesh)
This commit is contained in:
@@ -114,8 +114,14 @@ pub struct ClippedShape(
|
||||
pub Shape,
|
||||
);
|
||||
|
||||
/// A clip triangle and some textured triangles, all in points (logical pixels).
|
||||
pub type PaintJob = (emath::Rect, Mesh);
|
||||
|
||||
/// Grouped by clip rectangles, in points (logical pixels).
|
||||
pub type PaintJobs = Vec<PaintJob>;
|
||||
/// A [`Mesh`] within a clip rectangle.
|
||||
///
|
||||
/// Everything is using logical points.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ClippedMesh(
|
||||
/// Clip / scissor rectangle.
|
||||
/// Only show the part of the [`Mesh`] that falls within this.
|
||||
pub emath::Rect,
|
||||
/// The shape
|
||||
pub Mesh,
|
||||
);
|
||||
|
||||
@@ -107,17 +107,17 @@ impl AllocInfo {
|
||||
|
||||
pub fn format(&self, what: &str) -> String {
|
||||
if self.num_allocs() == 0 {
|
||||
format!("{:6} {:12}", 0, what)
|
||||
format!("{:6} {:14}", 0, what)
|
||||
} else if self.num_allocs() == 1 {
|
||||
format!(
|
||||
"{:6} {:12} {} 1 allocation",
|
||||
"{:6} {:14} {} 1 allocation",
|
||||
self.num_elements,
|
||||
what,
|
||||
self.megabytes()
|
||||
)
|
||||
} else if self.element_size != ElementSize::Heterogenous {
|
||||
format!(
|
||||
"{:6} {:12} {} {:3} allocations",
|
||||
"{:6} {:14} {} {:3} allocations",
|
||||
self.num_elements(),
|
||||
what,
|
||||
self.megabytes(),
|
||||
@@ -125,7 +125,7 @@ impl AllocInfo {
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{:6} {:12} {} {:3} allocations",
|
||||
"{:6} {:14} {} {:3} allocations",
|
||||
"",
|
||||
what,
|
||||
self.megabytes(),
|
||||
@@ -145,7 +145,7 @@ pub struct PaintStats {
|
||||
pub shape_vec: AllocInfo,
|
||||
|
||||
/// Number of separate clip rectangles
|
||||
pub jobs: AllocInfo,
|
||||
pub clipped_meshes: AllocInfo,
|
||||
pub vertices: AllocInfo,
|
||||
pub indices: AllocInfo,
|
||||
}
|
||||
@@ -188,9 +188,9 @@ impl PaintStats {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_paint_jobs(mut self, paint_jobs: &[crate::PaintJob]) -> Self {
|
||||
self.jobs += AllocInfo::from_slice(paint_jobs);
|
||||
for (_, indices) in paint_jobs {
|
||||
pub fn with_clipped_meshes(mut self, clipped_meshes: &[crate::ClippedMesh]) -> Self {
|
||||
self.clipped_meshes += AllocInfo::from_slice(clipped_meshes);
|
||||
for ClippedMesh(_, indices) in clipped_meshes {
|
||||
self.vertices += AllocInfo::from_slice(&indices.vertices);
|
||||
self.indices += AllocInfo::from_slice(&indices.indices);
|
||||
}
|
||||
@@ -202,7 +202,7 @@ impl PaintStats {
|
||||
// + self.shape_text
|
||||
// + self.shape_path
|
||||
// + self.shape_mesh
|
||||
// + self.jobs
|
||||
// + self.clipped_meshes
|
||||
// + self.vertices
|
||||
// + self.indices
|
||||
// }
|
||||
|
||||
@@ -668,27 +668,28 @@ pub fn tessellate_shapes(
|
||||
shapes: Vec<ClippedShape>,
|
||||
options: TessellationOptions,
|
||||
fonts: &Fonts,
|
||||
) -> Vec<(Rect, Mesh)> {
|
||||
) -> Vec<ClippedMesh> {
|
||||
let mut tessellator = Tessellator::from_options(options);
|
||||
|
||||
let mut jobs = PaintJobs::default();
|
||||
let mut clipped_meshes: Vec<ClippedMesh> = Vec::default();
|
||||
|
||||
for ClippedShape(clip_rect, shape) in shapes {
|
||||
let start_new_job = match jobs.last() {
|
||||
let start_new_mesh = match clipped_meshes.last() {
|
||||
None => true,
|
||||
Some(job) => job.0 != clip_rect || job.1.texture_id != shape.texture_id(),
|
||||
Some(cm) => cm.0 != clip_rect || cm.1.texture_id != shape.texture_id(),
|
||||
};
|
||||
|
||||
if start_new_job {
|
||||
jobs.push((clip_rect, Mesh::default()));
|
||||
if start_new_mesh {
|
||||
clipped_meshes.push(ClippedMesh(clip_rect, Mesh::default()));
|
||||
}
|
||||
|
||||
let out = &mut jobs.last_mut().unwrap().1;
|
||||
let out = &mut clipped_meshes.last_mut().unwrap().1;
|
||||
tessellator.clip_rect = clip_rect;
|
||||
tessellator.tessellate_shape(fonts, shape, out);
|
||||
}
|
||||
|
||||
if options.debug_paint_clip_rects {
|
||||
for (clip_rect, mesh) in &mut jobs {
|
||||
for ClippedMesh(clip_rect, mesh) in &mut clipped_meshes {
|
||||
tessellator.clip_rect = Rect::everything();
|
||||
tessellator.tessellate_shape(
|
||||
fonts,
|
||||
@@ -704,14 +705,14 @@ pub fn tessellate_shapes(
|
||||
}
|
||||
|
||||
if options.debug_ignore_clip_rects {
|
||||
for (clip_rect, _) in &mut jobs {
|
||||
for ClippedMesh(clip_rect, _) in &mut clipped_meshes {
|
||||
*clip_rect = Rect::everything();
|
||||
}
|
||||
}
|
||||
|
||||
for (_, mesh) in &jobs {
|
||||
for ClippedMesh(_, mesh) in &clipped_meshes {
|
||||
debug_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh");
|
||||
}
|
||||
|
||||
jobs
|
||||
clipped_meshes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user