Files
wsg/lib/vertex.rs
T
2026-07-06 10:40:00 +02:00

23 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! # Vertex Module
//!
//! Defines `Vertex`, the CPU-side data layout that is sent to the GPU as vertex attribute buffers.
//! The struct's field order and offsets must exactly match the shader input attributes defined in
//! PipelineCache::build_pipeline() — any mismatch will corrupt GPU rendering output.
//!
//! ## Technical Points
//! - `#[repr(C)]` ensures fields are laid out contiguously without Rust padding reordering, matching C ABI.
//! - `bytemuck::Pod + bytemuck::Zeroable` enables safe `cast_slice()` conversion for GPU buffer uploads.
/// Per-vertex attribute tuple: position (3D), texture coordinate (2D), color (RGBA).
/// Must match the vertex buffer layout in PipelineCache::build_pipeline() byte-for-byte.
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vertex {
/// XYZ coordinates of this vertex in world space. Offset: 0 bytes.
pub position: [f32; 3],
/// UV texture coordinates. Offset: 12 bytes (after 3 × f32 = 12 bytes).
pub uv: [f32; 2],
/// RGBA color values. Offset: 20 bytes (after 5 × f32 = 20 bytes).
pub color: [f32; 4],
}