aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/evas/engines/gl_common/shader/evas_gl_shaders.x
blob: dec8aa93bc5835bccea98dacc1db2b1689a25926 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */
/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */

static const char fragment_glsl[] =
   "/* General-purpose fragment shader for all operations in Evas.\n"
   " * This file can either be used directly by evas at runtime to\n"
   " * generate its shaders with the appropriate #defines, or passed\n"
   " * through cpp first (in which case the precision must be manually added).\n"
   " */\n"
   "#ifdef GL_ES\n"
   "# ifdef GL_FRAGMENT_PRECISION_HIGH\n"
   "precision highp float;\n"
   "# else\n"
   "precision mediump float;\n"
   "# endif\n"
   "# ifdef SHD_EXTERNAL\n"
   "extension GL_OES_EGL_image_external : require\n"
   "#  define SAMPLER_EXTERNAL_OES samplerExternalOES\n"
   "# endif\n"
   "#else\n"
   "# define SAMPLER_EXTERNAL_OES sampler2D\n"
   "#endif\n"
   "#ifndef SHD_NOMUL\n"
   "varying vec4 col;\n"
   "#endif\n"
   "#ifdef SHD_EXTERNAL\n"
   "uniform SAMPLER_EXTERNAL_OES tex;\n"
   "varying vec2 tex_c;\n"
   "#define ADD_NOISE 1\n"
   "#elif defined(SHD_TEX)\n"
   "uniform sampler2D tex;\n"
   "varying vec2 tex_c;\n"
   "#define ADD_NOISE 1\n"
   "#endif\n"
   "#if defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "uniform sampler2D texuv;\n"
   "varying vec2 tex_c2;\n"
   "#endif\n"
   "#if defined(SHD_YUV)\n"
   "uniform sampler2D texu;\n"
   "uniform sampler2D texv;\n"
   "varying vec2 tex_c2;\n"
   "varying vec2 tex_c3;\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "uniform sampler2D texa;\n"
   "varying vec2 tex_a;\n"
   "#endif\n"
   "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
   "varying vec4 div_s;\n"
   "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "varying vec2 tex_s[2];\n"
   "# else\n"
   "varying vec2 tex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "uniform sampler2D texm;\n"
   "varying vec2 tex_m;\n"
   "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[2];\n"
   "# elif defined(SHD_MASKSAM22)\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_ALPHA\n"
   "# define SWZ aaaa\n"
   "#else\n"
   "# ifndef SHD_BGRA\n"
   "#  if defined(SHD_IMG) && defined(SHD_BIGENDIAN)\n"
   "#   define SWZ gbar\n"
   "#  else\n"
   "#   define SWZ bgra\n"
   "#endif\n"
   "# else\n"
   "#  if defined(SHD_IMG) && defined(SHD_BIGENDIAN)\n"
   "#   define SWZ grab\n"
   "#  else\n"
   "#   define SWZ rgba\n"
   "#  endif\n"
   "# endif\n"
   "#endif\n"
   "#ifdef ADD_NOISE\n"
   "float rand(vec2 co)\n"
   "{\n"
   "   /* Magic 'random' number in range [0..1]. 'co' should be random coordinate.\n"
   "    * Distribution is not great. Falls apart with lowp float. */\n"
   "   return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5;\n"
   "}\n"
   "#endif\n"
   "void main()\n"
   "{\n"
   "   vec4 c;\n"
   "#if defined(SHD_YUV) || defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "   float r, g, b, y, u, v, vmu;\n"
   "# if defined(SHD_YUV)\n"
   "   y = texture2D(tex, tex_c).r;\n"
   "   u = texture2D(texu, tex_c2).r;\n"
   "   v = texture2D(texv, tex_c3).r;\n"
   "# elif defined(SHD_NV12) || defined(SHD_YUY2)\n"
   "   y = texture2D(tex, tex_c).g;\n"
   "   u = texture2D(texuv, tex_c2).g;\n"
   "   v = texture2D(texuv, tex_c2).a;\n"
   "# endif\n"
   "// center u and v around 0 for uv and y (with 128/255 for u + v, 16/255 for y)\n"
   "   u = u - 0.5;\n"
   "   v = v - 0.5;\n"
   "# if defined (SHD_YUV_709)\n"
   "// 709 yuv colorspace for hd content\n"
   "   y = (y - 0.062) * 1.164;\n"
   "   vmu = (v * 0.534) + (u * 0.213);\n"
   "   v = v * 1.793;\n"
   "   u = u * 2.115;\n"
   "# else\n"
   "// 601 colorspace constants (older yuv content)\n"
   "   y = (y - 0.062) * 1.164;\n"
   "   vmu = (v * 0.813) + (u * 0.391);\n"
   "   v = v * 1.596;\n"
   "   u = u * 2.018;\n"
   "# endif\n"
   "// common yuv\n"
   "   r = y + v;\n"
   "   g = y - vmu;\n"
   "   b = y + u;\n"
   "   c = vec4(r, g, b, 1.0);\n"
   "#elif defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "   vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;\n"
   "   vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;\n"
   "   c = (col00 + col01) / div_s;\n"
   "#elif defined(SHD_SAM22)\n"
   "   vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;\n"
   "   vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;\n"
   "   vec4 col10 = texture2D(tex, tex_c + tex_s[2]).SWZ;\n"
   "   vec4 col11 = texture2D(tex, tex_c + tex_s[3]).SWZ;\n"
   "   c = (col00 + col01 + col10 + col11) / div_s;\n"
   "#elif defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "   c = texture2D(tex, tex_c).SWZ;\n"
   "#else\n"
   "   c = vec4(1, 1, 1, 1);\n"
   "#endif\n"
   "#ifdef ADD_NOISE\n"
   "   vec4 noise = vec4(rand(tex_c) / 256.0, rand(tex_c + vec2(1, 1)) / 256.0, rand(tex_c + vec2(2, 2)) / 256.0, 0);\n"
   "   noise.a = max(noise.r, noise.g);\n"
   "   noise.a = max(noise.a, noise.b);\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "   float ma;\n"
   "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "   float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
   "   float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
   "   ma = (ma00 + ma01) / maskdiv_s;\n"
   "# elif defined(SHD_MASKSAM22)\n"
   "   float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
   "   float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
   "   float ma10 = texture2D(texm, tex_m + masktex_s[2]).a;\n"
   "   float ma11 = texture2D(texm, tex_m + masktex_s[3]).a;\n"
   "   ma = (ma00 + ma01 + ma10 + ma11) / maskdiv_s;\n"
   "# else\n"
   "   ma = texture2D(texm, tex_m).a;\n"
   "# endif\n"
   "#endif\n"
   "#ifdef SHD_AFILL\n"
   "   c.a = 1.0;\n"
   "#endif\n"
   "   gl_FragColor =\n"
   "       c\n"
   "#ifndef SHD_NOMUL\n"
   "     * col\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "	 * ma\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "     * texture2D(texa, tex_a).r\n"
   "#endif\n"
   "#ifdef ADD_NOISE\n"
   "     + noise\n"
   "#endif\n"
   "   ;\n"
   "}\n";

