Skip to main content

rustial_renderer_wgpu/gpu/
image_overlay_vertex.rs

1//! Vertex type for image overlay rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for the image overlay GPU pipeline.
6///
7/// Each image overlay is a textured quad with four of these vertices.
8#[repr(C)]
9#[derive(Debug, Clone, Copy, Pod, Zeroable)]
10pub struct ImageOverlayVertex {
11    /// Position `[x, y, z]` in camera-relative meters.
12    pub position: [f32; 3],
13    /// Texture coordinate `[u, v]` in `[0..1]` range.
14    pub uv: [f32; 2],
15    /// Per-vertex opacity (0.0–1.0).
16    pub opacity: f32,
17}
18
19impl ImageOverlayVertex {
20    /// Vertex buffer layout for the image overlay pipeline.
21    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
22        wgpu::VertexBufferLayout {
23            array_stride: std::mem::size_of::<ImageOverlayVertex>() as wgpu::BufferAddress,
24            step_mode: wgpu::VertexStepMode::Vertex,
25            attributes: &[
26                // position
27                wgpu::VertexAttribute {
28                    offset: 0,
29                    shader_location: 0,
30                    format: wgpu::VertexFormat::Float32x3,
31                },
32                // uv
33                wgpu::VertexAttribute {
34                    offset: 12,
35                    shader_location: 1,
36                    format: wgpu::VertexFormat::Float32x2,
37                },
38                // opacity
39                wgpu::VertexAttribute {
40                    offset: 20,
41                    shader_location: 2,
42                    format: wgpu::VertexFormat::Float32,
43                },
44            ],
45        }
46    }
47}