1 2 /** 3 * quad polygon stipple stage 4 */ 5 6 #include "sp_context.h" 7 #include "sp_quad.h" 8 #include "sp_quad_pipe.h" 9 #include "pipe/p_defines.h" 10 #include "util/u_memory.h" 11 12 13 /** 14 * Apply polygon stipple to quads produced by triangle rasterization 15 */ 16 static void stipple_quad(struct quad_stage * qs,struct quad_header * quads[],unsigned nr)17stipple_quad(struct quad_stage *qs, struct quad_header *quads[], unsigned nr) 18 { 19 static const uint bit31 = 1u << 31; 20 static const uint bit30 = 1u << 30; 21 unsigned pass = nr; 22 23 struct softpipe_context *softpipe = qs->softpipe; 24 unsigned q; 25 26 pass = 0; 27 28 for (q = 0; q < nr; q++) { 29 struct quad_header *quad = quads[q]; 30 31 const int col0 = quad->input.x0 % 32; 32 const int y0 = quad->input.y0; 33 const int y1 = y0 + 1; 34 const uint stipple0 = softpipe->poly_stipple.stipple[y0 % 32]; 35 const uint stipple1 = softpipe->poly_stipple.stipple[y1 % 32]; 36 37 /* turn off quad mask bits that fail the stipple test */ 38 if ((stipple0 & (bit31 >> col0)) == 0) 39 quad->inout.mask &= ~MASK_TOP_LEFT; 40 41 if ((stipple0 & (bit30 >> col0)) == 0) 42 quad->inout.mask &= ~MASK_TOP_RIGHT; 43 44 if ((stipple1 & (bit31 >> col0)) == 0) 45 quad->inout.mask &= ~MASK_BOTTOM_LEFT; 46 47 if ((stipple1 & (bit30 >> col0)) == 0) 48 quad->inout.mask &= ~MASK_BOTTOM_RIGHT; 49 50 if (quad->inout.mask) 51 quads[pass++] = quad; 52 } 53 54 qs->next->run(qs->next, quads, pass); 55 } 56 57 stipple_begin(struct quad_stage * qs)58static void stipple_begin(struct quad_stage *qs) 59 { 60 qs->next->begin(qs->next); 61 } 62 63 stipple_destroy(struct quad_stage * qs)64static void stipple_destroy(struct quad_stage *qs) 65 { 66 FREE( qs ); 67 } 68 69 70 struct quad_stage * sp_quad_polygon_stipple_stage(struct softpipe_context * softpipe)71sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe ) 72 { 73 struct quad_stage *stage = CALLOC_STRUCT(quad_stage); 74 75 stage->softpipe = softpipe; 76 stage->begin = stipple_begin; 77 stage->run = stipple_quad; 78 stage->destroy = stipple_destroy; 79 80 return stage; 81 } 82