mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Rename Triangles to Mesh
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#![allow(clippy::manual_range_contains)]
|
||||
|
||||
pub mod color;
|
||||
mod mesh;
|
||||
pub mod mutex;
|
||||
mod shadow;
|
||||
mod shape;
|
||||
@@ -53,10 +54,10 @@ mod stroke;
|
||||
pub mod tessellator;
|
||||
pub mod text;
|
||||
mod texture_atlas;
|
||||
mod triangles;
|
||||
|
||||
pub use {
|
||||
color::{Color32, Rgba},
|
||||
mesh::{Mesh, Vertex},
|
||||
shadow::Shadow,
|
||||
shape::Shape,
|
||||
stats::PaintStats,
|
||||
@@ -64,7 +65,6 @@ pub use {
|
||||
tessellator::TessellationOptions,
|
||||
text::{Galley, TextStyle},
|
||||
texture_atlas::{Texture, TextureAtlas},
|
||||
triangles::{Triangles, Vertex},
|
||||
};
|
||||
|
||||
pub use ahash;
|
||||
@@ -76,7 +76,7 @@ pub use emath;
|
||||
/// (so it doesn't do bilinear blending with bottom right corner).
|
||||
pub const WHITE_UV: emath::Pos2 = emath::pos2(0.0, 0.0);
|
||||
|
||||
/// What texture to use in a [`Triangles`] mesh.
|
||||
/// What texture to use in a [`Mesh`] mesh.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum TextureId {
|
||||
/// The egui font texture.
|
||||
@@ -115,7 +115,7 @@ pub struct ClippedShape(
|
||||
);
|
||||
|
||||
/// A clip triangle and some textured triangles, all in points (logical pixels).
|
||||
pub type PaintJob = (emath::Rect, Triangles);
|
||||
pub type PaintJob = (emath::Rect, Mesh);
|
||||
|
||||
/// Grouped by clip rectangles, in points (logical pixels).
|
||||
pub type PaintJobs = Vec<PaintJob>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::*;
|
||||
use emath::*;
|
||||
|
||||
/// The vertex type.
|
||||
/// The 2D vertex type.
|
||||
///
|
||||
/// Should be friendly to send to GPU as is.
|
||||
#[repr(C)]
|
||||
@@ -20,9 +20,9 @@ pub struct Vertex {
|
||||
pub color: Color32, // 32 bit
|
||||
}
|
||||
|
||||
/// Textured triangles.
|
||||
/// Textured triangles in two dimensions.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Triangles {
|
||||
pub struct Mesh {
|
||||
/// Draw as triangles (i.e. the length is always multiple of three).
|
||||
///
|
||||
/// egui is NOT consistent with what winding order it uses, so turn off backface culling.
|
||||
@@ -35,7 +35,7 @@ pub struct Triangles {
|
||||
pub texture_id: TextureId,
|
||||
}
|
||||
|
||||
impl Triangles {
|
||||
impl Mesh {
|
||||
pub fn with_texture(texture_id: TextureId) -> Self {
|
||||
Self {
|
||||
texture_id,
|
||||
@@ -60,7 +60,7 @@ impl Triangles {
|
||||
}
|
||||
|
||||
/// Append all the indices and vertices of `other` to `self`.
|
||||
pub fn append(&mut self, other: Triangles) {
|
||||
pub fn append(&mut self, other: Mesh) {
|
||||
debug_assert!(other.is_valid());
|
||||
|
||||
if self.is_empty() {
|
||||
@@ -68,7 +68,7 @@ impl Triangles {
|
||||
} else {
|
||||
assert_eq!(
|
||||
self.texture_id, other.texture_id,
|
||||
"Can't merge Triangles using different textures"
|
||||
"Can't merge Mesh using different textures"
|
||||
);
|
||||
|
||||
let index_offset = self.vertices.len() as u32;
|
||||
@@ -151,7 +151,7 @@ impl Triangles {
|
||||
///
|
||||
/// Splits this mesh into many smaller meshes (if needed).
|
||||
/// All the returned meshes will have indices that fit into a `u16`.
|
||||
pub fn split_to_u16(self) -> Vec<Triangles> {
|
||||
pub fn split_to_u16(self) -> Vec<Mesh> {
|
||||
const MAX_SIZE: u32 = 1 << 16;
|
||||
|
||||
if self.vertices.len() < MAX_SIZE as usize {
|
||||
@@ -190,7 +190,7 @@ impl Triangles {
|
||||
MAX_SIZE
|
||||
);
|
||||
|
||||
output.push(Triangles {
|
||||
output.push(Mesh {
|
||||
indices: self.indices[span_start..index_cursor]
|
||||
.iter()
|
||||
.map(|vi| vi - min_vindex)
|
||||
@@ -30,7 +30,7 @@ impl Shadow {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tessellate(&self, rect: emath::Rect, corner_radius: f32) -> Triangles {
|
||||
pub fn tessellate(&self, rect: emath::Rect, corner_radius: f32) -> Mesh {
|
||||
// tessellator.clip_rect = clip_rect; // TODO: culling
|
||||
|
||||
let Self { extrusion, color } = *self;
|
||||
@@ -47,8 +47,8 @@ impl Shadow {
|
||||
anti_alias: true,
|
||||
..Default::default()
|
||||
});
|
||||
let mut triangles = Triangles::default();
|
||||
tessellator.tessellate_rect(&rect, &mut triangles);
|
||||
triangles
|
||||
let mut mesh = Mesh::default();
|
||||
tessellator.tessellate_rect(&rect, &mut mesh);
|
||||
mesh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
text::{Fonts, Galley, TextStyle},
|
||||
Color32, Stroke, Triangles,
|
||||
Color32, Mesh, Stroke,
|
||||
};
|
||||
use emath::*;
|
||||
|
||||
@@ -47,7 +47,7 @@ pub enum Shape {
|
||||
text_style: TextStyle, // TODO: Font?
|
||||
color: Color32,
|
||||
},
|
||||
Triangles(Triangles),
|
||||
Mesh(Mesh),
|
||||
}
|
||||
|
||||
/// ## Constructors
|
||||
@@ -144,14 +144,19 @@ impl Shape {
|
||||
|
||||
/// ## Operations
|
||||
impl Shape {
|
||||
pub fn triangles(triangles: Triangles) -> Self {
|
||||
debug_assert!(triangles.is_valid());
|
||||
Self::Triangles(triangles)
|
||||
pub fn mesh(mesh: Mesh) -> Self {
|
||||
debug_assert!(mesh.is_valid());
|
||||
Self::Mesh(mesh)
|
||||
}
|
||||
|
||||
#[deprecated = "Renamed `mesh`"]
|
||||
pub fn triangles(mesh: Mesh) -> Self {
|
||||
Self::mesh(mesh)
|
||||
}
|
||||
|
||||
pub fn texture_id(&self) -> super::TextureId {
|
||||
if let Shape::Triangles(triangles) = self {
|
||||
triangles.texture_id
|
||||
if let Shape::Mesh(mesh) = self {
|
||||
mesh.texture_id
|
||||
} else {
|
||||
super::TextureId::Egui
|
||||
}
|
||||
@@ -185,8 +190,8 @@ impl Shape {
|
||||
Shape::Text { pos, .. } => {
|
||||
*pos += delta;
|
||||
}
|
||||
Shape::Triangles(triangles) => {
|
||||
triangles.translate(delta);
|
||||
Shape::Mesh(mesh) => {
|
||||
mesh.translate(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ impl AllocInfo {
|
||||
// | Shape::Rect { .. } => Self::default(),
|
||||
// Shape::Path { points, .. } => Self::from_slice(points),
|
||||
// Shape::Text { galley, .. } => Self::from_galley(galley),
|
||||
// Shape::Triangles(triangles) => Self::from_triangles(triangles),
|
||||
// Shape::Mesh(mesh) => Self::from_mesh(mesh),
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -75,8 +75,8 @@ impl AllocInfo {
|
||||
Self::from_slice(galley.text.as_bytes()) + Self::from_slice(&galley.rows)
|
||||
}
|
||||
|
||||
pub fn from_triangles(triangles: &Triangles) -> Self {
|
||||
Self::from_slice(&triangles.indices) + Self::from_slice(&triangles.vertices)
|
||||
pub fn from_mesh(mesh: &Mesh) -> Self {
|
||||
Self::from_slice(&mesh.indices) + Self::from_slice(&mesh.vertices)
|
||||
}
|
||||
|
||||
pub fn from_slice<T>(slice: &[T]) -> Self {
|
||||
@@ -182,8 +182,8 @@ impl PaintStats {
|
||||
Shape::Text { galley, .. } => {
|
||||
self.shape_text += AllocInfo::from_galley(galley);
|
||||
}
|
||||
Shape::Triangles(triangles) => {
|
||||
self.shape_mesh += AllocInfo::from_triangles(triangles);
|
||||
Shape::Mesh(mesh) => {
|
||||
self.shape_mesh += AllocInfo::from_mesh(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Converts graphics primitives into textured triangles.
|
||||
//!
|
||||
//! This module converts lines, circles, text and more represented by [`Shape`]
|
||||
//! into textured triangles represented by [`Triangles`].
|
||||
//! into textured triangles represented by [`Mesh`].
|
||||
|
||||
#![allow(clippy::identity_op)]
|
||||
|
||||
@@ -239,7 +239,7 @@ fn fill_closed_path(
|
||||
path: &[PathPoint],
|
||||
color: Color32,
|
||||
options: TessellationOptions,
|
||||
out: &mut Triangles,
|
||||
out: &mut Mesh,
|
||||
) {
|
||||
if color == Color32::TRANSPARENT {
|
||||
return;
|
||||
@@ -285,7 +285,7 @@ fn stroke_path(
|
||||
path_type: PathType,
|
||||
stroke: Stroke,
|
||||
options: TessellationOptions,
|
||||
out: &mut Triangles,
|
||||
out: &mut Mesh,
|
||||
) {
|
||||
if stroke.width <= 0.0 || stroke.color == Color32::TRANSPARENT {
|
||||
return;
|
||||
@@ -427,7 +427,7 @@ fn mul_color(color: Color32, factor: f32) -> Color32 {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Converts [`Shape`]s into [`Triangles`].
|
||||
/// Converts [`Shape`]s into [`Mesh`].
|
||||
pub struct Tessellator {
|
||||
options: TessellationOptions,
|
||||
/// Only used for culling
|
||||
@@ -446,7 +446,7 @@ impl Tessellator {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tessellate a single [`Shape`] into a [`Triangles`].
|
||||
/// Tessellate a single [`Shape`] into a [`Mesh`].
|
||||
///
|
||||
/// * `shape`: the shape to tessellate
|
||||
/// * `options`: tessellation quality
|
||||
@@ -454,7 +454,7 @@ impl Tessellator {
|
||||
/// * `out`: where the triangles are put
|
||||
/// * `scratchpad_path`: if you plan to run `tessellate_shape`
|
||||
/// many times, pass it a reference to the same `Path` to avoid excessive allocations.
|
||||
pub fn tessellate_shape(&mut self, fonts: &Fonts, shape: Shape, out: &mut Triangles) {
|
||||
pub fn tessellate_shape(&mut self, fonts: &Fonts, shape: Shape, out: &mut Mesh) {
|
||||
let clip_rect = self.clip_rect;
|
||||
let options = self.options;
|
||||
|
||||
@@ -487,11 +487,11 @@ impl Tessellator {
|
||||
fill_closed_path(&path.0, fill, options, out);
|
||||
stroke_path(&path.0, Closed, stroke, options, out);
|
||||
}
|
||||
Shape::Triangles(triangles) => {
|
||||
if triangles.is_valid() {
|
||||
out.append(triangles);
|
||||
Shape::Mesh(mesh) => {
|
||||
if mesh.is_valid() {
|
||||
out.append(mesh);
|
||||
} else {
|
||||
debug_assert!(false, "Invalid Triangles in Shape::Triangles");
|
||||
debug_assert!(false, "Invalid Mesh in Shape::Mesh");
|
||||
}
|
||||
}
|
||||
Shape::LineSegment { points, stroke } => {
|
||||
@@ -562,7 +562,7 @@ impl Tessellator {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn tessellate_rect(&mut self, rect: &PaintRect, out: &mut Triangles) {
|
||||
pub(crate) fn tessellate_rect(&mut self, rect: &PaintRect, out: &mut Mesh) {
|
||||
let PaintRect {
|
||||
mut rect,
|
||||
corner_radius,
|
||||
@@ -599,7 +599,7 @@ impl Tessellator {
|
||||
galley: &super::Galley,
|
||||
text_style: super::TextStyle,
|
||||
color: Color32,
|
||||
out: &mut Triangles,
|
||||
out: &mut Mesh,
|
||||
) {
|
||||
if color == Color32::TRANSPARENT {
|
||||
return;
|
||||
@@ -663,12 +663,12 @@ impl Tessellator {
|
||||
/// * `fonts`: font source when tessellating text
|
||||
///
|
||||
/// ## Returns
|
||||
/// A list of clip rectangles with matching [`Triangles`].
|
||||
/// A list of clip rectangles with matching [`Mesh`].
|
||||
pub fn tessellate_shapes(
|
||||
shapes: Vec<ClippedShape>,
|
||||
options: TessellationOptions,
|
||||
fonts: &Fonts,
|
||||
) -> Vec<(Rect, Triangles)> {
|
||||
) -> Vec<(Rect, Mesh)> {
|
||||
let mut tessellator = Tessellator::from_options(options);
|
||||
|
||||
let mut jobs = PaintJobs::default();
|
||||
@@ -679,7 +679,7 @@ pub fn tessellate_shapes(
|
||||
};
|
||||
|
||||
if start_new_job {
|
||||
jobs.push((clip_rect, Triangles::default()));
|
||||
jobs.push((clip_rect, Mesh::default()));
|
||||
}
|
||||
|
||||
let out = &mut jobs.last_mut().unwrap().1;
|
||||
@@ -688,7 +688,7 @@ pub fn tessellate_shapes(
|
||||
}
|
||||
|
||||
if options.debug_paint_clip_rects {
|
||||
for (clip_rect, triangles) in &mut jobs {
|
||||
for (clip_rect, mesh) in &mut jobs {
|
||||
tessellator.clip_rect = Rect::everything();
|
||||
tessellator.tessellate_shape(
|
||||
fonts,
|
||||
@@ -698,7 +698,7 @@ pub fn tessellate_shapes(
|
||||
fill: Default::default(),
|
||||
stroke: Stroke::new(2.0, Color32::from_rgb(150, 255, 150)),
|
||||
},
|
||||
triangles,
|
||||
mesh,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -709,11 +709,8 @@ pub fn tessellate_shapes(
|
||||
}
|
||||
}
|
||||
|
||||
for (_, triangles) in &jobs {
|
||||
debug_assert!(
|
||||
triangles.is_valid(),
|
||||
"Tessellator generated invalid Triangles"
|
||||
);
|
||||
for (_, mesh) in &jobs {
|
||||
debug_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh");
|
||||
}
|
||||
|
||||
jobs
|
||||
|
||||
Reference in New Issue
Block a user