Skip to main content

rustial_renderer_wgpu/gpu/
column_vertex.rs

1//! Vertex types for instanced column rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// Shared unit-box vertex for instanced column rendering.
6#[repr(C)]
7#[derive(Debug, Clone, Copy, Pod, Zeroable)]
8pub struct ColumnVertex {
9    /// Unit-box local position.
10    pub position: [f32; 3],
11    /// Unit-box local normal.
12    pub normal: [f32; 3],
13}
14
15impl ColumnVertex {
16    /// Vertex layout for the shared unit-box mesh.
17    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
18        wgpu::VertexBufferLayout {
19            array_stride: std::mem::size_of::<ColumnVertex>() 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::Float32x3,
31                },
32            ],
33        }
34    }
35}
36
37/// Per-instance column transform/color data.
38#[repr(C)]
39#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable)]
40pub struct ColumnInstanceData {
41    /// Column base-center position in camera-relative meters.
42    pub base_position: [f32; 3],
43    /// Width, height, and reserved padding.
44    pub dimensions: [f32; 4],
45    /// Per-instance RGBA color.
46    pub color: [f32; 4],
47}
48
49impl ColumnInstanceData {
50    /// Vertex layout for per-instance column data.
51    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
52        wgpu::VertexBufferLayout {
53            array_stride: std::mem::size_of::<ColumnInstanceData>() as wgpu::BufferAddress,
54            step_mode: wgpu::VertexStepMode::Instance,
55            attributes: &[
56                wgpu::VertexAttribute {
57                    offset: 0,
58                    shader_location: 2,
59                    format: wgpu::VertexFormat::Float32x3,
60                },
61                wgpu::VertexAttribute {
62                    offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
63                    shader_location: 3,
64                    format: wgpu::VertexFormat::Float32x4,
65                },
66                wgpu::VertexAttribute {
67                    offset: (std::mem::size_of::<[f32; 3]>() + std::mem::size_of::<[f32; 4]>())
68                        as wgpu::BufferAddress,
69                    shader_location: 4,
70                    format: wgpu::VertexFormat::Float32x4,
71                },
72            ],
73        }
74    }
75}