Skip to main content

rustial_renderer_wgpu/gpu/
vertex.rs

1//! Tile vertex definition.
2
3use bytemuck::{Pod, Zeroable};
4
5/// Vertex for tile quad rendering.
6#[repr(C)]
7#[derive(Debug, Clone, Copy, Pod, Zeroable)]
8pub struct TileVertex {
9    /// Position `[x, y, z]` in camera-relative meters.
10    pub position: [f32; 3],
11    /// Texture coordinate `[u, v]`.
12    pub uv: [f32; 2],
13    /// Tile opacity used for fallback transition softening.
14    pub opacity: f32,
15}
16
17impl TileVertex {
18    /// Vertex buffer layout descriptor.
19    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
20        wgpu::VertexBufferLayout {
21            array_stride: std::mem::size_of::<TileVertex>() as wgpu::BufferAddress,
22            step_mode: wgpu::VertexStepMode::Vertex,
23            attributes: &[
24                wgpu::VertexAttribute {
25                    offset: 0,
26                    shader_location: 0,
27                    format: wgpu::VertexFormat::Float32x3,
28                },
29                wgpu::VertexAttribute {
30                    offset: 12,
31                    shader_location: 1,
32                    format: wgpu::VertexFormat::Float32x2,
33                },
34                wgpu::VertexAttribute {
35                    offset: 20,
36                    shader_location: 2,
37                    format: wgpu::VertexFormat::Float32,
38                },
39            ],
40        }
41    }
42}