commit 7dd18d02750f8f0951c16df3d006e8f0904fe9d9 Author: Eric Anholt Date: Mon Jan 28 16:17:59 2008 -0800 [965] Emit front facing to fogc.y in for glFrontFacing in the fragment shader. diff --git a/src/mesa/drivers/dri/i965/brw_sf_emit.c b/src/mesa/drivers/dri/i965/brw_sf_emit.c index 080a02b..55e927a 100644 --- a/src/mesa/drivers/dri/i965/brw_sf_emit.c +++ b/src/mesa/drivers/dri/i965/brw_sf_emit.c @@ -79,6 +79,44 @@ static void copy_bfc( struct brw_sf_compile *c, } } +/** + * Sets VERT_RESULT_FOGC.Y of the vertices to the front facing flag of the + * primitive. + * + * This is currently executed if the fragment program uses VERT_RESULT_FOGC + * at all, but this could be eliminated with a scan of the FP contents. + */ +static void +set_frontfacing( struct brw_sf_compile *c ) +{ + struct brw_compile *p = &c->func; + GLuint frontface_conditional; + int i; + + if (!have_attr(c, VERT_RESULT_FOGC)) + return; + + if (c->key.frontface_ccw) + frontface_conditional = BRW_CONDITIONAL_G; + else + frontface_conditional = BRW_CONDITIONAL_L; + + /* Store the front facing result (1 or 0) in the low bit of the flag reg */ + brw_CMP(p, vec4(brw_null_reg()), frontface_conditional, c->det, + brw_imm_f(0)); + brw_set_predicate_control(p, BRW_PREDICATE_NONE); + + for (i = 0; i < 3; i++) { + struct brw_reg fogc = get_vert_attr(c, c->vert[i], VERT_RESULT_FOGC); + + /* Move the front facing result from the flag reg low bit to the Y + * component of fogcoord for this vertex, where the fragment shader + * would look for it. + */ + brw_AND(p, brw_writemask(fogc, WRITEMASK_Y), brw_flag_reg(), + brw_imm_ud(1)); + } +} static void do_twoside_color( struct brw_sf_compile *c ) { @@ -355,6 +393,7 @@ void brw_emit_tri_setup( struct brw_sf_compile *c, GLboolean allocate) invert_det(c); copy_z_inv_w(c); + set_frontfacing(c); if (c->key.do_twoside_color) do_twoside_color(c);