2 * Mesa 3-D graphics library
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keithw@valinux.com>
33 #include "tnl/t_context.h"
35 #include "ss_triangle.h"
36 #include "ss_context.h"
38 #define SS_RGBA_BIT 0x1
39 #define SS_OFFSET_BIT 0x2
40 #define SS_TWOSIDE_BIT 0x4
41 #define SS_UNFILLED_BIT 0x8
42 #define SS_MAX_TRIFUNC 0x10
44 static triangle_func tri_tab
[SS_MAX_TRIFUNC
];
45 static quad_func quad_tab
[SS_MAX_TRIFUNC
];
48 static void _swsetup_render_line_tri( GLcontext
*ctx
,
49 GLuint e0
, GLuint e1
, GLuint e2
)
51 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
52 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
53 GLubyte
*ef
= VB
->EdgeFlag
;
54 SWvertex
*verts
= swsetup
->verts
;
55 SWvertex
*v0
= &verts
[e0
];
56 SWvertex
*v1
= &verts
[e1
];
57 SWvertex
*v2
= &verts
[e2
];
62 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
63 COPY_CHAN4(c
[0], v0
->color
);
64 COPY_CHAN4(c
[1], v1
->color
);
65 COPY_CHAN4(s
[0], v0
->specular
);
66 COPY_CHAN4(s
[1], v1
->specular
);
70 COPY_CHAN4(v0
->color
, v2
->color
);
71 COPY_CHAN4(v1
->color
, v2
->color
);
72 COPY_CHAN4(v0
->specular
, v2
->specular
);
73 COPY_CHAN4(v1
->specular
, v2
->specular
);
74 v0
->index
= v2
->index
;
75 v1
->index
= v2
->index
;
78 if (swsetup
->render_prim
== GL_POLYGON
) {
79 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
80 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
81 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
83 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
84 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
85 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
88 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
89 COPY_CHAN4(v0
->color
, c
[0]);
90 COPY_CHAN4(v1
->color
, c
[1]);
91 COPY_CHAN4(v0
->specular
, s
[0]);
92 COPY_CHAN4(v1
->specular
, s
[1]);
98 static void _swsetup_render_point_tri( GLcontext
*ctx
,
99 GLuint e0
, GLuint e1
, GLuint e2
)
101 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
102 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
103 GLubyte
*ef
= VB
->EdgeFlag
;
104 SWvertex
*verts
= swsetup
->verts
;
105 SWvertex
*v0
= &verts
[e0
];
106 SWvertex
*v1
= &verts
[e1
];
107 SWvertex
*v2
= &verts
[e2
];
112 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
113 COPY_CHAN4(c
[0], v0
->color
);
114 COPY_CHAN4(c
[1], v1
->color
);
115 COPY_CHAN4(s
[0], v0
->specular
);
116 COPY_CHAN4(s
[1], v1
->specular
);
120 COPY_CHAN4(v0
->color
, v2
->color
);
121 COPY_CHAN4(v1
->color
, v2
->color
);
122 COPY_CHAN4(v0
->specular
, v2
->specular
);
123 COPY_CHAN4(v1
->specular
, v2
->specular
);
124 v0
->index
= v2
->index
;
125 v1
->index
= v2
->index
;
128 if (ef
[e0
]) _swrast_Point( ctx
, v0
);
129 if (ef
[e1
]) _swrast_Point( ctx
, v1
);
130 if (ef
[e2
]) _swrast_Point( ctx
, v2
);
132 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
133 COPY_CHAN4(v0
->color
, c
[0]);
134 COPY_CHAN4(v1
->color
, c
[1]);
135 COPY_CHAN4(v0
->specular
, s
[0]);
136 COPY_CHAN4(v1
->specular
, s
[1]);
142 #define SS_COLOR(a,b) COPY_4UBV(a,b)
143 #define SS_SPEC(a,b) COPY_4UBV(a,b)
144 #define SS_IND(a,b) (a = b)
148 #include "ss_tritmp.h"
150 #define IND (SS_OFFSET_BIT)
151 #define TAG(x) x##_offset
152 #include "ss_tritmp.h"
154 #define IND (SS_TWOSIDE_BIT)
155 #define TAG(x) x##_twoside
156 #include "ss_tritmp.h"
158 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
159 #define TAG(x) x##_offset_twoside
160 #include "ss_tritmp.h"
162 #define IND (SS_UNFILLED_BIT)
163 #define TAG(x) x##_unfilled
164 #include "ss_tritmp.h"
166 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
167 #define TAG(x) x##_offset_unfilled
168 #include "ss_tritmp.h"
170 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
171 #define TAG(x) x##_twoside_unfilled
172 #include "ss_tritmp.h"
174 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
175 #define TAG(x) x##_offset_twoside_unfilled
176 #include "ss_tritmp.h"
178 #define IND (0|SS_RGBA_BIT)
179 #define TAG(x) x##_rgba
180 #include "ss_tritmp.h"
182 #define IND (SS_OFFSET_BIT|SS_RGBA_BIT)
183 #define TAG(x) x##_offset_rgba
184 #include "ss_tritmp.h"
186 #define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT)
187 #define TAG(x) x##_twoside_rgba
188 #include "ss_tritmp.h"
190 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT)
191 #define TAG(x) x##_offset_twoside_rgba
192 #include "ss_tritmp.h"
194 #define IND (SS_UNFILLED_BIT|SS_RGBA_BIT)
195 #define TAG(x) x##_unfilled_rgba
196 #include "ss_tritmp.h"
198 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
199 #define TAG(x) x##_offset_unfilled_rgba
200 #include "ss_tritmp.h"
202 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
203 #define TAG(x) x##_twoside_unfilled_rgba
204 #include "ss_tritmp.h"
206 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
207 #define TAG(x) x##_offset_twoside_unfilled_rgba
208 #include "ss_tritmp.h"
211 void _swsetup_trifuncs_init( GLcontext
*ctx
)
218 init_offset_twoside();
220 init_offset_unfilled();
221 init_twoside_unfilled();
222 init_offset_twoside_unfilled();
227 init_offset_twoside_rgba();
228 init_unfilled_rgba();
229 init_offset_unfilled_rgba();
230 init_twoside_unfilled_rgba();
231 init_offset_twoside_unfilled_rgba();
235 static void swsetup_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
237 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
238 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
242 for (i
= first
; i
< last
; i
++)
243 if (VB
->ClipMask
[VB
->Elts
[i
]] == 0)
244 _swrast_Point( ctx
, &verts
[VB
->Elts
[i
]] );
247 for (i
= first
; i
< last
; i
++)
248 if (VB
->ClipMask
[i
] == 0)
249 _swrast_Point( ctx
, &verts
[i
] );
253 static void swsetup_line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
255 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
256 _swrast_Line( ctx
, &verts
[v0
], &verts
[v1
] );
261 void _swsetup_choose_trifuncs( GLcontext
*ctx
)
263 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
266 if (ctx
->Polygon
._OffsetAny
)
267 ind
|= SS_OFFSET_BIT
;
269 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
270 ind
|= SS_TWOSIDE_BIT
;
272 if (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
)
273 ind
|= SS_UNFILLED_BIT
;
275 if (ctx
->Visual
.rgbMode
)
278 swsetup
->Triangle
= tri_tab
[ind
];
279 swsetup
->Quad
= quad_tab
[ind
];
280 swsetup
->Line
= swsetup_line
;
281 swsetup
->Points
= swsetup_points
;