Initialize.cpp revision 70da3d432409368f214058c466fe0265b6b9a070
1// 2// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. 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 13#include "Initialize.h" 14 15#include "intermediate.h" 16 17void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable) 18{ 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); 23 24 TType *int2 = new TType(EbtInt, 2); 25 TType *int3 = new TType(EbtInt, 3); 26 TType *int4 = new TType(EbtInt, 4); 27 28 // 29 // Angle and Trigonometric Functions. 30 // 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); 35 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); 40 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); 45 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); 50 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); 55 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); 60 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); 65 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); 70 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); 75 76 // 77 // Exponential Functions. 78 // 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); 83 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); 88 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); 93 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); 98 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); 103 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); 108 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); 113 114 // 115 // Common Functions. 116 // 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); 121 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); 126 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); 131 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); 136 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); 141 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); 149 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); 157 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); 165 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); 173 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); 181 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); 189 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); 197 198 // 199 // Geometric Functions. 200 // 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); 205 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); 210 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); 215 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); 221 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); 226 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); 231 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); 236 237 TType *mat2 = new TType(EbtFloat, 2, true); 238 TType *mat3 = new TType(EbtFloat, 3, true); 239 TType *mat4 = new TType(EbtFloat, 4, true); 240 241 // 242 // Matrix Functions. 243 // 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); 247 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); 252 253 // 254 // Vector relational functions. 255 // 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); 259 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); 263 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); 267 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); 271 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); 275 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); 279 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); 283 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); 287 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); 291 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); 295 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); 299 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); 303 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); 307 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); 311 312 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2); 313 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3); 314 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4); 315 316 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2); 317 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3); 318 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4); 319 320 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2); 321 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3); 322 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4); 323 324 TType *sampler2D = new TType(EbtSampler2D); 325 TType *samplerCube = new TType(EbtSamplerCube); 326 TType *sampler3D = new TType(EbtSampler3D); 327 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 { 339 TType *samplerExternalOES = new TType(EbtSamplerExternalOES); 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 } 346 347 if(type == GL_FRAGMENT_SHADER) 348 { 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); 353 354 if(resources.OES_standard_derivatives) 355 { 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); 360 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); 370 } 371 } 372 373 if(type == GL_VERTEX_SHADER) 374 { 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); 380 } 381 382 // 383 // Depth range in window coordinates 384 // 385 TTypeList *members = NewPoolTTypeList(); 386 TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; 387 TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; 388 TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0}; 389 near.type->setFieldName("near"); 390 far.type->setFieldName("far"); 391 diff.type->setFieldName("diff"); 392 members->push_back(near); 393 members->push_back(far); 394 members->push_back(diff); 395 TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true); 396 symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters); 397 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters")); 398 depthRange->setQualifier(EvqUniform); 399 symbolTable.insert(COMMON_BUILTINS, *depthRange); 400 401 // 402 // Implementation dependent built-in constants. 403 // 404 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs); 405 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); 406 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); 407 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); 408 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); 409 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); 410 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors); 411 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers); 412} 413 414void IdentifyBuiltIns(GLenum shaderType, 415 const ShBuiltInResources &resources, 416 TSymbolTable &symbolTable) 417{ 418 // 419 // First, insert some special built-in variables that are not in 420 // the built-in header files. 421 // 422 switch(shaderType) 423 { 424 case GL_FRAGMENT_SHADER: 425 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); 426 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); 427 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); 428 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); 429 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); 430 break; 431 case GL_VERTEX_SHADER: 432 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); 433 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); 434 break; 435 default: assert(false && "Language not supported"); 436 } 437 438 // 439 // Next, identify which built-ins from the already loaded headers have 440 // a mapping to an operator. Those that are not identified as such are 441 // expected to be resolved through a library of functions, versus as 442 // operations. 443 // 444 symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul); 445 446 symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual); 447 symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual); 448 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan); 449 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan); 450 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual); 451 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual); 452 453 symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians); 454 symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees); 455 symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin); 456 symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos); 457 symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan); 458 symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin); 459 symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos); 460 symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan); 461 462 symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow); 463 symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2); 464 symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog); 465 symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp); 466 symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2); 467 symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt); 468 symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt); 469 470 symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs); 471 symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign); 472 symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor); 473 symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil); 474 symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract); 475 symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod); 476 symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin); 477 symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax); 478 symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp); 479 symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix); 480 symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep); 481 symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep); 482 483 symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength); 484 symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance); 485 symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot); 486 symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross); 487 symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize); 488 symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward); 489 symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect); 490 symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract); 491 492 symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny); 493 symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll); 494 symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot); 495 496 // Map language-specific operators. 497 switch(shaderType) 498 { 499 case GL_VERTEX_SHADER: 500 break; 501 case GL_FRAGMENT_SHADER: 502 if(resources.OES_standard_derivatives) 503 { 504 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx); 505 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy); 506 symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth); 507 508 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives"); 509 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives"); 510 symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives"); 511 } 512 break; 513 default: break; 514 } 515 516 // Finally add resource-specific variables. 517 switch(shaderType) 518 { 519 case GL_FRAGMENT_SHADER: 520 { 521 // Set up gl_FragData. The array size. 522 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); 523 fragData.setArraySize(resources.MaxDrawBuffers); 524 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData)); 525 } 526 break; 527 default: break; 528 } 529} 530 531void InitExtensionBehavior(const ShBuiltInResources& resources, 532 TExtensionBehavior& extBehavior) 533{ 534 if(resources.OES_standard_derivatives) 535 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; 536 if(resources.OES_fragment_precision_high) 537 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined; 538 if(resources.OES_EGL_image_external) 539 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; 540} 541