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.
30 #define GLSL_TYPE_UINT 0
31 #define GLSL_TYPE_INT 1
32 #define GLSL_TYPE_FLOAT 2
33 #define GLSL_TYPE_BOOL 3
34 #define GLSL_TYPE_SAMPLER 4
35 #define GLSL_TYPE_STRUCT 5
36 #define GLSL_TYPE_ARRAY 6
37 #define GLSL_TYPE_FUNCTION 7
38 #define GLSL_TYPE_VOID 8
39 #define GLSL_TYPE_ERROR 9
41 #define is_numeric_base_type(b) \
42 (((b) >= GLSL_TYPE_UINT) && ((b) <= GLSL_TYPE_FLOAT))
44 #define is_integer_base_type(b) \
45 (((b) == GLSL_TYPE_UINT) || ((b) == GLSL_TYPE_INT))
47 #define is_error_type(t) ((t)->base_type == GLSL_TYPE_ERROR)
49 enum glsl_sampler_dim
{
50 GLSL_SAMPLER_DIM_1D
= 0,
53 GLSL_SAMPLER_DIM_CUBE
,
54 GLSL_SAMPLER_DIM_RECT
,
62 unsigned sampler_dimensionality
:3;
63 unsigned sampler_shadow
:1;
64 unsigned sampler_array
:1;
65 unsigned sampler_type
:2; /**< Type of data returned using this sampler.
66 * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
67 * and \c GLSL_TYPE_UINT are valid.
70 unsigned vector_elements
:3; /**< 0, 2, 3, or 4 vector elements. */
71 unsigned matrix_rows
:3; /**< 0, 2, 3, or 4 matrix rows. */
74 * Name of the data type
76 * This may be \c NULL for anonymous structures, for arrays, or for
82 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
83 * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
84 * the number of values pointed to by \c fields.structure (below).
86 * For \c GLSL_TYPE_FUNCTION, it is the number of parameters to the
87 * function. The return value from a function is implicitly the first
88 * parameter. The types of the parameters are stored in
89 * \c fields.parameters (below).
94 * Subtype of composite data types.
97 const struct glsl_type
*array
; /**< Type of array elements. */
98 const struct glsl_type
*parameters
; /**< Parameters to function. */
99 const struct glsl_struct_field
*structure
;/**< List of struct fields. */
103 glsl_type(unsigned base_type
, unsigned vector_elements
,
104 unsigned matrix_rows
, const char *name
) :
105 base_type(base_type
),
106 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
108 vector_elements(vector_elements
), matrix_rows(matrix_rows
),
112 memset(& fields
, 0, sizeof(fields
));
115 glsl_type(enum glsl_sampler_dim dim
, bool shadow
, bool array
,
116 unsigned type
, const char *name
) :
117 base_type(GLSL_TYPE_SAMPLER
),
118 sampler_dimensionality(dim
), sampler_shadow(shadow
),
119 sampler_array(array
), sampler_type(type
),
120 vector_elements(0), matrix_rows(0),
124 memset(& fields
, 0, sizeof(fields
));
127 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
129 base_type(GLSL_TYPE_STRUCT
),
130 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
132 vector_elements(0), matrix_rows(0),
136 this->fields
.structure
= fields
;
140 * Query whether or not a type is a scalar (non-vector and non-matrix).
142 bool is_scalar() const
144 return (vector_elements
== 0)
145 && (base_type
>= GLSL_TYPE_UINT
)
146 && (base_type
<= GLSL_TYPE_BOOL
);
150 * Query whether or not a type is a vector
152 bool is_vector() const
154 return (vector_elements
> 0)
155 && (matrix_rows
== 0)
156 && (base_type
>= GLSL_TYPE_UINT
)
157 && (base_type
<= GLSL_TYPE_BOOL
);
161 * Query whether or not a type is a matrix
163 bool is_matrix() const
165 /* GLSL only has float matrices. */
166 return (matrix_rows
> 0) && (base_type
== GLSL_TYPE_FLOAT
);
170 struct glsl_struct_field
{
171 const struct glsl_type
*type
;
175 struct _mesa_glsl_parse_state
;
182 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*state
);
184 extern const struct glsl_type
*
185 _mesa_glsl_get_vector_type(unsigned base_type
, unsigned vector_length
);
187 extern const struct glsl_type
*const glsl_error_type
;
188 extern const struct glsl_type
*const glsl_int_type
;
189 extern const struct glsl_type
*const glsl_uint_type
;
190 extern const struct glsl_type
*const glsl_float_type
;
191 extern const struct glsl_type
*const glsl_bool_type
;
197 #endif /* GLSL_TYPES_H */