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 "main/imports.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
;
58 static void unfilled_begin( struct draw_stage
*stage
)
60 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
62 unfilled
->mode
[0] = stage
->draw
->setup
.fill_ccw
; /* front */
63 unfilled
->mode
[1] = stage
->draw
->setup
.fill_cw
; /* back */
65 stage
->next
->begin( stage
->next
);
68 static void point( struct draw_stage
*stage
,
69 struct vertex_header
*v0
)
71 struct prim_header tmp
;
73 stage
->next
->point( stage
->next
, &tmp
);
76 static void line( struct draw_stage
*stage
,
77 struct vertex_header
*v0
,
78 struct vertex_header
*v1
)
80 struct prim_header tmp
;
83 stage
->next
->line( stage
->next
, &tmp
);
87 static void points( struct draw_stage
*stage
,
88 struct prim_header
*header
)
90 struct vertex_header
*v0
= header
->v
[0];
91 struct vertex_header
*v1
= header
->v
[1];
92 struct vertex_header
*v2
= header
->v
[2];
94 if (v0
->edgeflag
) point( stage
, v0
);
95 if (v1
->edgeflag
) point( stage
, v1
);
96 if (v2
->edgeflag
) point( stage
, v2
);
100 static void lines( struct draw_stage
*stage
,
101 struct prim_header
*header
)
103 struct vertex_header
*v0
= header
->v
[0];
104 struct vertex_header
*v1
= header
->v
[1];
105 struct vertex_header
*v2
= header
->v
[2];
107 if (v0
->edgeflag
) line( stage
, v0
, v1
);
108 if (v1
->edgeflag
) line( stage
, v1
, v2
);
109 if (v2
->edgeflag
) line( stage
, v2
, v0
);
115 * Note edgeflags in the vertex struct is not sufficient as we will
116 * need to manipulate them when decomposing primitives???
118 static void unfilled_tri( struct draw_stage
*stage
,
119 struct prim_header
*header
)
121 struct unfilled_stage
*unfilled
= unfilled_stage(stage
);
122 GLuint mode
= unfilled
->mode
[header
->det
> 0.0];
125 case PIPE_POLYGON_MODE_FILL
:
126 stage
->next
->tri( stage
->next
, header
);
128 case PIPE_POLYGON_MODE_LINE
:
129 lines( stage
, header
);
131 case PIPE_POLYGON_MODE_POINT
:
132 points( stage
, header
);
139 static void unfilled_line( struct draw_stage
*stage
,
140 struct prim_header
*header
)
142 stage
->next
->line( stage
->next
, header
);
146 static void unfilled_point( struct draw_stage
*stage
,
147 struct prim_header
*header
)
149 stage
->next
->point( stage
->next
, header
);
153 static void unfilled_end( struct draw_stage
*stage
)
155 stage
->next
->end( stage
->next
);
160 * Create unfilled triangle stage.
162 struct draw_stage
*draw_unfilled_stage( struct draw_context
*draw
)
164 struct unfilled_stage
*unfilled
= CALLOC_STRUCT(unfilled_stage
);
166 draw_alloc_tmps( &unfilled
->stage
, 0 );
168 unfilled
->stage
.draw
= draw
;
169 unfilled
->stage
.next
= NULL
;
170 unfilled
->stage
.tmp
= NULL
;
171 unfilled
->stage
.begin
= unfilled_begin
;
172 unfilled
->stage
.point
= unfilled_point
;
173 unfilled
->stage
.line
= unfilled_line
;
174 unfilled
->stage
.tri
= unfilled_tri
;
175 unfilled
->stage
.end
= unfilled_end
;
177 return &unfilled
->stage
;