Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / include / GLSLANG / ShaderVars.h
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
51     bool isArray() const { return arraySize > 0; }
52     unsigned int elementCount() const { return std::max(1u, arraySize); }
53     bool isStruct() const { return !fields.empty(); }
54
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
61     // variable.
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;
69
70     GLenum type;
71     GLenum precision;
72     std::string name;
73     std::string mappedName;
74     unsigned int arraySize;
75     bool staticUse;
76     std::vector<ShaderVariable> fields;
77     std::string structName;
78
79   protected:
80     bool isSameVariableAtLinkTime(const ShaderVariable &other,
81                                   bool matchPrecision) const;
82
83     bool operator==(const ShaderVariable &other) const;
84     bool operator!=(const ShaderVariable &other) const
85     {
86         return !operator==(other);
87     }
88 };
89
90 struct COMPILER_EXPORT Uniform : public ShaderVariable
91 {
92     Uniform();
93     ~Uniform();
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
98     {
99         return !operator==(other);
100     }
101
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;
106 };
107
108 struct COMPILER_EXPORT Attribute : public ShaderVariable
109 {
110     Attribute();
111     ~Attribute();
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
116     {
117         return !operator==(other);
118     }
119
120     int location;
121 };
122
123 struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable
124 {
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
131     {
132         return !operator==(other);
133     }
134
135     // Decide whether two InterfaceBlock fields are the same at shader
136     // link time, assuming one from vertex shader and the other from
137     // fragment shader.
138     // See GLSL ES Spec 3.00.3, sec 4.3.7.
139     bool isSameInterfaceBlockFieldAtLinkTime(
140         const InterfaceBlockField &other) const;
141
142     bool isRowMajorLayout;
143 };
144
145 struct COMPILER_EXPORT Varying : public ShaderVariable
146 {
147     Varying();
148     ~Varying();
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
153     {
154         return !operator==(other);
155     }
156
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;
161
162     InterpolationType interpolation;
163     bool isInvariant;
164 };
165
166 struct COMPILER_EXPORT InterfaceBlock
167 {
168     InterfaceBlock();
169     ~InterfaceBlock();
170     InterfaceBlock(const InterfaceBlock &other);
171     InterfaceBlock &operator=(const InterfaceBlock &other);
172
173     std::string name;
174     std::string mappedName;
175     std::string instanceName;
176     unsigned int arraySize;
177     BlockLayoutType layout;
178     bool isRowMajorLayout;
179     bool staticUse;
180     std::vector<InterfaceBlockField> fields;
181 };
182
183 }
184
185 #endif // _COMPILER_INTERFACE_VARIABLES_