blob: 4fa4806e7851627b29a874b6d853558c55dd33c0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#if defined(GLES2_RENDERER) ///////////////////////////////////////////
precision highp float;
#define FLAT
#define IN varying
#define INT float
#define SWITCH(X) int ind = int(X);
#define CASE(N) if (ind == N) {gl_FragColor = texture2D(textures[N], texCoords); return;}
#define DEFAULT(X) X;
#define END_SWITCH
#else // GLSL3_RENDERER ///////////////////////////////////////////////
#define FLAT flat
#define IN in
#define INT int
#define SWITCH(X) switch(X) {
#define CASE(N) case N: color = texture(textures[N], texCoords); break;
#define DEFAULT(X) default: X;
#define END_SWITCH }
out vec4 color;
#endif ////////////////////////////////////////////////////////////////
// Index in the textures[] uniform.
FLAT IN INT texId;
// Texture coordinates.
IN vec2 texCoords;
// Array with graphics data.
uniform sampler2D textures[16];
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.
SWITCH(texId)
CASE(0)
CASE(1)
CASE(2)
CASE(3)
CASE(4)
CASE(5)
CASE(6)
CASE(7)
CASE(8)
CASE(9)
CASE(10)
CASE(11)
CASE(12)
CASE(13)
CASE(14)
CASE(15)
DEFAULT(discard)
END_SWITCH
}
|