From: Brian Paul Date: Mon, 30 Nov 2009 15:56:47 +0000 (-0700) Subject: st/mesa: handle front/back-face +1/-1 vs. 1/0 conversion X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7725744433827509d1da1cf1b27cda4bc8012ef3;p=mesa.git st/mesa: handle front/back-face +1/-1 vs. 1/0 conversion Fixes progs/glsl/twoside.c demo. --- diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index d84832f5392..5e8e61135e6 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -675,6 +675,31 @@ emit_inverted_wpos( struct st_translate *t, } +/** + * OpenGL's fragment gl_FrontFace input is 1 for front-facing, 0 for back. + * TGSI uses +1 for front, -1 for back. + * This function converts the TGSI value to the GL value. Simply clamping/ + * saturating the value to [0,1] does the job. + */ +static void +emit_face_var( struct st_translate *t, + const struct gl_program *program ) +{ + struct ureg_program *ureg = t->ureg; + struct ureg_dst face_temp = ureg_DECL_temporary( ureg ); + struct ureg_src face_input = t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]]; + + /* MOV_SAT face_temp, input[face] + */ + face_temp = ureg_saturate( face_temp ); + ureg_MOV( ureg, face_temp, face_input ); + + /* Use face_temp as face input from here on: + */ + t->inputs[t->inputMapping[FRAG_ATTRIB_FACE]] = ureg_src(face_temp); +} + + /** * Translate Mesa program to TGSI format. * \param program the program to translate @@ -746,6 +771,10 @@ st_translate_mesa_program( emit_inverted_wpos( t, program ); } + if (program->InputsRead & FRAG_BIT_FACE) { + emit_face_var( t, program ); + } + /* * Declare output attributes. */