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
;
49 /* Set the validate's next stage to the rasterize stage, so that it
50 * can be found later if needed for flushing.
55 * NOTE: we build up the pipeline in end-to-start order.
57 * TODO: make the current primitive part of the state and build
58 * shorter pipelines for lines & points.
61 if ((draw
->rasterizer
->line_width
!= 1.0 && draw
->convert_wide_lines
) ||
62 (draw
->rasterizer
->point_size
!= 1.0 && draw
->convert_wide_points
) ||
63 draw
->rasterizer
->point_sprite
) {
64 draw
->pipeline
.wide
->next
= next
;
65 next
= draw
->pipeline
.wide
;
68 if (draw
->rasterizer
->line_stipple_enable
) {
69 draw
->pipeline
.stipple
->next
= next
;
70 next
= draw
->pipeline
.stipple
;
71 precalc_flat
= 1; /* only needed for lines really */
74 if (draw
->rasterizer
->fill_cw
!= PIPE_POLYGON_MODE_FILL
||
75 draw
->rasterizer
->fill_ccw
!= PIPE_POLYGON_MODE_FILL
) {
76 draw
->pipeline
.unfilled
->next
= next
;
77 next
= draw
->pipeline
.unfilled
;
78 precalc_flat
= 1; /* only needed for triangles really */
82 if (draw
->rasterizer
->flatshade
&& precalc_flat
) {
83 draw
->pipeline
.flatshade
->next
= next
;
84 next
= draw
->pipeline
.flatshade
;
87 if (draw
->rasterizer
->offset_cw
||
88 draw
->rasterizer
->offset_ccw
) {
89 draw
->pipeline
.offset
->next
= next
;
90 next
= draw
->pipeline
.offset
;
94 if (draw
->rasterizer
->light_twoside
) {
95 draw
->pipeline
.twoside
->next
= next
;
96 next
= draw
->pipeline
.twoside
;
100 /* Always run the cull stage as we calculate determinant there
103 * This can actually be a win as culling out the triangles can lead
104 * to less work emitting vertices, smaller vertex buffers, etc.
105 * It's difficult to say whether this will be true in general.
107 if (need_det
|| draw
->rasterizer
->cull_mode
) {
108 draw
->pipeline
.cull
->next
= next
;
109 next
= draw
->pipeline
.cull
;
114 if (!draw
->rasterizer
->bypass_clipping
)
116 draw
->pipeline
.clip
->next
= next
;
117 next
= draw
->pipeline
.clip
;
121 draw
->pipeline
.first
= next
;
125 static void validate_tri( struct draw_stage
*stage
,
126 struct prim_header
*header
)
128 struct draw_stage
*pipeline
= validate_pipeline( stage
);
129 pipeline
->tri( pipeline
, header
);
132 static void validate_line( struct draw_stage
*stage
,
133 struct prim_header
*header
)
135 struct draw_stage
*pipeline
= validate_pipeline( stage
);
136 pipeline
->line( pipeline
, header
);
139 static void validate_point( struct draw_stage
*stage
,
140 struct prim_header
*header
)
142 struct draw_stage
*pipeline
= validate_pipeline( stage
);
143 pipeline
->point( pipeline
, header
);
146 static void validate_reset_stipple_counter( struct draw_stage
*stage
)
148 struct draw_stage
*pipeline
= validate_pipeline( stage
);
149 pipeline
->reset_stipple_counter( pipeline
);
152 static void validate_flush( struct draw_stage
*stage
,
155 /* May need to pass a backend flush on to the rasterize stage.
158 stage
->next
->flush( stage
->next
, flags
);
162 static void validate_destroy( struct draw_stage
*stage
)
169 * Create validate pipeline stage.
171 struct draw_stage
*draw_validate_stage( struct draw_context
*draw
)
173 struct draw_stage
*stage
= CALLOC_STRUCT(draw_stage
);
177 stage
->point
= validate_point
;
178 stage
->line
= validate_line
;
179 stage
->tri
= validate_tri
;
180 stage
->flush
= validate_flush
;
181 stage
->reset_stipple_counter
= validate_reset_stipple_counter
;
182 stage
->destroy
= validate_destroy
;