3 * quad polygon stipple stage
6 #include "sp_context.h"
8 #include "sp_quad_pipe.h"
9 #include "pipe/p_defines.h"
10 #include "util/u_memory.h"
14 * Apply polygon stipple to quads produced by triangle rasterization
17 stipple_quad(struct quad_stage
*qs
, struct quad_header
*quad
)
19 static const uint bit31
= 1 << 31;
20 static const uint bit30
= 1 << 30;
22 if (quad
->input
.prim
== QUAD_PRIM_TRI
) {
23 struct softpipe_context
*softpipe
= qs
->softpipe
;
24 /* need to invert Y to index into OpenGL's stipple pattern */
25 const int col0
= quad
->input
.x0
% 32;
26 const int y0
= quad
->input
.y0
;
27 const int y1
= y0
+ 1;
28 const uint stipple0
= softpipe
->poly_stipple
.stipple
[y0
% 32];
29 const uint stipple1
= softpipe
->poly_stipple
.stipple
[y1
% 32];
31 /* turn off quad mask bits that fail the stipple test */
32 if ((stipple0
& (bit31
>> col0
)) == 0)
33 quad
->inout
.mask
&= ~MASK_TOP_LEFT
;
35 if ((stipple0
& (bit30
>> col0
)) == 0)
36 quad
->inout
.mask
&= ~MASK_TOP_RIGHT
;
38 if ((stipple1
& (bit31
>> col0
)) == 0)
39 quad
->inout
.mask
&= ~MASK_BOTTOM_LEFT
;
41 if ((stipple1
& (bit30
>> col0
)) == 0)
42 quad
->inout
.mask
&= ~MASK_BOTTOM_RIGHT
;
44 if (!quad
->inout
.mask
) {
45 /* all fragments failed stipple test, end of quad pipeline */
50 qs
->next
->run(qs
->next
, quad
);
54 static void stipple_begin(struct quad_stage
*qs
)
56 qs
->next
->begin(qs
->next
);
60 static void stipple_destroy(struct quad_stage
*qs
)
67 sp_quad_polygon_stipple_stage( struct softpipe_context
*softpipe
)
69 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
71 stage
->softpipe
= softpipe
;
72 stage
->begin
= stipple_begin
;
73 stage
->run
= stipple_quad
;
74 stage
->destroy
= stipple_destroy
;