2 * Copyright © 2010 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.
24 #include "glsl_parser_extras.h"
25 #include "glsl_symbol_table.h"
27 #include "builtin_variables.h"
30 #define Elements(x) (sizeof(x)/sizeof(*(x)))
34 add_builtin_variable(const builtin_variable
*proto
, exec_list
*instructions
,
35 glsl_symbol_table
*symtab
)
37 /* Create a new variable declaration from the description supplied by
40 const glsl_type
*const type
= symtab
->get_type(proto
->type
);
44 ir_variable
*var
= new ir_variable(type
, proto
->name
);
46 var
->mode
= proto
->mode
;
47 if (var
->mode
!= ir_var_out
)
48 var
->read_only
= true;
51 /* Once the variable is created an initialized, add it to the symbol table
52 * and add the declaration to the IR stream.
54 instructions
->push_tail(var
);
56 symtab
->add_variable(var
->name
, var
);
61 generate_110_vs_variables(exec_list
*instructions
,
62 glsl_symbol_table
*symtab
)
64 for (unsigned i
= 0; i
< Elements(builtin_core_vs_variables
); i
++) {
65 add_builtin_variable(& builtin_core_vs_variables
[i
],
66 instructions
, symtab
);
70 ; i
< Elements(builtin_110_deprecated_vs_variables
)
72 add_builtin_variable(& builtin_110_deprecated_vs_variables
[i
],
73 instructions
, symtab
);
76 /* FINISHME: Add support fo gl_TexCoord. The size of this array is
77 * FINISHME: implementation dependent based on the value of
78 * FINISHME: GL_MAX_TEXTURE_COORDS.
84 generate_120_vs_variables(exec_list
*instructions
,
85 glsl_symbol_table
*symtab
)
87 /* GLSL version 1.20 did not add any built-in variables in the vertex
90 generate_110_vs_variables(instructions
, symtab
);
95 generate_130_vs_variables(exec_list
*instructions
,
96 glsl_symbol_table
*symtab
)
98 generate_120_vs_variables(instructions
, symtab
);
100 for (unsigned i
= 0; i
< Elements(builtin_130_vs_variables
); i
++) {
101 add_builtin_variable(& builtin_130_vs_variables
[i
],
102 instructions
, symtab
);
105 /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
106 * FINISHME: implementation dependent based on the value of
107 * FINISHME: GL_MAX_CLIP_DISTANCES.
113 initialize_vs_variables(exec_list
*instructions
,
114 struct _mesa_glsl_parse_state
*state
)
117 switch (state
->language_version
) {
119 generate_110_vs_variables(instructions
, state
->symbols
);
122 generate_120_vs_variables(instructions
, state
->symbols
);
125 generate_130_vs_variables(instructions
, state
->symbols
);
132 _mesa_glsl_initialize_variables(exec_list
*instructions
,
133 struct _mesa_glsl_parse_state
*state
)
135 switch (state
->target
) {
137 initialize_vs_variables(instructions
, state
);
139 case geometry_shader
:
140 case fragment_shader
: