i965g: more files compiling
[mesa.git] / src / gallium / drivers / i965 / brw_pipe_rast.c
1
2 #include "util/u_memory.h"
3 #include "pipe/p_defines.h"
4 #include "brw_context.h"
5 #include "brw_defines.h"
6 #include "brw_pipe_rast.h"
7 #include "brw_wm.h"
8
9
10 static unsigned translate_fill( unsigned fill )
11 {
12 switch (fill) {
13 case PIPE_POLYGON_MODE_FILL:
14 return CLIP_FILL;
15 case PIPE_POLYGON_MODE_LINE:
16 return CLIP_LINE;
17 case PIPE_POLYGON_MODE_POINT:
18 return CLIP_POINT;
19 default:
20 assert(0);
21 return CLIP_FILL;
22 }
23 }
24
25
26 /* Calculates the key for triangle-mode clipping. Non-triangle
27 * clipping keys use much less information and are computed on the
28 * fly.
29 */
30 static void
31 calculate_clip_key_rast( const struct brw_context *brw,
32 const struct pipe_rasterizer_state *templ,
33 const struct brw_rasterizer_state *rast,
34 struct brw_clip_prog_key *key)
35 {
36 memset(key, 0, sizeof *key);
37
38 if (brw->chipset.is_igdng)
39 key->clip_mode = BRW_CLIPMODE_KERNEL_CLIP;
40 else
41 key->clip_mode = BRW_CLIPMODE_NORMAL;
42
43 key->do_flat_shading = templ->flatshade;
44
45 if (templ->cull_mode == PIPE_WINDING_BOTH) {
46 key->clip_mode = BRW_CLIPMODE_REJECT_ALL;
47 return;
48 }
49
50 key->fill_ccw = CLIP_CULL;
51 key->fill_cw = CLIP_CULL;
52
53 if (!(templ->cull_mode & PIPE_WINDING_CCW)) {
54 key->fill_ccw = translate_fill(templ->fill_ccw);
55 }
56
57 if (!(templ->cull_mode & PIPE_WINDING_CW)) {
58 key->fill_cw = translate_fill(templ->fill_cw);
59 }
60
61 if (key->fill_cw != CLIP_FILL ||
62 key->fill_ccw != CLIP_FILL) {
63 key->do_unfilled = 1;
64 key->clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED;
65 }
66
67 key->offset_ccw = templ->offset_ccw;
68 key->offset_cw = templ->offset_cw;
69
70 if (templ->light_twoside && key->fill_cw != CLIP_CULL)
71 key->copy_bfc_cw = 1;
72
73 if (templ->light_twoside && key->fill_ccw != CLIP_CULL)
74 key->copy_bfc_ccw = 1;
75 }
76
77
78 static void
79 calculate_line_stipple_rast( const struct pipe_rasterizer_state *templ,
80 struct brw_line_stipple *bls )
81 {
82 GLfloat tmp = 1.0f / (templ->line_stipple_factor + 1);
83 GLint tmpi = tmp * (1<<13);
84
85 bls->header.opcode = CMD_LINE_STIPPLE_PATTERN;
86 bls->header.length = sizeof(*bls)/4 - 2;
87 bls->bits0.pattern = templ->line_stipple_pattern;
88 bls->bits1.repeat_count = templ->line_stipple_factor + 1;
89 bls->bits1.inverse_repeat_count = tmpi;
90 }
91
92 static void *brw_create_rasterizer_state( struct pipe_context *pipe,
93 const struct pipe_rasterizer_state *templ )
94 {
95 struct brw_context *brw = brw_context(pipe);
96 struct brw_rasterizer_state *rast;
97
98 rast = CALLOC_STRUCT(brw_rasterizer_state);
99 if (rast == NULL)
100 return NULL;
101
102 rast->templ = *templ;
103
104 calculate_clip_key_rast( brw, templ, rast, &rast->clip_key );
105
106 if (templ->line_stipple_enable)
107 calculate_line_stipple_rast( templ, &rast->bls );
108
109 /* Caclculate lookup value for WM IZ table.
110 */
111 if (templ->line_smooth) {
112 if (templ->fill_cw == PIPE_POLYGON_MODE_LINE &&
113 templ->fill_ccw == PIPE_POLYGON_MODE_LINE) {
114 rast->unfilled_aa_line = AA_ALWAYS;
115 }
116 else if (templ->fill_cw == PIPE_POLYGON_MODE_LINE ||
117 templ->fill_ccw == PIPE_POLYGON_MODE_LINE) {
118 rast->unfilled_aa_line = AA_SOMETIMES;
119 }
120 else {
121 rast->unfilled_aa_line = AA_NEVER;
122 }
123 }
124 else {
125 rast->unfilled_aa_line = AA_NEVER;
126 }
127
128 return (void *)rast;
129 }
130
131
132 static void brw_bind_rasterizer_state(struct pipe_context *pipe,
133 void *cso)
134 {
135 struct brw_context *brw = brw_context(pipe);
136 brw->curr.rast = (const struct brw_rasterizer_state *)cso;
137 brw->state.dirty.mesa |= PIPE_NEW_RAST;
138 }
139
140 static void brw_delete_rasterizer_state(struct pipe_context *pipe,
141 void *cso)
142 {
143 struct brw_context *brw = brw_context(pipe);
144 assert((const void *)cso != (const void *)brw->curr.rast);
145 FREE(cso);
146 }
147
148
149
150 void brw_pipe_rast_init( struct brw_context *brw )
151 {
152 brw->base.create_rasterizer_state = brw_create_rasterizer_state;
153 brw->base.bind_rasterizer_state = brw_bind_rasterizer_state;
154 brw->base.delete_rasterizer_state = brw_delete_rasterizer_state;
155 }
156
157 void brw_pipe_rast_cleanup( struct brw_context *brw )
158 {
159 }