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.
Currently Alacritty only works on hardware which supports OpenGL 3.3 or more, which can become problematic with older devices. This patch adds a new GLES2 renderer, since it is much more widely supported, especially on weaker hardware like phones or a Raspberry Pi. While the GLES2 renderer is slower than the OpenGL 3.3+ version, it is still significantly faster than software rendering. However because of this performance difference it is only used when necessary and there should be no difference for machines supporting OpenGL 3.3+. The two renderers are largely independent and separated in the `renderer/text/glsl3` and `renderer/text/gles2` modules. Separate shaders are also required for text rendering. The rectangle rendering for underlines and the visual bell works identically for both versions, but does have some version-specific shader code. Fixes alacritty#128. Co-authored-by: Christian Duerr <[email protected]>
- Loading branch information
1 parent
00383ae
commit 1880522
Showing
18 changed files
with
2,066 additions
and
1,241 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
varying mediump vec2 TexCoords; | ||
varying mediump vec3 fg; | ||
varying highp float colored; | ||
varying mediump vec4 bg; | ||
|
||
uniform highp int renderingPass; | ||
uniform sampler2D mask; | ||
|
||
#define COLORED 1 | ||
|
||
mediump float max_rgb(mediump vec3 mask) { | ||
return max(max(mask.r, mask.g), mask.b); | ||
} | ||
|
||
void render_text() { | ||
mediump vec4 mask = texture2D(mask, TexCoords); | ||
mediump float m_rgb = max_rgb(mask.rgb); | ||
|
||
if (renderingPass == 1) { | ||
gl_FragColor = vec4(mask.rgb, m_rgb); | ||
} else if (renderingPass == 2) { | ||
gl_FragColor = bg * (vec4(m_rgb) - vec4(mask.rgb, m_rgb)); | ||
} else { | ||
gl_FragColor = vec4(fg, 1.) * vec4(mask.rgb, m_rgb); | ||
} | ||
} | ||
|
||
// Render colored bitmaps. | ||
void render_bitmap() { | ||
if (renderingPass == 2) { | ||
discard; | ||
} | ||
mediump vec4 mask = texture2D(mask, TexCoords); | ||
if (renderingPass == 1) { | ||
gl_FragColor = mask.aaaa; | ||
} else { | ||
gl_FragColor = mask; | ||
} | ||
} | ||
|
||
void main() { | ||
// Handle background pass drawing before anything else. | ||
if (renderingPass == 0) { | ||
if (bg.a == 0.0) { | ||
discard; | ||
} | ||
|
||
gl_FragColor = vec4(bg.rgb * bg.a, bg.a); | ||
return; | ||
} | ||
|
||
if (int(colored) == COLORED) { | ||
render_bitmap(); | ||
} else { | ||
render_text(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Cell coords. | ||
attribute vec2 cellCoords; | ||
|
||
// Glyph coords. | ||
attribute vec2 glyphCoords; | ||
|
||
// uv mapping. | ||
attribute vec2 uv; | ||
|
||
// Text foreground rgb packed together with cell flags. textColor.a | ||
// are the bitflags; consult RenderingGlyphFlags in renderer/mod.rs | ||
// for the possible values. | ||
attribute vec4 textColor; | ||
|
||
// Background color. | ||
attribute vec4 backgroundColor; | ||
|
||
varying vec2 TexCoords; | ||
varying vec3 fg; | ||
varying float colored; | ||
varying vec4 bg; | ||
|
||
uniform highp int renderingPass; | ||
uniform vec4 projection; | ||
|
||
void main() { | ||
vec2 projectionOffset = projection.xy; | ||
vec2 projectionScale = projection.zw; | ||
|
||
vec2 position; | ||
if (renderingPass == 0) { | ||
TexCoords = vec2(0, 0); | ||
position = cellCoords; | ||
} else { | ||
TexCoords = uv; | ||
position = glyphCoords; | ||
} | ||
|
||
fg = vec3(float(textColor.r), float(textColor.g), float(textColor.b)) / 255.; | ||
colored = float(textColor.a); | ||
bg = vec4(float(backgroundColor.r), float(backgroundColor.g), float(backgroundColor.b), | ||
float(backgroundColor.a)) / 255.; | ||
|
||
vec2 finalPosition = projectionOffset + position * projectionScale; | ||
gl_Position = vec4(finalPosition, 0., 1.); | ||
} |
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,4 +1,3 @@ | ||
#version 330 core | ||
in vec2 TexCoords; | ||
flat in vec4 fg; | ||
flat in vec4 bg; | ||
|
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,4 +1,3 @@ | ||
#version 330 core | ||
// Cell properties. | ||
layout(location = 0) in vec2 gridCoords; | ||
|
||
|
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,11 +1,16 @@ | ||
#version 330 core | ||
#if defined(GLES2_RENDERER) | ||
attribute vec2 aPos; | ||
attribute vec4 aColor; | ||
|
||
varying mediump vec4 color; | ||
#else | ||
layout (location = 0) in vec2 aPos; | ||
layout (location = 1) in vec4 aColor; | ||
|
||
flat out vec4 color; | ||
#endif | ||
|
||
void main() | ||
{ | ||
void main() { | ||
color = aColor; | ||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); | ||
} |
Oops, something went wrong.