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 COMMON_SHADERVARIABLE_H_
11 #define COMMON_SHADERVARIABLE_H_
17 #include <GLES3/gl3.h>
18 #include <GLES2/gl2.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
45 unsigned int arraySize;
47 ShaderVariable(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn)
49 precision(precisionIn),
51 arraySize(arraySizeIn)
54 bool isArray() const { return arraySize > 0; }
55 unsigned int elementCount() const { return std::max(1u, arraySize); }
58 // Uniform registers (and element indices) are assigned when outputting shader code
59 struct Uniform : public ShaderVariable
61 unsigned int registerIndex;
62 unsigned int elementIndex; // Offset within a register, for struct members
63 std::vector<Uniform> fields;
65 Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
66 unsigned int registerIndexIn, unsigned int elementIndexIn)
67 : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
68 registerIndex(registerIndexIn),
69 elementIndex(elementIndexIn)
72 bool isStruct() const { return !fields.empty(); }
75 struct Attribute : public ShaderVariable
80 : ShaderVariable(GL_NONE, GL_NONE, "", 0),
84 Attribute(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, int locationIn)
85 : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
90 struct InterfaceBlockField : public ShaderVariable
92 bool isRowMajorMatrix;
93 std::vector<InterfaceBlockField> fields;
95 InterfaceBlockField(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, bool isRowMajorMatrix)
96 : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
97 isRowMajorMatrix(isRowMajorMatrix)
100 bool isStruct() const { return !fields.empty(); }
103 struct Varying : public ShaderVariable
105 InterpolationType interpolation;
106 std::vector<Varying> fields;
107 std::string structName;
109 Varying(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn, InterpolationType interpolationIn)
110 : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
111 interpolation(interpolationIn)
114 bool isStruct() const { return !fields.empty(); }
117 struct BlockMemberInfo
122 bool isRowMajorMatrix;
124 static BlockMemberInfo getDefaultBlockInfo()
126 return BlockMemberInfo(-1, -1, -1, false);
129 BlockMemberInfo(int offset, int arrayStride, int matrixStride, bool isRowMajorMatrix)
131 arrayStride(arrayStride),
132 matrixStride(matrixStride),
133 isRowMajorMatrix(isRowMajorMatrix)
137 typedef std::vector<BlockMemberInfo> BlockMemberInfoArray;
139 struct InterfaceBlock
142 unsigned int arraySize;
144 BlockLayoutType layout;
145 bool isRowMajorLayout;
146 std::vector<InterfaceBlockField> fields;
147 std::vector<BlockMemberInfo> blockInfo;
149 unsigned int registerIndex;
151 InterfaceBlock(const char *name, unsigned int arraySize, unsigned int registerIndex)
153 arraySize(arraySize),
154 layout(BLOCKLAYOUT_SHARED),
155 registerIndex(registerIndex),
156 isRowMajorLayout(false)
162 #endif // COMMON_SHADERVARIABLE_H_