Added origin_lower_left field to pipe_rasterizer_state
[mesa.git] / src / mesa / pipe / softpipe / sp_quad_stipple.c
1
2 /**
3 * quad polygon stipple stage
4 */
5
6 #include "sp_context.h"
7 #include "sp_headers.h"
8 #include "sp_quad.h"
9 #include "pipe/p_defines.h"
10 #include "pipe/p_util.h"
11
12
13 /**
14 * Apply polygon stipple to quads produced by triangle rasterization
15 */
16 static void
17 stipple_quad(struct quad_stage *qs, struct quad_header *quad)
18 {
19 static const uint bit31 = 1 << 31;
20 static const uint bit30 = 1 << 30;
21
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 */
25 int y0, y1;
26 uint stipple0, stipple1;
27 if (softpipe->rasterizer->origin_lower_left) {
28 y0 = softpipe->framebuffer.cbufs[0]->height - 1 - quad->y0;
29 y1 = y0 - 1;
30 }
31 else {
32 y0 = quad->y0;
33 y1 = y0 + 1;
34 }
35 stipple0 = softpipe->poly_stipple.stipple[y0 % 32];
36 stipple1 = softpipe->poly_stipple.stipple[y1 % 32];
37
38 #if 1
39 const int col0 = quad->x0 % 32;
40 if ((stipple0 & (bit31 >> col0)) == 0)
41 quad->mask &= ~MASK_TOP_LEFT;
42
43 if ((stipple0 & (bit30 >> col0)) == 0)
44 quad->mask &= ~MASK_TOP_RIGHT;
45
46 if ((stipple1 & (bit31 >> col0)) == 0)
47 quad->mask &= ~MASK_BOTTOM_LEFT;
48
49 if ((stipple1 & (bit30 >> col0)) == 0)
50 quad->mask &= ~MASK_BOTTOM_RIGHT;
51 #else
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.
56 */
57 const int col0 = 30 - (quad->x0 % 32);
58 quad->mask &= (((stipple0 >> col0) & 0x3) |
59 (((stipple1 >> col0) & 0x3) << 2));
60 #endif
61 if (!quad->mask)
62 return;
63 }
64
65 qs->next->run(qs->next, quad);
66 }
67
68
69 static void stipple_begin(struct quad_stage *qs)
70 {
71 qs->next->begin(qs->next);
72 }
73
74
75 static void stipple_destroy(struct quad_stage *qs)
76 {
77 FREE( qs );
78 }
79
80
81 struct quad_stage *
82 sp_quad_polygon_stipple_stage( struct softpipe_context *softpipe )
83 {
84 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
85
86 stage->softpipe = softpipe;
87 stage->begin = stipple_begin;
88 stage->run = stipple_quad;
89 stage->destroy = stipple_destroy;
90
91 return stage;
92 }