rustial-renderer-wgpu 1.0.0

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! Vertex type for SDF symbol / text rendering.

use bytemuck::{Pod, Zeroable};

/// A vertex for the symbol GPU pipeline.
///
/// Renders SDF glyphs and icons as textured quads.  Each glyph is a quad
/// (4 vertices, 6 indices) that samples from an SDF glyph atlas texture.
/// The fragment shader thresholds the SDF to produce crisp, scalable text
/// with optional halo.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct SymbolVertex {
    /// Glyph anchor position `[x, y, z]` in camera-relative meters.
    pub position: [f32; 3],
    /// Glyph quad offset from anchor `[dx, dy]` in world-space meters.
    pub glyph_offset: [f32; 2],
    /// Texture coordinates `[u, v]` into the SDF atlas.
    pub tex_coord: [f32; 2],
    /// Text colour `[r, g, b, a]`.
    pub color: [f32; 4],
    /// Halo colour `[r, g, b, a]`.
    pub halo_color: [f32; 4],
    /// Symbol parameters: `[halo_width, gamma_scale, 0, 0]`.
    pub params: [f32; 4],
}

impl SymbolVertex {
    /// Vertex buffer layout for the symbol pipeline.
    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: std::mem::size_of::<SymbolVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                // position
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                // glyph_offset
                wgpu::VertexAttribute {
                    offset: 12,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x2,
                },
                // tex_coord
                wgpu::VertexAttribute {
                    offset: 20,
                    shader_location: 2,
                    format: wgpu::VertexFormat::Float32x2,
                },
                // color
                wgpu::VertexAttribute {
                    offset: 28,
                    shader_location: 3,
                    format: wgpu::VertexFormat::Float32x4,
                },
                // halo_color
                wgpu::VertexAttribute {
                    offset: 44,
                    shader_location: 4,
                    format: wgpu::VertexFormat::Float32x4,
                },
                // params
                wgpu::VertexAttribute {
                    offset: 60,
                    shader_location: 5,
                    format: wgpu::VertexFormat::Float32x4,
                },
            ],
        }
    }
}