draw: move some pipeline-specific code & state to draw_pipe.[ch]
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe.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 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "pipe/p_util.h"
34 #include "draw/draw_private.h"
35 #include "draw/draw_pipe.h"
36
37
38 boolean draw_pipeline_init( struct draw_context *draw )
39 {
40 /* create pipeline stages */
41 draw->pipeline.wide_line = draw_wide_line_stage( draw );
42 draw->pipeline.wide_point = draw_wide_point_stage( draw );
43 draw->pipeline.stipple = draw_stipple_stage( draw );
44 draw->pipeline.unfilled = draw_unfilled_stage( draw );
45 draw->pipeline.twoside = draw_twoside_stage( draw );
46 draw->pipeline.offset = draw_offset_stage( draw );
47 draw->pipeline.clip = draw_clip_stage( draw );
48 draw->pipeline.flatshade = draw_flatshade_stage( draw );
49 draw->pipeline.cull = draw_cull_stage( draw );
50 draw->pipeline.validate = draw_validate_stage( draw );
51 draw->pipeline.first = draw->pipeline.validate;
52
53 if (!draw->pipeline.wide_line ||
54 !draw->pipeline.wide_point ||
55 !draw->pipeline.stipple ||
56 !draw->pipeline.unfilled ||
57 !draw->pipeline.twoside ||
58 !draw->pipeline.offset ||
59 !draw->pipeline.clip ||
60 !draw->pipeline.flatshade ||
61 !draw->pipeline.cull ||
62 !draw->pipeline.validate)
63 return FALSE;
64
65 /* these defaults are oriented toward the needs of softpipe */
66 draw->pipeline.wide_point_threshold = 1000000.0; /* infinity */
67 draw->pipeline.wide_line_threshold = 1.0;
68 draw->pipeline.line_stipple = TRUE;
69 draw->pipeline.point_sprite = TRUE;
70
71 return TRUE;
72 }
73
74
75 void draw_pipeline_destroy( struct draw_context *draw )
76 {
77 if (draw->pipeline.wide_line)
78 draw->pipeline.wide_line->destroy( draw->pipeline.wide_line );
79 if (draw->pipeline.wide_point)
80 draw->pipeline.wide_point->destroy( draw->pipeline.wide_point );
81 if (draw->pipeline.stipple)
82 draw->pipeline.stipple->destroy( draw->pipeline.stipple );
83 if (draw->pipeline.unfilled)
84 draw->pipeline.unfilled->destroy( draw->pipeline.unfilled );
85 if (draw->pipeline.twoside)
86 draw->pipeline.twoside->destroy( draw->pipeline.twoside );
87 if (draw->pipeline.offset)
88 draw->pipeline.offset->destroy( draw->pipeline.offset );
89 if (draw->pipeline.clip)
90 draw->pipeline.clip->destroy( draw->pipeline.clip );
91 if (draw->pipeline.flatshade)
92 draw->pipeline.flatshade->destroy( draw->pipeline.flatshade );
93 if (draw->pipeline.cull)
94 draw->pipeline.cull->destroy( draw->pipeline.cull );
95 if (draw->pipeline.validate)
96 draw->pipeline.validate->destroy( draw->pipeline.validate );
97 if (draw->pipeline.aaline)
98 draw->pipeline.aaline->destroy( draw->pipeline.aaline );
99 if (draw->pipeline.aapoint)
100 draw->pipeline.aapoint->destroy( draw->pipeline.aapoint );
101 if (draw->pipeline.pstipple)
102 draw->pipeline.pstipple->destroy( draw->pipeline.pstipple );
103 if (draw->pipeline.rasterize)
104 draw->pipeline.rasterize->destroy( draw->pipeline.rasterize );
105 }
106
107
108
109
110 /* This is only used for temporary verts.
111 */
112 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
113
114
115 /**
116 * Allocate space for temporary post-transform vertices, such as for clipping.
117 */
118 void draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr )
119 {
120 assert(!stage->tmp);
121
122 stage->nr_tmps = nr;
123
124 if (nr) {
125 ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr );
126 unsigned i;
127
128 stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );
129
130 for (i = 0; i < nr; i++)
131 stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
132 }
133 }
134
135
136 void draw_free_temp_verts( struct draw_stage *stage )
137 {
138 if (stage->tmp) {
139 FREE( stage->tmp[0] );
140 FREE( stage->tmp );
141 stage->tmp = NULL;
142 }
143 }
144
145 void draw_reset_vertex_ids(struct draw_context *draw)
146 {
147 struct draw_stage *stage = draw->pipeline.first;
148
149 while (stage) {
150 unsigned i;
151
152 for (i = 0; i < stage->nr_tmps; i++)
153 stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID;
154
155 stage = stage->next;
156 }
157
158 draw_pt_reset_vertex_ids(draw);
159 }
160
161