gallium: added draw_need_pipeline() predicate function
[mesa.git] / src / gallium / auxiliary / draw / draw_unfilled.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 * \brief Drawing stage for handling glPolygonMode(line/point).
30 * Convert triangles to points or lines as needed.
31 */
32
33 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "pipe/p_util.h"
37 #include "pipe/p_defines.h"
38 #include "draw_private.h"
39
40
41 struct unfilled_stage {
42 struct draw_stage stage;
43
44 /** [0] = front face, [1] = back face.
45 * legal values: PIPE_POLYGON_MODE_FILL, PIPE_POLYGON_MODE_LINE,
46 * and PIPE_POLYGON_MODE_POINT,
47 */
48 unsigned mode[2];
49 };
50
51
52 static INLINE struct unfilled_stage *unfilled_stage( struct draw_stage *stage )
53 {
54 return (struct unfilled_stage *)stage;
55 }
56
57
58
59 static void point( struct draw_stage *stage,
60 struct vertex_header *v0 )
61 {
62 struct prim_header tmp;
63 tmp.v[0] = v0;
64 stage->next->point( stage->next, &tmp );
65 }
66
67 static void line( struct draw_stage *stage,
68 struct vertex_header *v0,
69 struct vertex_header *v1 )
70 {
71 struct prim_header tmp;
72 tmp.v[0] = v0;
73 tmp.v[1] = v1;
74 stage->next->line( stage->next, &tmp );
75 }
76
77
78 static void points( struct draw_stage *stage,
79 struct prim_header *header )
80 {
81 struct vertex_header *v0 = header->v[0];
82 struct vertex_header *v1 = header->v[1];
83 struct vertex_header *v2 = header->v[2];
84
85 if (header->edgeflags & 0x1) point( stage, v0 );
86 if (header->edgeflags & 0x2) point( stage, v1 );
87 if (header->edgeflags & 0x4) point( stage, v2 );
88 }
89
90
91 static void lines( struct draw_stage *stage,
92 struct prim_header *header )
93 {
94 struct vertex_header *v0 = header->v[0];
95 struct vertex_header *v1 = header->v[1];
96 struct vertex_header *v2 = header->v[2];
97
98 #if 0
99 assert(((header->edgeflags & 0x1) >> 0) == header->v[0]->edgeflag);
100 assert(((header->edgeflags & 0x2) >> 1) == header->v[1]->edgeflag);
101 assert(((header->edgeflags & 0x4) >> 2) == header->v[2]->edgeflag);
102 #endif
103
104 if (header->edgeflags & 0x4) line( stage, v2, v0 );
105 if (header->edgeflags & 0x1) line( stage, v0, v1 );
106 if (header->edgeflags & 0x2) line( stage, v1, v2 );
107 }
108
109
110 /* Unfilled tri:
111 *
112 * Note edgeflags in the vertex struct is not sufficient as we will
113 * need to manipulate them when decomposing primitives???
114 */
115 static void unfilled_tri( struct draw_stage *stage,
116 struct prim_header *header )
117 {
118 struct unfilled_stage *unfilled = unfilled_stage(stage);
119 unsigned mode = unfilled->mode[header->det >= 0.0];
120
121 switch (mode) {
122 case PIPE_POLYGON_MODE_FILL:
123 stage->next->tri( stage->next, header );
124 break;
125 case PIPE_POLYGON_MODE_LINE:
126 lines( stage, header );
127 break;
128 case PIPE_POLYGON_MODE_POINT:
129 points( stage, header );
130 break;
131 default:
132 assert(0);
133 }
134 }
135
136
137 static void unfilled_first_tri( struct draw_stage *stage,
138 struct prim_header *header )
139 {
140 struct unfilled_stage *unfilled = unfilled_stage(stage);
141
142 unfilled->mode[0] = stage->draw->rasterizer->fill_ccw; /* front */
143 unfilled->mode[1] = stage->draw->rasterizer->fill_cw; /* back */
144
145 stage->tri = unfilled_tri;
146 stage->tri( stage, header );
147 }
148
149
150 static void unfilled_line( struct draw_stage *stage,
151 struct prim_header *header )
152 {
153 stage->next->line( stage->next, header );
154 }
155
156
157 static void unfilled_point( struct draw_stage *stage,
158 struct prim_header *header )
159 {
160 stage->next->point( stage->next, header );
161 }
162
163
164 static void unfilled_flush( struct draw_stage *stage,
165 unsigned flags )
166 {
167 stage->next->flush( stage->next, flags );
168
169 stage->tri = unfilled_first_tri;
170 }
171
172
173 static void unfilled_reset_stipple_counter( struct draw_stage *stage )
174 {
175 stage->next->reset_stipple_counter( stage->next );
176 }
177
178
179 static void unfilled_destroy( struct draw_stage *stage )
180 {
181 draw_free_temp_verts( stage );
182 FREE( stage );
183 }
184
185
186 /**
187 * Create unfilled triangle stage.
188 */
189 struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
190 {
191 struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
192
193 draw_alloc_temp_verts( &unfilled->stage, 0 );
194
195 unfilled->stage.draw = draw;
196 unfilled->stage.next = NULL;
197 unfilled->stage.tmp = NULL;
198 unfilled->stage.point = unfilled_point;
199 unfilled->stage.line = unfilled_line;
200 unfilled->stage.tri = unfilled_first_tri;
201 unfilled->stage.flush = unfilled_flush;
202 unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
203 unfilled->stage.destroy = unfilled_destroy;
204
205 return &unfilled->stage;
206 }