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 "util/u_memory.h"
37 #include "pipe/p_defines.h"
38 #include "draw_private.h"
39 #include "draw_pipe.h"
42 struct unfilled_stage
{
43 struct draw_stage stage
;
45 /** [0] = front face, [1] = back face.
46 * legal values: PIPE_POLYGON_MODE_FILL, PIPE_POLYGON_MODE_LINE,
47 * and PIPE_POLYGON_MODE_POINT,
53 static INLINE
struct unfilled_stage
*unfilled_stage( struct draw_stage
*stage
)
55 return (struct unfilled_stage
*)stage
;
60 static void point( struct draw_stage
*stage
,
61 struct vertex_header
*v0
)
63 struct prim_header tmp
;
65 stage
->next
->point( stage
->next
, &tmp
);
68 static void line( struct draw_stage
*stage
,
69 struct vertex_header
*v0
,
70 struct vertex_header
*v1
)
72 struct prim_header tmp
;
75 stage
->next
->line( stage
->next
, &tmp
);
79 static void points( struct draw_stage
*stage
,
80 struct prim_header
*header
)
82 struct vertex_header
*v0
= header
->v
[0];
83 struct vertex_header
*v1
= header
->v
[1];
84 struct vertex_header
*v2
= header
->v
[2];
86 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_0
) && v0
->edgeflag
) point( stage
, v0
);
87 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_1
) && v1
->edgeflag
) point( stage
, v1
);
88 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_2
) && v2
->edgeflag
) point( stage
, v2
);
92 static void lines( struct draw_stage
*stage
,
93 struct prim_header
*header
)
95 struct vertex_header
*v0
= header
->v
[0];
96 struct vertex_header
*v1
= header
->v
[1];
97 struct vertex_header
*v2
= header
->v
[2];
99 if (header
->flags
& DRAW_PIPE_RESET_STIPPLE
)
100 stage
->next
->reset_stipple_counter( stage
->next
);
102 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_2
) && v2
->edgeflag
) line( stage
, v2
, v0
);
103 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_0
) && v0
->edgeflag
) line( stage
, v0
, v1
);
104 if ((header
->flags
& DRAW_PIPE_EDGE_FLAG_1
) && v1
->edgeflag
) line( stage
, v1
, v2
);
110 * Note edgeflags in the vertex struct is not sufficient as we will
111 * need to manipulate them when decomposing primitives.
113 * We currently keep the vertex edgeflag and primitive edgeflag mask
114 * separate until the last possible moment.
116 static void unfilled_tri( struct draw_stage
*stage
,
117 struct prim_header
*header
)
119 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
120 unsigned mode
= unfilled
->mode
[header
->det
>= 0.0];
123 case PIPE_POLYGON_MODE_FILL
:
124 stage
->next
->tri( stage
->next
, header
);
126 case PIPE_POLYGON_MODE_LINE
:
127 lines( stage
, header
);
129 case PIPE_POLYGON_MODE_POINT
:
130 points( stage
, header
);
138 static void unfilled_first_tri( struct draw_stage
*stage
,
139 struct prim_header
*header
)
141 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
143 unfilled
->mode
[0] = stage
->draw
->rasterizer
->fill_ccw
; /* front */
144 unfilled
->mode
[1] = stage
->draw
->rasterizer
->fill_cw
; /* back */
146 stage
->tri
= unfilled_tri
;
147 stage
->tri( stage
, header
);
152 static void unfilled_flush( struct draw_stage
*stage
,
155 stage
->next
->flush( stage
->next
, flags
);
157 stage
->tri
= unfilled_first_tri
;
161 static void unfilled_reset_stipple_counter( struct draw_stage
*stage
)
163 stage
->next
->reset_stipple_counter( stage
->next
);
167 static void unfilled_destroy( struct draw_stage
*stage
)
169 draw_free_temp_verts( stage
);
175 * Create unfilled triangle stage.
177 struct draw_stage
*draw_unfilled_stage( struct draw_context
*draw
)
179 struct unfilled_stage
*unfilled
= CALLOC_STRUCT(unfilled_stage
);
180 if (unfilled
== NULL
)
183 if (!draw_alloc_temp_verts( &unfilled
->stage
, 0 ))
186 unfilled
->stage
.draw
= draw
;
187 unfilled
->stage
.name
= "unfilled";
188 unfilled
->stage
.next
= NULL
;
189 unfilled
->stage
.tmp
= NULL
;
190 unfilled
->stage
.point
= draw_pipe_passthrough_point
;
191 unfilled
->stage
.line
= draw_pipe_passthrough_line
;
192 unfilled
->stage
.tri
= unfilled_first_tri
;
193 unfilled
->stage
.flush
= unfilled_flush
;
194 unfilled
->stage
.reset_stipple_counter
= unfilled_reset_stipple_counter
;
195 unfilled
->stage
.destroy
= unfilled_destroy
;
197 return &unfilled
->stage
;
201 unfilled
->stage
.destroy( &unfilled
->stage
);