forked from alacritty/alacritty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dual source blending in GLES2 renderer
GLES2 has GL_EXT_blend_func_extended extension that enables dual-source blending, so essentially we can reuse fragment shader from GLSL3 renderer and do 1 rendering pass instead of 3 for the text. Co-authored-by: Kirill Chibisov <[email protected]> Co-authored-by: Christian Duerr <[email protected]>
- Loading branch information
1 parent
29b1ff5
commit 6dc670c
Showing
9 changed files
with
193 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.