1 // 2 // Copyright (c) 2013-2014 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 // ShaderVars.h: 7 // Types to represent GL variables (varyings, uniforms, etc) 8 // 9 10 #ifndef _COMPILER_INTERFACE_VARIABLES_ 11 #define _COMPILER_INTERFACE_VARIABLES_ 12 13 #include <string> 14 #include <vector> 15 #include <algorithm> 16 17 // Assume ShaderLang.h is included before ShaderVars.h, for sh::GLenum 18 // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h 19 20 namespace sh 21 { 22 23 // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec 24 enum InterpolationType 25 { 26 INTERPOLATION_SMOOTH, 27 INTERPOLATION_CENTROID, 28 INTERPOLATION_FLAT 29 }; 30 31 // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec 32 enum BlockLayoutType 33 { 34 BLOCKLAYOUT_STANDARD, 35 BLOCKLAYOUT_PACKED, 36 BLOCKLAYOUT_SHARED 37 }; 38 39 // Base class for all variables defined in shaders, including Varyings, Uniforms, etc 40 // Note: we must override the copy constructor and assignment operator so we can 41 // work around excessive GCC binary bloating: 42 // See https://code.google.com/p/angleproject/issues/detail?id=697 43 struct COMPILER_EXPORT ShaderVariable 44 { 45 ShaderVariable(); 46 ShaderVariable(GLenum typeIn, unsigned int arraySizeIn); 47 ~ShaderVariable(); 48 ShaderVariable(const ShaderVariable &other); 49 ShaderVariable &operator=(const ShaderVariable &other); 50 isArrayShaderVariable51 bool isArray() const { return arraySize > 0; } elementCountShaderVariable52 unsigned int elementCount() const { return std::max(1u, arraySize); } isStructShaderVariable53 bool isStruct() const { return !fields.empty(); } 54 55 GLenum type; 56 GLenum precision; 57 std::string name; 58 std::string mappedName; 59 unsigned int arraySize; 60 bool staticUse; 61 std::vector<ShaderVariable> fields; 62 std::string structName; 63 }; 64 65 struct COMPILER_EXPORT Uniform : public ShaderVariable 66 { 67 Uniform(); 68 ~Uniform(); 69 Uniform(const Uniform &other); 70 Uniform &operator=(const Uniform &other); 71 }; 72 73 struct COMPILER_EXPORT Attribute : public ShaderVariable 74 { 75 Attribute(); 76 ~Attribute(); 77 Attribute(const Attribute &other); 78 Attribute &operator=(const Attribute &other); 79 80 int location; 81 }; 82 83 struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable 84 { 85 InterfaceBlockField(); 86 ~InterfaceBlockField(); 87 InterfaceBlockField(const InterfaceBlockField &other); 88 InterfaceBlockField &operator=(const InterfaceBlockField &other); 89 90 bool isRowMajorLayout; 91 }; 92 93 struct COMPILER_EXPORT Varying : public ShaderVariable 94 { 95 Varying(); 96 ~Varying(); 97 Varying(const Varying &other); 98 Varying &operator=(const Varying &other); 99 100 InterpolationType interpolation; 101 bool isInvariant; 102 }; 103 104 struct COMPILER_EXPORT InterfaceBlock 105 { 106 InterfaceBlock(); 107 ~InterfaceBlock(); 108 InterfaceBlock(const InterfaceBlock &other); 109 InterfaceBlock &operator=(const InterfaceBlock &other); 110 111 std::string name; 112 std::string mappedName; 113 std::string instanceName; 114 unsigned int arraySize; 115 BlockLayoutType layout; 116 bool isRowMajorLayout; 117 bool staticUse; 118 std::vector<InterfaceBlockField> fields; 119 }; 120 121 } 122 123 #endif // _COMPILER_INTERFACE_VARIABLES_ 124