static const char vertex_glsl[] =
   "/* General-purpose vertex shader for all operations in Evas.\n"
   " * This file can either be used directly by evas at runtime to\n"
   " * generate its shaders with the appropriate #defines, or passed\n"
   " * through cpp first (in which case the precision must be manually added).\n"
   " */\n"
   "#ifdef GL_ES\n"
   "precision highp float;\n"
   "#endif\n"
   "attribute vec4 vertex;\n"
   "uniform mat4 mvp;\n"
   "/* All except nomul */\n"
   "#ifndef SHD_NOMUL\n"
   "attribute vec4 color;\n"
   "varying vec4 col;\n"
   "#endif\n"
   "/* All images & fonts */\n"
   "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "attribute vec2 tex_coord;\n"
   "varying vec2 tex_c;\n"
   "#endif\n"
   "/* NV12, YUY2 */\n"
   "#if defined(SHD_NV12) || defined(SHD_YUY2) || defined(SHD_YUV)\n"
   "attribute vec2 tex_coord2;\n"
   "varying vec2 tex_c2;\n"
   "#endif\n"
   "/* YUV */\n"
   "#ifdef SHD_YUV\n"
   "attribute vec2 tex_coord3;\n"
   "varying vec2 tex_c3;\n"
   "#endif\n"
   "/* RGB+A */\n"
   "#ifdef SHD_TEXA\n"
   "attribute vec2 tex_coorda;\n"
   "varying vec2 tex_a;\n"
   "#endif\n"
   "/* Sampling */\n"
   "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
   "attribute vec2 tex_sample;\n"
   "varying vec4 div_s;\n"
   "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
   "varying vec2 tex_s[2];\n"
   "# else\n"
   "varying vec2 tex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "/* Masking */\n"
   "#ifdef SHD_MASK\n"
   "attribute vec4 mask_coord;\n"
   "varying vec2 tex_m;\n"
   "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
   "attribute vec2 tex_masksample;\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[2];\n"
   "# elif defined(SHD_MASKSAM22)\n"
   "attribute vec2 tex_masksample;\n"
   "varying float maskdiv_s;\n"
   "varying vec2 masktex_s[4];\n"
   "# endif\n"
   "#endif\n"
   "void main()\n"
   "{\n"
   "   gl_Position = mvp * vertex;\n"
   "#ifndef SHD_NOMUL\n"
   "   col = color;\n"
   "#endif\n"
   "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
   "   tex_c = tex_coord;\n"
   "#endif\n"
   "#ifdef SHD_NV12\n"
   "   tex_c2 = tex_coord2 * 0.5;\n"
   "#endif\n"
   "#ifdef SHD_YUY2\n"
   "   tex_c2 = vec2(tex_coord2.x * 0.5, tex_coord2.y);\n"
   "#endif\n"
   "#ifdef SHD_YUV\n"
   "   tex_c2 = tex_coord2;\n"
   "   tex_c3 = tex_coord3;\n"
   "#endif\n"
   "#ifdef SHD_TEXA\n"
   "   tex_a = tex_coorda;\n"
   "#endif\n"
   "#if defined(SHD_SAM12)\n"
   "   tex_s[0] = vec2(0, -tex_sample.y);\n"
   "   tex_s[1] = vec2(0,  tex_sample.y);\n"
   "   div_s = vec4(2, 2, 2, 2);\n"
   "#elif defined(SHD_SAM21)\n"
   "   tex_s[0] = vec2(-tex_sample.x, 0);\n"
   "   tex_s[1] = vec2( tex_sample.x, 0);\n"
   "   div_s = vec4(2, 2, 2, 2);\n"
   "#elif defined(SHD_SAM22)\n"
   "   tex_s[0] = vec2(-tex_sample.x, -tex_sample.y);\n"
   "   tex_s[1] = vec2( tex_sample.x, -tex_sample.y);\n"
   "   tex_s[2] = vec2( tex_sample.x,  tex_sample.y);\n"
   "   tex_s[3] = vec2(-tex_sample.x,  tex_sample.y);\n"
   "   div_s = vec4(4, 4, 4, 4);\n"
   "#endif\n"
   "#if defined(SHD_MASKSAM12)\n"
   "   masktex_s[0] = vec2(0, -tex_masksample.y);\n"
   "   masktex_s[1] = vec2(0,  tex_masksample.y);\n"
   "   maskdiv_s = 2.0;\n"
   "#elif defined(SHD_MASKSAM21)\n"
   "   masktex_s[0] = vec2(-tex_masksample.x, 0);\n"
   "   masktex_s[1] = vec2( tex_masksample.x, 0);\n"
   "   maskdiv_s = 2.0;\n"
   "#elif defined(SHD_MASKSAM22)\n"
   "   masktex_s[0] = vec2(-tex_masksample.x, -tex_masksample.y);\n"
   "   masktex_s[1] = vec2( tex_masksample.x, -tex_masksample.y);\n"
   "   masktex_s[2] = vec2( tex_masksample.x,  tex_masksample.y);\n"
   "   masktex_s[3] = vec2(-tex_masksample.x,  tex_masksample.y);\n"
   "   maskdiv_s = 4.0;\n"
   "#endif\n"
   "#ifdef SHD_MASK\n"
   "   // mask_coord.w contains the Y-invert flag\n"
   "   // position on screen in [0..1] range of current pixel\n"
   "   vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
   "   tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;\n"
   "#endif\n"
   "}\n";