glsl_type: Make all static objects be class private
[mesa.git] / src / glsl / builtin_types.h
1 /*
2 * Copyright © 2009 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef Elements
25 #define Elements(x) (sizeof(x)/sizeof(*(x)))
26 #endif
27
28 const glsl_type glsl_type::_error_type =
29 glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
30
31 const glsl_type glsl_type::void_type =
32 glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
33
34 const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
35
36 /** \name Core built-in types
37 *
38 * These types exist in all versions of GLSL.
39 */
40 /*@{*/
41
42 const glsl_type glsl_type::builtin_core_types[] = {
43 glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"),
44 glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"),
45 glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"),
46 glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"),
47 glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"),
48 glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"),
49 glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"),
50 glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"),
51 glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"),
52 glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"),
53 glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"),
54 glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"),
55 glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"),
56 glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"),
57 glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"),
58 glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
59 "sampler1D"),
60 glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
61 "sampler1DShadow"),
62 glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
63 "sampler2D"),
64 glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
65 "sampler2DShadow"),
66 glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
67 "sampler3D"),
68 glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
69 "samplerCube"),
70 };
71
72 const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
73 const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
74 const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
75 const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
76 const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
77 const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
78 const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
79 const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
80 const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
81 const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
82 /*@}*/
83
84 /** \name GLSL structures that have not been deprecated.
85 */
86 /*@{*/
87
88 static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
89 { glsl_type::float_type, "near" },
90 { glsl_type::float_type, "far" },
91 { glsl_type::float_type, "diff" },
92 };
93
94 const glsl_type glsl_type::builtin_structure_types[] = {
95 glsl_type(gl_DepthRangeParameters_fields,
96 Elements(gl_DepthRangeParameters_fields),
97 "gl_DepthRangeParameters"),
98 };
99 /*@}*/
100
101 /** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
102 */
103 /*@{*/
104
105 static const struct glsl_struct_field gl_PointParameters_fields[] = {
106 { glsl_type::float_type, "size" },
107 { glsl_type::float_type, "sizeMin" },
108 { glsl_type::float_type, "sizeMax" },
109 { glsl_type::float_type, "fadeThresholdSize" },
110 { glsl_type::float_type, "distanceConstantAttenuation" },
111 { glsl_type::float_type, "distanceLinearAttenuation" },
112 { glsl_type::float_type, "distanceQuadraticAttenuation" },
113 };
114
115 static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
116 { glsl_type::vec4_type, "emission" },
117 { glsl_type::vec4_type, "ambient" },
118 { glsl_type::vec4_type, "diffuse" },
119 { glsl_type::vec4_type, "specular" },
120 { glsl_type::float_type, "shininess" },
121 };
122
123 static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
124 { glsl_type::vec4_type, "ambient" },
125 { glsl_type::vec4_type, "diffuse" },
126 { glsl_type::vec4_type, "specular" },
127 { glsl_type::vec4_type, "position" },
128 { glsl_type::vec4_type, "halfVector" },
129 { glsl_type::vec3_type, "spotDirection" },
130 { glsl_type::float_type, "spotExponent" },
131 { glsl_type::float_type, "spotCutoff" },
132 { glsl_type::float_type, "spotCosCutoff" },
133 { glsl_type::float_type, "constantAttenuation" },
134 { glsl_type::float_type, "linearAttenuation" },
135 { glsl_type::float_type, "quadraticAttenuation" },
136 };
137
138 static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
139 { glsl_type::vec4_type, "ambient" },
140 };
141
142 static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
143 { glsl_type::vec4_type, "sceneColor" },
144 };
145
146 static const struct glsl_struct_field gl_LightProducts_fields[] = {
147 { glsl_type::vec4_type, "ambient" },
148 { glsl_type::vec4_type, "diffuse" },
149 { glsl_type::vec4_type, "specular" },
150 };
151
152 static const struct glsl_struct_field gl_FogParameters_fields[] = {
153 { glsl_type::vec4_type, "color" },
154 { glsl_type::float_type, "density" },
155 { glsl_type::float_type, "start" },
156 { glsl_type::float_type, "end" },
157 { glsl_type::float_type, "scale" },
158 };
159
160 const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
161 glsl_type(gl_PointParameters_fields,
162 Elements(gl_PointParameters_fields),
163 "gl_PointParameters"),
164 glsl_type(gl_MaterialParameters_fields,
165 Elements(gl_MaterialParameters_fields),
166 "gl_MaterialParameters"),
167 glsl_type(gl_LightSourceParameters_fields,
168 Elements(gl_LightSourceParameters_fields),
169 "gl_LightSourceParameters"),
170 glsl_type(gl_LightModelParameters_fields,
171 Elements(gl_LightModelParameters_fields),
172 "gl_LightModelParameters"),
173 glsl_type(gl_LightModelProducts_fields,
174 Elements(gl_LightModelProducts_fields),
175 "gl_LightModelProducts"),
176 glsl_type(gl_LightProducts_fields,
177 Elements(gl_LightProducts_fields),
178 "gl_LightProducts"),
179 glsl_type(gl_FogParameters_fields,
180 Elements(gl_FogParameters_fields),
181 "gl_FogParameters"),
182 };
183 /*@}*/
184
185 /** \name Types added in GLSL 1.20
186 */
187 /*@{*/
188
189 const glsl_type glsl_type::builtin_120_types[] = {
190 glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
191 glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
192 glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
193 glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
194 glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
195 glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
196 };
197 const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
198 const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
199 const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
200 const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
201 const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
202 const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
203 /*@}*/
204
205 /** \name Types added in GLSL 1.30
206 */
207 /*@{*/
208
209 const glsl_type glsl_type::builtin_130_types[] = {
210 glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"),
211 glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
212 glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
213 glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
214
215 /* 1D and 2D texture arrays */
216 glsl_type(GL_SAMPLER_1D_ARRAY,
217 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
218 glsl_type(GL_INT_SAMPLER_1D_ARRAY,
219 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
220 glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
221 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
222 glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
223 GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
224 glsl_type(GL_SAMPLER_2D_ARRAY,
225 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
226 glsl_type(GL_INT_SAMPLER_2D_ARRAY,
227 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
228 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
229 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
230 glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
231 GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
232
233 /* cube shadow samplers */
234 glsl_type(GL_SAMPLER_CUBE_SHADOW,
235 GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
236
237 /* signed and unsigned integer samplers */
238 glsl_type(GL_INT_SAMPLER_1D,
239 GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
240 glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
241 GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
242 glsl_type(GL_INT_SAMPLER_2D,
243 GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
244 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
245 GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
246 glsl_type(GL_INT_SAMPLER_3D,
247 GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
248 glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
249 GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
250 glsl_type(GL_INT_SAMPLER_CUBE,
251 GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
252 glsl_type(GL_INT_SAMPLER_CUBE,
253 GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
254 };
255
256 const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
257 const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
258 /*@}*/
259
260 /** \name Sampler types added by GL_ARB_texture_rectangle
261 */
262 /*@{*/
263
264 const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
265 glsl_type(GL_SAMPLER_2D_RECT,
266 GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
267 glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
268 GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
269 };
270 /*@}*/
271
272 /** \name Sampler types added by GL_EXT_texture_array
273 */
274 /*@{*/
275
276 const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
277 glsl_type(GL_SAMPLER_1D_ARRAY,
278 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
279 glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
280 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
281 glsl_type(GL_SAMPLER_2D_ARRAY,
282 GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
283 glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
284 GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
285 };
286 /*@}*/
287
288 /** \name Sampler types added by GL_EXT_texture_buffer_object
289 */
290 /*@{*/
291
292 const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
293 glsl_type(GL_SAMPLER_BUFFER,
294 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
295 glsl_type(GL_INT_SAMPLER_BUFFER,
296 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
297 glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
298 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
299 };
300 /*@}*/