From: Eric Anholt Date: Thu, 8 Apr 2010 21:34:38 +0000 (-0700) Subject: Add builtin normalize() functions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=925759283a6396faeefb8b33761dd1c681d1593d;p=mesa.git Add builtin normalize() functions. Fixes CorrectSqizzle2.vert. --- diff --git a/builtin_function.cpp b/builtin_function.cpp index e537141e3f0..1fdf8829360 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -188,6 +188,24 @@ generate_max(exec_list *instructions, } +static void +generate_normalize(exec_list *instructions, + ir_variable **declarations, + const glsl_type *type) +{ + ir_dereference *const arg = new ir_dereference(declarations[0]); + ir_rvalue *temp; + ir_rvalue *result; + + temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg); + temp = new ir_expression(ir_unop_rsq, glsl_type::float_type, temp, NULL); + result = new ir_expression(ir_binop_mul, type, arg, temp); + + ir_instruction *inst = new ir_return(result); + instructions->push_tail(inst); +} + + static void generate_pow(exec_list *instructions, ir_variable **declarations, @@ -386,6 +404,8 @@ generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions) /* FINISHME: distance() */ generate_dot_functions(symtab, instructions); /* FINISHME: cross() */ + make_gentype_function(symtab, instructions, "normalize", 1, + generate_normalize); /* FINISHME: normalize() */ /* FINISHME: ftransform() */ /* FINISHME: faceforward() */