Merge branch 'master' of git+ssh://michal@git.freedesktop.org/git/mesa/mesa into...
[mesa.git] / src / mesa / pipe / 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 "main/imports.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 GLuint 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 static void unfilled_begin( struct draw_stage *stage )
59 {
60 struct unfilled_stage *unfilled = unfilled_stage(stage);
61
62 unfilled->mode[0] = stage->draw->setup.fill_ccw; /* front */
63 unfilled->mode[1] = stage->draw->setup.fill_cw; /* back */
64
65 stage->next->begin( stage->next );
66 }
67
68 static void point( struct draw_stage *stage,
69 struct vertex_header *v0 )
70 {
71 struct prim_header tmp;
72 tmp.v[0] = v0;
73 stage->next->point( stage->next, &tmp );
74 }
75
76 static void line( struct draw_stage *stage,
77 struct vertex_header *v0,
78 struct vertex_header *v1 )
79 {
80 struct prim_header tmp;
81 tmp.v[0] = v0;
82 tmp.v[1] = v1;
83 stage->next->line( stage->next, &tmp );
84 }
85
86
87 static void points( struct draw_stage *stage,
88 struct prim_header *header )
89 {
90 struct vertex_header *v0 = header->v[0];
91 struct vertex_header *v1 = header->v[1];
92 struct vertex_header *v2 = header->v[2];
93
94 if (v0->edgeflag) point( stage, v0 );
95 if (v1->edgeflag) point( stage, v1 );
96 if (v2->edgeflag) point( stage, v2 );
97 }
98
99
100 static void lines( struct draw_stage *stage,
101 struct prim_header *header )
102 {
103 struct vertex_header *v0 = header->v[0];
104 struct vertex_header *v1 = header->v[1];
105 struct vertex_header *v2 = header->v[2];
106
107 if (v0->edgeflag) line( stage, v0, v1 );
108 if (v1->edgeflag) line( stage, v1, v2 );
109 if (v2->edgeflag) line( stage, v2, v0 );
110 }
111
112
113 /* Unfilled tri:
114 *
115 * Note edgeflags in the vertex struct is not sufficient as we will
116 * need to manipulate them when decomposing primitives???
117 */
118 static void unfilled_tri( struct draw_stage *stage,
119 struct prim_header *header )
120 {
121 struct unfilled_stage *unfilled = unfilled_stage(stage);
122 GLuint mode = unfilled->mode[header->det > 0.0];
123
124 switch (mode) {
125 case PIPE_POLYGON_MODE_FILL:
126 stage->next->tri( stage->next, header );
127 break;
128 case PIPE_POLYGON_MODE_LINE:
129 lines( stage, header );
130 break;
131 case PIPE_POLYGON_MODE_POINT:
132 points( stage, header );
133 break;
134 default:
135 abort();
136 }
137 }
138
139 static void unfilled_line( struct draw_stage *stage,
140 struct prim_header *header )
141 {
142 stage->next->line( stage->next, header );
143 }
144
145
146 static void unfilled_point( struct draw_stage *stage,
147 struct prim_header *header )
148 {
149 stage->next->point( stage->next, header );
150 }
151
152
153 static void unfilled_end( struct draw_stage *stage )
154 {
155 stage->next->end( stage->next );
156 }
157
158
159 static void unfilled_reset_stipple_counter( struct draw_stage *stage )
160 {
161 stage->next->reset_stipple_counter( stage->next );
162 }
163
164
165 /**
166 * Create unfilled triangle stage.
167 */
168 struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
169 {
170 struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
171
172 draw_alloc_tmps( &unfilled->stage, 0 );
173
174 unfilled->stage.draw = draw;
175 unfilled->stage.next = NULL;
176 unfilled->stage.tmp = NULL;
177 unfilled->stage.begin = unfilled_begin;
178 unfilled->stage.point = unfilled_point;
179 unfilled->stage.line = unfilled_line;
180 unfilled->stage.tri = unfilled_tri;
181 unfilled->stage.end = unfilled_end;
182 unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
183
184 return &unfilled->stage;
185 }