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 #define is_numeric_base_type(b) \
43 (((b) >= GLSL_TYPE_UINT) && ((b) <= GLSL_TYPE_FLOAT))
45 #define is_integer_base_type(b) \
46 (((b) == GLSL_TYPE_UINT) || ((b) == GLSL_TYPE_INT))
48 #define is_error_type(t) ((t)->base_type == GLSL_TYPE_ERROR)
50 enum glsl_sampler_dim
{
51 GLSL_SAMPLER_DIM_1D
= 0,
54 GLSL_SAMPLER_DIM_CUBE
,
55 GLSL_SAMPLER_DIM_RECT
,
63 unsigned sampler_dimensionality
:3;
64 unsigned sampler_shadow
:1;
65 unsigned sampler_array
:1;
66 unsigned sampler_type
:2; /**< Type of data returned using this sampler.
67 * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
68 * and \c GLSL_TYPE_UINT are valid.
71 unsigned vector_elements
:3; /**< 0, 2, 3, or 4 vector elements. */
72 unsigned matrix_rows
:3; /**< 0, 2, 3, or 4 matrix rows. */
75 * Name of the data type
77 * This may be \c NULL for anonymous structures, for arrays, or for
83 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
84 * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
85 * the number of values pointed to by \c fields.structure (below).
87 * For \c GLSL_TYPE_FUNCTION, it is the number of parameters to the
88 * function. The return value from a function is implicitly the first
89 * parameter. The types of the parameters are stored in
90 * \c fields.parameters (below).
95 * Subtype of composite data types.
98 const struct glsl_type
*array
; /**< Type of array elements. */
99 const struct glsl_type
*parameters
; /**< Parameters to function. */
100 const struct glsl_struct_field
*structure
;/**< List of struct fields. */
104 glsl_type(unsigned base_type
, unsigned vector_elements
,
105 unsigned matrix_rows
, const char *name
) :
106 base_type(base_type
),
107 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
109 vector_elements(vector_elements
), matrix_rows(matrix_rows
),
113 memset(& fields
, 0, sizeof(fields
));
116 glsl_type(enum glsl_sampler_dim dim
, bool shadow
, bool array
,
117 unsigned type
, const char *name
) :
118 base_type(GLSL_TYPE_SAMPLER
),
119 sampler_dimensionality(dim
), sampler_shadow(shadow
),
120 sampler_array(array
), sampler_type(type
),
121 vector_elements(0), matrix_rows(0),
125 memset(& fields
, 0, sizeof(fields
));
128 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
130 base_type(GLSL_TYPE_STRUCT
),
131 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
133 vector_elements(0), matrix_rows(0),
137 this->fields
.structure
= fields
;
141 * Query whether or not a type is a scalar (non-vector and non-matrix).
143 bool is_scalar() const
145 return (vector_elements
== 0)
146 && (base_type
>= GLSL_TYPE_UINT
)
147 && (base_type
<= GLSL_TYPE_BOOL
);
151 * Query whether or not a type is a vector
153 bool is_vector() const
155 return (vector_elements
> 0)
156 && (matrix_rows
== 0)
157 && (base_type
>= GLSL_TYPE_UINT
)
158 && (base_type
<= GLSL_TYPE_BOOL
);
162 * Query whether or not a type is a matrix
164 bool is_matrix() const
166 /* GLSL only has float matrices. */
167 return (matrix_rows
> 0) && (base_type
== GLSL_TYPE_FLOAT
);
171 struct glsl_struct_field
{
172 const struct glsl_type
*type
;
176 struct _mesa_glsl_parse_state
;
183 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*state
);
185 extern const struct glsl_type
*
186 _mesa_glsl_get_vector_type(unsigned base_type
, unsigned vector_length
);
188 extern const struct glsl_type
*const glsl_error_type
;
189 extern const struct glsl_type
*const glsl_int_type
;
190 extern const struct glsl_type
*const glsl_uint_type
;
191 extern const struct glsl_type
*const glsl_float_type
;
192 extern const struct glsl_type
*const glsl_bool_type
;
198 #endif /* GLSL_TYPES_H */