3 * quad polygon stipple stage
6 #include "sp_context.h"
7 #include "sp_headers.h"
9 #include "pipe/p_defines.h"
10 #include "pipe/p_util.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
->prim
== PRIM_TRI
) {
23 struct softpipe_context
*softpipe
= qs
->softpipe
;
24 /* need to invert Y to index into OpenGL's stipple pattern */
26 uint stipple0
, stipple1
;
27 if (softpipe
->rasterizer
->origin_lower_left
) {
28 y0
= softpipe
->framebuffer
.cbufs
[0]->height
- 1 - quad
->y0
;
35 stipple0
= softpipe
->poly_stipple
.stipple
[y0
% 32];
36 stipple1
= softpipe
->poly_stipple
.stipple
[y1
% 32];
39 const int col0
= quad
->x0
% 32;
40 if ((stipple0
& (bit31
>> col0
)) == 0)
41 quad
->mask
&= ~MASK_TOP_LEFT
;
43 if ((stipple0
& (bit30
>> col0
)) == 0)
44 quad
->mask
&= ~MASK_TOP_RIGHT
;
46 if ((stipple1
& (bit31
>> col0
)) == 0)
47 quad
->mask
&= ~MASK_BOTTOM_LEFT
;
49 if ((stipple1
& (bit30
>> col0
)) == 0)
50 quad
->mask
&= ~MASK_BOTTOM_RIGHT
;
52 /* We'd like to use this code, but we'd need to redefine
53 * MASK_TOP_LEFT to be (1 << 1) and MASK_TOP_RIGHT to be (1 << 0),
54 * and similarly for the BOTTOM bits. But that may have undesirable
55 * side effects elsewhere.
57 const int col0
= 30 - (quad
->x0
% 32);
58 quad
->mask
&= (((stipple0
>> col0
) & 0x3) |
59 (((stipple1
>> col0
) & 0x3) << 2));
65 qs
->next
->run(qs
->next
, quad
);
69 static void stipple_begin(struct quad_stage
*qs
)
71 qs
->next
->begin(qs
->next
);
75 static void stipple_destroy(struct quad_stage
*qs
)
82 sp_quad_polygon_stipple_stage( struct softpipe_context
*softpipe
)
84 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
86 stage
->softpipe
= softpipe
;
87 stage
->begin
= stipple_begin
;
88 stage
->run
= stipple_quad
;
89 stage
->destroy
= stipple_destroy
;