Skip to main content

wgpu_shapes/render/
instance.rs

1use wgpu::VertexStepMode;
2use wgpu_noboiler::vertex::Vertex;
3
4#[repr(C)]
5#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
6pub struct Instance {
7    pub position: [f32; 2],
8    pub scale: [f32; 2],
9    pub rotation: f32,
10    //todo transparency
11    //problem: transparency only works in the same drawCall
12    pub color: [f32; 3],
13    pub layer: u32,
14}
15
16impl Vertex<5> for Instance {
17    const STEP_MODE: VertexStepMode = VertexStepMode::Instance;
18
19    const ATTRIBS: [wgpu::VertexAttribute; 5] = wgpu::vertex_attr_array![1 => Float32x2,2 => Float32x2,3 => Float32,4 => Float32x3, 5 => Uint32];
20}
21
22#[repr(C)]
23#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
24pub struct TextureInstance {
25    pub position: [f32; 2],
26    pub scale: [f32; 2],
27    pub rotation: f32,
28    pub layer: u32,
29    pub texture_position: [f32; 2],
30    pub texture_scale: [f32; 2],
31}
32
33impl Vertex<6> for TextureInstance {
34    const STEP_MODE: VertexStepMode = VertexStepMode::Instance;
35
36    const ATTRIBS: [wgpu::VertexAttribute; 6] = wgpu::vertex_attr_array![1 => Float32x2,2 => Float32x2,3 => Float32, 4 => Uint32, 5 => Float32x2,6 => Float32x2];
37}