2 * Copyright © 2009 Intel Corporation
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:
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
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.
25 #define Elements(x) (sizeof(x)/sizeof(*(x)))
28 static const struct glsl_type _error_type
=
29 glsl_type(GLSL_TYPE_ERROR
, 0, 0, "");
31 static const struct glsl_type void_type
=
32 glsl_type(GLSL_TYPE_VOID
, 0, 0, "void");
34 const glsl_type
*const glsl_type::error_type
= & _error_type
;
36 /** \name Core built-in types
38 * These types exist in all versions of GLSL.
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"),
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::ivec4_type
= & builtin_core_types
[7];
69 const glsl_type
*const glsl_type::float_type
= & builtin_core_types
[8];
70 const glsl_type
*const glsl_type::vec2_type
= & builtin_core_types
[9];
71 const glsl_type
*const glsl_type::vec3_type
= & builtin_core_types
[10];
72 const glsl_type
*const glsl_type::vec4_type
= & builtin_core_types
[11];
73 const glsl_type
*const glsl_type::mat2_type
= & builtin_core_types
[12];
74 const glsl_type
*const glsl_type::mat3_type
= & builtin_core_types
[13];
75 const glsl_type
*const glsl_type::mat4_type
= & builtin_core_types
[14];
78 /** \name GLSL structures that have not been deprecated.
82 static const struct glsl_struct_field gl_DepthRangeParameters_fields
[] = {
83 { glsl_type::float_type
, "near" },
84 { glsl_type::float_type
, "far" },
85 { glsl_type::float_type
, "diff" },
88 static const struct glsl_type builtin_structure_types
[] = {
89 glsl_type(gl_DepthRangeParameters_fields
,
90 Elements(gl_DepthRangeParameters_fields
),
91 "gl_DepthRangeParameters"),
95 /** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30
99 static const struct glsl_struct_field gl_PointParameters_fields
[] = {
100 { glsl_type::float_type
, "size" },
101 { glsl_type::float_type
, "sizeMin" },
102 { glsl_type::float_type
, "sizeMax" },
103 { glsl_type::float_type
, "fadeThresholdSize" },
104 { glsl_type::float_type
, "distanceConstantAttenuation" },
105 { glsl_type::float_type
, "distanceLinearAttenuation" },
106 { glsl_type::float_type
, "distanceQuadraticAttenuation" },
109 static const struct glsl_struct_field gl_MaterialParameters_fields
[] = {
110 { glsl_type::vec4_type
, "emission" },
111 { glsl_type::vec4_type
, "ambient" },
112 { glsl_type::vec4_type
, "diffuse" },
113 { glsl_type::vec4_type
, "specular" },
114 { glsl_type::float_type
, "shininess" },
117 static const struct glsl_struct_field gl_LightSourceParameters_fields
[] = {
118 { glsl_type::vec4_type
, "ambient" },
119 { glsl_type::vec4_type
, "diffuse" },
120 { glsl_type::vec4_type
, "specular" },
121 { glsl_type::vec4_type
, "position" },
122 { glsl_type::vec4_type
, "halfVector" },
123 { glsl_type::vec3_type
, "spotDirection" },
124 { glsl_type::float_type
, "spotExponent" },
125 { glsl_type::float_type
, "spotCutoff" },
126 { glsl_type::float_type
, "spotCosCutoff" },
127 { glsl_type::float_type
, "constantAttenuation" },
128 { glsl_type::float_type
, "linearAttenuation" },
129 { glsl_type::float_type
, "quadraticAttenuation" },
132 static const struct glsl_struct_field gl_LightModelParameters_fields
[] = {
133 { glsl_type::vec4_type
, "ambient" },
136 static const struct glsl_struct_field gl_LightModelProducts_fields
[] = {
137 { glsl_type::vec4_type
, "sceneColor" },
140 static const struct glsl_struct_field gl_LightProducts_fields
[] = {
141 { glsl_type::vec4_type
, "ambient" },
142 { glsl_type::vec4_type
, "diffuse" },
143 { glsl_type::vec4_type
, "specular" },
146 static const struct glsl_struct_field gl_FogParameters_fields
[] = {
147 { glsl_type::vec4_type
, "color" },
148 { glsl_type::float_type
, "density" },
149 { glsl_type::float_type
, "start" },
150 { glsl_type::float_type
, "end" },
151 { glsl_type::float_type
, "scale" },
154 static const struct glsl_type builtin_110_deprecated_structure_types
[] = {
155 glsl_type(gl_PointParameters_fields
,
156 Elements(gl_PointParameters_fields
),
157 "gl_PointParameters"),
158 glsl_type(gl_MaterialParameters_fields
,
159 Elements(gl_MaterialParameters_fields
),
160 "gl_MaterialParameters"),
161 glsl_type(gl_LightSourceParameters_fields
,
162 Elements(gl_LightSourceParameters_fields
),
163 "gl_LightSourceParameters"),
164 glsl_type(gl_LightModelParameters_fields
,
165 Elements(gl_LightModelParameters_fields
),
166 "gl_LightModelParameters"),
167 glsl_type(gl_LightModelProducts_fields
,
168 Elements(gl_LightModelProducts_fields
),
169 "gl_LightModelProducts"),
170 glsl_type(gl_LightProducts_fields
,
171 Elements(gl_LightProducts_fields
),
173 glsl_type(gl_FogParameters_fields
,
174 Elements(gl_FogParameters_fields
),
179 /** \name Types added in GLSL 1.20
183 static const struct glsl_type builtin_120_types
[] = {
184 glsl_type( GLSL_TYPE_FLOAT
, 3, 2, "mat2x3"),
185 glsl_type( GLSL_TYPE_FLOAT
, 4, 2, "mat2x4"),
186 glsl_type( GLSL_TYPE_FLOAT
, 2, 3, "mat3x2"),
187 glsl_type( GLSL_TYPE_FLOAT
, 4, 3, "mat3x4"),
188 glsl_type( GLSL_TYPE_FLOAT
, 2, 4, "mat4x2"),
189 glsl_type( GLSL_TYPE_FLOAT
, 3, 4, "mat4x3"),
191 const glsl_type
*const glsl_type::mat2x3_type
= & builtin_120_types
[0];
192 const glsl_type
*const glsl_type::mat2x4_type
= & builtin_120_types
[1];
193 const glsl_type
*const glsl_type::mat3x2_type
= & builtin_120_types
[2];
194 const glsl_type
*const glsl_type::mat3x4_type
= & builtin_120_types
[3];
195 const glsl_type
*const glsl_type::mat4x2_type
= & builtin_120_types
[4];
196 const glsl_type
*const glsl_type::mat4x3_type
= & builtin_120_types
[5];
199 /** \name Types added in GLSL 1.30
203 static const struct glsl_type builtin_130_types
[] = {
204 glsl_type( GLSL_TYPE_UINT
, 1, 1, "uint"),
205 glsl_type( GLSL_TYPE_UINT
, 2, 1, "uvec2"),
206 glsl_type( GLSL_TYPE_UINT
, 3, 1, "uvec3"),
207 glsl_type( GLSL_TYPE_UINT
, 4, 1, "uvec4"),
209 /* 1D and 2D texture arrays */
210 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 1, GLSL_TYPE_FLOAT
, "sampler1DArray"),
211 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 1, GLSL_TYPE_INT
, "isampler1DArray"),
212 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 1, GLSL_TYPE_UINT
, "usampler1DArray"),
213 glsl_type( GLSL_SAMPLER_DIM_1D
, 1, 1, GLSL_TYPE_FLOAT
, "sampler1DArrayShadow"),
214 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 1, GLSL_TYPE_FLOAT
, "sampler2DArray"),
215 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 1, GLSL_TYPE_INT
, "isampler2DArray"),
216 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 1, GLSL_TYPE_UINT
, "usampler2DArray"),
217 glsl_type( GLSL_SAMPLER_DIM_2D
, 1, 1, GLSL_TYPE_FLOAT
, "sampler2DArrayShadow"),
219 /* cube shadow samplers */
220 glsl_type(GLSL_SAMPLER_DIM_CUBE
, 1, 0, GLSL_TYPE_FLOAT
, "samplerCubeShadow"),
222 /* signed and unsigned integer samplers */
223 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 0, GLSL_TYPE_INT
, "isampler1D"),
224 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 0, GLSL_TYPE_UINT
, "usampler1D"),
225 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 0, GLSL_TYPE_INT
, "isampler2D"),
226 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 0, GLSL_TYPE_UINT
, "usampler2D"),
227 glsl_type( GLSL_SAMPLER_DIM_3D
, 0, 0, GLSL_TYPE_INT
, "isampler3D"),
228 glsl_type( GLSL_SAMPLER_DIM_3D
, 0, 0, GLSL_TYPE_UINT
, "usampler3D"),
229 glsl_type(GLSL_SAMPLER_DIM_CUBE
, 0, 0, GLSL_TYPE_INT
, "isamplerCube"),
230 glsl_type(GLSL_SAMPLER_DIM_CUBE
, 0, 0, GLSL_TYPE_UINT
, "usamplerCube"),
233 const glsl_type
*const glsl_type::uint_type
= & builtin_130_types
[0];
234 const glsl_type
*const glsl_type::uvec4_type
= & builtin_130_types
[3];
237 /** \name Sampler types added by GL_ARB_texture_rectangle
241 static const struct glsl_type builtin_ARB_texture_rectangle_types
[] = {
242 glsl_type(GLSL_SAMPLER_DIM_RECT
, 0, 0, GLSL_TYPE_FLOAT
, "sampler2DRect"),
243 glsl_type(GLSL_SAMPLER_DIM_RECT
, 1, 0, GLSL_TYPE_FLOAT
, "sampler2DRectShadow"),
247 /** \name Sampler types added by GL_EXT_texture_array
251 static const struct glsl_type builtin_EXT_texture_array_types
[] = {
252 glsl_type( GLSL_SAMPLER_DIM_1D
, 0, 1, GLSL_TYPE_FLOAT
, "sampler1DArray"),
253 glsl_type( GLSL_SAMPLER_DIM_2D
, 0, 1, GLSL_TYPE_FLOAT
, "sampler2DArray"),
254 glsl_type( GLSL_SAMPLER_DIM_1D
, 1, 1, GLSL_TYPE_FLOAT
, "sampler1DArrayShadow"),
255 glsl_type( GLSL_SAMPLER_DIM_2D
, 1, 1, GLSL_TYPE_FLOAT
, "sampler2DArrayShadow"),
259 /** \name Sampler types added by GL_EXT_texture_buffer_object
263 static const struct glsl_type builtin_EXT_texture_buffer_object_types
[] = {
264 glsl_type( GLSL_SAMPLER_DIM_BUF
, 0, 0, GLSL_TYPE_FLOAT
, "samplerBuffer"),
265 glsl_type( GLSL_SAMPLER_DIM_BUF
, 0, 0, GLSL_TYPE_INT
, "isamplerBuffer"),
266 glsl_type( GLSL_SAMPLER_DIM_BUF
, 0, 0, GLSL_TYPE_UINT
, "usamplerBuffer"),