aboutsummaryrefslogtreecommitdiff
path: root/alacritty/res
diff options
context:
space:
mode:
authorAyose <ayosec@gmail.com>2021-03-10 20:21:36 +0000
committerbetaboon <betaboon@0x80.ninja>2021-08-17 15:44:40 +0200
commit0fd3793a963015e8f91021e35dbb2169d15c3211 (patch)
treea83c1f53a123f84376a58cf2a5114ad581092e0a /alacritty/res
parentc24d7dfd0d2d8849f0398d7cb1a65d6562ee7a0d (diff)
downloadr-alacritty-0fd3793a963015e8f91021e35dbb2169d15c3211.tar.gz
r-alacritty-0fd3793a963015e8f91021e35dbb2169d15c3211.tar.bz2
r-alacritty-0fd3793a963015e8f91021e35dbb2169d15c3211.zip
Add Sixel support
Fixes #910
Diffstat (limited to 'alacritty/res')
-rw-r--r--alacritty/res/graphics.f.glsl40
-rw-r--r--alacritty/res/graphics.v.glsl79
2 files changed, 119 insertions, 0 deletions
diff --git a/alacritty/res/graphics.f.glsl b/alacritty/res/graphics.f.glsl
new file mode 100644
index 00000000..28da2a68
--- /dev/null
+++ b/alacritty/res/graphics.f.glsl
@@ -0,0 +1,40 @@
+#version 330 core
+
+// Index in the textures[] uniform.
+flat in int texId;
+
+// Texture coordinates.
+in vec2 texCoords;
+
+// Array with graphics data.
+uniform sampler2D textures[16];
+
+// Computed color.
+out vec4 color;
+
+void main() {
+ // The expression `textures[texId]` can't be used in OpenGL 3.3.
+ // If we try to use it, the compiler throws this error:
+ //
+ // sampler arrays indexed with non-constant expressions
+ // are forbidden in GLSL 1.30 and later
+ //
+ // To overcome this limitation we use a switch for every valid
+ // value of `texId`.
+ //
+ // The first expression (`textures[texId]`) works with OpenGL 4.0
+ // or later (using `#version 400 core`). If Alacritty drops support
+ // for OpenGL 3.3, this switch block can be replaced with it.
+
+
+#define TEX(N) case N: color = texture(textures[N], texCoords); break;
+
+ switch(texId) {
+ TEX( 0) TEX( 1) TEX( 2) TEX( 3)
+ TEX( 4) TEX( 5) TEX( 6) TEX( 7)
+ TEX( 8) TEX( 9) TEX(10) TEX(11)
+ TEX(12) TEX(13) TEX(14) TEX(15)
+ default:
+ discard;
+ }
+}
diff --git a/alacritty/res/graphics.v.glsl b/alacritty/res/graphics.v.glsl
new file mode 100644
index 00000000..56998e9d
--- /dev/null
+++ b/alacritty/res/graphics.v.glsl
@@ -0,0 +1,79 @@
+#version 330 core
+
+// ------
+// INPUTS
+
+// Texture associated to the graphic.
+layout(location = 0) in int textureId;
+
+// Sides where the vertex is located.
+//
+// Bit 0 (LSB) is 0 for top and 1 for bottom.
+// Bit 1 is 0 for left and 1 for right.
+layout(location = 1) in int sides;
+
+// Column number in the grid where the left vertex is set.
+layout(location = 2) in float column;
+
+// Line number in the grid where the left vertex is set.
+layout(location = 3) in float line;
+
+// Height in pixels of the texture.
+layout(location = 4) in float height;
+
+// Width in pixels of the texture.
+layout(location = 5) in float width;
+
+// Offset in the X direction.
+layout(location = 6) in float offsetX;
+
+// Offset in the Y direction.
+layout(location = 7) in float offsetY;
+
+// Height in pixels of a single cell when the graphic was added.
+layout(location = 8) in float baseCellHeight;
+
+// -------
+// OUTPUTS
+
+// Texture sent to the fragment shader.
+flat out int texId;
+
+// Coordinates sent to the fragment shader.
+out vec2 texCoords;
+
+// --------
+// UNIFORMS
+
+// Width and height of a single cell.
+uniform vec2 cellDimensions;
+
+// Width and height of the view.
+uniform vec2 viewDimensions;
+
+
+#define IS_RIGHT_SIDE ((sides & 1) == 1)
+#define IS_BOTTOM_SIDE ((sides & 2) == 2)
+
+void main() {
+ float scale = cellDimensions.y / baseCellHeight;
+ float x = (column * cellDimensions.x - offsetX * scale) / (viewDimensions.x / 2) - 1;
+ float y = -(line * cellDimensions.y - offsetY * scale) / (viewDimensions.y / 2) + 1;
+
+ vec4 position = vec4(x, y, 0, 1);
+ vec2 coords = vec2(0, 0);
+
+ if(IS_RIGHT_SIDE) {
+ position.x += scale * width / (viewDimensions.x / 2);
+ coords.x = 1;
+ }
+
+ if(IS_BOTTOM_SIDE) {
+ position.y += -scale * height / (viewDimensions.y / 2);
+ coords.y = 1;
+ }
+
+ gl_Position = position;
+ texCoords = coords;
+ texId = textureId;
+}