bezier curves, i guess
This commit is contained in:
parent
06b52aa5d4
commit
ec477975f0
8 changed files with 614 additions and 44 deletions
|
|
@ -2,19 +2,21 @@
|
|||
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct Vertex {
|
||||
position: [f32; 2],
|
||||
color: [f32; 3],
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn new(position: [f32; 2], color: [f32; 3]) -> Vertex {
|
||||
Vertex {position, color}
|
||||
pub fn new(position: [f32; 2]) -> Vertex {
|
||||
Vertex { position }
|
||||
}
|
||||
|
||||
pub fn new_white(position: [f32; 2]) -> Vertex {
|
||||
Vertex {position, color: [1.0, 1.0, 1.0]}
|
||||
pub fn new_f64(position: [f64; 2]) -> Vertex {
|
||||
Vertex {
|
||||
position: position.map(|x| x as f32),
|
||||
}
|
||||
}
|
||||
|
||||
const ATTRIBS: [wgpu::VertexAttribute; 2] = wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x3];
|
||||
const ATTRIBS: [wgpu::VertexAttribute; 2] =
|
||||
wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x3];
|
||||
|
||||
pub const fn desc() -> wgpu::VertexBufferLayout<'static> {
|
||||
use std::mem;
|
||||
|
|
@ -26,3 +28,28 @@ impl Vertex {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct RenderData {
|
||||
pub vertices: Vec<Vertex>,
|
||||
pub indices: Vec<u32>,
|
||||
}
|
||||
|
||||
impl RenderData {
|
||||
pub fn new() -> RenderData {
|
||||
RenderData {
|
||||
vertices: vec![],
|
||||
indices: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(self: RenderData, other: RenderData) -> RenderData {
|
||||
let vertices_len = self.vertices.len() as u32;
|
||||
RenderData {
|
||||
vertices: self.vertices.into_iter().chain(other.vertices).collect(),
|
||||
indices: self
|
||||
.indices
|
||||
.into_iter()
|
||||
.chain(other.indices.into_iter().map(|i| i + vertices_len))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue