gallium: Use MALLOC().
[mesa.git] / src / mesa / tnl_dd / t_dd_tritmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28
29 /* Template for building functions to plug into the driver interface
30 * of t_vb_render.c:
31 * ctx->Driver.QuadFunc
32 * ctx->Driver.TriangleFunc
33 * ctx->Driver.LineFunc
34 * ctx->Driver.PointsFunc
35 *
36 * DO_TWOSIDE: Plug back-color values from the VB into backfacing triangles,
37 * and restore vertices afterwards.
38 * DO_OFFSET: Calculate offset for triangles and adjust vertices. Restore
39 * vertices after rendering.
40 * DO_FLAT: For hardware without native flatshading, copy provoking colors
41 * into the other vertices. Restore after rendering.
42 * DO_UNFILLED: Decompose triangles to lines and points where appropriate.
43 * DO_TWOSTENCIL:Gross hack for two-sided stencil.
44 *
45 * HAVE_RGBA: Vertices have rgba values (otherwise index values).
46 * HAVE_SPEC: Vertices have secondary rgba values.
47 *
48 * VERT_X(v): Alias for vertex x value.
49 * VERT_Y(v): Alias for vertex y value.
50 * VERT_Z(v): Alias for vertex z value.
51 * DEPTH_SCALE: Scale for constant offset.
52 * REVERSE_DEPTH: Viewport depth range reversed.
53 *
54 * VERTEX: Hardware vertex type.
55 * GET_VERTEX(n): Retreive vertex with index n.
56 * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw.
57 *
58 * VERT_SET_RGBA: Assign vertex rgba from VB color.
59 * VERT_COPY_RGBA: Copy vertex rgba another vertex.
60 * VERT_SAVE_RGBA: Save vertex rgba to a local variable.
61 * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable.
62 * --> Similar for IND and SPEC.
63 *
64 * LOCAL_VARS(n): (At least) define local vars for save/restore rgba.
65 *
66 */
67
68 #if HAVE_RGBA
69 #define VERT_SET_IND( v, c ) (void) c
70 #define VERT_COPY_IND( v0, v1 )
71 #define VERT_SAVE_IND( idx )
72 #define VERT_RESTORE_IND( idx )
73 #if HAVE_BACK_COLORS
74 #define VERT_SET_RGBA( v, c )
75 #endif
76 #else
77 #define VERT_SET_RGBA( v, c ) (void) c
78 #define VERT_COPY_RGBA( v0, v1 )
79 #define VERT_SAVE_RGBA( idx )
80 #define VERT_RESTORE_RGBA( idx )
81 #if HAVE_BACK_COLORS
82 #define VERT_SET_IND( v, c )
83 #endif
84 #endif
85
86 #if !HAVE_SPEC
87 #define VERT_SET_SPEC( v, c ) (void) c
88 #define VERT_COPY_SPEC( v0, v1 )
89 #define VERT_SAVE_SPEC( idx )
90 #define VERT_RESTORE_SPEC( idx )
91 #if HAVE_BACK_COLORS
92 #define VERT_COPY_SPEC1( v )
93 #endif
94 #else
95 #if HAVE_BACK_COLORS
96 #define VERT_SET_SPEC( v, c )
97 #endif
98 #endif
99
100 #if !HAVE_BACK_COLORS
101 #define VERT_COPY_SPEC1( v )
102 #define VERT_COPY_IND1( v )
103 #define VERT_COPY_RGBA1( v )
104 #endif
105
106 #ifndef INSANE_VERTICES
107 #define VERT_SET_Z(v,val) VERT_Z(v) = val
108 #define VERT_Z_ADD(v,val) VERT_Z(v) += val
109 #endif
110
111 #ifndef REVERSE_DEPTH
112 #define REVERSE_DEPTH 0
113 #endif
114
115 /* disable twostencil for un-aware drivers */
116 #ifndef HAVE_STENCIL_TWOSIDE
117 #define HAVE_STENCIL_TWOSIDE 0
118 #endif
119 #ifndef DO_TWOSTENCIL
120 #define DO_TWOSTENCIL 0
121 #endif
122 #ifndef SETUP_STENCIL
123 #define SETUP_STENCIL(f)
124 #endif
125 #ifndef UNSET_STENCIL
126 #define UNSET_STENCIL(f)
127 #endif
128
129 #if DO_TRI
130 static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
131 {
132 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
133 VERTEX *v[3];
134 GLfloat offset = 0;
135 GLfloat z[3];
136 GLenum mode = GL_FILL;
137 GLuint facing = 0;
138 LOCAL_VARS(3);
139
140 /* fprintf(stderr, "%s\n", __FUNCTION__); */
141
142 v[0] = (VERTEX *)GET_VERTEX(e0);
143 v[1] = (VERTEX *)GET_VERTEX(e1);
144 v[2] = (VERTEX *)GET_VERTEX(e2);
145
146 if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
147 {
148 GLfloat ex = VERT_X(v[0]) - VERT_X(v[2]);
149 GLfloat ey = VERT_Y(v[0]) - VERT_Y(v[2]);
150 GLfloat fx = VERT_X(v[1]) - VERT_X(v[2]);
151 GLfloat fy = VERT_Y(v[1]) - VERT_Y(v[2]);
152 GLfloat cc = ex*fy - ey*fx;
153
154 if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
155 {
156 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
157
158 if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
159 ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
160 }
161
162 if (DO_UNFILLED) {
163 if (facing) {
164 mode = ctx->Polygon.BackMode;
165 if (ctx->Polygon.CullFlag &&
166 ctx->Polygon.CullFaceMode != GL_FRONT) {
167 return;
168 }
169 } else {
170 mode = ctx->Polygon.FrontMode;
171 if (ctx->Polygon.CullFlag &&
172 ctx->Polygon.CullFaceMode != GL_BACK) {
173 return;
174 }
175 }
176 }
177
178 if (DO_TWOSIDE && facing == 1)
179 {
180 if (HAVE_RGBA) {
181 if (HAVE_BACK_COLORS) {
182 if (!DO_FLAT) {
183 VERT_SAVE_RGBA( 0 );
184 VERT_SAVE_RGBA( 1 );
185 VERT_COPY_RGBA1( v[0] );
186 VERT_COPY_RGBA1( v[1] );
187 }
188 VERT_SAVE_RGBA( 2 );
189 VERT_COPY_RGBA1( v[2] );
190 if (HAVE_SPEC) {
191 if (!DO_FLAT) {
192 VERT_SAVE_SPEC( 0 );
193 VERT_SAVE_SPEC( 1 );
194 VERT_COPY_SPEC1( v[0] );
195 VERT_COPY_SPEC1( v[1] );
196 }
197 VERT_SAVE_SPEC( 2 );
198 VERT_COPY_SPEC1( v[2] );
199 }
200 }
201 else {
202 GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
203 (void) vbcolor;
204
205 if (!DO_FLAT) {
206 VERT_SAVE_RGBA( 0 );
207 VERT_SAVE_RGBA( 1 );
208 }
209 VERT_SAVE_RGBA( 2 );
210
211 if (VB->ColorPtr[1]->stride) {
212 ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLfloat));
213
214 if (!DO_FLAT) {
215 VERT_SET_RGBA( v[0], vbcolor[e0] );
216 VERT_SET_RGBA( v[1], vbcolor[e1] );
217 }
218 VERT_SET_RGBA( v[2], vbcolor[e2] );
219 }
220 else {
221 if (!DO_FLAT) {
222 VERT_SET_RGBA( v[0], vbcolor[0] );
223 VERT_SET_RGBA( v[1], vbcolor[0] );
224 }
225 VERT_SET_RGBA( v[2], vbcolor[0] );
226 }
227
228 if (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
229 GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
230 ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLfloat));
231
232 if (!DO_FLAT) {
233 VERT_SAVE_SPEC( 0 );
234 VERT_SAVE_SPEC( 1 );
235 VERT_SET_SPEC( v[0], vbspec[e0] );
236 VERT_SET_SPEC( v[1], vbspec[e1] );
237 }
238 VERT_SAVE_SPEC( 2 );
239 VERT_SET_SPEC( v[2], vbspec[e2] );
240 }
241 }
242 }
243 else {
244 GLfloat (*vbindex) = (GLfloat *)VB->IndexPtr[1]->data;
245 if (!DO_FLAT) {
246 VERT_SAVE_IND( 0 );
247 VERT_SAVE_IND( 1 );
248 VERT_SET_IND( v[0], vbindex[e0] );
249 VERT_SET_IND( v[1], vbindex[e1] );
250 }
251 VERT_SAVE_IND( 2 );
252 VERT_SET_IND( v[2], vbindex[e2] );
253 }
254 }
255 }
256
257
258 if (DO_OFFSET)
259 {
260 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
261 z[0] = VERT_Z(v[0]);
262 z[1] = VERT_Z(v[1]);
263 z[2] = VERT_Z(v[2]);
264 if (cc * cc > 1e-16) {
265 GLfloat ic = 1.0 / cc;
266 GLfloat ez = z[0] - z[2];
267 GLfloat fz = z[1] - z[2];
268 GLfloat a = ey*fz - ez*fy;
269 GLfloat b = ez*fx - ex*fz;
270 GLfloat ac = a * ic;
271 GLfloat bc = b * ic;
272 if ( ac < 0.0f ) ac = -ac;
273 if ( bc < 0.0f ) bc = -bc;
274 offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
275 }
276 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
277 }
278 }
279
280 if (DO_FLAT) {
281 if (HAVE_RGBA) {
282 VERT_SAVE_RGBA( 0 );
283 VERT_SAVE_RGBA( 1 );
284 VERT_COPY_RGBA( v[0], v[2] );
285 VERT_COPY_RGBA( v[1], v[2] );
286 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
287 VERT_SAVE_SPEC( 0 );
288 VERT_SAVE_SPEC( 1 );
289 VERT_COPY_SPEC( v[0], v[2] );
290 VERT_COPY_SPEC( v[1], v[2] );
291 }
292 }
293 else {
294 VERT_SAVE_IND( 0 );
295 VERT_SAVE_IND( 1 );
296 VERT_COPY_IND( v[0], v[2] );
297 VERT_COPY_IND( v[1], v[2] );
298 }
299 }
300
301 if (mode == GL_POINT) {
302 if (DO_OFFSET && ctx->Polygon.OffsetPoint) {
303 VERT_Z_ADD(v[0], offset);
304 VERT_Z_ADD(v[1], offset);
305 VERT_Z_ADD(v[2], offset);
306 }
307 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
308 SETUP_STENCIL(facing);
309 UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
310 UNSET_STENCIL(facing);
311 } else {
312 UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
313 }
314 } else if (mode == GL_LINE) {
315 if (DO_OFFSET && ctx->Polygon.OffsetLine) {
316 VERT_Z_ADD(v[0], offset);
317 VERT_Z_ADD(v[1], offset);
318 VERT_Z_ADD(v[2], offset);
319 }
320 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
321 SETUP_STENCIL(facing);
322 UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
323 UNSET_STENCIL(facing);
324 } else {
325 UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
326 }
327 } else {
328 if (DO_OFFSET && ctx->Polygon.OffsetFill) {
329 VERT_Z_ADD(v[0], offset);
330 VERT_Z_ADD(v[1], offset);
331 VERT_Z_ADD(v[2], offset);
332 }
333 if (DO_UNFILLED)
334 RASTERIZE( GL_TRIANGLES );
335 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
336 SETUP_STENCIL(facing);
337 TRI( v[0], v[1], v[2] );
338 UNSET_STENCIL(facing);
339 } else {
340 TRI( v[0], v[1], v[2] );
341 }
342 }
343
344 if (DO_OFFSET)
345 {
346 VERT_SET_Z(v[0], z[0]);
347 VERT_SET_Z(v[1], z[1]);
348 VERT_SET_Z(v[2], z[2]);
349 }
350
351 if (DO_TWOSIDE && facing == 1)
352 {
353 if (HAVE_RGBA) {
354 if (!DO_FLAT) {
355 VERT_RESTORE_RGBA( 0 );
356 VERT_RESTORE_RGBA( 1 );
357 }
358 VERT_RESTORE_RGBA( 2 );
359 if (HAVE_SPEC) {
360 if (!DO_FLAT) {
361 VERT_RESTORE_SPEC( 0 );
362 VERT_RESTORE_SPEC( 1 );
363 }
364 VERT_RESTORE_SPEC( 2 );
365 }
366 }
367 else {
368 if (!DO_FLAT) {
369 VERT_RESTORE_IND( 0 );
370 VERT_RESTORE_IND( 1 );
371 }
372 VERT_RESTORE_IND( 2 );
373 }
374 }
375
376
377 if (DO_FLAT) {
378 if (HAVE_RGBA) {
379 VERT_RESTORE_RGBA( 0 );
380 VERT_RESTORE_RGBA( 1 );
381 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
382 VERT_RESTORE_SPEC( 0 );
383 VERT_RESTORE_SPEC( 1 );
384 }
385 }
386 else {
387 VERT_RESTORE_IND( 0 );
388 VERT_RESTORE_IND( 1 );
389 }
390 }
391 }
392 #endif
393
394 #if DO_QUAD
395 #if DO_FULL_QUAD
396 static void TAG(quad)( GLcontext *ctx,
397 GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
398 {
399 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
400 VERTEX *v[4];
401 GLfloat offset = 0;
402 GLfloat z[4];
403 GLenum mode = GL_FILL;
404 GLuint facing = 0;
405 LOCAL_VARS(4);
406
407 v[0] = (VERTEX *)GET_VERTEX(e0);
408 v[1] = (VERTEX *)GET_VERTEX(e1);
409 v[2] = (VERTEX *)GET_VERTEX(e2);
410 v[3] = (VERTEX *)GET_VERTEX(e3);
411
412 if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
413 {
414 GLfloat ex = VERT_X(v[2]) - VERT_X(v[0]);
415 GLfloat ey = VERT_Y(v[2]) - VERT_Y(v[0]);
416 GLfloat fx = VERT_X(v[3]) - VERT_X(v[1]);
417 GLfloat fy = VERT_Y(v[3]) - VERT_Y(v[1]);
418 GLfloat cc = ex*fy - ey*fx;
419
420 if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
421 {
422 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
423
424 if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
425 ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
426 }
427
428 if (DO_UNFILLED) {
429 if (facing) {
430 mode = ctx->Polygon.BackMode;
431 if (ctx->Polygon.CullFlag &&
432 ctx->Polygon.CullFaceMode != GL_FRONT) {
433 return;
434 }
435 } else {
436 mode = ctx->Polygon.FrontMode;
437 if (ctx->Polygon.CullFlag &&
438 ctx->Polygon.CullFaceMode != GL_BACK) {
439 return;
440 }
441 }
442 }
443
444 if (DO_TWOSIDE && facing == 1)
445 {
446 if (HAVE_RGBA) {
447 GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
448 (void)vbcolor;
449
450 if (HAVE_BACK_COLORS) {
451 if (!DO_FLAT) {
452 VERT_SAVE_RGBA( 0 );
453 VERT_SAVE_RGBA( 1 );
454 VERT_SAVE_RGBA( 2 );
455 VERT_COPY_RGBA1( v[0] );
456 VERT_COPY_RGBA1( v[1] );
457 VERT_COPY_RGBA1( v[2] );
458 }
459 VERT_SAVE_RGBA( 3 );
460 VERT_COPY_RGBA1( v[3] );
461 if (HAVE_SPEC) {
462 if (!DO_FLAT) {
463 VERT_SAVE_SPEC( 0 );
464 VERT_SAVE_SPEC( 1 );
465 VERT_SAVE_SPEC( 2 );
466 VERT_COPY_SPEC1( v[0] );
467 VERT_COPY_SPEC1( v[1] );
468 VERT_COPY_SPEC1( v[2] );
469 }
470 VERT_SAVE_SPEC( 3 );
471 VERT_COPY_SPEC1( v[3] );
472 }
473 }
474 else {
475 if (!DO_FLAT) {
476 VERT_SAVE_RGBA( 0 );
477 VERT_SAVE_RGBA( 1 );
478 VERT_SAVE_RGBA( 2 );
479 }
480 VERT_SAVE_RGBA( 3 );
481
482 if (VB->ColorPtr[1]->stride) {
483 if (!DO_FLAT) {
484 VERT_SET_RGBA( v[0], vbcolor[e0] );
485 VERT_SET_RGBA( v[1], vbcolor[e1] );
486 VERT_SET_RGBA( v[2], vbcolor[e2] );
487 }
488 VERT_SET_RGBA( v[3], vbcolor[e3] );
489 }
490 else {
491 if (!DO_FLAT) {
492 VERT_SET_RGBA( v[0], vbcolor[0] );
493 VERT_SET_RGBA( v[1], vbcolor[0] );
494 VERT_SET_RGBA( v[2], vbcolor[0] );
495 }
496 VERT_SET_RGBA( v[3], vbcolor[0] );
497 }
498
499 if (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
500 GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
501 ASSERT(VB->SecondaryColorPtr[1]->stride==4*sizeof(GLfloat));
502
503 if (!DO_FLAT) {
504 VERT_SAVE_SPEC( 0 );
505 VERT_SAVE_SPEC( 1 );
506 VERT_SAVE_SPEC( 2 );
507 VERT_SET_SPEC( v[0], vbspec[e0] );
508 VERT_SET_SPEC( v[1], vbspec[e1] );
509 VERT_SET_SPEC( v[2], vbspec[e2] );
510 }
511 VERT_SAVE_SPEC( 3 );
512 VERT_SET_SPEC( v[3], vbspec[e3] );
513 }
514 }
515 }
516 else {
517 GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
518 if (!DO_FLAT) {
519 VERT_SAVE_IND( 0 );
520 VERT_SAVE_IND( 1 );
521 VERT_SAVE_IND( 2 );
522 VERT_SET_IND( v[0], vbindex[e0] );
523 VERT_SET_IND( v[1], vbindex[e1] );
524 VERT_SET_IND( v[2], vbindex[e2] );
525 }
526 VERT_SAVE_IND( 3 );
527 VERT_SET_IND( v[3], vbindex[e3] );
528 }
529 }
530 }
531
532
533 if (DO_OFFSET)
534 {
535 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
536 z[0] = VERT_Z(v[0]);
537 z[1] = VERT_Z(v[1]);
538 z[2] = VERT_Z(v[2]);
539 z[3] = VERT_Z(v[3]);
540 if (cc * cc > 1e-16) {
541 GLfloat ez = z[2] - z[0];
542 GLfloat fz = z[3] - z[1];
543 GLfloat a = ey*fz - ez*fy;
544 GLfloat b = ez*fx - ex*fz;
545 GLfloat ic = 1.0 / cc;
546 GLfloat ac = a * ic;
547 GLfloat bc = b * ic;
548 if ( ac < 0.0f ) ac = -ac;
549 if ( bc < 0.0f ) bc = -bc;
550 offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
551 }
552 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
553 }
554 }
555
556 if (DO_FLAT) {
557 if (HAVE_RGBA) {
558 VERT_SAVE_RGBA( 0 );
559 VERT_SAVE_RGBA( 1 );
560 VERT_SAVE_RGBA( 2 );
561 VERT_COPY_RGBA( v[0], v[3] );
562 VERT_COPY_RGBA( v[1], v[3] );
563 VERT_COPY_RGBA( v[2], v[3] );
564 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
565 VERT_SAVE_SPEC( 0 );
566 VERT_SAVE_SPEC( 1 );
567 VERT_SAVE_SPEC( 2 );
568 VERT_COPY_SPEC( v[0], v[3] );
569 VERT_COPY_SPEC( v[1], v[3] );
570 VERT_COPY_SPEC( v[2], v[3] );
571 }
572 }
573 else {
574 VERT_SAVE_IND( 0 );
575 VERT_SAVE_IND( 1 );
576 VERT_SAVE_IND( 2 );
577 VERT_COPY_IND( v[0], v[3] );
578 VERT_COPY_IND( v[1], v[3] );
579 VERT_COPY_IND( v[2], v[3] );
580 }
581 }
582
583 if (mode == GL_POINT) {
584 if (( DO_OFFSET) && ctx->Polygon.OffsetPoint) {
585 VERT_Z_ADD(v[0], offset);
586 VERT_Z_ADD(v[1], offset);
587 VERT_Z_ADD(v[2], offset);
588 VERT_Z_ADD(v[3], offset);
589 }
590 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
591 SETUP_STENCIL(facing);
592 UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
593 UNSET_STENCIL(facing);
594 } else {
595 UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
596 }
597 } else if (mode == GL_LINE) {
598 if (DO_OFFSET && ctx->Polygon.OffsetLine) {
599 VERT_Z_ADD(v[0], offset);
600 VERT_Z_ADD(v[1], offset);
601 VERT_Z_ADD(v[2], offset);
602 VERT_Z_ADD(v[3], offset);
603 }
604 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
605 SETUP_STENCIL(facing);
606 UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
607 UNSET_STENCIL(facing);
608 } else {
609 UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
610 }
611 } else {
612 if (DO_OFFSET && ctx->Polygon.OffsetFill) {
613 VERT_Z_ADD(v[0], offset);
614 VERT_Z_ADD(v[1], offset);
615 VERT_Z_ADD(v[2], offset);
616 VERT_Z_ADD(v[3], offset);
617 }
618 RASTERIZE( GL_QUADS );
619 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
620 SETUP_STENCIL(facing);
621 QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
622 UNSET_STENCIL(facing);
623 } else {
624 QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
625 }
626 }
627
628 if (DO_OFFSET)
629 {
630 VERT_SET_Z(v[0], z[0]);
631 VERT_SET_Z(v[1], z[1]);
632 VERT_SET_Z(v[2], z[2]);
633 VERT_SET_Z(v[3], z[3]);
634 }
635
636 if (DO_TWOSIDE && facing == 1)
637 {
638 if (HAVE_RGBA) {
639 if (!DO_FLAT) {
640 VERT_RESTORE_RGBA( 0 );
641 VERT_RESTORE_RGBA( 1 );
642 VERT_RESTORE_RGBA( 2 );
643 }
644 VERT_RESTORE_RGBA( 3 );
645 if (HAVE_SPEC) {
646 if (!DO_FLAT) {
647 VERT_RESTORE_SPEC( 0 );
648 VERT_RESTORE_SPEC( 1 );
649 VERT_RESTORE_SPEC( 2 );
650 }
651 VERT_RESTORE_SPEC( 3 );
652 }
653 }
654 else {
655 if (!DO_FLAT) {
656 VERT_RESTORE_IND( 0 );
657 VERT_RESTORE_IND( 1 );
658 VERT_RESTORE_IND( 2 );
659 }
660 VERT_RESTORE_IND( 3 );
661 }
662 }
663
664
665 if (DO_FLAT) {
666 if (HAVE_RGBA) {
667 VERT_RESTORE_RGBA( 0 );
668 VERT_RESTORE_RGBA( 1 );
669 VERT_RESTORE_RGBA( 2 );
670 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
671 VERT_RESTORE_SPEC( 0 );
672 VERT_RESTORE_SPEC( 1 );
673 VERT_RESTORE_SPEC( 2 );
674 }
675 }
676 else {
677 VERT_RESTORE_IND( 0 );
678 VERT_RESTORE_IND( 1 );
679 VERT_RESTORE_IND( 2 );
680 }
681 }
682 }
683 #else
684 static void TAG(quad)( GLcontext *ctx, GLuint e0,
685 GLuint e1, GLuint e2, GLuint e3 )
686 {
687 if (DO_UNFILLED) {
688 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
689 GLubyte ef1 = VB->EdgeFlag[e1];
690 GLubyte ef3 = VB->EdgeFlag[e3];
691 VB->EdgeFlag[e1] = 0;
692 TAG(triangle)( ctx, e0, e1, e3 );
693 VB->EdgeFlag[e1] = ef1;
694 VB->EdgeFlag[e3] = 0;
695 TAG(triangle)( ctx, e1, e2, e3 );
696 VB->EdgeFlag[e3] = ef3;
697 } else {
698 TAG(triangle)( ctx, e0, e1, e3 );
699 TAG(triangle)( ctx, e1, e2, e3 );
700 }
701 }
702 #endif
703 #endif
704
705 #if DO_LINE
706 static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
707 {
708 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
709 VERTEX *v[2];
710 LOCAL_VARS(2);
711
712 v[0] = (VERTEX *)GET_VERTEX(e0);
713 v[1] = (VERTEX *)GET_VERTEX(e1);
714
715 if (DO_FLAT) {
716 if (HAVE_RGBA) {
717 VERT_SAVE_RGBA( 0 );
718 VERT_COPY_RGBA( v[0], v[1] );
719 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
720 VERT_SAVE_SPEC( 0 );
721 VERT_COPY_SPEC( v[0], v[1] );
722 }
723 }
724 else {
725 VERT_SAVE_IND( 0 );
726 VERT_COPY_IND( v[0], v[1] );
727 }
728 }
729
730 LINE( v[0], v[1] );
731
732 if (DO_FLAT) {
733 if (HAVE_RGBA) {
734 VERT_RESTORE_RGBA( 0 );
735
736 if (HAVE_SPEC && VB->SecondaryColorPtr[0]) {
737 VERT_RESTORE_SPEC( 0 );
738 }
739 }
740 else {
741 VERT_RESTORE_IND( 0 );
742 }
743 }
744 }
745 #endif
746
747 #if DO_POINTS
748 static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
749 {
750 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
751 GLuint i;
752 LOCAL_VARS(1);
753
754 if (VB->Elts == 0) {
755 for ( i = first ; i < last ; i++ ) {
756 if ( VB->ClipMask[i] == 0 ) {
757 VERTEX *v = (VERTEX *)GET_VERTEX(i);
758 POINT( v );
759 }
760 }
761 } else {
762 for ( i = first ; i < last ; i++ ) {
763 GLuint e = VB->Elts[i];
764 if ( VB->ClipMask[e] == 0 ) {
765 VERTEX *v = (VERTEX *)GET_VERTEX(e);
766 POINT( v );
767 }
768 }
769 }
770 }
771 #endif
772
773 static void TAG(init)( void )
774 {
775 #if DO_QUAD
776 TAB[IND].quad = TAG(quad);
777 #endif
778 #if DO_TRI
779 TAB[IND].triangle = TAG(triangle);
780 #endif
781 #if DO_LINE
782 TAB[IND].line = TAG(line);
783 #endif
784 #if DO_POINTS
785 TAB[IND].points = TAG(points);
786 #endif
787 }
788
789 #undef IND
790 #undef TAG
791
792 #if HAVE_RGBA
793 #undef VERT_SET_IND
794 #undef VERT_COPY_IND
795 #undef VERT_SAVE_IND
796 #undef VERT_RESTORE_IND
797 #if HAVE_BACK_COLORS
798 #undef VERT_SET_RGBA
799 #endif
800 #else
801 #undef VERT_SET_RGBA
802 #undef VERT_COPY_RGBA
803 #undef VERT_SAVE_RGBA
804 #undef VERT_RESTORE_RGBA
805 #if HAVE_BACK_COLORS
806 #undef VERT_SET_IND
807 #endif
808 #endif
809
810 #if !HAVE_SPEC
811 #undef VERT_SET_SPEC
812 #undef VERT_COPY_SPEC
813 #undef VERT_SAVE_SPEC
814 #undef VERT_RESTORE_SPEC
815 #if HAVE_BACK_COLORS
816 #undef VERT_COPY_SPEC1
817 #endif
818 #else
819 #if HAVE_BACK_COLORS
820 #undef VERT_SET_SPEC
821 #endif
822 #endif
823
824 #if !HAVE_BACK_COLORS
825 #undef VERT_COPY_SPEC1
826 #undef VERT_COPY_IND1
827 #undef VERT_COPY_RGBA1
828 #endif
829
830 #ifndef INSANE_VERTICES
831 #undef VERT_SET_Z
832 #undef VERT_Z_ADD
833 #endif