2010-02-22 21:19:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2009 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2010-03-31 22:37:42 +01:00
|
|
|
#include <cstdio>
|
2010-02-22 21:19:34 +00:00
|
|
|
#include <stdlib.h>
|
2010-03-19 18:57:24 +00:00
|
|
|
#include "glsl_symbol_table.h"
|
2010-02-22 21:19:34 +00:00
|
|
|
#include "glsl_parser_extras.h"
|
|
|
|
#include "glsl_types.h"
|
|
|
|
#include "builtin_types.h"
|
2010-06-25 01:08:53 +01:00
|
|
|
extern "C" {
|
2010-03-31 00:58:19 +01:00
|
|
|
#include "hash_table.h"
|
2010-06-25 01:08:53 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-03-31 00:58:19 +01:00
|
|
|
hash_table *glsl_type::array_types = NULL;
|
|
|
|
|
2010-06-28 19:09:40 +01:00
|
|
|
glsl_type::glsl_type(GLenum gl_type,
|
|
|
|
unsigned base_type, unsigned vector_elements,
|
|
|
|
unsigned matrix_columns, const char *name) :
|
|
|
|
gl_type(gl_type),
|
|
|
|
base_type(base_type),
|
|
|
|
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
|
|
|
|
sampler_type(0),
|
|
|
|
vector_elements(vector_elements), matrix_columns(matrix_columns),
|
|
|
|
name(name),
|
|
|
|
length(0)
|
|
|
|
{
|
|
|
|
/* Neither dimension is zero or both dimensions are zero.
|
|
|
|
*/
|
|
|
|
assert((vector_elements == 0) == (matrix_columns == 0));
|
|
|
|
memset(& fields, 0, sizeof(fields));
|
|
|
|
}
|
|
|
|
|
|
|
|
glsl_type::glsl_type(GLenum gl_type,
|
|
|
|
enum glsl_sampler_dim dim, bool shadow, bool array,
|
|
|
|
unsigned type, const char *name) :
|
|
|
|
gl_type(gl_type),
|
|
|
|
base_type(GLSL_TYPE_SAMPLER),
|
|
|
|
sampler_dimensionality(dim), sampler_shadow(shadow),
|
|
|
|
sampler_array(array), sampler_type(type),
|
|
|
|
vector_elements(0), matrix_columns(0),
|
|
|
|
name(name),
|
|
|
|
length(0)
|
|
|
|
{
|
|
|
|
memset(& fields, 0, sizeof(fields));
|
|
|
|
}
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
static void
|
2010-03-19 18:57:24 +00:00
|
|
|
add_types_to_symbol_table(glsl_symbol_table *symtab,
|
2010-02-22 21:19:34 +00:00
|
|
|
const struct glsl_type *types,
|
2010-04-08 01:13:44 +01:00
|
|
|
unsigned num_types, bool warn)
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-04-08 01:13:44 +01:00
|
|
|
(void) warn;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-04-08 01:13:44 +01:00
|
|
|
for (unsigned i = 0; i < num_types; i++) {
|
2010-03-19 18:57:24 +00:00
|
|
|
symtab->add_type(types[i].name, & types[i]);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
void
|
|
|
|
glsl_type::generate_110_types(glsl_symbol_table *symtab)
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
|
|
|
add_types_to_symbol_table(symtab, builtin_core_types,
|
2010-04-08 01:13:44 +01:00
|
|
|
Elements(builtin_core_types),
|
|
|
|
false);
|
2010-02-22 21:19:34 +00:00
|
|
|
add_types_to_symbol_table(symtab, builtin_structure_types,
|
2010-04-08 01:13:44 +01:00
|
|
|
Elements(builtin_structure_types),
|
|
|
|
false);
|
2010-02-22 21:19:34 +00:00
|
|
|
add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
|
2010-04-08 01:13:44 +01:00
|
|
|
Elements(builtin_110_deprecated_structure_types),
|
|
|
|
false);
|
|
|
|
add_types_to_symbol_table(symtab, & void_type, 1, false);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
void
|
|
|
|
glsl_type::generate_120_types(glsl_symbol_table *symtab)
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
|
|
|
generate_110_types(symtab);
|
|
|
|
|
|
|
|
add_types_to_symbol_table(symtab, builtin_120_types,
|
2010-04-08 01:13:44 +01:00
|
|
|
Elements(builtin_120_types), false);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
void
|
|
|
|
glsl_type::generate_130_types(glsl_symbol_table *symtab)
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
|
|
|
generate_120_types(symtab);
|
|
|
|
|
|
|
|
add_types_to_symbol_table(symtab, builtin_130_types,
|
2010-04-08 01:13:44 +01:00
|
|
|
Elements(builtin_130_types), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
void
|
|
|
|
glsl_type::generate_ARB_texture_rectangle_types(glsl_symbol_table *symtab,
|
|
|
|
bool warn)
|
2010-04-08 01:13:44 +01:00
|
|
|
{
|
|
|
|
add_types_to_symbol_table(symtab, builtin_ARB_texture_rectangle_types,
|
|
|
|
Elements(builtin_ARB_texture_rectangle_types),
|
|
|
|
warn);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-28 19:01:57 +01:00
|
|
|
void
|
|
|
|
glsl_type::generate_EXT_texture_array_types(glsl_symbol_table *symtab,
|
|
|
|
bool warn)
|
2010-06-09 00:17:17 +01:00
|
|
|
{
|
|
|
|
add_types_to_symbol_table(symtab, builtin_EXT_texture_array_types,
|
|
|
|
Elements(builtin_EXT_texture_array_types),
|
|
|
|
warn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
void
|
|
|
|
_mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
|
|
|
|
{
|
|
|
|
switch (state->language_version) {
|
|
|
|
case 110:
|
2010-06-28 19:01:57 +01:00
|
|
|
glsl_type::generate_110_types(state->symbols);
|
2010-02-22 21:19:34 +00:00
|
|
|
break;
|
|
|
|
case 120:
|
2010-06-28 19:01:57 +01:00
|
|
|
glsl_type::generate_120_types(state->symbols);
|
2010-02-22 21:19:34 +00:00
|
|
|
break;
|
|
|
|
case 130:
|
2010-06-28 19:01:57 +01:00
|
|
|
glsl_type::generate_130_types(state->symbols);
|
2010-02-22 21:19:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* error */
|
|
|
|
break;
|
|
|
|
}
|
2010-04-08 01:13:44 +01:00
|
|
|
|
|
|
|
if (state->ARB_texture_rectangle_enable) {
|
2010-06-28 19:01:57 +01:00
|
|
|
glsl_type::generate_ARB_texture_rectangle_types(state->symbols,
|
2010-04-08 01:13:44 +01:00
|
|
|
state->ARB_texture_rectangle_warn);
|
|
|
|
}
|
2010-06-09 00:17:17 +01:00
|
|
|
|
|
|
|
if (state->EXT_texture_array_enable && state->language_version < 130) {
|
|
|
|
// These are already included in 130; don't create twice.
|
2010-06-28 19:01:57 +01:00
|
|
|
glsl_type::generate_EXT_texture_array_types(state->symbols,
|
2010-06-09 00:17:17 +01:00
|
|
|
state->EXT_texture_array_warn);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 00:31:39 +00:00
|
|
|
const glsl_type *glsl_type::get_base_type() const
|
|
|
|
{
|
|
|
|
switch (base_type) {
|
|
|
|
case GLSL_TYPE_UINT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return uint_type;
|
2010-03-24 00:31:39 +00:00
|
|
|
case GLSL_TYPE_INT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return int_type;
|
2010-03-24 00:31:39 +00:00
|
|
|
case GLSL_TYPE_FLOAT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return float_type;
|
2010-03-24 00:31:39 +00:00
|
|
|
case GLSL_TYPE_BOOL:
|
2010-03-26 21:33:41 +00:00
|
|
|
return bool_type;
|
2010-03-24 00:31:39 +00:00
|
|
|
default:
|
2010-03-26 21:33:41 +00:00
|
|
|
return error_type;
|
2010-03-24 00:31:39 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-25 00:11:30 +00:00
|
|
|
|
|
|
|
|
2010-04-01 00:30:56 +01:00
|
|
|
ir_function *
|
2010-04-23 21:21:22 +01:00
|
|
|
glsl_type::generate_constructor(glsl_symbol_table *symtab) const
|
2010-04-01 00:30:56 +01:00
|
|
|
{
|
2010-06-24 02:11:51 +01:00
|
|
|
void *ctx = symtab;
|
|
|
|
|
2010-04-01 00:30:56 +01:00
|
|
|
/* Generate the function name and add it to the symbol table.
|
|
|
|
*/
|
2010-06-24 02:11:51 +01:00
|
|
|
ir_function *const f = new(ctx) ir_function(name);
|
2010-04-01 00:30:56 +01:00
|
|
|
|
|
|
|
bool added = symtab->add_function(name, f);
|
|
|
|
assert(added);
|
|
|
|
|
2010-06-24 02:11:51 +01:00
|
|
|
ir_function_signature *const sig = new(ctx) ir_function_signature(this);
|
2010-04-01 00:37:10 +01:00
|
|
|
f->add_signature(sig);
|
2010-04-01 00:30:56 +01:00
|
|
|
|
2010-04-23 21:21:22 +01:00
|
|
|
ir_variable **declarations =
|
|
|
|
(ir_variable **) malloc(sizeof(ir_variable *) * this->length);
|
2010-04-01 00:30:56 +01:00
|
|
|
for (unsigned i = 0; i < length; i++) {
|
|
|
|
char *const param_name = (char *) malloc(10);
|
|
|
|
|
|
|
|
snprintf(param_name, 10, "p%08X", i);
|
|
|
|
|
2010-04-21 20:13:48 +01:00
|
|
|
ir_variable *var = (this->base_type == GLSL_TYPE_ARRAY)
|
2010-06-24 02:11:51 +01:00
|
|
|
? new(ctx) ir_variable(fields.array, param_name)
|
|
|
|
: new(ctx) ir_variable(fields.structure[i].type, param_name);
|
2010-04-01 00:30:56 +01:00
|
|
|
|
|
|
|
var->mode = ir_var_in;
|
2010-04-23 21:21:22 +01:00
|
|
|
declarations[i] = var;
|
2010-04-01 00:30:56 +01:00
|
|
|
sig->parameters.push_tail(var);
|
|
|
|
}
|
|
|
|
|
2010-04-23 21:21:22 +01:00
|
|
|
/* Generate the body of the constructor. The body assigns each of the
|
|
|
|
* parameters to a portion of a local variable called __retval that has
|
|
|
|
* the same type as the constructor. After initializing __retval,
|
|
|
|
* __retval is returned.
|
|
|
|
*/
|
2010-06-24 02:11:51 +01:00
|
|
|
ir_variable *retval = new(ctx) ir_variable(this, "__retval");
|
2010-04-23 21:21:22 +01:00
|
|
|
sig->body.push_tail(retval);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < length; i++) {
|
|
|
|
ir_dereference *const lhs = (this->base_type == GLSL_TYPE_ARRAY)
|
2010-06-24 02:11:51 +01:00
|
|
|
? (ir_dereference *) new(ctx) ir_dereference_array(retval,
|
|
|
|
new(ctx) ir_constant(i))
|
|
|
|
: (ir_dereference *) new(ctx) ir_dereference_record(retval,
|
|
|
|
fields.structure[i].name);
|
2010-04-23 21:21:22 +01:00
|
|
|
|
2010-06-24 02:11:51 +01:00
|
|
|
ir_dereference *const rhs = new(ctx) ir_dereference_variable(declarations[i]);
|
|
|
|
ir_instruction *const assign = new(ctx) ir_assignment(lhs, rhs, NULL);
|
2010-04-23 21:21:22 +01:00
|
|
|
|
|
|
|
sig->body.push_tail(assign);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(declarations);
|
|
|
|
|
2010-06-24 02:11:51 +01:00
|
|
|
ir_dereference *const retref = new(ctx) ir_dereference_variable(retval);
|
|
|
|
ir_instruction *const inst = new(ctx) ir_return(retref);
|
2010-04-23 21:21:22 +01:00
|
|
|
sig->body.push_tail(inst);
|
|
|
|
|
2010-04-01 00:30:56 +01:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-19 01:52:59 +01:00
|
|
|
glsl_type::glsl_type(void *ctx, const glsl_type *array, unsigned length) :
|
2010-03-31 22:37:42 +01:00
|
|
|
base_type(GLSL_TYPE_ARRAY),
|
|
|
|
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
|
|
|
|
sampler_type(0),
|
|
|
|
vector_elements(0), matrix_columns(0),
|
|
|
|
name(NULL), length(length)
|
|
|
|
{
|
|
|
|
this->fields.array = array;
|
|
|
|
|
|
|
|
/* Allow a maximum of 10 characters for the array size. This is enough
|
|
|
|
* for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
|
|
|
|
* NUL.
|
|
|
|
*/
|
|
|
|
const unsigned name_length = strlen(array->name) + 10 + 3;
|
2010-06-19 01:52:59 +01:00
|
|
|
char *const n = (char *) talloc_size(ctx, name_length);
|
2010-03-31 22:37:42 +01:00
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
snprintf(n, name_length, "%s[]", array->name);
|
|
|
|
else
|
|
|
|
snprintf(n, name_length, "%s[%u]", array->name, length);
|
|
|
|
|
|
|
|
this->name = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-25 00:11:30 +00:00
|
|
|
const glsl_type *
|
|
|
|
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
|
|
|
|
{
|
2010-03-28 09:24:55 +01:00
|
|
|
if (base_type == GLSL_TYPE_VOID)
|
|
|
|
return &void_type;
|
|
|
|
|
2010-03-25 00:11:30 +00:00
|
|
|
if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
|
2010-03-26 21:33:41 +00:00
|
|
|
return error_type;
|
2010-03-25 00:11:30 +00:00
|
|
|
|
|
|
|
/* Treat GLSL vectors as Nx1 matrices.
|
|
|
|
*/
|
|
|
|
if (columns == 1) {
|
|
|
|
switch (base_type) {
|
|
|
|
case GLSL_TYPE_UINT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return uint_type + (rows - 1);
|
2010-03-25 00:11:30 +00:00
|
|
|
case GLSL_TYPE_INT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return int_type + (rows - 1);
|
2010-03-25 00:11:30 +00:00
|
|
|
case GLSL_TYPE_FLOAT:
|
2010-03-26 21:33:41 +00:00
|
|
|
return float_type + (rows - 1);
|
2010-03-25 00:11:30 +00:00
|
|
|
case GLSL_TYPE_BOOL:
|
2010-03-26 21:33:41 +00:00
|
|
|
return bool_type + (rows - 1);
|
2010-03-25 00:11:30 +00:00
|
|
|
default:
|
2010-03-26 21:33:41 +00:00
|
|
|
return error_type;
|
2010-03-25 00:11:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
|
2010-03-26 21:33:41 +00:00
|
|
|
return error_type;
|
2010-03-25 00:11:30 +00:00
|
|
|
|
|
|
|
/* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
|
|
|
|
* combinations are valid:
|
|
|
|
*
|
|
|
|
* 1 2 3 4
|
|
|
|
* 1
|
|
|
|
* 2 x x x
|
|
|
|
* 3 x x x
|
|
|
|
* 4 x x x
|
|
|
|
*/
|
|
|
|
#define IDX(c,r) (((c-1)*3) + (r-1))
|
|
|
|
|
|
|
|
switch (IDX(columns, rows)) {
|
|
|
|
case IDX(2,2): return mat2_type;
|
|
|
|
case IDX(2,3): return mat2x3_type;
|
|
|
|
case IDX(2,4): return mat2x4_type;
|
|
|
|
case IDX(3,2): return mat3x2_type;
|
|
|
|
case IDX(3,3): return mat3_type;
|
|
|
|
case IDX(3,4): return mat3x4_type;
|
|
|
|
case IDX(4,2): return mat4x2_type;
|
|
|
|
case IDX(4,3): return mat4x3_type;
|
|
|
|
case IDX(4,4): return mat4_type;
|
2010-03-26 21:33:41 +00:00
|
|
|
default: return error_type;
|
2010-03-25 00:11:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!"Should not get here.");
|
2010-03-26 21:33:41 +00:00
|
|
|
return error_type;
|
2010-03-25 00:11:30 +00:00
|
|
|
}
|
2010-03-31 00:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
glsl_type::array_key_compare(const void *a, const void *b)
|
|
|
|
{
|
2010-04-01 00:13:38 +01:00
|
|
|
const glsl_type *const key1 = (glsl_type *) a;
|
|
|
|
const glsl_type *const key2 = (glsl_type *) b;
|
2010-03-31 00:58:19 +01:00
|
|
|
|
2010-04-01 00:13:38 +01:00
|
|
|
/* Return zero is the types match (there is zero difference) or non-zero
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
return ((key1->fields.array == key2->fields.array)
|
|
|
|
&& (key1->length == key2->length)) ? 0 : 1;
|
2010-03-31 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
glsl_type::array_key_hash(const void *a)
|
|
|
|
{
|
2010-04-01 00:13:38 +01:00
|
|
|
const glsl_type *const key = (glsl_type *) a;
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
const glsl_type *t;
|
|
|
|
unsigned l;
|
|
|
|
char nul;
|
|
|
|
} hash_key = {
|
|
|
|
key->fields.array,
|
|
|
|
key->length,
|
|
|
|
'\0'
|
|
|
|
};
|
2010-03-31 00:58:19 +01:00
|
|
|
|
2010-04-01 00:13:38 +01:00
|
|
|
return hash_table_string_hash(& hash_key);
|
2010-03-31 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const glsl_type *
|
2010-06-19 01:52:59 +01:00
|
|
|
glsl_type::get_array_instance(void *ctx, const glsl_type *base,
|
|
|
|
unsigned array_size)
|
2010-03-31 00:58:19 +01:00
|
|
|
{
|
2010-06-19 01:52:59 +01:00
|
|
|
const glsl_type key(ctx, base, array_size);
|
2010-03-31 00:58:19 +01:00
|
|
|
|
|
|
|
if (array_types == NULL) {
|
|
|
|
array_types = hash_table_ctor(64, array_key_hash, array_key_compare);
|
|
|
|
}
|
|
|
|
|
|
|
|
const glsl_type *t = (glsl_type *) hash_table_find(array_types, & key);
|
|
|
|
if (t == NULL) {
|
2010-06-24 03:04:45 +01:00
|
|
|
t = new(ctx) glsl_type(ctx, base, array_size);
|
2010-03-31 00:58:19 +01:00
|
|
|
|
2010-04-01 00:13:38 +01:00
|
|
|
hash_table_insert(array_types, (void *) t, t);
|
2010-03-31 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(t->base_type == GLSL_TYPE_ARRAY);
|
|
|
|
assert(t->length == array_size);
|
|
|
|
assert(t->fields.array == base);
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
2010-04-19 23:40:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
const glsl_type *
|
|
|
|
glsl_type::field_type(const char *name) const
|
|
|
|
{
|
|
|
|
if (this->base_type != GLSL_TYPE_STRUCT)
|
|
|
|
return error_type;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < this->length; i++) {
|
|
|
|
if (strcmp(name, this->fields.structure[i].name) == 0)
|
|
|
|
return this->fields.structure[i].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error_type;
|
|
|
|
}
|
2010-06-10 01:27:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
glsl_type::field_index(const char *name) const
|
|
|
|
{
|
|
|
|
if (this->base_type != GLSL_TYPE_STRUCT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < this->length; i++) {
|
|
|
|
if (strcmp(name, this->fields.structure[i].name) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2010-06-22 00:05:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
glsl_type::component_slots() const
|
|
|
|
{
|
|
|
|
switch (this->base_type) {
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
return this->components();
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT: {
|
|
|
|
unsigned size = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < this->length; i++)
|
|
|
|
size += this->fields.structure[i].type->component_slots();
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
return this->length * this->fields.array->component_slots();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|