From 0bd1cbcd0d28dbadfb0c3e1f8b048a18b56bc72c Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 14 May 2010 13:04:42 +0100 Subject: gallium: convert rasterizer state to use gl-style front/back concepts Use front/back instead of cw/ccw throughout. Also, use offset_point/line/fill instead of offset_cw/ccw. Brings gallium representation of this state into line with its main user, and also what turns out to be the most common hardware representation. This fixes a long-standing bias in the interface towards the architecture of the software rasterizer. --- src/gallium/drivers/softpipe/sp_context.h | 3 +++ src/gallium/drivers/softpipe/sp_setup.c | 41 +++---------------------------- 2 files changed, 7 insertions(+), 37 deletions(-) (limited to 'src/gallium/drivers/softpipe') diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index aa69625768..b3d3fe620f 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -109,6 +109,9 @@ struct softpipe_context { /** The reduced version of the primitive supplied by the state tracker */ unsigned reduced_api_prim; + /** Derived information about which winding orders to cull */ + unsigned cull_mode; + /** * The reduced primitive after unfilled triangles, wide-line decomposition, * etc, are taken into account. This is the primitive type that's actually diff --git a/src/gallium/drivers/softpipe/sp_setup.c b/src/gallium/drivers/softpipe/sp_setup.c index 35ef9e698d..ca02d4df48 100644 --- a/src/gallium/drivers/softpipe/sp_setup.c +++ b/src/gallium/drivers/softpipe/sp_setup.c @@ -111,34 +111,12 @@ struct setup_context { uint numFragsWritten; /**< per primitive */ #endif - unsigned winding; /* which winding to cull */ unsigned nr_vertex_attrs; }; -/** - * Do triangle cull test using tri determinant (sign indicates orientation) - * \return true if triangle is to be culled. - */ -static INLINE boolean -cull_tri(const struct setup_context *setup, float det) -{ - if (det != 0) { - /* if (det < 0 then Z points toward camera and triangle is - * counter-clockwise winding. - */ - unsigned winding = (det < 0) ? PIPE_WINDING_CCW : PIPE_WINDING_CW; - - if ((winding & setup->winding) == 0) - return FALSE; - } - - /* Culled: - */ - return TRUE; -} @@ -393,8 +371,8 @@ setup_sort_vertices(struct setup_context *setup, * 0 = front-facing, 1 = back-facing */ setup->facing = - ((det > 0.0) ^ - (setup->softpipe->rasterizer->front_winding == PIPE_WINDING_CW)); + ((det < 0.0) ^ + (setup->softpipe->rasterizer->front_ccw)); /* Prepare pixel offset for rasterisation: * - pixel center (0.5, 0.5) for GL, or @@ -832,8 +810,8 @@ sp_setup_tri(struct setup_context *setup, setup->numFragsWritten = 0; #endif - if (cull_tri( setup, det )) - return; + /* Culling already done by draw module. + */ if (!setup_sort_vertices( setup, det, v0, v1, v2 )) return; @@ -1418,17 +1396,6 @@ sp_setup_prepare(struct setup_context *setup) setup->nr_vertex_attrs = draw_num_shader_outputs(sp->draw); sp->quad.first->begin( sp->quad.first ); - - if (sp->reduced_api_prim == PIPE_PRIM_TRIANGLES && - sp->rasterizer->fill_cw == PIPE_POLYGON_MODE_FILL && - sp->rasterizer->fill_ccw == PIPE_POLYGON_MODE_FILL) { - /* we'll do culling */ - setup->winding = sp->rasterizer->cull_mode; - } - else { - /* 'draw' will do culling */ - setup->winding = PIPE_WINDING_NONE; - } } -- cgit v1.2.3 From 4ff1274e2312c7d9d8538dc443af500ec3b769cf Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 14 May 2010 20:36:08 +0100 Subject: softpipe: restore culling code --- src/gallium/drivers/softpipe/sp_setup.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/gallium/drivers/softpipe') diff --git a/src/gallium/drivers/softpipe/sp_setup.c b/src/gallium/drivers/softpipe/sp_setup.c index ca02d4df48..5d727dc00d 100644 --- a/src/gallium/drivers/softpipe/sp_setup.c +++ b/src/gallium/drivers/softpipe/sp_setup.c @@ -111,6 +111,7 @@ struct setup_context { uint numFragsWritten; /**< per primitive */ #endif + unsigned cull_face; /* which faces cull */ unsigned nr_vertex_attrs; }; @@ -374,6 +375,14 @@ setup_sort_vertices(struct setup_context *setup, ((det < 0.0) ^ (setup->softpipe->rasterizer->front_ccw)); + { + unsigned face = setup->facing == 0 ? PIPE_FACE_FRONT : PIPE_FACE_BACK; + + if (face & setup->cull_face) + return FALSE; + } + + /* Prepare pixel offset for rasterisation: * - pixel center (0.5, 0.5) for GL, or * - assume (0.0, 0.0) for other APIs. @@ -810,11 +819,9 @@ sp_setup_tri(struct setup_context *setup, setup->numFragsWritten = 0; #endif - /* Culling already done by draw module. - */ - if (!setup_sort_vertices( setup, det, v0, v1, v2 )) return; + setup_tri_coefficients( setup ); setup_tri_edges( setup ); @@ -1396,6 +1403,17 @@ sp_setup_prepare(struct setup_context *setup) setup->nr_vertex_attrs = draw_num_shader_outputs(sp->draw); sp->quad.first->begin( sp->quad.first ); + + if (sp->reduced_api_prim == PIPE_PRIM_TRIANGLES && + sp->rasterizer->fill_front == PIPE_POLYGON_MODE_FILL && + sp->rasterizer->fill_back == PIPE_POLYGON_MODE_FILL) { + /* we'll do culling */ + setup->cull_face = sp->rasterizer->cull_face; + } + else { + /* 'draw' will do culling */ + setup->cull_face = PIPE_FACE_NONE; + } } -- cgit v1.2.3