acd2d76d5a929307397a243fb8a3ae6018b3defb
[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 const glsl_type glsl_type::_error_type =
25 glsl_type(GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0, "");
26
27 const glsl_type glsl_type::_void_type =
28 glsl_type(GL_INVALID_ENUM, GLSL_TYPE_VOID, 0, 0, "void");
29
30 const glsl_type glsl_type::_sampler3D_type =
31 glsl_type(GL_SAMPLER_3D, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT,
32 "sampler3D");
33
34 const glsl_type glsl_type::_samplerCubeShadow_type =
35 glsl_type(GL_SAMPLER_CUBE_SHADOW,
36 GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT,
37 "samplerCubeShadow");
38
39 const glsl_type *const glsl_type::error_type = & glsl_type::_error_type;
40 const glsl_type *const glsl_type::void_type = & glsl_type::_void_type;
41
42 /** \name Core built-in types
43 *
44 * These types exist in all versions of GLSL.
45 */
46 /*@{*/
47
48 const glsl_type glsl_type::builtin_core_types[] = {
49 glsl_type(GL_BOOL, GLSL_TYPE_BOOL, 1, 1, "bool"),
50 glsl_type(GL_BOOL_VEC2, GLSL_TYPE_BOOL, 2, 1, "bvec2"),
51 glsl_type(GL_BOOL_VEC3, GLSL_TYPE_BOOL, 3, 1, "bvec3"),
52 glsl_type(GL_BOOL_VEC4, GLSL_TYPE_BOOL, 4, 1, "bvec4"),
53 glsl_type(GL_INT, GLSL_TYPE_INT, 1, 1, "int"),
54 glsl_type(GL_INT_VEC2, GLSL_TYPE_INT, 2, 1, "ivec2"),
55 glsl_type(GL_INT_VEC3, GLSL_TYPE_INT, 3, 1, "ivec3"),
56 glsl_type(GL_INT_VEC4, GLSL_TYPE_INT, 4, 1, "ivec4"),
57 glsl_type(GL_FLOAT, GLSL_TYPE_FLOAT, 1, 1, "float"),
58 glsl_type(GL_FLOAT_VEC2, GLSL_TYPE_FLOAT, 2, 1, "vec2"),
59 glsl_type(GL_FLOAT_VEC3, GLSL_TYPE_FLOAT, 3, 1, "vec3"),
60 glsl_type(GL_FLOAT_VEC4, GLSL_TYPE_FLOAT, 4, 1, "vec4"),
61 glsl_type(GL_FLOAT_MAT2, GLSL_TYPE_FLOAT, 2, 2, "mat2"),
62 glsl_type(GL_FLOAT_MAT3, GLSL_TYPE_FLOAT, 3, 3, "mat3"),
63 glsl_type(GL_FLOAT_MAT4, GLSL_TYPE_FLOAT, 4, 4, "mat4"),
64 glsl_type(GL_SAMPLER_2D, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT,
65 "sampler2D"),
66 glsl_type(GL_SAMPLER_CUBE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT,
67 "samplerCube"),
68 };
69
70 const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
71 const glsl_type *const glsl_type::bvec2_type = & builtin_core_types[1];
72 const glsl_type *const glsl_type::bvec3_type = & builtin_core_types[2];
73 const glsl_type *const glsl_type::bvec4_type = & builtin_core_types[3];
74 const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
75 const glsl_type *const glsl_type::ivec2_type = & builtin_core_types[5];
76 const glsl_type *const glsl_type::ivec3_type = & builtin_core_types[6];
77 const glsl_type *const glsl_type::ivec4_type = & builtin_core_types[7];
78 const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
79 const glsl_type *const glsl_type::vec2_type = & builtin_core_types[9];
80 const glsl_type *const glsl_type::vec3_type = & builtin_core_types[10];
81 const glsl_type *const glsl_type::vec4_type = & builtin_core_types[11];
82 const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
83 const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
84 const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
85 /*@}*/
86
87 /** \name GLSL structures that have not been deprecated.
88 */
89 /*@{*/
90
91 static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
92 { glsl_type::float_type, "near", false },
93 { glsl_type::float_type, "far", false },
94 { glsl_type::float_type, "diff", false },
95 };
96
97 const glsl_type glsl_type::builtin_structure_types[] = {
98 glsl_type(gl_DepthRangeParameters_fields,
99 Elements(gl_DepthRangeParameters_fields),
100 "gl_DepthRangeParameters"),
101 };
102 /*@}*/
103
104 /** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
105 */
106 /*@{*/
107
108 static const struct glsl_struct_field gl_PointParameters_fields[] = {
109 { glsl_type::float_type, "size", false },
110 { glsl_type::float_type, "sizeMin", false },
111 { glsl_type::float_type, "sizeMax", false },
112 { glsl_type::float_type, "fadeThresholdSize", false },
113 { glsl_type::float_type, "distanceConstantAttenuation", false },
114 { glsl_type::float_type, "distanceLinearAttenuation", false },
115 { glsl_type::float_type, "distanceQuadraticAttenuation", false },
116 };
117
118 static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
119 { glsl_type::vec4_type, "emission", false },
120 { glsl_type::vec4_type, "ambient", false },
121 { glsl_type::vec4_type, "diffuse", false },
122 { glsl_type::vec4_type, "specular", false },
123 { glsl_type::float_type, "shininess", false },
124 };
125
126 static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
127 { glsl_type::vec4_type, "ambient", false },
128 { glsl_type::vec4_type, "diffuse", false },
129 { glsl_type::vec4_type, "specular", false },
130 { glsl_type::vec4_type, "position", false },
131 { glsl_type::vec4_type, "halfVector", false },
132 { glsl_type::vec3_type, "spotDirection", false },
133 { glsl_type::float_type, "spotExponent", false },
134 { glsl_type::float_type, "spotCutoff", false },
135 { glsl_type::float_type, "spotCosCutoff", false },
136 { glsl_type::float_type, "constantAttenuation", false },
137 { glsl_type::float_type, "linearAttenuation", false },
138 { glsl_type::float_type, "quadraticAttenuation", false },
139 };
140
141 static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
142 { glsl_type::vec4_type, "ambient", false },
143 };
144
145 static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
146 { glsl_type::vec4_type, "sceneColor", false },
147 };
148
149 static const struct glsl_struct_field gl_LightProducts_fields[] = {
150 { glsl_type::vec4_type, "ambient", false },
151 { glsl_type::vec4_type, "diffuse", false },
152 { glsl_type::vec4_type, "specular", false },
153 };
154
155 static const struct glsl_struct_field gl_FogParameters_fields[] = {
156 { glsl_type::vec4_type, "color", false },
157 { glsl_type::float_type, "density", false },
158 { glsl_type::float_type, "start", false },
159 { glsl_type::float_type, "end", false },
160 { glsl_type::float_type, "scale", false },
161 };
162
163 const glsl_type glsl_type::builtin_110_deprecated_structure_types[] = {
164 glsl_type(gl_PointParameters_fields,
165 Elements(gl_PointParameters_fields),
166 "gl_PointParameters"),
167 glsl_type(gl_MaterialParameters_fields,
168 Elements(gl_MaterialParameters_fields),
169 "gl_MaterialParameters"),
170 glsl_type(gl_LightSourceParameters_fields,
171 Elements(gl_LightSourceParameters_fields),
172 "gl_LightSourceParameters"),
173 glsl_type(gl_LightModelParameters_fields,
174 Elements(gl_LightModelParameters_fields),
175 "gl_LightModelParameters"),
176 glsl_type(gl_LightModelProducts_fields,
177 Elements(gl_LightModelProducts_fields),
178 "gl_LightModelProducts"),
179 glsl_type(gl_LightProducts_fields,
180 Elements(gl_LightProducts_fields),
181 "gl_LightProducts"),
182 glsl_type(gl_FogParameters_fields,
183 Elements(gl_FogParameters_fields),
184 "gl_FogParameters"),
185 };
186 /*@}*/
187
188 /** \name Types in GLSL 1.10 (but not GLSL ES 1.00)
189 */
190 /*@{*/
191 const glsl_type glsl_type::builtin_110_types[] = {
192 glsl_type(GL_SAMPLER_1D, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT,
193 "sampler1D"),
194 glsl_type(GL_SAMPLER_1D_SHADOW, GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT,
195 "sampler1DShadow"),
196 glsl_type(GL_SAMPLER_2D_SHADOW, GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT,
197 "sampler2DShadow"),
198 };
199 /*@}*/
200
201 /** \name Types added in GLSL 1.20
202 */
203 /*@{*/
204
205 const glsl_type glsl_type::builtin_120_types[] = {
206 glsl_type(GL_FLOAT_MAT2x3, GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
207 glsl_type(GL_FLOAT_MAT2x4, GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
208 glsl_type(GL_FLOAT_MAT3x2, GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
209 glsl_type(GL_FLOAT_MAT3x4, GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
210 glsl_type(GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
211 glsl_type(GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
212 };
213 const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
214 const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
215 const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
216 const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
217 const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
218 const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
219 /*@}*/
220
221 /** \name Types added in GLSL 1.30
222 */
223 /*@{*/
224
225 const glsl_type glsl_type::builtin_130_types[] = {
226 glsl_type(GL_UNSIGNED_INT, GLSL_TYPE_UINT, 1, 1, "uint"),
227 glsl_type(GL_UNSIGNED_INT_VEC2, GLSL_TYPE_UINT, 2, 1, "uvec2"),
228 glsl_type(GL_UNSIGNED_INT_VEC3, GLSL_TYPE_UINT, 3, 1, "uvec3"),
229 glsl_type(GL_UNSIGNED_INT_VEC4, GLSL_TYPE_UINT, 4, 1, "uvec4"),
230
231 /* 1D and 2D texture arrays - several of these are included only in
232 * builtin_EXT_texture_array_types.
233 */
234 glsl_type(GL_INT_SAMPLER_1D_ARRAY,
235 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
236 glsl_type(GL_UNSIGNED_INT_SAMPLER_1D_ARRAY,
237 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
238 glsl_type(GL_INT_SAMPLER_2D_ARRAY,
239 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
240 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_ARRAY,
241 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
242
243 /* cube shadow samplers */
244 glsl_type(GL_SAMPLER_CUBE_SHADOW,
245 GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
246
247 /* signed and unsigned integer samplers */
248 glsl_type(GL_INT_SAMPLER_1D,
249 GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
250 glsl_type(GL_UNSIGNED_INT_SAMPLER_1D,
251 GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
252 glsl_type(GL_INT_SAMPLER_2D,
253 GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
254 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D,
255 GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
256 glsl_type(GL_INT_SAMPLER_3D,
257 GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
258 glsl_type(GL_UNSIGNED_INT_SAMPLER_3D,
259 GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
260 glsl_type(GL_INT_SAMPLER_CUBE,
261 GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
262 glsl_type(GL_INT_SAMPLER_CUBE,
263 GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
264 };
265
266 const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
267 const glsl_type *const glsl_type::uvec2_type = & builtin_130_types[1];
268 const glsl_type *const glsl_type::uvec3_type = & builtin_130_types[2];
269 const glsl_type *const glsl_type::uvec4_type = & builtin_130_types[3];
270 /*@}*/
271
272
273 /** \name Types added in GLSL 1.40
274 */
275 /*@{*/
276 const glsl_type glsl_type::builtin_140_types[] = {
277 glsl_type(GL_INT_SAMPLER_2D_RECT,
278 GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_INT, "isampler2DRect"),
279 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_RECT,
280 GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_UINT, "usampler2DRect"),
281 };
282 /*@}*/
283
284 /** \name Sampler types added by GL_ARB_texture_rectangle
285 */
286 /*@{*/
287
288 const glsl_type glsl_type::builtin_ARB_texture_rectangle_types[] = {
289 glsl_type(GL_SAMPLER_2D_RECT,
290 GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
291 glsl_type(GL_SAMPLER_2D_RECT_SHADOW,
292 GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
293 };
294 /*@}*/
295
296 /** \name Sampler types added by GL_EXT_texture_array
297 */
298 /*@{*/
299
300 const glsl_type glsl_type::builtin_EXT_texture_array_types[] = {
301 glsl_type(GL_SAMPLER_1D_ARRAY,
302 GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
303 glsl_type(GL_SAMPLER_2D_ARRAY,
304 GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
305 glsl_type(GL_SAMPLER_1D_ARRAY_SHADOW,
306 GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
307 glsl_type(GL_SAMPLER_2D_ARRAY_SHADOW,
308 GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
309 };
310 /*@}*/
311
312 /** \name Sampler types added by GL_EXT_texture_buffer_object
313 */
314 /*@{*/
315
316 const glsl_type glsl_type::builtin_EXT_texture_buffer_object_types[] = {
317 glsl_type(GL_SAMPLER_BUFFER,
318 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
319 glsl_type(GL_INT_SAMPLER_BUFFER,
320 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
321 glsl_type(GL_UNSIGNED_INT_SAMPLER_BUFFER,
322 GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
323 };
324 /*@}*/
325
326 /** \name Sampler types added by GL_OES_EGL_image_external
327 */
328 /*@{*/
329
330 const glsl_type glsl_type::builtin_OES_EGL_image_external_types[] = {
331 glsl_type(GL_SAMPLER_EXTERNAL_OES,
332 GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT, "samplerExternalOES"),
333 };
334 /*@}*/
335
336 /** \name Sampler types added by GL_ARB_texture_cube_map_array
337 */
338 /*@{*/
339 const glsl_type glsl_type::builtin_ARB_texture_cube_map_array_types[] = {
340 glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY,
341 GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_FLOAT, "samplerCubeArray"),
342 glsl_type(GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW,
343 GLSL_SAMPLER_DIM_CUBE, 1, 1, GLSL_TYPE_FLOAT, "samplerCubeArrayShadow"),
344 glsl_type(GL_INT_SAMPLER_CUBE_MAP_ARRAY,
345 GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_INT, "isamplerCubeArray"),
346 glsl_type(GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY,
347 GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT, "usamplerCubeArray"),
348 };
349 /*@}*/
350
351 /** \name Sampler types added by GL_ARB_texture_multisample
352 */
353 /*@{*/
354 const glsl_type glsl_type::builtin_ARB_texture_multisample_types[] = {
355 glsl_type(GL_SAMPLER_2D_MULTISAMPLE,
356 GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_FLOAT, "sampler2DMS"),
357 glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE,
358 GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_INT, "isampler2DMS"),
359 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE,
360 GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_UINT, "usampler2DMS"),
361 glsl_type(GL_SAMPLER_2D_MULTISAMPLE_ARRAY,
362 GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_FLOAT, "sampler2DMSArray"),
363 glsl_type(GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
364 GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_INT, "isampler2DMSArray"),
365 glsl_type(GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
366 GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_UINT, "usampler2DMSArray"),
367 };
368 /*@}*/