73910fd4af0f0a242a2ae68c5a8ec149360f7edf
[mesa.git] / 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 static const struct glsl_type _error_type =
29 glsl_type(GLSL_TYPE_ERROR, 0, 0, "");
30
31 static const struct glsl_type void_type =
32 glsl_type(GLSL_TYPE_VOID, 0, 0, "void");
33
34 const glsl_type *const glsl_type::error_type = & _error_type;
35
36 /** \name Core built-in types
37 *
38 * These types exist in all versions of GLSL.
39 */
40 /*@{*/
41
42 static const struct glsl_type builtin_core_types[] = {
43 glsl_type( GLSL_TYPE_BOOL, 1, 1, "bool"),
44 glsl_type( GLSL_TYPE_BOOL, 2, 1, "bvec2"),
45 glsl_type( GLSL_TYPE_BOOL, 3, 1, "bvec3"),
46 glsl_type( GLSL_TYPE_BOOL, 4, 1, "bvec4"),
47 glsl_type( GLSL_TYPE_INT, 1, 1, "int"),
48 glsl_type( GLSL_TYPE_INT, 2, 1, "ivec2"),
49 glsl_type( GLSL_TYPE_INT, 3, 1, "ivec3"),
50 glsl_type( GLSL_TYPE_INT, 4, 1, "ivec4"),
51 glsl_type( GLSL_TYPE_FLOAT, 1, 1, "float"),
52 glsl_type( GLSL_TYPE_FLOAT, 2, 1, "vec2"),
53 glsl_type( GLSL_TYPE_FLOAT, 3, 1, "vec3"),
54 glsl_type( GLSL_TYPE_FLOAT, 4, 1, "vec4"),
55 glsl_type( GLSL_TYPE_FLOAT, 2, 2, "mat2"),
56 glsl_type( GLSL_TYPE_FLOAT, 3, 3, "mat3"),
57 glsl_type( GLSL_TYPE_FLOAT, 4, 4, "mat4"),
58 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT, "sampler1D"),
59 glsl_type( GLSL_SAMPLER_DIM_1D, 1, 0, GLSL_TYPE_FLOAT, "sampler1DShadow"),
60 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT, "sampler2D"),
61 glsl_type( GLSL_SAMPLER_DIM_2D, 1, 0, GLSL_TYPE_FLOAT, "sampler2DShadow"),
62 glsl_type( GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT, "sampler3D"),
63 glsl_type(GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT, "samplerCube"),
64 };
65
66 const glsl_type *const glsl_type::bool_type = & builtin_core_types[0];
67 const glsl_type *const glsl_type::int_type = & builtin_core_types[4];
68 const glsl_type *const glsl_type::float_type = & builtin_core_types[8];
69 const glsl_type *const glsl_type::mat2_type = & builtin_core_types[12];
70 const glsl_type *const glsl_type::mat3_type = & builtin_core_types[13];
71 const glsl_type *const glsl_type::mat4_type = & builtin_core_types[14];
72 /*@}*/
73
74 /** \name GLSL structures that have not been deprecated.
75 */
76 /*@{*/
77
78 static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = {
79 { & builtin_core_types[ 8], "near" },
80 { & builtin_core_types[ 8], "far" },
81 { & builtin_core_types[ 8], "diff" },
82 };
83
84 static const struct glsl_type builtin_structure_types[] = {
85 glsl_type(gl_DepthRangeParameters_fields,
86 Elements(gl_DepthRangeParameters_fields),
87 "gl_DepthRangeParameters"),
88 };
89 /*@}*/
90
91 /** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
92 */
93 /*@{*/
94
95 static const struct glsl_struct_field gl_PointParameters_fields[] = {
96 { & builtin_core_types[ 8], "size" },
97 { & builtin_core_types[ 8], "sizeMin" },
98 { & builtin_core_types[ 8], "sizeMax" },
99 { & builtin_core_types[ 8], "fadeThresholdSize" },
100 { & builtin_core_types[ 8], "distanceConstantAttenuation" },
101 { & builtin_core_types[ 8], "distanceLinearAttenuation" },
102 { & builtin_core_types[ 8], "distanceQuadraticAttenuation" },
103 };
104
105 static const struct glsl_struct_field gl_MaterialParameters_fields[] = {
106 { & builtin_core_types[11], "emission" },
107 { & builtin_core_types[11], "ambient" },
108 { & builtin_core_types[11], "diffuse" },
109 { & builtin_core_types[11], "specular" },
110 { & builtin_core_types[ 8], "shininess" },
111 };
112
113 static const struct glsl_struct_field gl_LightSourceParameters_fields[] = {
114 { & builtin_core_types[11], "ambient" },
115 { & builtin_core_types[11], "diffuse" },
116 { & builtin_core_types[11], "specular" },
117 { & builtin_core_types[11], "position" },
118 { & builtin_core_types[11], "halfVector" },
119 { & builtin_core_types[10], "spotDirection" },
120 { & builtin_core_types[ 8], "spotExponent" },
121 { & builtin_core_types[ 8], "spotCutoff" },
122 { & builtin_core_types[ 8], "spotCosCutoff" },
123 { & builtin_core_types[ 8], "constantAttenuation" },
124 { & builtin_core_types[ 8], "linearAttenuation" },
125 { & builtin_core_types[ 8], "quadraticAttenuation" },
126 };
127
128 static const struct glsl_struct_field gl_LightModelParameters_fields[] = {
129 { & builtin_core_types[11], "ambient" },
130 };
131
132 static const struct glsl_struct_field gl_LightModelProducts_fields[] = {
133 { & builtin_core_types[11], "sceneColor" },
134 };
135
136 static const struct glsl_struct_field gl_LightProducts_fields[] = {
137 { & builtin_core_types[11], "ambient" },
138 { & builtin_core_types[11], "diffuse" },
139 { & builtin_core_types[11], "specular" },
140 };
141
142 static const struct glsl_struct_field gl_FogParameters_fields[] = {
143 { & builtin_core_types[11], "color" },
144 { & builtin_core_types[ 8], "density" },
145 { & builtin_core_types[ 8], "start" },
146 { & builtin_core_types[ 8], "end" },
147 { & builtin_core_types[ 8], "scale" },
148 };
149
150 static const struct glsl_type builtin_110_deprecated_structure_types[] = {
151 glsl_type(gl_PointParameters_fields,
152 Elements(gl_PointParameters_fields),
153 "gl_PointParameters"),
154 glsl_type(gl_MaterialParameters_fields,
155 Elements(gl_MaterialParameters_fields),
156 "gl_MaterialParameters"),
157 glsl_type(gl_LightSourceParameters_fields,
158 Elements(gl_LightSourceParameters_fields),
159 "gl_LightSourceParameters"),
160 glsl_type(gl_LightModelParameters_fields,
161 Elements(gl_LightModelParameters_fields),
162 "gl_LightModelParameters"),
163 glsl_type(gl_LightModelProducts_fields,
164 Elements(gl_LightModelProducts_fields),
165 "gl_LightModelProducts"),
166 glsl_type(gl_LightProducts_fields,
167 Elements(gl_LightProducts_fields),
168 "gl_LightProducts"),
169 glsl_type(gl_FogParameters_fields,
170 Elements(gl_FogParameters_fields),
171 "gl_FogParameters"),
172 };
173 /*@}*/
174
175 /** \name Types added in GLSL 1.20
176 */
177 /*@{*/
178
179 static const struct glsl_type builtin_120_types[] = {
180 glsl_type( GLSL_TYPE_FLOAT, 3, 2, "mat2x3"),
181 glsl_type( GLSL_TYPE_FLOAT, 4, 2, "mat2x4"),
182 glsl_type( GLSL_TYPE_FLOAT, 2, 3, "mat3x2"),
183 glsl_type( GLSL_TYPE_FLOAT, 4, 3, "mat3x4"),
184 glsl_type( GLSL_TYPE_FLOAT, 2, 4, "mat4x2"),
185 glsl_type( GLSL_TYPE_FLOAT, 3, 4, "mat4x3"),
186 };
187 const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];
188 const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];
189 const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];
190 const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];
191 const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];
192 const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];
193 /*@}*/
194
195 /** \name Types added in GLSL 1.30
196 */
197 /*@{*/
198
199 static const struct glsl_type builtin_130_types[] = {
200 glsl_type( GLSL_TYPE_UINT, 1, 1, "uint"),
201 glsl_type( GLSL_TYPE_UINT, 2, 1, "uvec2"),
202 glsl_type( GLSL_TYPE_UINT, 3, 1, "uvec3"),
203 glsl_type( GLSL_TYPE_UINT, 4, 1, "uvec4"),
204
205 /* 1D and 2D texture arrays */
206 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT, "sampler1DArray"),
207 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT, "isampler1DArray"),
208 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT, "usampler1DArray"),
209 glsl_type( GLSL_SAMPLER_DIM_1D, 1, 1, GLSL_TYPE_FLOAT, "sampler1DArrayShadow"),
210 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT, "sampler2DArray"),
211 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT, "isampler2DArray"),
212 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT, "usampler2DArray"),
213 glsl_type( GLSL_SAMPLER_DIM_2D, 1, 1, GLSL_TYPE_FLOAT, "sampler2DArrayShadow"),
214
215 /* cube shadow samplers */
216 glsl_type(GLSL_SAMPLER_DIM_CUBE, 1, 0, GLSL_TYPE_FLOAT, "samplerCubeShadow"),
217
218 /* signed and unsigned integer samplers */
219 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT, "isampler1D"),
220 glsl_type( GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT, "usampler1D"),
221 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT, "isampler2D"),
222 glsl_type( GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT, "usampler2D"),
223 glsl_type( GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT, "isampler3D"),
224 glsl_type( GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT, "usampler3D"),
225 glsl_type(GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT, "isamplerCube"),
226 glsl_type(GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT, "usamplerCube"),
227 };
228
229 const glsl_type *const glsl_type::uint_type = & builtin_130_types[0];
230 /*@}*/
231
232 /** \name Sampler types added by GL_ARB_texture_rectangle
233 */
234 /*@{*/
235
236 static const struct glsl_type builtin_ARB_texture_rectangle_types[] = {
237 glsl_type(GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT, "sampler2DRect"),
238 glsl_type(GLSL_SAMPLER_DIM_RECT, 1, 0, GLSL_TYPE_FLOAT, "sampler2DRectShadow"),
239 };
240 /*@}*/
241
242 /** \name Sampler types added by GL_EXT_texture_buffer_object
243 */
244 /*@{*/
245
246 static const struct glsl_type builtin_EXT_texture_buffer_object_types[] = {
247 glsl_type( GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT, "samplerBuffer"),
248 glsl_type( GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT, "isamplerBuffer"),
249 glsl_type( GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT, "usamplerBuffer"),
250 };
251 /*@}*/