Group all solid triangles independently of color

This commit is contained in:
Héctor Ramón Jiménez 2022-11-14 00:02:42 +01:00
parent 5b0dfcd0b0
commit 33c3c0c0aa
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
23 changed files with 1343 additions and 1084 deletions

View file

@ -1,15 +1,12 @@
//! Draw geometry using meshes of triangles.
use crate::Color;
#[cfg(not(target_arch = "wasm32"))]
use crate::Gradient;
use bytemuck::{Pod, Zeroable};
/// A set of [`Vertex2D`] and indices representing a list of triangles.
#[derive(Clone, Debug)]
pub struct Mesh2D {
pub struct Mesh2D<T> {
/// The vertices of the mesh
pub vertices: Vec<Vertex2D>,
pub vertices: Vec<T>,
/// The list of vertex indices that defines the triangles of the mesh.
///
/// Therefore, this list should always have a length that is a multiple of 3.
@ -24,25 +21,13 @@ pub struct Vertex2D {
pub position: [f32; 2],
}
#[derive(Debug, Clone, PartialEq)]
/// Supported shaders for triangle primitives.
pub enum Style {
/// Fill a primitive with a solid color.
Solid(Color),
#[cfg(not(target_arch = "wasm32"))]
/// Fill a primitive with an interpolated color.
Gradient(Gradient),
}
/// A two-dimensional vertex with a color.
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
#[repr(C)]
pub struct ColoredVertex2D {
/// The vertex position in 2D space.
pub position: [f32; 2],
impl From<Color> for Style {
fn from(color: Color) -> Self {
Self::Solid(color)
}
}
#[cfg(not(target_arch = "wasm32"))]
impl From<Gradient> for Style {
fn from(gradient: Gradient) -> Self {
Self::Gradient(gradient)
}
/// The color of the vertex in __linear__ RGBA.
pub color: [f32; 4],
}