aboutsummaryrefslogtreecommitdiff
path: root/alacritty/res/glsl3
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty/res/glsl3')
-rw-r--r--alacritty/res/glsl3/text.f.glsl65
-rw-r--r--alacritty/res/glsl3/text.v.glsl28
2 files changed, 67 insertions, 26 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);
}
}
diff --git a/alacritty/res/glsl3/text.v.glsl b/alacritty/res/glsl3/text.v.glsl
index 5c22e0e6..7e0cd881 100644
--- a/alacritty/res/glsl3/text.v.glsl
+++ b/alacritty/res/glsl3/text.v.glsl
@@ -23,9 +23,9 @@ flat out vec4 bg;
uniform vec2 cellDim;
uniform vec4 projection;
-uniform int backgroundPass;
+uniform int renderingPass;
-#define WIDE_CHAR 1
+#define WIDE_CHAR 2
void main() {
vec2 projectionOffset = projection.xy;
@@ -39,12 +39,23 @@ void main() {
// Position of cell from top-left
vec2 cellPosition = cellDim * gridCoords;
- if (backgroundPass != 0) {
+ fg = vec4(textColor.rgb / 255.0, textColor.a);
+ bg = backgroundColor / 255.0;
+
+ float occupiedCells = 1;
+ if ((int(fg.a) >= WIDE_CHAR)) {
+ // Update wide char x dimension so it'll cover the following spacer.
+ occupiedCells = 2;
+
+ // Since we don't perform bitwise operations due to limitations of
+ // the GLES2 renderer,we subtract wide char bits keeping only colored.
+ fg.a = round(fg.a - WIDE_CHAR);
+ }
+
+ if (renderingPass == 0) {
vec2 backgroundDim = cellDim;
- if ((int(textColor.a) & WIDE_CHAR) != 0) {
- // Update wide char x dimension so it'll cover the following spacer.
- backgroundDim.x *= 2;
- }
+ backgroundDim.x *= occupiedCells;
+
vec2 finalPosition = cellPosition + backgroundDim * position;
gl_Position =
vec4(projectionOffset + projectionScale * finalPosition, 0.0, 1.0);
@@ -63,7 +74,4 @@ void main() {
vec2 uvSize = uv.zw;
TexCoords = uvOffset + position * uvSize;
}
-
- bg = backgroundColor / 255.0;
- fg = vec4(textColor.rgb / 255.0, textColor.a);
}