summaryrefslogtreecommitdiff
path: root/src/vector/layouts.zig
blob: 5d1756895aa9d6008bd1b523292cc9d30115c69d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! What the vector GPU backend hands its shaders. These Zig structs are the
//! only definition: the shaders include GLSL generated from them (see
//! `glsl.zig`). No imports, so the shader build can compile this alone.

pub const max_stops = 32;

/// A path point in device pixels, for stencil fans.
pub const Vertex = extern struct {
    position: [2]f32,

    pub const glsl = .vertex;
};

/// A point of a painted triangle (a cover quad, or a convex fill's fan),
/// carrying its fill's paint, so fills of any paint share one draw.
pub const Painted = extern struct {
    position: [2]f32,
    /// Solid paints: the premultiplied color times the fill's alpha.
    /// Gradients: the alpha, in all four.
    color: [4]f32,
    /// The gradient's index in the pass's `Paint` buffer; -1 for solid.
    gradient: f32,

    pub const glsl = .vertex;
};

pub const Viewport = extern struct {
    size: [2]f32,
    pad: [2]f32 = .{ 0, 0 },

    pub const glsl = .{ .uniform = .{ .set = 1, .instance = "viewport" } };
};

/// A resolved gradient `Paint`, as `paint.frag` reads it from a storage
/// buffer (all members are vec4s, so std430 lays it out as std140 would).
pub const Paint = extern struct {
    /// Premultiplied solid color.
    color: [4]f32,
    /// Device pixels to gradient space: a, c, e; then the kind (0 solid,
    /// 1 linear, 2 radial).
    row0: [4]f32,
    /// b, d, f; then the spread (0 pad, 1 reflect, 2 repeat).
    row1: [4]f32,
    /// p0 then p1.
    points: [4]f32,
    /// Radius, alpha (unused: the vertices carry it), stop count.
    extra: [4]f32,
    /// Stop offsets, four per element.
    offsets: [max_stops / 4][4]f32,
    /// Straight stop colors.
    colors: [max_stops][4]f32,

    pub const glsl = .plain;
};