Optimize `Mesh::add_rect_with_uv` (#7511)
This commit is contained in:
parent
a8e36e3313
commit
742b1dc920
|
|
@ -169,9 +169,7 @@ impl Mesh {
|
||||||
/// Add a triangle.
|
/// Add a triangle.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_triangle(&mut self, a: u32, b: u32, c: u32) {
|
pub fn add_triangle(&mut self, a: u32, b: u32, c: u32) {
|
||||||
self.indices.push(a);
|
self.indices.extend_from_slice(&[a, b, c]);
|
||||||
self.indices.push(b);
|
|
||||||
self.indices.push(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make room for this many additional triangles (will reserve 3x as many indices).
|
/// Make room for this many additional triangles (will reserve 3x as many indices).
|
||||||
|
|
@ -189,33 +187,35 @@ impl Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rectangle with a texture and color.
|
/// Rectangle with a texture and color.
|
||||||
|
#[inline(always)]
|
||||||
pub fn add_rect_with_uv(&mut self, rect: Rect, uv: Rect, color: Color32) {
|
pub fn add_rect_with_uv(&mut self, rect: Rect, uv: Rect, color: Color32) {
|
||||||
#![allow(clippy::identity_op)]
|
#![allow(clippy::identity_op)]
|
||||||
|
|
||||||
let idx = self.vertices.len() as u32;
|
let idx = self.vertices.len() as u32;
|
||||||
self.add_triangle(idx + 0, idx + 1, idx + 2);
|
self.indices
|
||||||
self.add_triangle(idx + 2, idx + 1, idx + 3);
|
.extend_from_slice(&[idx + 0, idx + 1, idx + 2, idx + 2, idx + 1, idx + 3]);
|
||||||
|
|
||||||
self.vertices.push(Vertex {
|
self.vertices.extend_from_slice(&[
|
||||||
pos: rect.left_top(),
|
Vertex {
|
||||||
uv: uv.left_top(),
|
pos: rect.left_top(),
|
||||||
color,
|
uv: uv.left_top(),
|
||||||
});
|
color,
|
||||||
self.vertices.push(Vertex {
|
},
|
||||||
pos: rect.right_top(),
|
Vertex {
|
||||||
uv: uv.right_top(),
|
pos: rect.right_top(),
|
||||||
color,
|
uv: uv.right_top(),
|
||||||
});
|
color,
|
||||||
self.vertices.push(Vertex {
|
},
|
||||||
pos: rect.left_bottom(),
|
Vertex {
|
||||||
uv: uv.left_bottom(),
|
pos: rect.left_bottom(),
|
||||||
color,
|
uv: uv.left_bottom(),
|
||||||
});
|
color,
|
||||||
self.vertices.push(Vertex {
|
},
|
||||||
pos: rect.right_bottom(),
|
Vertex {
|
||||||
uv: uv.right_bottom(),
|
pos: rect.right_bottom(),
|
||||||
color,
|
uv: uv.right_bottom(),
|
||||||
});
|
color,
|
||||||
|
},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uniformly colored rectangle.
|
/// Uniformly colored rectangle.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue