1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#if defined(GL_ES)
6    #if GL_ES == 1
7        // Sampler default precision is lowp on mobile GPUs.
8        // This causes RGBA32F texture data to be clamped to 16 bit floats on some GPUs (e.g. Mali-T880).
9        // Define highp precision macro to allow lossless FLOAT texture sampling.
10        #define HIGHP_SAMPLER_FLOAT highp
11
12        // Default int precision in GLES 3 is highp (32 bits) in vertex shaders
13        // and mediump (16 bits) in fragment shaders. If an int is being used as
14        // a texel address in a fragment shader it, and therefore requires > 16
15        // bits, it must be qualified with this.
16        #define HIGHP_FS_ADDRESS highp
17
18        // texelFetchOffset is buggy on some Android GPUs (see issue #1694).
19        // Fallback to texelFetch on mobile GPUs.
20        #define TEXEL_FETCH(sampler, position, lod, offset) texelFetch(sampler, position + offset, lod)
21    #else
22        #define HIGHP_SAMPLER_FLOAT
23        #define HIGHP_FS_ADDRESS
24        #define TEXEL_FETCH(sampler, position, lod, offset) texelFetchOffset(sampler, position, lod, offset)
25    #endif
26#else
27    #define HIGHP_SAMPLER_FLOAT
28    #define HIGHP_FS_ADDRESS
29    #if defined(PLATFORM_MACOS) && !defined(SWGL)
30        // texelFetchOffset introduces a variety of shader compilation bugs on macOS Intel so avoid it.
31        #define TEXEL_FETCH(sampler, position, lod, offset) texelFetch(sampler, position + offset, lod)
32    #else
33        #define TEXEL_FETCH(sampler, position, lod, offset) texelFetchOffset(sampler, position, lod, offset)
34    #endif
35#endif
36
37#ifdef SWGL
38    #define SWGL_DRAW_SPAN
39    #define SWGL_CLIP_MASK
40    #define SWGL_ANTIALIAS
41    #define SWGL_BLEND
42    #define SWGL_CLIP_DIST
43#endif
44
45#ifdef WR_VERTEX_SHADER
46    #ifdef SWGL
47        // Annotate a vertex attribute as being flat per each drawn primitive instance.
48        // SWGL can use this information to avoid redundantly loading the attribute in all SIMD lanes.
49        #define PER_INSTANCE flat
50    #else
51        #define PER_INSTANCE
52    #endif
53
54    #if __VERSION__ != 100
55        #define varying out
56        #define attribute in
57    #endif
58#endif
59
60#ifdef WR_FRAGMENT_SHADER
61    precision highp float;
62    #if __VERSION__ != 100
63        #define varying in
64    #endif
65#endif
66
67// Flat interpolation is not supported on ESSL 1
68#if __VERSION__ == 100
69    #define flat
70#endif
71