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 **************************************************************************/
29 * \brief Drawing stage for handling glPolygonMode(line/point).
30 * Convert triangles to points or lines as needed.
33 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
36 #include "pipe/p_util.h"
37 #include "pipe/p_defines.h"
38 #include "draw_private.h"
41 struct unfilled_stage
{
42 struct draw_stage stage
;
44 /** [0] = front face, [1] = back face.
45 * legal values: PIPE_POLYGON_MODE_FILL, PIPE_POLYGON_MODE_LINE,
46 * and PIPE_POLYGON_MODE_POINT,
52 static INLINE
struct unfilled_stage
*unfilled_stage( struct draw_stage
*stage
)
54 return (struct unfilled_stage
*)stage
;
59 static void point( struct draw_stage
*stage
,
60 struct vertex_header
*v0
)
62 struct prim_header tmp
;
64 stage
->next
->point( stage
->next
, &tmp
);
67 static void line( struct draw_stage
*stage
,
68 struct vertex_header
*v0
,
69 struct vertex_header
*v1
)
71 struct prim_header tmp
;
74 stage
->next
->line( stage
->next
, &tmp
);
78 static void points( struct draw_stage
*stage
,
79 struct prim_header
*header
)
81 struct vertex_header
*v0
= header
->v
[0];
82 struct vertex_header
*v1
= header
->v
[1];
83 struct vertex_header
*v2
= header
->v
[2];
85 if (header
->edgeflags
& 0x1) point( stage
, v0
);
86 if (header
->edgeflags
& 0x2) point( stage
, v1
);
87 if (header
->edgeflags
& 0x4) point( stage
, v2
);
91 static void lines( struct draw_stage
*stage
,
92 struct prim_header
*header
)
94 struct vertex_header
*v0
= header
->v
[0];
95 struct vertex_header
*v1
= header
->v
[1];
96 struct vertex_header
*v2
= header
->v
[2];
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
);
104 if (header
->edgeflags
& 0x1) line( stage
, v0
, v1
);
105 if (header
->edgeflags
& 0x2) line( stage
, v1
, v2
);
106 if (header
->edgeflags
& 0x4) line( stage
, v2
, v0
);
112 * Note edgeflags in the vertex struct is not sufficient as we will
113 * need to manipulate them when decomposing primitives???
115 static void unfilled_tri( struct draw_stage
*stage
,
116 struct prim_header
*header
)
118 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
119 unsigned mode
= unfilled
->mode
[header
->det
>= 0.0];
122 case PIPE_POLYGON_MODE_FILL
:
123 stage
->next
->tri( stage
->next
, header
);
125 case PIPE_POLYGON_MODE_LINE
:
126 lines( stage
, header
);
128 case PIPE_POLYGON_MODE_POINT
:
129 points( stage
, header
);
137 static void unfilled_first_tri( struct draw_stage
*stage
,
138 struct prim_header
*header
)
140 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
142 unfilled
->mode
[0] = stage
->draw
->rasterizer
->fill_ccw
; /* front */
143 unfilled
->mode
[1] = stage
->draw
->rasterizer
->fill_cw
; /* back */
145 stage
->tri
= unfilled_tri
;
146 stage
->tri( stage
, header
);
150 static void unfilled_line( struct draw_stage
*stage
,
151 struct prim_header
*header
)
153 stage
->next
->line( stage
->next
, header
);
157 static void unfilled_point( struct draw_stage
*stage
,
158 struct prim_header
*header
)
160 stage
->next
->point( stage
->next
, header
);
164 static void unfilled_flush( struct draw_stage
*stage
,
167 stage
->next
->flush( stage
->next
, flags
);
169 stage
->tri
= unfilled_first_tri
;
173 static void unfilled_reset_stipple_counter( struct draw_stage
*stage
)
175 stage
->next
->reset_stipple_counter( stage
->next
);
179 static void unfilled_destroy( struct draw_stage
*stage
)
181 draw_free_temp_verts( stage
);
187 * Create unfilled triangle stage.
189 struct draw_stage
*draw_unfilled_stage( struct draw_context
*draw
)
191 struct unfilled_stage
*unfilled
= CALLOC_STRUCT(unfilled_stage
);
193 draw_alloc_temp_verts( &unfilled
->stage
, 0 );
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
;
205 return &unfilled
->stage
;