1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
31 #include "pipe/p_util.h"
32 #include "pipe/p_defines.h"
33 #include "draw_private.h"
40 * Rebuild the rendering pipeline.
42 static struct draw_stage
*validate_pipeline( struct draw_stage
*stage
)
44 struct draw_context
*draw
= stage
->draw
;
45 struct draw_stage
*next
= draw
->pipeline
.rasterize
;
48 boolean wide_lines
, wide_points
;
50 /* Set the validate's next stage to the rasterize stage, so that it
51 * can be found later if needed for flushing.
55 /* drawing wide lines? */
56 wide_lines
= (draw
->rasterizer
->line_width
> draw
->wide_line_threshold
57 && !draw
->rasterizer
->line_smooth
);
59 /* drawing large points? */
60 if (draw
->rasterizer
->point_smooth
&& draw
->pipeline
.aapoint
)
62 else if (draw
->rasterizer
->point_size
> draw
->wide_point_threshold
)
68 * NOTE: we build up the pipeline in end-to-start order.
70 * TODO: make the current primitive part of the state and build
71 * shorter pipelines for lines & points.
74 if (draw
->rasterizer
->line_smooth
&& draw
->pipeline
.aaline
) {
75 draw
->pipeline
.aaline
->next
= next
;
76 next
= draw
->pipeline
.aaline
;
79 if (draw
->rasterizer
->point_smooth
&& draw
->pipeline
.aapoint
) {
80 draw
->pipeline
.aapoint
->next
= next
;
81 next
= draw
->pipeline
.aapoint
;
85 draw
->pipeline
.wide_line
->next
= next
;
86 next
= draw
->pipeline
.wide_line
;
90 if (wide_points
|| draw
->rasterizer
->point_sprite
) {
91 draw
->pipeline
.wide_point
->next
= next
;
92 next
= draw
->pipeline
.wide_point
;
95 if (draw
->rasterizer
->line_stipple_enable
) {
96 draw
->pipeline
.stipple
->next
= next
;
97 next
= draw
->pipeline
.stipple
;
98 precalc_flat
= 1; /* only needed for lines really */
101 if (draw
->rasterizer
->poly_stipple_enable
102 && draw
->pipeline
.pstipple
) {
103 draw
->pipeline
.pstipple
->next
= next
;
104 next
= draw
->pipeline
.pstipple
;
107 if (draw
->rasterizer
->fill_cw
!= PIPE_POLYGON_MODE_FILL
||
108 draw
->rasterizer
->fill_ccw
!= PIPE_POLYGON_MODE_FILL
) {
109 draw
->pipeline
.unfilled
->next
= next
;
110 next
= draw
->pipeline
.unfilled
;
111 precalc_flat
= 1; /* only needed for triangles really */
115 if (draw
->rasterizer
->flatshade
&& precalc_flat
) {
116 draw
->pipeline
.flatshade
->next
= next
;
117 next
= draw
->pipeline
.flatshade
;
120 if (draw
->rasterizer
->offset_cw
||
121 draw
->rasterizer
->offset_ccw
) {
122 draw
->pipeline
.offset
->next
= next
;
123 next
= draw
->pipeline
.offset
;
127 if (draw
->rasterizer
->light_twoside
) {
128 draw
->pipeline
.twoside
->next
= next
;
129 next
= draw
->pipeline
.twoside
;
133 /* Always run the cull stage as we calculate determinant there
136 * This can actually be a win as culling out the triangles can lead
137 * to less work emitting vertices, smaller vertex buffers, etc.
138 * It's difficult to say whether this will be true in general.
140 if (need_det
|| draw
->rasterizer
->cull_mode
) {
141 draw
->pipeline
.cull
->next
= next
;
142 next
= draw
->pipeline
.cull
;
147 if (!draw
->rasterizer
->bypass_clipping
)
149 draw
->pipeline
.clip
->next
= next
;
150 next
= draw
->pipeline
.clip
;
154 draw
->pipeline
.first
= next
;
158 static void validate_tri( struct draw_stage
*stage
,
159 struct prim_header
*header
)
161 struct draw_stage
*pipeline
= validate_pipeline( stage
);
162 pipeline
->tri( pipeline
, header
);
165 static void validate_line( struct draw_stage
*stage
,
166 struct prim_header
*header
)
168 struct draw_stage
*pipeline
= validate_pipeline( stage
);
169 pipeline
->line( pipeline
, header
);
172 static void validate_point( struct draw_stage
*stage
,
173 struct prim_header
*header
)
175 struct draw_stage
*pipeline
= validate_pipeline( stage
);
176 pipeline
->point( pipeline
, header
);
179 static void validate_reset_stipple_counter( struct draw_stage
*stage
)
181 struct draw_stage
*pipeline
= validate_pipeline( stage
);
182 pipeline
->reset_stipple_counter( pipeline
);
185 static void validate_flush( struct draw_stage
*stage
,
188 /* May need to pass a backend flush on to the rasterize stage.
191 stage
->next
->flush( stage
->next
, flags
);
195 static void validate_destroy( struct draw_stage
*stage
)
202 * Create validate pipeline stage.
204 struct draw_stage
*draw_validate_stage( struct draw_context
*draw
)
206 struct draw_stage
*stage
= CALLOC_STRUCT(draw_stage
);
210 stage
->point
= validate_point
;
211 stage
->line
= validate_line
;
212 stage
->tri
= validate_tri
;
213 stage
->flush
= validate_flush
;
214 stage
->reset_stipple_counter
= validate_reset_stipple_counter
;
215 stage
->destroy
= validate_destroy
;