aboutsummaryrefslogtreecommitdiff
path: root/alacritty/res/graphics.f.glsl
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2021-10-05 14:36:31 -0600
committerJosh Rahm <rahm@google.com>2021-10-05 14:36:31 -0600
commit7a209fa45f1f4d07cb4a885e8ea3d03e47cf48ae (patch)
tree026d75fdc19e19952cfba3020c118f24df4ac412 /alacritty/res/graphics.f.glsl
parent1725e30e144b04e2e2e30efc76eb968c97a0eabf (diff)
parent98fbb3f9285d8c00836e3bcfa6e1e13bf809e2a2 (diff)
downloadr-alacritty-7a209fa45f1f4d07cb4a885e8ea3d03e47cf48ae.tar.gz
r-alacritty-7a209fa45f1f4d07cb4a885e8ea3d03e47cf48ae.tar.bz2
r-alacritty-7a209fa45f1f4d07cb4a885e8ea3d03e47cf48ae.zip
Merge remote-tracking branch 'betaboon/graphics' into experimental
Diffstat (limited to 'alacritty/res/graphics.f.glsl')
-rw-r--r--alacritty/res/graphics.f.glsl40
1 files changed, 40 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;
+ }
+}