Skip to main content

rustial_renderer_wgpu/gpu/
grid_extrusion_vertex.rs

1//! Vertex type for lit grid extrusion geometry rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for extruded grid geometry with position, normal, and color.
6#[repr(C)]
7#[derive(Debug, Clone, Copy, Pod, Zeroable)]
8pub struct GridExtrusionVertex {
9    /// Position `[x, y, z]` in camera-relative meters.
10    pub position: [f32; 3],
11    /// Surface normal `[x, y, z]`.
12    pub normal: [f32; 3],
13    /// Per-vertex RGBA color.
14    pub color: [f32; 4],
15}
16
17impl GridExtrusionVertex {
18    /// Vertex buffer layout for the grid extrusion pipeline.
19    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
20        wgpu::VertexBufferLayout {
21            array_stride: std::mem::size_of::<GridExtrusionVertex>() 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: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
31                    shader_location: 1,
32                    format: wgpu::VertexFormat::Float32x3,
33                },
34                wgpu::VertexAttribute {
35                    offset: (std::mem::size_of::<[f32; 3]>() * 2) as wgpu::BufferAddress,
36                    shader_location: 2,
37                    format: wgpu::VertexFormat::Float32x4,
38                },
39            ],
40        }
41    }
42}