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 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
31 #include "pipe/p_util.h"
32 #include "draw_private.h"
35 static void flatshade_begin( struct draw_stage
*stage
)
37 stage
->next
->begin( stage
->next
);
42 static INLINE
void copy_attr( unsigned attr
,
43 struct vertex_header
*dst
,
44 const struct vertex_header
*src
)
47 memcpy( dst
->data
[attr
],
49 sizeof(src
->data
[0]) );
54 static INLINE
void copy_colors( struct draw_stage
*stage
,
55 struct vertex_header
*dst
,
56 const struct vertex_header
*src
)
58 const uint num_attribs
= stage
->draw
->vertex_info
.num_attribs
;
59 const enum interp_mode
*interp
= stage
->draw
->vertex_info
.interp_mode
;
62 /* Look for constant/flat attribs and duplicate from src to dst vertex */
63 /* skip attrib[0] which is vert pos */
64 for (i
= 1; i
< num_attribs
; i
++) {
65 if (interp
[i
] == INTERP_CONSTANT
) {
66 copy_attr( i
, dst
, src
);
73 * Flatshade tri. Required for clipping and when unfilled tris are
74 * active, otherwise handled by hardware.
76 static void flatshade_tri( struct draw_stage
*stage
,
77 struct prim_header
*header
)
79 struct prim_header tmp
;
81 tmp
.det
= header
->det
;
82 tmp
.edgeflags
= header
->edgeflags
;
83 tmp
.v
[0] = dup_vert(stage
, header
->v
[0], 0);
84 tmp
.v
[1] = dup_vert(stage
, header
->v
[1], 1);
85 tmp
.v
[2] = header
->v
[2];
87 copy_colors(stage
, tmp
.v
[0], tmp
.v
[2]);
88 copy_colors(stage
, tmp
.v
[1], tmp
.v
[2]);
90 stage
->next
->tri( stage
->next
, &tmp
);
95 * Flatshade line. Required for clipping.
97 static void flatshade_line( struct draw_stage
*stage
,
98 struct prim_header
*header
)
100 struct prim_header tmp
;
102 tmp
.v
[0] = dup_vert(stage
, header
->v
[0], 0);
103 tmp
.v
[1] = header
->v
[1];
105 copy_colors(stage
, tmp
.v
[0], tmp
.v
[1]);
107 stage
->next
->line( stage
->next
, &tmp
);
111 static void flatshade_point( struct draw_stage
*stage
,
112 struct prim_header
*header
)
114 stage
->next
->point( stage
->next
, header
);
118 static void flatshade_end( struct draw_stage
*stage
)
120 stage
->next
->end( stage
->next
);
124 static void flatshade_reset_stipple_counter( struct draw_stage
*stage
)
126 stage
->next
->reset_stipple_counter( stage
->next
);
131 * Create flatshading drawing stage.
133 struct draw_stage
*draw_flatshade_stage( struct draw_context
*draw
)
135 struct draw_stage
*flatshade
= CALLOC_STRUCT(draw_stage
);
137 draw_alloc_tmps( flatshade
, 2 );
139 flatshade
->draw
= draw
;
140 flatshade
->next
= NULL
;
141 flatshade
->begin
= flatshade_begin
;
142 flatshade
->point
= flatshade_point
;
143 flatshade
->line
= flatshade_line
;
144 flatshade
->tri
= flatshade_tri
;
145 flatshade
->end
= flatshade_end
;
146 flatshade
->reset_stipple_counter
= flatshade_reset_stipple_counter
;