Skip to main content

std140_layout

Function std140_layout 

pub fn std140_layout(
    wgsl_struct_src: &str,
) -> Result<Vec<Std140Member>, CompileError>
Expand description

Generate a std140-aligned uniform buffer layout from a WGSL struct.

This is used by the host side to pack uniform data before uploading to WebGL2. The layout follows std140 rules:

  • scalars: 4 bytes
  • vec2: 8 bytes (aligned 8)
  • vec3: 12 bytes (aligned 16)
  • vec4: 16 bytes (aligned 16)
  • mat4x4: 64 bytes (16 bytes per column, aligned 16)
  • arrays: each element aligned to vec4 (16 bytes)
  • structs: aligned to vec4 (16 bytes), size rounded up to 16