use cgmath::Point2;
use std::mem;
use crate::platform::core::{
traits::{VertexAttributesLayout, VertexBufferLayout},
BufferAddress, VertexAttribute, VertexFormat, VertexStepMode,
};
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct P2T2 {
pub pos: Point2<f32>,
pub uv: Point2<f32>,
}
impl Default for P2T2 {
fn default() -> Self {
Self {
pos: Point2 { x: 0.0, y: 0.0 },
uv: Point2 { x: 0.0, y: 0.0 },
}
}
}
impl P2T2 {
pub fn new(pos: Point2<f32>, uv: Point2<f32>) -> Self {
Self { pos, uv }
}
pub fn from_components(pos: [f32; 2], uv: [f32; 2]) -> Self {
Self {
pos: Point2 {
x: pos[0],
y: pos[1],
},
uv: Point2 { x: uv[0], y: uv[1] },
}
}
}
impl VertexAttributesLayout for P2T2 {
fn layout() -> &'static VertexBufferLayout<'static> {
&VertexBufferLayout {
array_stride: mem::size_of::<P2T2>() as BufferAddress,
step_mode: VertexStepMode::Vertex,
attributes: &[
VertexAttribute {
offset: 0,
shader_location: 0,
format: VertexFormat::Float32x2,
},
VertexAttribute {
offset: std::mem::size_of::<[f32; 2]>() as BufferAddress, shader_location: 1,
format: VertexFormat::Float32x2,
},
],
}
}
}