Mesa (master): st/mesa: handle front/back-face +1/-1 vs. 1/0 conversion

Brian Paul brianp at kemper.freedesktop.org
Mon Nov 30 16:02:54 UTC 2009


Module: Mesa
Branch: master
Commit: 7725744433827509d1da1cf1b27cda4bc8012ef3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7725744433827509d1da1cf1b27cda4bc8012ef3

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Nov 30 08:56:47 2009 -0700

st/mesa: handle front/back-face +1/-1 vs. 1/0 conversion

Fixes progs/glsl/twoside.c demo.

---

 src/mesa/state_tracker/st_mesa_to_tgsi.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index d84832f..5e8e611 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -676,6 +676,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
  * \param numInputs  number of input registers used
@@ -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.
        */




More information about the mesa-commit mailing list