gallium: split draw_wide_prim stage into separate point/line stages.
[mesa.git] / src / gallium / auxiliary / draw / draw_validate.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #include "pipe/p_util.h"
32 #include "pipe/p_defines.h"
33 #include "draw_private.h"
34
35
36
37
38
39 /**
40 * Rebuild the rendering pipeline.
41 */
42 static struct draw_stage *validate_pipeline( struct draw_stage *stage )
43 {
44 struct draw_context *draw = stage->draw;
45 struct draw_stage *next = draw->pipeline.rasterize;
46 int need_det = 0;
47 int precalc_flat = 0;
48 boolean wide_lines, wide_points;
49
50 /* Set the validate's next stage to the rasterize stage, so that it
51 * can be found later if needed for flushing.
52 */
53 stage->next = next;
54
55 /* drawing wide lines? */
56 wide_lines = (draw->rasterizer->line_width > draw->wide_line_threshold
57 && !draw->rasterizer->line_smooth);
58
59 /* drawing large points? */
60 if (draw->rasterizer->point_smooth && draw->pipeline.aapoint)
61 wide_points = FALSE;
62 else if (draw->rasterizer->point_size > draw->wide_point_threshold)
63 wide_points = TRUE;
64 else
65 wide_points = FALSE;
66
67 /*
68 * NOTE: we build up the pipeline in end-to-start order.
69 *
70 * TODO: make the current primitive part of the state and build
71 * shorter pipelines for lines & points.
72 */
73
74 if (draw->rasterizer->line_smooth && draw->pipeline.aaline) {
75 draw->pipeline.aaline->next = next;
76 next = draw->pipeline.aaline;
77 }
78
79 if (draw->rasterizer->point_smooth && draw->pipeline.aapoint) {
80 draw->pipeline.aapoint->next = next;
81 next = draw->pipeline.aapoint;
82 }
83
84 if (wide_lines) {
85 draw->pipeline.wide_line->next = next;
86 next = draw->pipeline.wide_line;
87 }
88
89 if (wide_points || draw->rasterizer->point_sprite) {
90 draw->pipeline.wide_point->next = next;
91 next = draw->pipeline.wide_point;
92 }
93
94 if (draw->rasterizer->line_stipple_enable) {
95 draw->pipeline.stipple->next = next;
96 next = draw->pipeline.stipple;
97 precalc_flat = 1; /* only needed for lines really */
98 }
99
100 if (draw->rasterizer->poly_stipple_enable
101 && draw->pipeline.pstipple) {
102 draw->pipeline.pstipple->next = next;
103 next = draw->pipeline.pstipple;
104 }
105
106 if (draw->rasterizer->fill_cw != PIPE_POLYGON_MODE_FILL ||
107 draw->rasterizer->fill_ccw != PIPE_POLYGON_MODE_FILL) {
108 draw->pipeline.unfilled->next = next;
109 next = draw->pipeline.unfilled;
110 precalc_flat = 1; /* only needed for triangles really */
111 need_det = 1;
112 }
113
114 if (draw->rasterizer->flatshade && precalc_flat) {
115 draw->pipeline.flatshade->next = next;
116 next = draw->pipeline.flatshade;
117 }
118
119 if (draw->rasterizer->offset_cw ||
120 draw->rasterizer->offset_ccw) {
121 draw->pipeline.offset->next = next;
122 next = draw->pipeline.offset;
123 need_det = 1;
124 }
125
126 if (draw->rasterizer->light_twoside) {
127 draw->pipeline.twoside->next = next;
128 next = draw->pipeline.twoside;
129 need_det = 1;
130 }
131
132 /* Always run the cull stage as we calculate determinant there
133 * also.
134 *
135 * This can actually be a win as culling out the triangles can lead
136 * to less work emitting vertices, smaller vertex buffers, etc.
137 * It's difficult to say whether this will be true in general.
138 */
139 if (need_det || draw->rasterizer->cull_mode) {
140 draw->pipeline.cull->next = next;
141 next = draw->pipeline.cull;
142 }
143
144 /* Clip stage
145 */
146 if (!draw->rasterizer->bypass_clipping)
147 {
148 draw->pipeline.clip->next = next;
149 next = draw->pipeline.clip;
150 }
151
152
153 draw->pipeline.first = next;
154 return next;
155 }
156
157 static void validate_tri( struct draw_stage *stage,
158 struct prim_header *header )
159 {
160 struct draw_stage *pipeline = validate_pipeline( stage );
161 pipeline->tri( pipeline, header );
162 }
163
164 static void validate_line( struct draw_stage *stage,
165 struct prim_header *header )
166 {
167 struct draw_stage *pipeline = validate_pipeline( stage );
168 pipeline->line( pipeline, header );
169 }
170
171 static void validate_point( struct draw_stage *stage,
172 struct prim_header *header )
173 {
174 struct draw_stage *pipeline = validate_pipeline( stage );
175 pipeline->point( pipeline, header );
176 }
177
178 static void validate_reset_stipple_counter( struct draw_stage *stage )
179 {
180 struct draw_stage *pipeline = validate_pipeline( stage );
181 pipeline->reset_stipple_counter( pipeline );
182 }
183
184 static void validate_flush( struct draw_stage *stage,
185 unsigned flags )
186 {
187 /* May need to pass a backend flush on to the rasterize stage.
188 */
189 if (stage->next)
190 stage->next->flush( stage->next, flags );
191 }
192
193
194 static void validate_destroy( struct draw_stage *stage )
195 {
196 FREE( stage );
197 }
198
199
200 /**
201 * Create validate pipeline stage.
202 */
203 struct draw_stage *draw_validate_stage( struct draw_context *draw )
204 {
205 struct draw_stage *stage = CALLOC_STRUCT(draw_stage);
206
207 stage->draw = draw;
208 stage->next = NULL;
209 stage->point = validate_point;
210 stage->line = validate_line;
211 stage->tri = validate_tri;
212 stage->flush = validate_flush;
213 stage->reset_stipple_counter = validate_reset_stipple_counter;
214 stage->destroy = validate_destroy;
215
216 return stage;
217 }