John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // |
| 8 | // Create strings that declare built-in definitions, add built-ins that |
| 9 | // cannot be expressed in the files, and establish mappings between |
| 10 | // built-in functions and operators. |
| 11 | // |
| 12 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 13 | #include "Initialize.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 15 | #include "intermediate.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 16 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 17 | void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 18 | { |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 19 | TType *float1 = new TType(EbtFloat); |
| 20 | TType *float2 = new TType(EbtFloat, 2); |
| 21 | TType *float3 = new TType(EbtFloat, 3); |
| 22 | TType *float4 = new TType(EbtFloat, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 23 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 24 | TType *int2 = new TType(EbtInt, 2); |
| 25 | TType *int3 = new TType(EbtInt, 3); |
| 26 | TType *int4 = new TType(EbtInt, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 27 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 28 | // |
| 29 | // Angle and Trigonometric Functions. |
| 30 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 31 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "radians", float1); |
| 32 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "radians", float2); |
| 33 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "radians", float3); |
| 34 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "radians", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 35 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 36 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "degrees", float1); |
| 37 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "degrees", float2); |
| 38 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "degrees", float3); |
| 39 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "degrees", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 40 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 41 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sin", float1); |
| 42 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sin", float2); |
| 43 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sin", float3); |
| 44 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sin", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 45 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 46 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "cos", float1); |
| 47 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "cos", float2); |
| 48 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cos", float3); |
| 49 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "cos", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 50 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 51 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "tan", float1); |
| 52 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "tan", float2); |
| 53 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "tan", float3); |
| 54 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "tan", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 55 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 56 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "asin", float1); |
| 57 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "asin", float2); |
| 58 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "asin", float3); |
| 59 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "asin", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 60 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 61 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "acos", float1); |
| 62 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "acos", float2); |
| 63 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "acos", float3); |
| 64 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "acos", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 65 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 66 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1, float1); |
| 67 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2, float2); |
| 68 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3, float3); |
| 69 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 70 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 71 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1); |
| 72 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2); |
| 73 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3); |
| 74 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 75 | |
| 76 | // |
| 77 | // Exponential Functions. |
| 78 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 79 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1); |
| 80 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2); |
| 81 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3); |
| 82 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 83 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 84 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1); |
| 85 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2); |
| 86 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3); |
| 87 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 88 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 89 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1); |
| 90 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2); |
| 91 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3); |
| 92 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 93 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 94 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1); |
| 95 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2); |
| 96 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3); |
| 97 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 98 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 99 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1); |
| 100 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2); |
| 101 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3); |
| 102 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 103 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 104 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1); |
| 105 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2); |
| 106 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3); |
| 107 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 108 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 109 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1); |
| 110 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2); |
| 111 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3); |
| 112 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 113 | |
| 114 | // |
| 115 | // Common Functions. |
| 116 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 117 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1); |
| 118 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2); |
| 119 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3); |
| 120 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 121 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 122 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1); |
| 123 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2); |
| 124 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3); |
| 125 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 126 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 127 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1); |
| 128 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2); |
| 129 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3); |
| 130 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 131 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 132 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1); |
| 133 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2); |
| 134 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3); |
| 135 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 136 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 137 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1); |
| 138 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2); |
| 139 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3); |
| 140 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 141 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 142 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1); |
| 143 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1); |
| 144 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1); |
| 145 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1); |
| 146 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2); |
| 147 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3); |
| 148 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 149 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 150 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1); |
| 151 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1); |
| 152 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1); |
| 153 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1); |
| 154 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2); |
| 155 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3); |
| 156 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 157 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 158 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1); |
| 159 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1); |
| 160 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1); |
| 161 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1); |
| 162 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2); |
| 163 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3); |
| 164 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 165 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 166 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1); |
| 167 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1); |
| 168 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1); |
| 169 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1); |
| 170 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2); |
| 171 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3); |
| 172 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 173 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 174 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1); |
| 175 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1); |
| 176 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1); |
| 177 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1); |
| 178 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2); |
| 179 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3); |
| 180 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 181 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 182 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1); |
| 183 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2); |
| 184 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3); |
| 185 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4); |
| 186 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2); |
| 187 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3); |
| 188 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 189 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 190 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1); |
| 191 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2); |
| 192 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3); |
| 193 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4); |
| 194 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2); |
| 195 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3); |
| 196 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 197 | |
| 198 | // |
| 199 | // Geometric Functions. |
| 200 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 201 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1); |
| 202 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2); |
| 203 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3); |
| 204 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 205 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 206 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1); |
| 207 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2); |
| 208 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3); |
| 209 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 210 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 211 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1); |
| 212 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2); |
| 213 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3); |
| 214 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 215 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 216 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3); |
| 217 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1); |
| 218 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2); |
| 219 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3); |
| 220 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 221 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 222 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1); |
| 223 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2); |
| 224 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3); |
| 225 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 226 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 227 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1); |
| 228 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2); |
| 229 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3); |
| 230 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 231 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 232 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1); |
| 233 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1); |
| 234 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1); |
| 235 | symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 236 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 237 | TType *mat2 = new TType(EbtFloat, 2, true); |
| 238 | TType *mat3 = new TType(EbtFloat, 3, true); |
| 239 | TType *mat4 = new TType(EbtFloat, 4, true); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 240 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 241 | // |
| 242 | // Matrix Functions. |
| 243 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 244 | symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2); |
| 245 | symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3); |
| 246 | symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 247 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 248 | TType *bool1 = new TType(EbtBool); |
| 249 | TType *bool2 = new TType(EbtBool, 2); |
| 250 | TType *bool3 = new TType(EbtBool, 3); |
| 251 | TType *bool4 = new TType(EbtBool, 4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 252 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 253 | // |
| 254 | // Vector relational functions. |
| 255 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 256 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2); |
| 257 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3); |
| 258 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 259 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 260 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2); |
| 261 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3); |
| 262 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 263 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 264 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2); |
| 265 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3); |
| 266 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 267 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 268 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2); |
| 269 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3); |
| 270 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 271 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 272 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2); |
| 273 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3); |
| 274 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 275 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 276 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2); |
| 277 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3); |
| 278 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 279 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 280 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2); |
| 281 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3); |
| 282 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 283 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 284 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2); |
| 285 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3); |
| 286 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 287 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 288 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2); |
| 289 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3); |
| 290 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 291 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 292 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2); |
| 293 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3); |
| 294 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 295 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 296 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2); |
| 297 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3); |
| 298 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 299 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 300 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2); |
| 301 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3); |
| 302 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 303 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 304 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2); |
| 305 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3); |
| 306 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 307 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 308 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2); |
| 309 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3); |
| 310 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 311 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 312 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2); |
| 313 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3); |
| 314 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 315 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 316 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2); |
| 317 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3); |
| 318 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 319 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 320 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2); |
| 321 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3); |
| 322 | symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 323 | |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 324 | TType *sampler2D = new TType(EbtSampler2D); |
| 325 | TType *samplerCube = new TType(EbtSamplerCube); |
| 326 | TType *sampler3D = new TType(EbtSampler3D); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 327 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 328 | // |
| 329 | // Texture Functions for GLSL ES 1.0 |
| 330 | // |
| 331 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); |
| 332 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); |
| 333 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); |
| 334 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); |
| 335 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3); |
| 336 | |
| 337 | if(resources.OES_EGL_image_external) |
| 338 | { |
Nicolas Capens | 70da3d4 | 2015-02-18 16:58:10 -0500 | [diff] [blame] | 339 | TType *samplerExternalOES = new TType(EbtSamplerExternalOES); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 340 | |
| 341 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); |
| 342 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); |
| 343 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); |
| 344 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3); |
| 345 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 346 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 347 | if(type == GL_FRAGMENT_SHADER) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 348 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 349 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); |
| 350 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); |
| 351 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); |
| 352 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 353 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 354 | if(resources.OES_standard_derivatives) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 355 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 356 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1); |
| 357 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2); |
| 358 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3); |
| 359 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 360 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 361 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1); |
| 362 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2); |
| 363 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3); |
| 364 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4); |
| 365 | |
| 366 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1); |
| 367 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2); |
| 368 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3); |
| 369 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 370 | } |
| 371 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 372 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 373 | if(type == GL_VERTEX_SHADER) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 374 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 375 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); |
| 376 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); |
| 377 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); |
| 378 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); |
| 379 | symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 380 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 381 | |
Nicolas Capens | 82cd6d8 | 2015-02-18 17:53:39 -0500 | [diff] [blame^] | 382 | TType *gvec4 = new TType(EbtGVec4); |
| 383 | |
| 384 | TType *gsampler2D = new TType(EbtGSampler2D); |
| 385 | TType *gsamplerCube = new TType(EbtGSamplerCube); |
| 386 | TType *gsampler3D = new TType(EbtGSampler3D); |
| 387 | TType *gsampler2DArray = new TType(EbtGSampler2DArray); |
| 388 | |
| 389 | // |
| 390 | // Texture Functions for GLSL ES 3.0 |
| 391 | // |
| 392 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); |
| 393 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); |
| 394 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); |
| 395 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); |
| 396 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); |
| 397 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); |
| 398 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); |
| 399 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); |
| 400 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); |
| 401 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); |
| 402 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); |
| 403 | |
| 404 | if(type == GL_FRAGMENT_SHADER) |
| 405 | { |
| 406 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); |
| 407 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); |
| 408 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); |
| 409 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); |
| 410 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); |
| 411 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); |
| 412 | symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); |
| 413 | } |
| 414 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 415 | // |
| 416 | // Depth range in window coordinates |
| 417 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 418 | TTypeList *members = NewPoolTTypeList(); |
| 419 | TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 420 | TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 421 | TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; |
| 422 | near.type->setFieldName("near"); |
| 423 | far.type->setFieldName("far"); |
| 424 | diff.type->setFieldName("diff"); |
| 425 | members->push_back(near); |
| 426 | members->push_back(far); |
| 427 | members->push_back(diff); |
| 428 | TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 429 | symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 430 | TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters")); |
| 431 | depthRange->setQualifier(EvqUniform); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 432 | symbolTable.insert(COMMON_BUILTINS, *depthRange); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 433 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 434 | // |
| 435 | // Implementation dependent built-in constants. |
| 436 | // |
| 437 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 438 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 439 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); |
| 440 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); |
| 441 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); |
| 442 | symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 443 | symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors); |
| 444 | symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 447 | void IdentifyBuiltIns(GLenum shaderType, |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 448 | const ShBuiltInResources &resources, |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 449 | TSymbolTable &symbolTable) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 450 | { |
| 451 | // |
| 452 | // First, insert some special built-in variables that are not in |
| 453 | // the built-in header files. |
| 454 | // |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 455 | switch(shaderType) |
| 456 | { |
| 457 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 458 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); |
| 459 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); |
| 460 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); |
| 461 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); |
| 462 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 463 | break; |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 464 | case GL_VERTEX_SHADER: |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 465 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); |
| 466 | symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 467 | break; |
| 468 | default: assert(false && "Language not supported"); |
| 469 | } |
| 470 | |
| 471 | // |
| 472 | // Next, identify which built-ins from the already loaded headers have |
| 473 | // a mapping to an operator. Those that are not identified as such are |
| 474 | // expected to be resolved through a library of functions, versus as |
| 475 | // operations. |
| 476 | // |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 477 | symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 478 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 479 | symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual); |
| 480 | symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual); |
| 481 | symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan); |
| 482 | symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan); |
| 483 | symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual); |
| 484 | symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 485 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 486 | symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians); |
| 487 | symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees); |
| 488 | symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin); |
| 489 | symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos); |
| 490 | symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan); |
| 491 | symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin); |
| 492 | symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos); |
| 493 | symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 494 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 495 | symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow); |
| 496 | symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2); |
| 497 | symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog); |
| 498 | symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp); |
| 499 | symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2); |
| 500 | symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt); |
| 501 | symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 502 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 503 | symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs); |
| 504 | symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign); |
| 505 | symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor); |
| 506 | symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil); |
| 507 | symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract); |
| 508 | symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod); |
| 509 | symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin); |
| 510 | symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax); |
| 511 | symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp); |
| 512 | symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix); |
| 513 | symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep); |
| 514 | symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 515 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 516 | symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength); |
| 517 | symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance); |
| 518 | symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot); |
| 519 | symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross); |
| 520 | symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize); |
| 521 | symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward); |
| 522 | symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect); |
| 523 | symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 524 | |
Nicolas Capens | e285865 | 2015-02-18 15:30:51 -0500 | [diff] [blame] | 525 | symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny); |
| 526 | symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 527 | symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 528 | |
| 529 | // Map language-specific operators. |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 530 | switch(shaderType) |
| 531 | { |
| 532 | case GL_VERTEX_SHADER: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 533 | break; |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 534 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 535 | if(resources.OES_standard_derivatives) |
| 536 | { |
| 537 | symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx); |
| 538 | symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy); |
| 539 | symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 540 | |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 541 | symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives"); |
| 542 | symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives"); |
| 543 | symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives"); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 544 | } |
| 545 | break; |
| 546 | default: break; |
| 547 | } |
| 548 | |
| 549 | // Finally add resource-specific variables. |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 550 | switch(shaderType) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 551 | { |
Nicolas Capens | 08ca3c6 | 2015-02-13 16:06:45 -0500 | [diff] [blame] | 552 | case GL_FRAGMENT_SHADER: |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 553 | { |
| 554 | // Set up gl_FragData. The array size. |
| 555 | TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); |
| 556 | fragData.setArraySize(resources.MaxDrawBuffers); |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 557 | symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData)); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 558 | } |
| 559 | break; |
| 560 | default: break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | void InitExtensionBehavior(const ShBuiltInResources& resources, |
| 565 | TExtensionBehavior& extBehavior) |
| 566 | { |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 567 | if(resources.OES_standard_derivatives) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 568 | extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 569 | if(resources.OES_fragment_precision_high) |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 570 | extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined; |
Nicolas Capens | 3d7f6ed | 2015-02-18 16:34:50 -0500 | [diff] [blame] | 571 | if(resources.OES_EGL_image_external) |
| 572 | extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 573 | } |