64c3502508160e11f076876f7b995602d12d0be5
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 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "draw/draw_private.h"
34 #include "draw/draw_pipe.h"
35 #include "util/u_debug.h"
39 boolean
draw_pipeline_init( struct draw_context
*draw
)
41 /* create pipeline stages */
42 draw
->pipeline
.wide_line
= draw_wide_line_stage( draw
);
43 draw
->pipeline
.wide_point
= draw_wide_point_stage( draw
);
44 draw
->pipeline
.stipple
= draw_stipple_stage( draw
);
45 draw
->pipeline
.unfilled
= draw_unfilled_stage( draw
);
46 draw
->pipeline
.twoside
= draw_twoside_stage( draw
);
47 draw
->pipeline
.offset
= draw_offset_stage( draw
);
48 draw
->pipeline
.clip
= draw_clip_stage( draw
);
49 draw
->pipeline
.flatshade
= draw_flatshade_stage( draw
);
50 draw
->pipeline
.cull
= draw_cull_stage( draw
);
51 draw
->pipeline
.validate
= draw_validate_stage( draw
);
52 draw
->pipeline
.first
= draw
->pipeline
.validate
;
54 if (!draw
->pipeline
.wide_line
||
55 !draw
->pipeline
.wide_point
||
56 !draw
->pipeline
.stipple
||
57 !draw
->pipeline
.unfilled
||
58 !draw
->pipeline
.twoside
||
59 !draw
->pipeline
.offset
||
60 !draw
->pipeline
.clip
||
61 !draw
->pipeline
.flatshade
||
62 !draw
->pipeline
.cull
||
63 !draw
->pipeline
.validate
)
66 /* these defaults are oriented toward the needs of softpipe */
67 draw
->pipeline
.wide_point_threshold
= 1000000.0; /* infinity */
68 draw
->pipeline
.wide_line_threshold
= 1.0;
69 draw
->pipeline
.wide_point_sprites
= FALSE
;
70 draw
->pipeline
.line_stipple
= TRUE
;
71 draw
->pipeline
.point_sprite
= TRUE
;
77 void draw_pipeline_destroy( struct draw_context
*draw
)
79 if (draw
->pipeline
.wide_line
)
80 draw
->pipeline
.wide_line
->destroy( draw
->pipeline
.wide_line
);
81 if (draw
->pipeline
.wide_point
)
82 draw
->pipeline
.wide_point
->destroy( draw
->pipeline
.wide_point
);
83 if (draw
->pipeline
.stipple
)
84 draw
->pipeline
.stipple
->destroy( draw
->pipeline
.stipple
);
85 if (draw
->pipeline
.unfilled
)
86 draw
->pipeline
.unfilled
->destroy( draw
->pipeline
.unfilled
);
87 if (draw
->pipeline
.twoside
)
88 draw
->pipeline
.twoside
->destroy( draw
->pipeline
.twoside
);
89 if (draw
->pipeline
.offset
)
90 draw
->pipeline
.offset
->destroy( draw
->pipeline
.offset
);
91 if (draw
->pipeline
.clip
)
92 draw
->pipeline
.clip
->destroy( draw
->pipeline
.clip
);
93 if (draw
->pipeline
.flatshade
)
94 draw
->pipeline
.flatshade
->destroy( draw
->pipeline
.flatshade
);
95 if (draw
->pipeline
.cull
)
96 draw
->pipeline
.cull
->destroy( draw
->pipeline
.cull
);
97 if (draw
->pipeline
.validate
)
98 draw
->pipeline
.validate
->destroy( draw
->pipeline
.validate
);
99 if (draw
->pipeline
.aaline
)
100 draw
->pipeline
.aaline
->destroy( draw
->pipeline
.aaline
);
101 if (draw
->pipeline
.aapoint
)
102 draw
->pipeline
.aapoint
->destroy( draw
->pipeline
.aapoint
);
103 if (draw
->pipeline
.pstipple
)
104 draw
->pipeline
.pstipple
->destroy( draw
->pipeline
.pstipple
);
105 if (draw
->pipeline
.rasterize
)
106 draw
->pipeline
.rasterize
->destroy( draw
->pipeline
.rasterize
);
112 * Build primitive to render a point with vertex at v0.
114 static void do_point( struct draw_context
*draw
,
117 struct prim_header prim
;
121 prim
.v
[0] = (struct vertex_header
*)v0
;
123 draw
->pipeline
.first
->point( draw
->pipeline
.first
, &prim
);
128 * Build primitive to render a line with vertices at v0, v1.
129 * \param flags bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE
131 static void do_line( struct draw_context
*draw
,
136 struct prim_header prim
;
140 prim
.v
[0] = (struct vertex_header
*)v0
;
141 prim
.v
[1] = (struct vertex_header
*)v1
;
143 draw
->pipeline
.first
->line( draw
->pipeline
.first
, &prim
);
148 * Build primitive to render a triangle with vertices at v0, v1, v2.
149 * \param flags bitmask of DRAW_PIPE_EDGE_x, DRAW_PIPE_RESET_STIPPLE
151 static void do_triangle( struct draw_context
*draw
,
157 struct prim_header prim
;
159 prim
.v
[0] = (struct vertex_header
*)v0
;
160 prim
.v
[1] = (struct vertex_header
*)v1
;
161 prim
.v
[2] = (struct vertex_header
*)v2
;
165 draw
->pipeline
.first
->tri( draw
->pipeline
.first
, &prim
);
170 * Set up macros for draw_pt_decompose.h template code.
171 * This code uses vertex indexes / elements.
173 #define QUAD(i0,i1,i2,i3) \
175 ( DRAW_PIPE_RESET_STIPPLE | \
176 DRAW_PIPE_EDGE_FLAG_0 | \
177 DRAW_PIPE_EDGE_FLAG_2 ), \
178 verts + stride * elts[i0], \
179 verts + stride * elts[i1], \
180 verts + stride * elts[i3]); \
182 ( DRAW_PIPE_EDGE_FLAG_0 | \
183 DRAW_PIPE_EDGE_FLAG_1 ), \
184 verts + stride * elts[i1], \
185 verts + stride * elts[i2], \
186 verts + stride * elts[i3])
188 #define TRIANGLE(flags,i0,i1,i2) \
190 elts[i0], /* flags */ \
191 verts + stride * (elts[i0] & ~DRAW_PIPE_FLAG_MASK), \
192 verts + stride * (elts[i1] & ~DRAW_PIPE_FLAG_MASK), \
193 verts + stride * (elts[i2] & ~DRAW_PIPE_FLAG_MASK) );
195 #define LINE(flags,i0,i1) \
198 verts + stride * (elts[i0] & ~DRAW_PIPE_FLAG_MASK), \
199 verts + stride * (elts[i1] & ~DRAW_PIPE_FLAG_MASK) );
203 verts + stride * elts[i0] )
205 #define FUNC pipe_run
207 struct draw_context *draw, \
209 struct vertex_header *vertices, \
214 char *verts = (char *)vertices; \
215 boolean flatfirst = (draw->rasterizer->flatshade && \
216 draw->rasterizer->flatshade_first); \
222 #include "draw_pt_decompose.h"
229 * Code to run the pipeline on a fairly arbitrary collection of vertices.
230 * For drawing indexed primitives.
232 * Vertex headers must be pre-initialized with the
233 * UNDEFINED_VERTEX_ID, this code will cause that id to become
234 * overwritten, so it may have to be reset if there is the intention
235 * to reuse the vertices.
237 * This code provides a callback to reset the vertex id's which the
238 * draw_vbuf.c code uses when it has to perform a flush.
240 void draw_pipeline_run( struct draw_context
*draw
,
242 struct vertex_header
*vertices
,
243 unsigned vertex_count
,
248 char *verts
= (char *)vertices
;
250 draw
->pipeline
.verts
= verts
;
251 draw
->pipeline
.vertex_stride
= stride
;
252 draw
->pipeline
.vertex_count
= vertex_count
;
254 pipe_run(draw
, prim
, vertices
, stride
, elts
, count
);
256 draw
->pipeline
.verts
= NULL
;
257 draw
->pipeline
.vertex_count
= 0;
263 * Set up macros for draw_pt_decompose.h template code.
264 * This code is for non-indexed rendering (no elts).
266 #define QUAD(i0,i1,i2,i3) \
268 ( DRAW_PIPE_RESET_STIPPLE | \
269 DRAW_PIPE_EDGE_FLAG_0 | \
270 DRAW_PIPE_EDGE_FLAG_2 ), \
271 verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK), \
272 verts + stride * (i1), \
273 verts + stride * (i3)); \
275 ( DRAW_PIPE_EDGE_FLAG_0 | \
276 DRAW_PIPE_EDGE_FLAG_1 ), \
277 verts + stride * ((i1) & ~DRAW_PIPE_FLAG_MASK), \
278 verts + stride * (i2), \
279 verts + stride * (i3))
281 #define TRIANGLE(flags,i0,i1,i2) \
284 verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK), \
285 verts + stride * (i1), \
286 verts + stride * (i2))
288 #define LINE(flags,i0,i1) \
291 verts + stride * ((i0) & ~DRAW_PIPE_FLAG_MASK), \
292 verts + stride * (i1))
296 verts + stride * i0 )
298 #define FUNC pipe_run_linear
300 struct draw_context *draw, \
302 struct vertex_header *vertices, \
306 char *verts = (char *)vertices; \
307 boolean flatfirst = (draw->rasterizer->flatshade && \
308 draw->rasterizer->flatshade_first); \
314 #include "draw_pt_decompose.h"
318 * For drawing non-indexed primitives.
320 void draw_pipeline_run_linear( struct draw_context
*draw
,
322 struct vertex_header
*vertices
,
326 char *verts
= (char *)vertices
;
327 draw
->pipeline
.verts
= verts
;
328 draw
->pipeline
.vertex_stride
= stride
;
329 draw
->pipeline
.vertex_count
= count
;
331 pipe_run_linear(draw
, prim
, vertices
, stride
, count
);
333 draw
->pipeline
.verts
= NULL
;
334 draw
->pipeline
.vertex_count
= 0;
338 void draw_pipeline_flush( struct draw_context
*draw
,
341 draw
->pipeline
.first
->flush( draw
->pipeline
.first
, flags
);
342 draw
->pipeline
.first
= draw
->pipeline
.validate
;