3 * Copyright © 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
31 #define GLSL_TYPE_UINT 0
32 #define GLSL_TYPE_INT 1
33 #define GLSL_TYPE_FLOAT 2
34 #define GLSL_TYPE_BOOL 3
35 #define GLSL_TYPE_SAMPLER 4
36 #define GLSL_TYPE_STRUCT 5
37 #define GLSL_TYPE_ARRAY 6
38 #define GLSL_TYPE_FUNCTION 7
39 #define GLSL_TYPE_VOID 8
40 #define GLSL_TYPE_ERROR 9
42 enum glsl_sampler_dim
{
43 GLSL_SAMPLER_DIM_1D
= 0,
46 GLSL_SAMPLER_DIM_CUBE
,
47 GLSL_SAMPLER_DIM_RECT
,
55 unsigned sampler_dimensionality
:3;
56 unsigned sampler_shadow
:1;
57 unsigned sampler_array
:1;
58 unsigned sampler_type
:2; /**< Type of data returned using this sampler.
59 * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
60 * and \c GLSL_TYPE_UINT are valid.
63 unsigned vector_elements
:3; /**< 0, 2, 3, or 4 vector elements. */
64 unsigned matrix_columns
:3; /**< 0, 2, 3, or 4 matrix columns. */
67 * Name of the data type
69 * This may be \c NULL for anonymous structures, for arrays, or for
75 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
76 * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
77 * the number of values pointed to by \c fields.structure (below).
79 * For \c GLSL_TYPE_FUNCTION, it is the number of parameters to the
80 * function. The return value from a function is implicitly the first
81 * parameter. The types of the parameters are stored in
82 * \c fields.parameters (below).
87 * Subtype of composite data types.
90 const struct glsl_type
*array
; /**< Type of array elements. */
91 const struct glsl_type
*parameters
; /**< Parameters to function. */
92 const struct glsl_struct_field
*structure
;/**< List of struct fields. */
97 * \name Pointers to various public type singletons
100 static const glsl_type
*const error_type
;
101 static const glsl_type
*const int_type
;
102 static const glsl_type
*const uint_type
;
103 static const glsl_type
*const float_type
;
104 static const glsl_type
*const bool_type
;
108 glsl_type(unsigned base_type
, unsigned vector_elements
,
109 unsigned matrix_columns
, const char *name
) :
110 base_type(base_type
),
111 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
113 vector_elements(vector_elements
), matrix_columns(matrix_columns
),
117 memset(& fields
, 0, sizeof(fields
));
120 glsl_type(enum glsl_sampler_dim dim
, bool shadow
, bool array
,
121 unsigned type
, const char *name
) :
122 base_type(GLSL_TYPE_SAMPLER
),
123 sampler_dimensionality(dim
), sampler_shadow(shadow
),
124 sampler_array(array
), sampler_type(type
),
125 vector_elements(0), matrix_columns(0),
129 memset(& fields
, 0, sizeof(fields
));
132 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
134 base_type(GLSL_TYPE_STRUCT
),
135 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
137 vector_elements(0), matrix_columns(0),
141 this->fields
.structure
= fields
;
145 * For numeric and boolean derrived types returns the basic scalar type
147 * If the type is a numeric or boolean scalar, vector, or matrix type,
148 * this function gets the scalar type of the individual components. For
149 * all other types, including arrays of numeric or boolean types, the
150 * error type is returned.
152 const glsl_type
*get_base_type() const;
155 * Get the instance of a built-in scalar, vector, or matrix type
157 static const glsl_type
*get_instance(unsigned base_type
, unsigned rows
,
161 * Query the total number of scalars that make up a scalar, vector or matrix
163 unsigned components() const
165 return ((vector_elements
== 0) ? 1 : vector_elements
)
166 * ((matrix_columns
== 0) ? 1 : matrix_columns
);
171 * Query whether or not a type is a scalar (non-vector and non-matrix).
173 bool is_scalar() const
175 return (vector_elements
== 0)
176 && (base_type
>= GLSL_TYPE_UINT
)
177 && (base_type
<= GLSL_TYPE_BOOL
);
181 * Query whether or not a type is a vector
183 bool is_vector() const
185 return (vector_elements
> 0)
186 && (matrix_columns
== 0)
187 && (base_type
>= GLSL_TYPE_UINT
)
188 && (base_type
<= GLSL_TYPE_BOOL
);
192 * Query whether or not a type is a matrix
194 bool is_matrix() const
196 /* GLSL only has float matrices. */
197 return (matrix_columns
> 0) && (base_type
== GLSL_TYPE_FLOAT
);
201 * Query whether or not a type is a non-array numeric type
203 bool is_numeric() const
205 return (base_type
>= GLSL_TYPE_UINT
) && (base_type
<= GLSL_TYPE_FLOAT
);
209 * Query whether or not a type is an integral type
211 bool is_integer() const
213 return (base_type
== GLSL_TYPE_UINT
) || (base_type
== GLSL_TYPE_INT
);
217 * Query whether or not a type is a non-array boolean type
219 bool is_boolean() const
221 return base_type
== GLSL_TYPE_BOOL
;
225 * Query whether or not a type is a sampler
227 bool is_sampler() const
229 return base_type
== GLSL_TYPE_SAMPLER
;
233 * Query whether or not a type is the void type singleton.
237 return base_type
== GLSL_TYPE_VOID
;
241 * Query whether or not a type is the error type singleton.
243 bool is_error() const
245 return base_type
== GLSL_TYPE_ERROR
;
249 * Query the full type of a matrix row
252 * If the type is not a matrix, \c glsl_type::error_type is returned.
253 * Otherwise a type matching the rows of the matrix is returned.
255 const glsl_type
*row_type() const
258 ? get_instance(base_type
, matrix_columns
, 1)
263 * Query the full type of a matrix column
266 * If the type is not a matrix, \c glsl_type::error_type is returned.
267 * Otherwise a type matching the columns of the matrix is returned.
269 const glsl_type
*column_type() const
272 ? get_instance(base_type
, vector_elements
, 1)
278 * \name Pointers to various private type singletons
281 static const glsl_type
*const mat2_type
;
282 static const glsl_type
*const mat2x3_type
;
283 static const glsl_type
*const mat2x4_type
;
284 static const glsl_type
*const mat3x2_type
;
285 static const glsl_type
*const mat3_type
;
286 static const glsl_type
*const mat3x4_type
;
287 static const glsl_type
*const mat4x2_type
;
288 static const glsl_type
*const mat4x3_type
;
289 static const glsl_type
*const mat4_type
;
293 struct glsl_struct_field
{
294 const struct glsl_type
*type
;
298 struct _mesa_glsl_parse_state
;
305 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*state
);
308 _mesa_glsl_initialize_constructors(struct exec_list
*instructions
,
309 struct _mesa_glsl_parse_state
*state
);
315 #endif /* GLSL_TYPES_H */