Skip to main content

CLIPPED_SOLID

Constant CLIPPED_SOLID 

Source
pub const CLIPPED_SOLID: &str = r"
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

uniform float alpha;
uniform vec2 size;
uniform mat3 input_to_geo;
uniform vec2 geo_size;
uniform vec4 corner_radius;
uniform float geo_px;
uniform vec4 colour;
varying vec2 v_coords;

#if defined(DEBUG_FLAGS)
uniform float tint;
#endif

void main() {
    vec4 painted = colour * alpha;
#if defined(DEBUG_FLAGS)
    if (tint == 1.0)
        painted = vec4(0.0, 0.2, 0.0, 0.2) + painted * 0.8;
#endif
    vec2 geo = (input_to_geo * vec3(v_coords, 1.0)).xy;
    vec2 half_size = geo_size * 0.5;
    float picked = (geo.x < half_size.x)
        ? ((geo.y < half_size.y) ? corner_radius.x : corner_radius.z)
        : ((geo.y < half_size.y) ? corner_radius.y : corner_radius.w);
    float r = min(picked, min(half_size.x, half_size.y));
    vec2 p = abs(geo - half_size) - (half_size - vec2(r));
    float away = min(max(p.x, p.y), 0.0) + length(max(p, 0.0)) - r;
    float band = 0.5 / max(geo_px, 0.0001);
    gl_FragColor = painted * (1.0 - smoothstep(-band, band, away));
}
";
Expand description

The same, for a single-pixel buffer: smithay draws one as a solid colour, which no texture program reaches, so it is a pixel program over the surface’s rectangle with the colour as a uniform. v_coords runs 0..1 across that rectangle. Smithay prepends #version 100 itself. tests::the_solid_program_is_a_pixel_program, and wirecheck’s case 11h, which draws one.