9633469df1cc1eabfee205319b7a28e2ad3b3db6
1 /* $Id: ss_triangle.c,v 1.19 2002/10/29 20:29:00 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "tnl/t_context.h"
37 #include "ss_triangle.h"
38 #include "ss_context.h"
40 #define SS_RGBA_BIT 0x1
41 #define SS_OFFSET_BIT 0x2
42 #define SS_TWOSIDE_BIT 0x4
43 #define SS_UNFILLED_BIT 0x8
44 #define SS_MAX_TRIFUNC 0x10
46 static triangle_func tri_tab
[SS_MAX_TRIFUNC
];
47 static quad_func quad_tab
[SS_MAX_TRIFUNC
];
50 static void _swsetup_render_line_tri( GLcontext
*ctx
,
51 GLuint e0
, GLuint e1
, GLuint e2
)
53 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
54 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
55 GLubyte
*ef
= VB
->EdgeFlag
;
56 SWvertex
*verts
= swsetup
->verts
;
57 SWvertex
*v0
= &verts
[e0
];
58 SWvertex
*v1
= &verts
[e1
];
59 SWvertex
*v2
= &verts
[e2
];
64 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
65 COPY_CHAN4(c
[0], v0
->color
);
66 COPY_CHAN4(c
[1], v1
->color
);
67 COPY_CHAN4(s
[0], v0
->specular
);
68 COPY_CHAN4(s
[1], v1
->specular
);
72 COPY_CHAN4(v0
->color
, v2
->color
);
73 COPY_CHAN4(v1
->color
, v2
->color
);
74 COPY_CHAN4(v0
->specular
, v2
->specular
);
75 COPY_CHAN4(v1
->specular
, v2
->specular
);
76 v0
->index
= v2
->index
;
77 v1
->index
= v2
->index
;
80 if (swsetup
->render_prim
== GL_POLYGON
) {
81 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
82 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
83 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
85 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
86 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
87 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
90 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
91 COPY_CHAN4(v0
->color
, c
[0]);
92 COPY_CHAN4(v1
->color
, c
[1]);
93 COPY_CHAN4(v0
->specular
, s
[0]);
94 COPY_CHAN4(v1
->specular
, s
[1]);
100 static void _swsetup_render_point_tri( GLcontext
*ctx
,
101 GLuint e0
, GLuint e1
, GLuint e2
)
103 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
104 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
105 GLubyte
*ef
= VB
->EdgeFlag
;
106 SWvertex
*verts
= swsetup
->verts
;
107 SWvertex
*v0
= &verts
[e0
];
108 SWvertex
*v1
= &verts
[e1
];
109 SWvertex
*v2
= &verts
[e2
];
114 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
115 COPY_CHAN4(c
[0], v0
->color
);
116 COPY_CHAN4(c
[1], v1
->color
);
117 COPY_CHAN4(s
[0], v0
->specular
);
118 COPY_CHAN4(s
[1], v1
->specular
);
122 COPY_CHAN4(v0
->color
, v2
->color
);
123 COPY_CHAN4(v1
->color
, v2
->color
);
124 COPY_CHAN4(v0
->specular
, v2
->specular
);
125 COPY_CHAN4(v1
->specular
, v2
->specular
);
126 v0
->index
= v2
->index
;
127 v1
->index
= v2
->index
;
130 if (ef
[e0
]) _swrast_Point( ctx
, v0
);
131 if (ef
[e1
]) _swrast_Point( ctx
, v1
);
132 if (ef
[e2
]) _swrast_Point( ctx
, v2
);
134 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
135 COPY_CHAN4(v0
->color
, c
[0]);
136 COPY_CHAN4(v1
->color
, c
[1]);
137 COPY_CHAN4(v0
->specular
, s
[0]);
138 COPY_CHAN4(v1
->specular
, s
[1]);
145 #define SS_COLOR(a,b) COPY_CHAN4(a,b)
146 #define SS_SPEC(a,b) COPY_3V(a,b)
147 #define SS_IND(a,b) (a = b)
151 #include "ss_tritmp.h"
153 #define IND (SS_OFFSET_BIT)
154 #define TAG(x) x##_offset
155 #include "ss_tritmp.h"
157 #define IND (SS_TWOSIDE_BIT)
158 #define TAG(x) x##_twoside
159 #include "ss_tritmp.h"
161 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
162 #define TAG(x) x##_offset_twoside
163 #include "ss_tritmp.h"
165 #define IND (SS_UNFILLED_BIT)
166 #define TAG(x) x##_unfilled
167 #include "ss_tritmp.h"
169 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
170 #define TAG(x) x##_offset_unfilled
171 #include "ss_tritmp.h"
173 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
174 #define TAG(x) x##_twoside_unfilled
175 #include "ss_tritmp.h"
177 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
178 #define TAG(x) x##_offset_twoside_unfilled
179 #include "ss_tritmp.h"
181 #define IND (0|SS_RGBA_BIT)
182 #define TAG(x) x##_rgba
183 #include "ss_tritmp.h"
185 #define IND (SS_OFFSET_BIT|SS_RGBA_BIT)
186 #define TAG(x) x##_offset_rgba
187 #include "ss_tritmp.h"
189 #define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT)
190 #define TAG(x) x##_twoside_rgba
191 #include "ss_tritmp.h"
193 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT)
194 #define TAG(x) x##_offset_twoside_rgba
195 #include "ss_tritmp.h"
197 #define IND (SS_UNFILLED_BIT|SS_RGBA_BIT)
198 #define TAG(x) x##_unfilled_rgba
199 #include "ss_tritmp.h"
201 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
202 #define TAG(x) x##_offset_unfilled_rgba
203 #include "ss_tritmp.h"
205 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
206 #define TAG(x) x##_twoside_unfilled_rgba
207 #include "ss_tritmp.h"
209 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
210 #define TAG(x) x##_offset_twoside_unfilled_rgba
211 #include "ss_tritmp.h"
214 void _swsetup_trifuncs_init( GLcontext
*ctx
)
221 init_offset_twoside();
223 init_offset_unfilled();
224 init_twoside_unfilled();
225 init_offset_twoside_unfilled();
230 init_offset_twoside_rgba();
231 init_unfilled_rgba();
232 init_offset_unfilled_rgba();
233 init_twoside_unfilled_rgba();
234 init_offset_twoside_unfilled_rgba();
238 static void swsetup_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
240 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
241 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
245 for (i
= first
; i
< last
; i
++)
246 if (VB
->ClipMask
[VB
->Elts
[i
]] == 0)
247 _swrast_Point( ctx
, &verts
[VB
->Elts
[i
]] );
250 for (i
= first
; i
< last
; i
++)
251 if (VB
->ClipMask
[i
] == 0)
252 _swrast_Point( ctx
, &verts
[i
] );
256 static void swsetup_line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
258 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
259 _swrast_Line( ctx
, &verts
[v0
], &verts
[v1
] );
264 void _swsetup_choose_trifuncs( GLcontext
*ctx
)
266 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
269 if (ctx
->Polygon
.OffsetPoint
||
270 ctx
->Polygon
.OffsetLine
||
271 ctx
->Polygon
.OffsetFill
)
272 ind
|= SS_OFFSET_BIT
;
274 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
275 ind
|= SS_TWOSIDE_BIT
;
277 /* We piggyback the two-sided stencil front/back determination on the
278 * unfilled triangle path.
280 if ((ctx
->_TriangleCaps
& DD_TRI_UNFILLED
) ||
281 (ctx
->Stencil
.Enabled
&& ctx
->Stencil
.TestTwoSide
))
282 ind
|= SS_UNFILLED_BIT
;
284 if (ctx
->Visual
.rgbMode
)
287 tnl
->Driver
.Render
.Triangle
= tri_tab
[ind
];
288 tnl
->Driver
.Render
.Quad
= quad_tab
[ind
];
289 tnl
->Driver
.Render
.Line
= swsetup_line
;
290 tnl
->Driver
.Render
.Points
= swsetup_points
;