forked from alacritty/alacritty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a fallback GLES2 renderer for platforms not supporting OpenGL 3.3 providing ability to run alacritty on those. While its performance is slightly slower than glsl3 version it's way faster than software rendering with sofware emulated GL (e.g. llvmpipe), since that's what alacritty used on platforms not supporting required OpenGL version. Fixes alacritty#128.
- Loading branch information
Showing
18 changed files
with
2,030 additions
and
1,238 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.