b041c32ef5c1dac6992a5bd1d4c4a47f66c5d4a7
3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "tnl/t_context.h"
36 #include "ss_triangle.h"
37 #include "ss_context.h"
39 #define SS_RGBA_BIT 0x1
40 #define SS_OFFSET_BIT 0x2
41 #define SS_TWOSIDE_BIT 0x4
42 #define SS_UNFILLED_BIT 0x8
43 #define SS_MAX_TRIFUNC 0x10
45 static triangle_func tri_tab
[SS_MAX_TRIFUNC
];
46 static quad_func quad_tab
[SS_MAX_TRIFUNC
];
49 static void _swsetup_render_line_tri( GLcontext
*ctx
,
50 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
];
65 if (ctx
->Polygon
.CullFlag
) {
66 if (facing
== 1 && ctx
->Polygon
.CullFaceMode
!= GL_FRONT
)
68 if (facing
== 0 && ctx
->Polygon
.CullFaceMode
!= GL_BACK
)
72 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
73 COPY_CHAN4(c
[0], v0
->color
);
74 COPY_CHAN4(c
[1], v1
->color
);
75 COPY_CHAN4(s
[0], v0
->specular
);
76 COPY_CHAN4(s
[1], v1
->specular
);
80 COPY_CHAN4(v0
->color
, v2
->color
);
81 COPY_CHAN4(v1
->color
, v2
->color
);
82 COPY_CHAN4(v0
->specular
, v2
->specular
);
83 COPY_CHAN4(v1
->specular
, v2
->specular
);
84 v0
->index
= v2
->index
;
85 v1
->index
= v2
->index
;
88 if (swsetup
->render_prim
== GL_POLYGON
) {
89 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
90 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
91 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
93 if (ef
[e0
]) _swrast_Line( ctx
, v0
, v1
);
94 if (ef
[e1
]) _swrast_Line( ctx
, v1
, v2
);
95 if (ef
[e2
]) _swrast_Line( ctx
, v2
, v0
);
98 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
99 COPY_CHAN4(v0
->color
, c
[0]);
100 COPY_CHAN4(v1
->color
, c
[1]);
101 COPY_CHAN4(v0
->specular
, s
[0]);
102 COPY_CHAN4(v1
->specular
, s
[1]);
108 static void _swsetup_render_point_tri( GLcontext
*ctx
,
109 GLuint e0
, GLuint e1
, GLuint e2
,
112 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
113 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
114 GLubyte
*ef
= VB
->EdgeFlag
;
115 SWvertex
*verts
= swsetup
->verts
;
116 SWvertex
*v0
= &verts
[e0
];
117 SWvertex
*v1
= &verts
[e1
];
118 SWvertex
*v2
= &verts
[e2
];
124 if (ctx
->Polygon
.CullFlag
) {
125 if (facing
== 1 && ctx
->Polygon
.CullFaceMode
!= GL_FRONT
)
127 if (facing
== 0 && ctx
->Polygon
.CullFaceMode
!= GL_BACK
)
131 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
132 COPY_CHAN4(c
[0], v0
->color
);
133 COPY_CHAN4(c
[1], v1
->color
);
134 COPY_CHAN4(s
[0], v0
->specular
);
135 COPY_CHAN4(s
[1], v1
->specular
);
139 COPY_CHAN4(v0
->color
, v2
->color
);
140 COPY_CHAN4(v1
->color
, v2
->color
);
141 COPY_CHAN4(v0
->specular
, v2
->specular
);
142 COPY_CHAN4(v1
->specular
, v2
->specular
);
143 v0
->index
= v2
->index
;
144 v1
->index
= v2
->index
;
147 if (ef
[e0
]) _swrast_Point( ctx
, v0
);
148 if (ef
[e1
]) _swrast_Point( ctx
, v1
);
149 if (ef
[e2
]) _swrast_Point( ctx
, v2
);
151 if (ctx
->_TriangleCaps
& DD_FLATSHADE
) {
152 COPY_CHAN4(v0
->color
, c
[0]);
153 COPY_CHAN4(v1
->color
, c
[1]);
154 COPY_CHAN4(v0
->specular
, s
[0]);
155 COPY_CHAN4(v1
->specular
, s
[1]);
162 #define SS_COLOR(a,b) COPY_CHAN4(a,b)
163 #define SS_SPEC(a,b) COPY_3V(a,b)
164 #define SS_IND(a,b) (a = b)
168 #include "ss_tritmp.h"
170 #define IND (SS_OFFSET_BIT)
171 #define TAG(x) x##_offset
172 #include "ss_tritmp.h"
174 #define IND (SS_TWOSIDE_BIT)
175 #define TAG(x) x##_twoside
176 #include "ss_tritmp.h"
178 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
179 #define TAG(x) x##_offset_twoside
180 #include "ss_tritmp.h"
182 #define IND (SS_UNFILLED_BIT)
183 #define TAG(x) x##_unfilled
184 #include "ss_tritmp.h"
186 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
187 #define TAG(x) x##_offset_unfilled
188 #include "ss_tritmp.h"
190 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
191 #define TAG(x) x##_twoside_unfilled
192 #include "ss_tritmp.h"
194 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
195 #define TAG(x) x##_offset_twoside_unfilled
196 #include "ss_tritmp.h"
198 #define IND (0|SS_RGBA_BIT)
199 #define TAG(x) x##_rgba
200 #include "ss_tritmp.h"
202 #define IND (SS_OFFSET_BIT|SS_RGBA_BIT)
203 #define TAG(x) x##_offset_rgba
204 #include "ss_tritmp.h"
206 #define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT)
207 #define TAG(x) x##_twoside_rgba
208 #include "ss_tritmp.h"
210 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT)
211 #define TAG(x) x##_offset_twoside_rgba
212 #include "ss_tritmp.h"
214 #define IND (SS_UNFILLED_BIT|SS_RGBA_BIT)
215 #define TAG(x) x##_unfilled_rgba
216 #include "ss_tritmp.h"
218 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
219 #define TAG(x) x##_offset_unfilled_rgba
220 #include "ss_tritmp.h"
222 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
223 #define TAG(x) x##_twoside_unfilled_rgba
224 #include "ss_tritmp.h"
226 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
227 #define TAG(x) x##_offset_twoside_unfilled_rgba
228 #include "ss_tritmp.h"
231 void _swsetup_trifuncs_init( GLcontext
*ctx
)
238 init_offset_twoside();
240 init_offset_unfilled();
241 init_twoside_unfilled();
242 init_offset_twoside_unfilled();
247 init_offset_twoside_rgba();
248 init_unfilled_rgba();
249 init_offset_unfilled_rgba();
250 init_twoside_unfilled_rgba();
251 init_offset_twoside_unfilled_rgba();
255 static void swsetup_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
257 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
258 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
262 for (i
= first
; i
< last
; i
++)
263 if (VB
->ClipMask
[VB
->Elts
[i
]] == 0)
264 _swrast_Point( ctx
, &verts
[VB
->Elts
[i
]] );
267 for (i
= first
; i
< last
; i
++)
268 if (VB
->ClipMask
[i
] == 0)
269 _swrast_Point( ctx
, &verts
[i
] );
273 static void swsetup_line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
275 SWvertex
*verts
= SWSETUP_CONTEXT(ctx
)->verts
;
276 _swrast_Line( ctx
, &verts
[v0
], &verts
[v1
] );
281 void _swsetup_choose_trifuncs( GLcontext
*ctx
)
283 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
286 if (ctx
->Polygon
.OffsetPoint
||
287 ctx
->Polygon
.OffsetLine
||
288 ctx
->Polygon
.OffsetFill
)
289 ind
|= SS_OFFSET_BIT
;
291 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
292 ind
|= SS_TWOSIDE_BIT
;
294 /* We piggyback the two-sided stencil front/back determination on the
295 * unfilled triangle path.
297 if ((ctx
->_TriangleCaps
& DD_TRI_UNFILLED
) ||
298 (ctx
->Stencil
.Enabled
&& ctx
->Stencil
.TestTwoSide
))
299 ind
|= SS_UNFILLED_BIT
;
301 if (ctx
->Visual
.rgbMode
)
304 tnl
->Driver
.Render
.Triangle
= tri_tab
[ind
];
305 tnl
->Driver
.Render
.Quad
= quad_tab
[ind
];
306 tnl
->Driver
.Render
.Line
= swsetup_line
;
307 tnl
->Driver
.Render
.Points
= swsetup_points
;