Skip to main content

rustial_renderer_wgpu/gpu/
symbol_vertex.rs

1//! Vertex type for SDF symbol / text rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for the symbol GPU pipeline.
6///
7/// Renders SDF glyphs and icons as textured quads.  Each glyph is a quad
8/// (4 vertices, 6 indices) that samples from an SDF glyph atlas texture.
9/// The fragment shader thresholds the SDF to produce crisp, scalable text
10/// with optional halo.
11#[repr(C)]
12#[derive(Debug, Clone, Copy, Pod, Zeroable)]
13pub struct SymbolVertex {
14    /// Glyph anchor position `[x, y, z]` in camera-relative meters.
15    pub position: [f32; 3],
16    /// Glyph quad offset from anchor `[dx, dy]` in world-space meters.
17    pub glyph_offset: [f32; 2],
18    /// Texture coordinates `[u, v]` into the SDF atlas.
19    pub tex_coord: [f32; 2],
20    /// Text colour `[r, g, b, a]`.
21    pub color: [f32; 4],
22    /// Halo colour `[r, g, b, a]`.
23    pub halo_color: [f32; 4],
24    /// Symbol parameters: `[halo_width, gamma_scale, 0, 0]`.
25    pub params: [f32; 4],
26}
27
28impl SymbolVertex {
29    /// Vertex buffer layout for the symbol pipeline.
30    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
31        wgpu::VertexBufferLayout {
32            array_stride: std::mem::size_of::<SymbolVertex>() as wgpu::BufferAddress,
33            step_mode: wgpu::VertexStepMode::Vertex,
34            attributes: &[
35                // position
36                wgpu::VertexAttribute {
37                    offset: 0,
38                    shader_location: 0,
39                    format: wgpu::VertexFormat::Float32x3,
40                },
41                // glyph_offset
42                wgpu::VertexAttribute {
43                    offset: 12,
44                    shader_location: 1,
45                    format: wgpu::VertexFormat::Float32x2,
46                },
47                // tex_coord
48                wgpu::VertexAttribute {
49                    offset: 20,
50                    shader_location: 2,
51                    format: wgpu::VertexFormat::Float32x2,
52                },
53                // color
54                wgpu::VertexAttribute {
55                    offset: 28,
56                    shader_location: 3,
57                    format: wgpu::VertexFormat::Float32x4,
58                },
59                // halo_color
60                wgpu::VertexAttribute {
61                    offset: 44,
62                    shader_location: 4,
63                    format: wgpu::VertexFormat::Float32x4,
64                },
65                // params
66                wgpu::VertexAttribute {
67                    offset: 60,
68                    shader_location: 5,
69                    format: wgpu::VertexFormat::Float32x4,
70                },
71            ],
72        }
73    }
74}