From 0ac0fb91bd711ec80a058ab23bfe8011baa0a487 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 11 Jul 2007 09:52:00 -0600 Subject: [PATCH] Compute quad.facing from prim->det and polygon winding. Updated comments/questions about area vs. prim->det. --- src/mesa/pipe/softpipe/sp_headers.h | 2 +- src/mesa/pipe/softpipe/sp_prim_setup.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mesa/pipe/softpipe/sp_headers.h b/src/mesa/pipe/softpipe/sp_headers.h index 82f03ec..cd2dc98 100644 --- a/src/mesa/pipe/softpipe/sp_headers.h +++ b/src/mesa/pipe/softpipe/sp_headers.h @@ -74,7 +74,7 @@ struct quad_header { GLint x0; GLint y0; GLuint mask; - GLuint facing; /**< Front or back facing? */ + GLuint facing; /**< Front (0) or back (1) facing? */ struct { GLfloat color[4][QUAD_SIZE]; /* rrrr, gggg, bbbb, aaaa */ diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 8e43f5d..3321139 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -279,26 +279,32 @@ static GLboolean setup_sort_vertices( struct setup_stage *setup, setup->etop.dx = setup->vmax->data[0][0] - setup->vmid->data[0][0]; setup->etop.dy = setup->vmax->data[0][1] - setup->vmid->data[0][1]; - /* xxx: may need to adjust this sign according to the if-tree - * above: + /* + * Compute triangle's area. Use 1/area to compute partial + * derivatives of attributes later. * - * XXX: this is like 'det', but calculated from screen coords?? + * The area will be the same as prim->det, but the sign may be + * different depending on how the vertices get sorted above. + * + * To determine whether the primitive is front or back facing we + * use the prim->det value because its sign is correct. */ { const GLfloat area = (setup->emaj.dx * setup->ebot.dy - setup->ebot.dx * setup->emaj.dy); setup->oneoverarea = 1.0 / area; + /* + _mesa_printf("%s one-over-area %f area %f det %f\n", + __FUNCTION__, setup->oneoverarea, area, prim->det ); + */ } - /* XXX need to know if this is a front or back-facing triangle: + /* We need to know if this is a front or back-facing triangle for: * - the GLSL gl_FrontFacing fragment attribute (bool) * - two-sided stencil test */ - setup->quad.facing = 0; - - _mesa_printf("%s one-over-area %f\n", __FUNCTION__, setup->oneoverarea ); - + setup->quad.facing = (prim->det > 0.0) ^ (setup->softpipe->setup.front_winding == PIPE_WINDING_CW); return GL_TRUE; } -- 2.7.4