Skip to main content

Module buffer

Module buffer 

Source
Expand description

Vertex / uniform data layouts for the headless solid-fill + gradient pipelines.

All structs are #[repr(C)] and implement bytemuck::Pod / bytemuck::Zeroable so they can be uploaded to the GPU as raw bytes with a guaranteed, stable memory layout.

§Vertex layout (56 bytes = 14 × f32)

The struct was extended from the original 48-byte form to add an extra field ([f32; 2]) that carries per-kind auxiliary parameters:

kindlocalshape_xyshape_rextra
0 rectpixel pos
1 circlepixel poscentre (cx,cy)radius
2 rrect-uniformpixel poscentre (cx,cy)radiushalf-size (hw,hh)
3 rrect-per-cornerpixel poscentre (cx,cy)pack16(tl,tr)pack16(br,bl), pack16(hw,hh)
4 ellipsepixel poscentre (cx,cy)(rx, ry)
5 line-segpixel posfrom (ax,ay)half_width (+0.5=aa)to (bx,by)

For kind=3 the four corner radii and the half-extents are packed as u16 pairs into f32 bit patterns (see pack_u16_pair).

Structs§

Globals
Per-frame uniform block matching the WGSL Globals struct.
GradientUniforms
Per-gradient uniform block sent to gradient.wgsl.
GradientVertex
A single vertex fed to gradient.wgsl.
LineQuadParams
Parameters for a line-segment SDF quad.
Vertex
A single vertex fed to solid.wgsl.

Constants§

KIND_CIRCLE
Primitive discriminator value for an SDF circle.
KIND_ELLIPSE
Primitive discriminator value for an SDF ellipse.
KIND_LINE_SEG
Primitive discriminator value for a line-segment SDF.
KIND_RECT
Primitive discriminator value for a solid rectangle.
KIND_ROUNDED_RECT
Primitive discriminator value for a uniformly-rounded rectangle (SDF).
KIND_ROUNDED_RECT_PC
Primitive discriminator value for a per-corner rounded rectangle (SDF).
MAX_GRADIENT_STOPS
Maximum number of gradient colour stops supported in a single gradient draw.

Functions§

pack_u16_pair
Pack two u16 values into the bit pattern of a f32.
push_circle_quad
Append six vertices covering the bounding quad of the circle centred at (cx, cy) with radius, tagged as an SDF circle.
push_ellipse_quad
Append six vertices for an SDF ellipse centred at (cx, cy) with horizontal radius rx and vertical radius ry.
push_gradient_quad
Append six gradient vertices covering (x, y, w, h).
push_line_quad
Append six vertices for a line-segment SDF quad.
push_rect_quad
Append six vertices (two triangles) covering the axis-aligned rectangle (x, y, w, h) with a uniform color, tagged as a solid rectangle.
push_rounded_rect_per_corner_quad
Append six vertices for a per-corner rounded rectangle (SDF).
push_rounded_rect_quad
Append six vertices for a uniformly-rounded rectangle (SDF).
push_triangle
Append three vertices (one triangle) for a path fill triangle.