Initial commit. lol
[mesa.git] / glsl_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 #pragma once
25 #ifndef GLSL_TYPES_H
26 #define GLSL_TYPES_H
27
28 #define GLSL_TYPE_UINT 0
29 #define GLSL_TYPE_INT 1
30 #define GLSL_TYPE_FLOAT 2
31 #define GLSL_TYPE_BOOL 3
32 #define GLSL_TYPE_SAMPLER 4
33 #define GLSL_TYPE_STRUCT 5
34 #define GLSL_TYPE_ARRAY 6
35 #define GLSL_TYPE_FUNCTION 7
36 #define GLSL_TYPE_VOID 8
37 #define GLSL_TYPE_ERROR 9
38
39 #define is_numeric_base_type(b) \
40 (((b) >= GLSL_TYPE_UINT) && ((b) <= GLSL_TYPE_FLOAT))
41
42 #define is_integer_base_type(b) \
43 (((b) == GLSL_TYPE_UINT) || ((b) == GLSL_TYPE_INT))
44
45 #define is_error_type(t) ((t)->base_type == GLSL_TYPE_ERROR)
46
47 #define GLSL_SAMPLER_DIM_1D 0
48 #define GLSL_SAMPLER_DIM_2D 1
49 #define GLSL_SAMPLER_DIM_3D 2
50 #define GLSL_SAMPLER_DIM_CUBE 3
51 #define GLSL_SAMPLER_DIM_RECT 4
52 #define GLSL_SAMPLER_DIM_BUF 5
53
54
55 struct glsl_type {
56 unsigned base_type:4;
57
58 unsigned sampler_dimensionality:3;
59 unsigned sampler_shadow:1;
60 unsigned sampler_array:1;
61 unsigned sampler_type:2; /**< Type of data returned using this sampler.
62 * only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
63 * and \c GLSL_TYPE_UINT are valid.
64 */
65
66 unsigned vector_elements:3; /**< 0, 2, 3, or 4 vector elements. */
67 unsigned matrix_rows:3; /**< 0, 2, 3, or 4 matrix rows. */
68
69 /**
70 * Name of the data type
71 *
72 * This may be \c NULL for anonymous structures, for arrays, or for
73 * function types.
74 */
75 const char *name;
76
77 /**
78 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
79 * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
80 * the number of values pointed to by \c fields.structure (below).
81 *
82 * For \c GLSL_TYPE_FUNCTION, it is the number of parameters to the
83 * function. The return value from a function is implicitly the first
84 * parameter. The types of the parameters are stored in
85 * \c fields.parameters (below).
86 */
87 unsigned length;
88
89 /**
90 * Subtype of composite data types.
91 */
92 union {
93 const struct glsl_type *array; /**< Type of array elements. */
94 const struct glsl_type *parameters; /**< Parameters to function. */
95 const struct glsl_struct_field *structure;/**< List of struct fields. */
96 } fields;
97 };
98
99 #define is_glsl_type_scalar(t) \
100 (((t)->vector_elements == 0) \
101 && ((t)->base_type >= GLSL_TYPE_UINT) \
102 && ((t)->base_type <= GLSL_TYPE_BOOL))
103
104 #define is_glsl_type_vector(t) \
105 (((t)->vector_elements > 0) \
106 && ((t)->matrix_rows == 0) \
107 && ((t)->base_type >= GLSL_TYPE_UINT) \
108 && ((t)->base_type <= GLSL_TYPE_BOOL))
109
110 #define is_glsl_type_matrix(t) \
111 (((t)->matrix_rows > 0) \
112 && ((t)->base_type == GLSL_TYPE_FLOAT)) /* GLSL only has float matrices. */
113
114 struct glsl_struct_field {
115 const struct glsl_type *type;
116 const char *name;
117 };
118
119 struct _mesa_glsl_parse_state;
120
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124
125 extern void
126 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
127
128 extern const struct glsl_type *
129 _mesa_glsl_get_vector_type(unsigned base_type, unsigned vector_length);
130
131 extern const struct glsl_type *const glsl_error_type;
132 extern const struct glsl_type *const glsl_int_type;
133 extern const struct glsl_type *const glsl_uint_type;
134 extern const struct glsl_type *const glsl_float_type;
135 extern const struct glsl_type *const glsl_bool_type;
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif /* GLSL_TYPES_H */