summaryrefslogtreecommitdiffstats
path: root/gfx/wr/webrender/res/ps_quad_textured.glsl
blob: 2382623cdb9a1139f948a5c323aab66d79c123a3 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// This shader renders solid colors or simple images in a color or alpha target.

#include ps_quad

#ifndef SWGL_ANTIALIAS
varying highp vec2 vLocalPos;
#endif

#ifdef WR_VERTEX_SHADER
void main(void) {
    PrimitiveInfo info = ps_quad_main();

#ifndef SWGL_ANTIALIAS
    RectWithEndpoint xf_bounds = RectWithEndpoint(
        max(info.local_prim_rect.p0, info.local_clip_rect.p0),
        min(info.local_prim_rect.p1, info.local_clip_rect.p1)
    );
    vTransformBounds = vec4(xf_bounds.p0, xf_bounds.p1);

    vLocalPos = info.local_pos;

    if (info.edge_flags == 0) {
        v_flags.x = 0;
    } else {
        v_flags.x = 1;
    }
#endif

    if ((info.quad_flags & QF_SAMPLE_AS_MASK) != 0) {
        v_flags.z = 1;
    } else {
        v_flags.z = 0;
    }
}
#endif

#ifdef WR_FRAGMENT_SHADER
void main(void) {
    vec4 color = v_color;

#ifndef SWGL_ANTIALIAS
    if (v_flags.x != 0) {
        float alpha = init_transform_fs(vLocalPos);
        color *= alpha;
    }
#endif

    if (v_flags.y != 0) {
        vec2 uv = clamp(v_uv, v_uv_sample_bounds.xy, v_uv_sample_bounds.zw);
        vec4 texel = TEX_SAMPLE(sColor0, uv);
        if (v_flags.z != 0) {
            texel = texel.rrrr;
        }
        color *= texel;
    }

    oFragColor = color;
}

#if defined(SWGL_DRAW_SPAN)
void swgl_drawSpanRGBA8() {
    if (v_flags.y != 0) {
        if (v_flags.z != 0) {
            // Fall back to fragment shader as we don't specialize for mask yet. Perhaps
            // we can use an existing swgl commit or add a new one though?
        } else {
            swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_sample_bounds, v_color);
        }
    } else {
        swgl_commitSolidRGBA8(v_color);
    }
}
#endif

#endif