diff options
Diffstat (limited to 'alacritty/res/glsl3/text.f.glsl')
-rw-r--r-- | alacritty/res/glsl3/text.f.glsl | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/alacritty/res/glsl3/text.f.glsl b/alacritty/res/glsl3/text.f.glsl index eddc1734..1930e354 100644 --- a/alacritty/res/glsl3/text.f.glsl +++ b/alacritty/res/glsl3/text.f.glsl @@ -1,40 +1,73 @@ +#if defined(GLES2_RENDERER) +// Require extension for dual source blending to work on GLES2. +#extension GL_EXT_blend_func_extended: require + +#define int_t highp int +#define float_t highp float +#define vec3_t mediump vec3 +#define texture texture2D + +varying mediump vec2 TexCoords; +varying mediump vec3 fg; +varying highp float colored; +varying mediump vec4 bg; + +#define FRAG_COLOR gl_FragColor +#define ALPHA_MASK gl_SecondaryFragColorEXT +#else + +#define int_t int +#define float_t float +#define vec3_t vec3 + in vec2 TexCoords; flat in vec4 fg; flat in vec4 bg; -uniform int backgroundPass; layout(location = 0, index = 0) out vec4 color; layout(location = 0, index = 1) out vec4 alphaMask; -uniform sampler2D mask; +#define FRAG_COLOR color +#define ALPHA_MASK alphaMask +#endif -#define COLORED 2 +#define COLORED 1 + +uniform int_t renderingPass; +uniform sampler2D mask; void main() { - if (backgroundPass != 0) { + if (renderingPass == 0) { if (bg.a == 0.0) { discard; } - alphaMask = vec4(1.0); - + ALPHA_MASK = vec4(1.0); // Premultiply background color by alpha. - color = vec4(bg.rgb * bg.a, bg.a); - } else if ((int(fg.a) & COLORED) != 0) { + FRAG_COLOR = vec4(bg.rgb * bg.a, bg.a); + return; + } + +#if !defined(GLES2_RENDERER) + float_t colored = fg.a; +#endif + + // The wide char information is already stripped, so it's safe to check for equality here. + if (int(colored) == COLORED) { // Color glyphs, like emojis. - vec4 glyphColor = texture(mask, TexCoords); - alphaMask = vec4(glyphColor.a); + FRAG_COLOR = texture(mask, TexCoords); + ALPHA_MASK = vec4(FRAG_COLOR.a); // Revert alpha premultiplication. - if (glyphColor.a != 0) { - glyphColor.rgb = vec3(glyphColor.rgb / glyphColor.a); + if (FRAG_COLOR.a != 0.0) { + FRAG_COLOR.rgb = vec3(FRAG_COLOR.rgb / FRAG_COLOR.a); } - color = vec4(glyphColor.rgb, 1.0); + FRAG_COLOR = vec4(FRAG_COLOR.rgb, 1.0); } else { // Regular text glyphs. - vec3 textColor = texture(mask, TexCoords).rgb; - alphaMask = vec4(textColor, textColor.r); - color = vec4(fg.rgb, 1.0); + vec3_t textColor = texture(mask, TexCoords).rgb; + ALPHA_MASK = vec4(textColor, textColor.r); + FRAG_COLOR = vec4(fg.rgb, 1.0); } } |