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.
7 // Types to represent GL variables (varyings, uniforms, etc)
10 #ifndef _COMPILER_INTERFACE_VARIABLES_
11 #define _COMPILER_INTERFACE_VARIABLES_
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
23 // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec
24 enum InterpolationType
27 INTERPOLATION_CENTROID,
31 // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec
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
46 ShaderVariable(GLenum typeIn, unsigned int arraySizeIn);
48 ShaderVariable(const ShaderVariable &other);
49 ShaderVariable &operator=(const ShaderVariable &other);
51 bool isArray() const { return arraySize > 0; }
52 unsigned int elementCount() const { return std::max(1u, arraySize); }
53 bool isStruct() const { return !fields.empty(); }
55 // All of the shader's variables are described using nested data
56 // structures. This is needed in order to disambiguate similar looking
57 // types, such as two structs containing the same fields, but in
58 // different orders. "findInfoByMappedName" provides an easy query for
59 // users to dive into the data structure and fetch the unique variable
60 // instance corresponding to a dereferencing chain of the top-level
62 // Given a mapped name like 'a[0].b.c[0]', return the ShaderVariable
63 // that defines 'c' in |leafVar|, and the original name 'A[0].B.C[0]'
64 // in |originalName|, based on the assumption that |this| defines 'a'.
65 // If no match is found, return false.
66 bool findInfoByMappedName(const std::string &mappedFullName,
67 const ShaderVariable **leafVar,
68 std::string* originalFullName) const;
73 std::string mappedName;
74 unsigned int arraySize;
76 std::vector<ShaderVariable> fields;
77 std::string structName;
80 bool isSameVariableAtLinkTime(const ShaderVariable &other,
81 bool matchPrecision) const;
83 bool operator==(const ShaderVariable &other) const;
84 bool operator!=(const ShaderVariable &other) const
86 return !operator==(other);
90 struct COMPILER_EXPORT Uniform : public ShaderVariable
94 Uniform(const Uniform &other);
95 Uniform &operator=(const Uniform &other);
96 bool operator==(const Uniform &other) const;
97 bool operator!=(const Uniform &other) const
99 return !operator==(other);
102 // Decide whether two uniforms are the same at shader link time,
103 // assuming one from vertex shader and the other from fragment shader.
104 // See GLSL ES Spec 3.00.3, sec 4.3.5.
105 bool isSameUniformAtLinkTime(const Uniform &other) const;
108 struct COMPILER_EXPORT Attribute : public ShaderVariable
112 Attribute(const Attribute &other);
113 Attribute &operator=(const Attribute &other);
114 bool operator==(const Attribute &other) const;
115 bool operator!=(const Attribute &other) const
117 return !operator==(other);
123 struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable
125 InterfaceBlockField();
126 ~InterfaceBlockField();
127 InterfaceBlockField(const InterfaceBlockField &other);
128 InterfaceBlockField &operator=(const InterfaceBlockField &other);
129 bool operator==(const InterfaceBlockField &other) const;
130 bool operator!=(const InterfaceBlockField &other) const
132 return !operator==(other);
135 // Decide whether two InterfaceBlock fields are the same at shader
136 // link time, assuming one from vertex shader and the other from
138 // See GLSL ES Spec 3.00.3, sec 4.3.7.
139 bool isSameInterfaceBlockFieldAtLinkTime(
140 const InterfaceBlockField &other) const;
142 bool isRowMajorLayout;
145 struct COMPILER_EXPORT Varying : public ShaderVariable
149 Varying(const Varying &otherg);
150 Varying &operator=(const Varying &other);
151 bool operator==(const Varying &other) const;
152 bool operator!=(const Varying &other) const
154 return !operator==(other);
157 // Decide whether two varyings are the same at shader link time,
158 // assuming one from vertex shader and the other from fragment shader.
159 // See GLSL ES Spec 3.00.3, sec 4.3.9.
160 bool isSameVaryingAtLinkTime(const Varying &other) const;
162 InterpolationType interpolation;
166 struct COMPILER_EXPORT InterfaceBlock
170 InterfaceBlock(const InterfaceBlock &other);
171 InterfaceBlock &operator=(const InterfaceBlock &other);
174 std::string mappedName;
175 std::string instanceName;
176 unsigned int arraySize;
177 BlockLayoutType layout;
178 bool isRowMajorLayout;
180 std::vector<InterfaceBlockField> fields;
185 #endif // _COMPILER_INTERFACE_VARIABLES_