Skip to main content

rustial_renderer_wgpu/gpu/
vector_vertex.rs

1//! Vertex type for vector geometry rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for vector geometry with position and color.
6#[repr(C)]
7#[derive(Debug, Clone, Copy, Pod, Zeroable)]
8pub struct VectorVertex {
9    /// Position `[x, y, z]` in camera-relative meters.
10    pub position: [f32; 3],
11    /// Per-vertex RGBA color.
12    pub color: [f32; 4],
13}
14
15impl VectorVertex {
16    /// Vertex buffer layout for the vector pipeline.
17    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
18        wgpu::VertexBufferLayout {
19            array_stride: std::mem::size_of::<VectorVertex>() as wgpu::BufferAddress,
20            step_mode: wgpu::VertexStepMode::Vertex,
21            attributes: &[
22                wgpu::VertexAttribute {
23                    offset: 0,
24                    shader_location: 0,
25                    format: wgpu::VertexFormat::Float32x3,
26                },
27                wgpu::VertexAttribute {
28                    offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
29                    shader_location: 1,
30                    format: wgpu::VertexFormat::Float32x4,
31                },
32            ],
33        }
34    }
35}