diff options
author | Michal Krol <[email protected]> | 2006-02-18 15:11:18 +0000 |
---|---|---|
committer | Michal Krol <[email protected]> | 2006-02-18 15:11:18 +0000 |
commit | 3654193a4d417560c90b4bbe47d8070919cdc348 (patch) | |
tree | 9c984f7fe482f9af08575d6b3338cd4128e5455c /src/mesa/shader/slang/slang_storage.c | |
parent | e94be8d5c0b28c4eecf8492cb07ae9dff9026ada (diff) |
More GLSL code.
- general constructors allowed;
- implement noise functions (from Stefan Gustavson - thanks!)
- cosmetic stuff.
Diffstat (limited to 'src/mesa/shader/slang/slang_storage.c')
-rw-r--r-- | src/mesa/shader/slang/slang_storage.c | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c index a2d1ab9314b..2654ee0404b 100644 --- a/src/mesa/shader/slang/slang_storage.c +++ b/src/mesa/shader/slang/slang_storage.c @@ -36,15 +36,15 @@ /* slang_storage_array */ -int slang_storage_array_construct (slang_storage_array *arr) +GLboolean slang_storage_array_construct (slang_storage_array *arr) { arr->type = slang_stor_aggregate; arr->aggregate = NULL; arr->length = 0;
- return 1; + return GL_TRUE; } -void slang_storage_array_destruct (slang_storage_array *arr) +GLvoid slang_storage_array_destruct (slang_storage_array *arr) { if (arr->aggregate != NULL) { @@ -55,16 +55,16 @@ void slang_storage_array_destruct (slang_storage_array *arr) /* slang_storage_aggregate */ -int slang_storage_aggregate_construct (slang_storage_aggregate *agg) +GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *agg) { agg->arrays = NULL; agg->count = 0;
- return 1; + return GL_TRUE; } -void slang_storage_aggregate_destruct (slang_storage_aggregate *agg) +GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *agg) { - unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++) slang_storage_array_destruct (agg->arrays + i); @@ -73,7 +73,8 @@ void slang_storage_aggregate_destruct (slang_storage_aggregate *agg) static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggregate *agg) { - slang_storage_array *arr = NULL; + slang_storage_array *arr = NULL;
+ agg->arrays = (slang_storage_array *) slang_alloc_realloc (agg->arrays, agg->count * sizeof ( slang_storage_array), (agg->count + 1) * sizeof (slang_storage_array)); if (agg->arrays != NULL) @@ -88,88 +89,91 @@ static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggr /* _slang_aggregate_variable() */ -static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type, - unsigned int row_count) +static GLboolean aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type, + GLuint row_count) { slang_storage_array *arr = slang_storage_aggregate_push_new (agg); if (arr == NULL) - return 0; + return GL_FALSE; arr->type = basic_type; arr->length = row_count; - return 1; + return GL_TRUE; } -static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type, - unsigned int dimension) +static GLboolean aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type, + GLuint dimension) { slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL) - return 0; + return GL_FALSE; arr->type = slang_stor_aggregate; arr->length = dimension; - arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof ( - slang_storage_aggregate)); + arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate)); if (arr->aggregate == NULL) - return 0; + return GL_FALSE; if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
- return 0;
+ return GL_FALSE;
} if (!aggregate_vector (arr->aggregate, basic_type, dimension)) - return 0; - return 1; + return GL_FALSE; + return GL_TRUE; } -static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars, +static GLboolean aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars, slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals,
slang_machine *mach, slang_assembly_file *file, slang_atom_pool *atoms) { - unsigned int i; + GLuint i;
+ for (i = 0; i < vars->num_variables; i++) if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier, vars->variables[i].array_size, funcs, structs, globals, mach, file, atoms)) - return 0; - return 1; + return GL_FALSE; + return GL_TRUE; } -static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
+static GLboolean eval_array_size (slang_assembly_file *file, slang_machine *pmach,
slang_assembly_name_space *space, slang_operation *array_size, GLuint *plength,
slang_atom_pool *atoms)
{
slang_assembly_file_restore_point point;
- slang_assembly_local_info info;
- slang_assembly_flow_control flow;
- slang_assembly_stack_info stk;
slang_machine mach;
+ slang_assemble_ctx A;
+
+ A.file = file;
+ A.mach = pmach;
+ A.atoms = atoms;
+ A.space = *space;
+ A.local.ret_size = 0;
+ A.local.addr_tmp = 0;
+ A.local.swizzle_tmp = 4;
/* save the current assembly */
if (!slang_assembly_file_restore_point_save (file, &point))
- return 0;
+ return GL_FALSE;
/* setup the machine */
mach = *pmach;
mach.ip = file->count;
/* allocate local storage for expression */
- info.ret_size = 0;
- info.addr_tmp = 0;
- info.swizzle_tmp = 4;
if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, 20))
- return 0;
+ return GL_FALSE;
if (!slang_assembly_file_push_label (file, slang_asm_enter, 20))
- return 0;
+ return GL_FALSE;
/* insert the actual expression */
- if (!_slang_assemble_operation (file, array_size, 0, &flow, space, &info, &stk, pmach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (&A, array_size, slang_ref_forbid))
+ return GL_FALSE;
if (!slang_assembly_file_push (file, slang_asm_exit))
- return 0;
+ return GL_FALSE;
/* execute the expression */
if (!_slang_execute2 (file, &mach))
- return 0;
+ return GL_FALSE;
/* the evaluated expression is on top of the stack */
*plength = (GLuint) mach.mem[mach.sp + SLANG_MACHINE_GLOBAL_SIZE]._float;
@@ -177,11 +181,12 @@ static int eval_array_size (slang_assembly_file *file, slang_machine *pmach, /* restore the old assembly */
if (!slang_assembly_file_restore_point_load (file, &point))
- return 0;
- return 1;
+ return GL_FALSE;
+
+ return GL_TRUE;
}
-int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec, +GLboolean _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec, slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *vars, slang_machine *mach, slang_assembly_file *file,
slang_atom_pool *atoms) @@ -235,42 +240,41 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie arr = slang_storage_aggregate_push_new (agg); if (arr == NULL) - return 0; + return GL_FALSE; arr->type = slang_stor_aggregate; - arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof ( - slang_storage_aggregate)); + arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate)); if (arr->aggregate == NULL) - return 0; + return GL_FALSE; if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
- return 0;
+ return GL_FALSE;
} if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs,
vars, mach, file, atoms)) - return 0;
+ return GL_FALSE;
space.funcs = funcs;
space.structs = structs;
space.vars = vars;
if (!eval_array_size (file, mach, &space, array_size, &arr->length, atoms))
- return 0; + return GL_FALSE; } - return 1; + return GL_TRUE; default: - return 0; + return GL_FALSE; } } /* _slang_sizeof_aggregate() */ -unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg) +GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *agg) { - unsigned int i, size = 0;
+ GLuint i, size = 0;
for (i = 0; i < agg->count; i++) { - unsigned int element_size;
+ GLuint element_size;
if (agg->arrays[i].type == slang_stor_aggregate) element_size = _slang_sizeof_aggregate (agg->arrays[i].aggregate); @@ -283,20 +287,20 @@ unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg) /* _slang_flatten_aggregate () */ -int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg) +GLboolean _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg) { - unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++) { - unsigned int j;
+ GLuint j;
for (j = 0; j < agg->arrays[i].length; j++) { if (agg->arrays[i].type == slang_stor_aggregate) { if (!_slang_flatten_aggregate (flat, agg->arrays[i].aggregate)) - return 0; + return GL_FALSE; } else { @@ -304,12 +308,12 @@ int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage arr = slang_storage_aggregate_push_new (flat); if (arr == NULL) - return 0; + return GL_FALSE; arr->type = agg->arrays[i].type; arr->length = 1; } } } - return 1; + return GL_TRUE; } |