mesa/tnl_dd: Remove color-index support from t_dd_tritmp.h
[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_SPEC: Vertices have secondary rgba values.
46 *
47 * VERT_X(v): Alias for vertex x value.
48 * VERT_Y(v): Alias for vertex y value.
49 * VERT_Z(v): Alias for vertex z value.
50 * DEPTH_SCALE: Scale for constant offset.
51 * REVERSE_DEPTH: Viewport depth range reversed.
52 *
53 * VERTEX: Hardware vertex type.
54 * GET_VERTEX(n): Retreive vertex with index n.
55 * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw.
56 *
57 * VERT_SET_RGBA: Assign vertex rgba from VB color.
58 * VERT_COPY_RGBA: Copy vertex rgba another vertex.
59 * VERT_SAVE_RGBA: Save vertex rgba to a local variable.
60 * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable.
61 * --> Similar for SPEC.
62 *
63 * LOCAL_VARS(n): (At least) define local vars for save/restore rgba.
64 *
65 */
66
67 #if HAVE_BACK_COLORS
68 #define VERT_SET_RGBA( v, c )
69 #endif
70
71 #if !HAVE_SPEC
72 #define VERT_SET_SPEC( v, c ) (void) c
73 #define VERT_COPY_SPEC( v0, v1 )
74 #define VERT_SAVE_SPEC( idx )
75 #define VERT_RESTORE_SPEC( idx )
76 #if HAVE_BACK_COLORS
77 #define VERT_COPY_SPEC1( v )
78 #endif
79 #else
80 #if HAVE_BACK_COLORS
81 #define VERT_SET_SPEC( v, c )
82 #endif
83 #endif
84
85 #if !HAVE_BACK_COLORS
86 #define VERT_COPY_SPEC1( v )
87 #define VERT_COPY_RGBA1( v )
88 #endif
89
90 #ifndef INSANE_VERTICES
91 #define VERT_SET_Z(v,val) VERT_Z(v) = val
92 #define VERT_Z_ADD(v,val) VERT_Z(v) += val
93 #endif
94
95 #ifndef REVERSE_DEPTH
96 #define REVERSE_DEPTH 0
97 #endif
98
99 /* disable twostencil for un-aware drivers */
100 #ifndef HAVE_STENCIL_TWOSIDE
101 #define HAVE_STENCIL_TWOSIDE 0
102 #endif
103 #ifndef DO_TWOSTENCIL
104 #define DO_TWOSTENCIL 0
105 #endif
106 #ifndef SETUP_STENCIL
107 #define SETUP_STENCIL(f)
108 #endif
109 #ifndef UNSET_STENCIL
110 #define UNSET_STENCIL(f)
111 #endif
112
113 #if DO_TRI
114 static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
115 {
116 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
117 VERTEX *v[3];
118 GLfloat offset = 0;
119 GLfloat z[3] = { 0 };
120 GLenum mode = GL_FILL;
121 GLuint facing = 0;
122 LOCAL_VARS(3);
123
124 /* fprintf(stderr, "%s\n", __FUNCTION__); */
125
126 v[0] = (VERTEX *)GET_VERTEX(e0);
127 v[1] = (VERTEX *)GET_VERTEX(e1);
128 v[2] = (VERTEX *)GET_VERTEX(e2);
129
130 if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
131 {
132 GLfloat ex = VERT_X(v[0]) - VERT_X(v[2]);
133 GLfloat ey = VERT_Y(v[0]) - VERT_Y(v[2]);
134 GLfloat fx = VERT_X(v[1]) - VERT_X(v[2]);
135 GLfloat fy = VERT_Y(v[1]) - VERT_Y(v[2]);
136 GLfloat cc = ex*fy - ey*fx;
137
138 if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
139 {
140 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
141
142 if (DO_UNFILLED) {
143 if (facing) {
144 mode = ctx->Polygon.BackMode;
145 if (ctx->Polygon.CullFlag &&
146 ctx->Polygon.CullFaceMode != GL_FRONT) {
147 return;
148 }
149 } else {
150 mode = ctx->Polygon.FrontMode;
151 if (ctx->Polygon.CullFlag &&
152 ctx->Polygon.CullFaceMode != GL_BACK) {
153 return;
154 }
155 }
156 }
157
158 if (DO_TWOSIDE && facing == 1)
159 {
160 if (HAVE_BACK_COLORS) {
161 if (!DO_FLAT) {
162 VERT_SAVE_RGBA( 0 );
163 VERT_SAVE_RGBA( 1 );
164 VERT_COPY_RGBA1( v[0] );
165 VERT_COPY_RGBA1( v[1] );
166 }
167 VERT_SAVE_RGBA( 2 );
168 VERT_COPY_RGBA1( v[2] );
169 if (HAVE_SPEC) {
170 if (!DO_FLAT) {
171 VERT_SAVE_SPEC( 0 );
172 VERT_SAVE_SPEC( 1 );
173 VERT_COPY_SPEC1( v[0] );
174 VERT_COPY_SPEC1( v[1] );
175 }
176 VERT_SAVE_SPEC( 2 );
177 VERT_COPY_SPEC1( v[2] );
178 }
179 }
180 else {
181 GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
182 (void) vbcolor;
183
184 if (!DO_FLAT) {
185 VERT_SAVE_RGBA( 0 );
186 VERT_SAVE_RGBA( 1 );
187 }
188 VERT_SAVE_RGBA( 2 );
189
190 if (VB->BackfaceColorPtr->stride) {
191 ASSERT(VB->BackfaceColorPtr->stride == 4*sizeof(GLfloat));
192
193 if (!DO_FLAT) {
194 VERT_SET_RGBA( v[0], vbcolor[e0] );
195 VERT_SET_RGBA( v[1], vbcolor[e1] );
196 }
197 VERT_SET_RGBA( v[2], vbcolor[e2] );
198 }
199 else {
200 if (!DO_FLAT) {
201 VERT_SET_RGBA( v[0], vbcolor[0] );
202 VERT_SET_RGBA( v[1], vbcolor[0] );
203 }
204 VERT_SET_RGBA( v[2], vbcolor[0] );
205 }
206
207 if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
208 GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
209 ASSERT(VB->BackfaceSecondaryColorPtr->stride == 4*sizeof(GLfloat));
210
211 if (!DO_FLAT) {
212 VERT_SAVE_SPEC( 0 );
213 VERT_SAVE_SPEC( 1 );
214 VERT_SET_SPEC( v[0], vbspec[e0] );
215 VERT_SET_SPEC( v[1], vbspec[e1] );
216 }
217 VERT_SAVE_SPEC( 2 );
218 VERT_SET_SPEC( v[2], vbspec[e2] );
219 }
220 }
221 }
222 }
223
224
225 if (DO_OFFSET)
226 {
227 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
228 z[0] = VERT_Z(v[0]);
229 z[1] = VERT_Z(v[1]);
230 z[2] = VERT_Z(v[2]);
231 if (cc * cc > 1e-16) {
232 GLfloat ic = 1.0 / cc;
233 GLfloat ez = z[0] - z[2];
234 GLfloat fz = z[1] - z[2];
235 GLfloat a = ey*fz - ez*fy;
236 GLfloat b = ez*fx - ex*fz;
237 GLfloat ac = a * ic;
238 GLfloat bc = b * ic;
239 if ( ac < 0.0f ) ac = -ac;
240 if ( bc < 0.0f ) bc = -bc;
241 offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
242 }
243 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
244 }
245 }
246
247 if (DO_FLAT) {
248 VERT_SAVE_RGBA( 0 );
249 VERT_SAVE_RGBA( 1 );
250 VERT_COPY_RGBA( v[0], v[2] );
251 VERT_COPY_RGBA( v[1], v[2] );
252 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
253 VERT_SAVE_SPEC( 0 );
254 VERT_SAVE_SPEC( 1 );
255 VERT_COPY_SPEC( v[0], v[2] );
256 VERT_COPY_SPEC( v[1], v[2] );
257 }
258 }
259
260 if (mode == GL_POINT) {
261 if (DO_OFFSET && ctx->Polygon.OffsetPoint) {
262 VERT_Z_ADD(v[0], offset);
263 VERT_Z_ADD(v[1], offset);
264 VERT_Z_ADD(v[2], offset);
265 }
266 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
267 SETUP_STENCIL(facing);
268 UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
269 UNSET_STENCIL(facing);
270 } else {
271 UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
272 }
273 } else if (mode == GL_LINE) {
274 if (DO_OFFSET && ctx->Polygon.OffsetLine) {
275 VERT_Z_ADD(v[0], offset);
276 VERT_Z_ADD(v[1], offset);
277 VERT_Z_ADD(v[2], offset);
278 }
279 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
280 SETUP_STENCIL(facing);
281 UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
282 UNSET_STENCIL(facing);
283 } else {
284 UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
285 }
286 } else {
287 if (DO_OFFSET && ctx->Polygon.OffsetFill) {
288 VERT_Z_ADD(v[0], offset);
289 VERT_Z_ADD(v[1], offset);
290 VERT_Z_ADD(v[2], offset);
291 }
292 if (DO_UNFILLED)
293 RASTERIZE( GL_TRIANGLES );
294 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
295 SETUP_STENCIL(facing);
296 TRI( v[0], v[1], v[2] );
297 UNSET_STENCIL(facing);
298 } else {
299 TRI( v[0], v[1], v[2] );
300 }
301 }
302
303 if (DO_OFFSET)
304 {
305 VERT_SET_Z(v[0], z[0]);
306 VERT_SET_Z(v[1], z[1]);
307 VERT_SET_Z(v[2], z[2]);
308 }
309
310 if (DO_TWOSIDE && facing == 1)
311 {
312 if (!DO_FLAT) {
313 VERT_RESTORE_RGBA( 0 );
314 VERT_RESTORE_RGBA( 1 );
315 }
316 VERT_RESTORE_RGBA( 2 );
317 if (HAVE_SPEC) {
318 if (!DO_FLAT) {
319 VERT_RESTORE_SPEC( 0 );
320 VERT_RESTORE_SPEC( 1 );
321 }
322 VERT_RESTORE_SPEC( 2 );
323 }
324 }
325
326
327 if (DO_FLAT) {
328 VERT_RESTORE_RGBA( 0 );
329 VERT_RESTORE_RGBA( 1 );
330 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
331 VERT_RESTORE_SPEC( 0 );
332 VERT_RESTORE_SPEC( 1 );
333 }
334 }
335 }
336 #endif
337
338 #if DO_QUAD
339 #if DO_FULL_QUAD
340 static void TAG(quadr)( GLcontext *ctx,
341 GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
342 {
343 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
344 VERTEX *v[4];
345 GLfloat offset = 0;
346 GLfloat z[4] = { 0 };
347 GLenum mode = GL_FILL;
348 GLuint facing = 0;
349 LOCAL_VARS(4);
350
351 v[0] = (VERTEX *)GET_VERTEX(e0);
352 v[1] = (VERTEX *)GET_VERTEX(e1);
353 v[2] = (VERTEX *)GET_VERTEX(e2);
354 v[3] = (VERTEX *)GET_VERTEX(e3);
355
356 if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
357 {
358 GLfloat ex = VERT_X(v[2]) - VERT_X(v[0]);
359 GLfloat ey = VERT_Y(v[2]) - VERT_Y(v[0]);
360 GLfloat fx = VERT_X(v[3]) - VERT_X(v[1]);
361 GLfloat fy = VERT_Y(v[3]) - VERT_Y(v[1]);
362 GLfloat cc = ex*fy - ey*fx;
363
364 if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
365 {
366 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
367
368 if (DO_UNFILLED) {
369 if (facing) {
370 mode = ctx->Polygon.BackMode;
371 if (ctx->Polygon.CullFlag &&
372 ctx->Polygon.CullFaceMode != GL_FRONT) {
373 return;
374 }
375 } else {
376 mode = ctx->Polygon.FrontMode;
377 if (ctx->Polygon.CullFlag &&
378 ctx->Polygon.CullFaceMode != GL_BACK) {
379 return;
380 }
381 }
382 }
383
384 if (DO_TWOSIDE && facing == 1)
385 {
386 GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
387 (void)vbcolor;
388
389 if (HAVE_BACK_COLORS) {
390 if (!DO_FLAT) {
391 VERT_SAVE_RGBA( 0 );
392 VERT_SAVE_RGBA( 1 );
393 VERT_SAVE_RGBA( 2 );
394 VERT_COPY_RGBA1( v[0] );
395 VERT_COPY_RGBA1( v[1] );
396 VERT_COPY_RGBA1( v[2] );
397 }
398 VERT_SAVE_RGBA( 3 );
399 VERT_COPY_RGBA1( v[3] );
400 if (HAVE_SPEC) {
401 if (!DO_FLAT) {
402 VERT_SAVE_SPEC( 0 );
403 VERT_SAVE_SPEC( 1 );
404 VERT_SAVE_SPEC( 2 );
405 VERT_COPY_SPEC1( v[0] );
406 VERT_COPY_SPEC1( v[1] );
407 VERT_COPY_SPEC1( v[2] );
408 }
409 VERT_SAVE_SPEC( 3 );
410 VERT_COPY_SPEC1( v[3] );
411 }
412 }
413 else {
414 if (!DO_FLAT) {
415 VERT_SAVE_RGBA( 0 );
416 VERT_SAVE_RGBA( 1 );
417 VERT_SAVE_RGBA( 2 );
418 }
419 VERT_SAVE_RGBA( 3 );
420
421 if (VB->BackfaceColorPtr->stride) {
422 if (!DO_FLAT) {
423 VERT_SET_RGBA( v[0], vbcolor[e0] );
424 VERT_SET_RGBA( v[1], vbcolor[e1] );
425 VERT_SET_RGBA( v[2], vbcolor[e2] );
426 }
427 VERT_SET_RGBA( v[3], vbcolor[e3] );
428 }
429 else {
430 if (!DO_FLAT) {
431 VERT_SET_RGBA( v[0], vbcolor[0] );
432 VERT_SET_RGBA( v[1], vbcolor[0] );
433 VERT_SET_RGBA( v[2], vbcolor[0] );
434 }
435 VERT_SET_RGBA( v[3], vbcolor[0] );
436 }
437
438 if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
439 GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
440 ASSERT(VB->BackfaceSecondaryColorPtr->stride==4*sizeof(GLfloat));
441
442 if (!DO_FLAT) {
443 VERT_SAVE_SPEC( 0 );
444 VERT_SAVE_SPEC( 1 );
445 VERT_SAVE_SPEC( 2 );
446 VERT_SET_SPEC( v[0], vbspec[e0] );
447 VERT_SET_SPEC( v[1], vbspec[e1] );
448 VERT_SET_SPEC( v[2], vbspec[e2] );
449 }
450 VERT_SAVE_SPEC( 3 );
451 VERT_SET_SPEC( v[3], vbspec[e3] );
452 }
453 }
454 }
455 }
456
457
458 if (DO_OFFSET)
459 {
460 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
461 z[0] = VERT_Z(v[0]);
462 z[1] = VERT_Z(v[1]);
463 z[2] = VERT_Z(v[2]);
464 z[3] = VERT_Z(v[3]);
465 if (cc * cc > 1e-16) {
466 GLfloat ez = z[2] - z[0];
467 GLfloat fz = z[3] - z[1];
468 GLfloat a = ey*fz - ez*fy;
469 GLfloat b = ez*fx - ex*fz;
470 GLfloat ic = 1.0 / cc;
471 GLfloat ac = a * ic;
472 GLfloat bc = b * ic;
473 if ( ac < 0.0f ) ac = -ac;
474 if ( bc < 0.0f ) bc = -bc;
475 offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
476 }
477 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
478 }
479 }
480
481 if (DO_FLAT) {
482 VERT_SAVE_RGBA( 0 );
483 VERT_SAVE_RGBA( 1 );
484 VERT_SAVE_RGBA( 2 );
485 VERT_COPY_RGBA( v[0], v[3] );
486 VERT_COPY_RGBA( v[1], v[3] );
487 VERT_COPY_RGBA( v[2], v[3] );
488 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
489 VERT_SAVE_SPEC( 0 );
490 VERT_SAVE_SPEC( 1 );
491 VERT_SAVE_SPEC( 2 );
492 VERT_COPY_SPEC( v[0], v[3] );
493 VERT_COPY_SPEC( v[1], v[3] );
494 VERT_COPY_SPEC( v[2], v[3] );
495 }
496 }
497
498 if (mode == GL_POINT) {
499 if (( DO_OFFSET) && ctx->Polygon.OffsetPoint) {
500 VERT_Z_ADD(v[0], offset);
501 VERT_Z_ADD(v[1], offset);
502 VERT_Z_ADD(v[2], offset);
503 VERT_Z_ADD(v[3], offset);
504 }
505 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
506 SETUP_STENCIL(facing);
507 UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
508 UNSET_STENCIL(facing);
509 } else {
510 UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
511 }
512 } else if (mode == GL_LINE) {
513 if (DO_OFFSET && ctx->Polygon.OffsetLine) {
514 VERT_Z_ADD(v[0], offset);
515 VERT_Z_ADD(v[1], offset);
516 VERT_Z_ADD(v[2], offset);
517 VERT_Z_ADD(v[3], offset);
518 }
519 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
520 SETUP_STENCIL(facing);
521 UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
522 UNSET_STENCIL(facing);
523 } else {
524 UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
525 }
526 } else {
527 if (DO_OFFSET && ctx->Polygon.OffsetFill) {
528 VERT_Z_ADD(v[0], offset);
529 VERT_Z_ADD(v[1], offset);
530 VERT_Z_ADD(v[2], offset);
531 VERT_Z_ADD(v[3], offset);
532 }
533 RASTERIZE( GL_QUADS );
534 if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
535 SETUP_STENCIL(facing);
536 QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
537 UNSET_STENCIL(facing);
538 } else {
539 QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
540 }
541 }
542
543 if (DO_OFFSET)
544 {
545 VERT_SET_Z(v[0], z[0]);
546 VERT_SET_Z(v[1], z[1]);
547 VERT_SET_Z(v[2], z[2]);
548 VERT_SET_Z(v[3], z[3]);
549 }
550
551 if (DO_TWOSIDE && facing == 1)
552 {
553 if (!DO_FLAT) {
554 VERT_RESTORE_RGBA( 0 );
555 VERT_RESTORE_RGBA( 1 );
556 VERT_RESTORE_RGBA( 2 );
557 }
558 VERT_RESTORE_RGBA( 3 );
559 if (HAVE_SPEC) {
560 if (!DO_FLAT) {
561 VERT_RESTORE_SPEC( 0 );
562 VERT_RESTORE_SPEC( 1 );
563 VERT_RESTORE_SPEC( 2 );
564 }
565 VERT_RESTORE_SPEC( 3 );
566 }
567 }
568
569
570 if (DO_FLAT) {
571 VERT_RESTORE_RGBA( 0 );
572 VERT_RESTORE_RGBA( 1 );
573 VERT_RESTORE_RGBA( 2 );
574 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
575 VERT_RESTORE_SPEC( 0 );
576 VERT_RESTORE_SPEC( 1 );
577 VERT_RESTORE_SPEC( 2 );
578 }
579 }
580 }
581 #else
582 static void TAG(quadr)( GLcontext *ctx, GLuint e0,
583 GLuint e1, GLuint e2, GLuint e3 )
584 {
585 if (DO_UNFILLED) {
586 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
587 GLubyte ef1 = VB->EdgeFlag[e1];
588 GLubyte ef3 = VB->EdgeFlag[e3];
589 VB->EdgeFlag[e1] = 0;
590 TAG(triangle)( ctx, e0, e1, e3 );
591 VB->EdgeFlag[e1] = ef1;
592 VB->EdgeFlag[e3] = 0;
593 TAG(triangle)( ctx, e1, e2, e3 );
594 VB->EdgeFlag[e3] = ef3;
595 } else {
596 TAG(triangle)( ctx, e0, e1, e3 );
597 TAG(triangle)( ctx, e1, e2, e3 );
598 }
599 }
600 #endif
601 #endif
602
603 #if DO_LINE
604 static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
605 {
606 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
607 VERTEX *v[2];
608 LOCAL_VARS(2);
609
610 v[0] = (VERTEX *)GET_VERTEX(e0);
611 v[1] = (VERTEX *)GET_VERTEX(e1);
612
613 if (DO_FLAT) {
614 VERT_SAVE_RGBA( 0 );
615 VERT_COPY_RGBA( v[0], v[1] );
616 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
617 VERT_SAVE_SPEC( 0 );
618 VERT_COPY_SPEC( v[0], v[1] );
619 }
620 }
621
622 LINE( v[0], v[1] );
623
624 if (DO_FLAT) {
625 VERT_RESTORE_RGBA( 0 );
626
627 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
628 VERT_RESTORE_SPEC( 0 );
629 }
630 }
631 }
632 #endif
633
634 #if DO_POINTS
635 static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
636 {
637 struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
638 GLuint i;
639 LOCAL_VARS(1);
640
641 if (VB->Elts == 0) {
642 for ( i = first ; i < last ; i++ ) {
643 if ( VB->ClipMask[i] == 0 ) {
644 VERTEX *v = (VERTEX *)GET_VERTEX(i);
645 POINT( v );
646 }
647 }
648 } else {
649 for ( i = first ; i < last ; i++ ) {
650 GLuint e = VB->Elts[i];
651 if ( VB->ClipMask[e] == 0 ) {
652 VERTEX *v = (VERTEX *)GET_VERTEX(e);
653 POINT( v );
654 }
655 }
656 }
657 }
658 #endif
659
660 static void TAG(init)( void )
661 {
662 #if DO_QUAD
663 TAB[IND].quad = TAG(quadr);
664 #endif
665 #if DO_TRI
666 TAB[IND].triangle = TAG(triangle);
667 #endif
668 #if DO_LINE
669 TAB[IND].line = TAG(line);
670 #endif
671 #if DO_POINTS
672 TAB[IND].points = TAG(points);
673 #endif
674 }
675
676 #undef IND
677 #undef TAG
678
679 #if HAVE_BACK_COLORS
680 #undef VERT_SET_RGBA
681 #endif
682
683 #if !HAVE_SPEC
684 #undef VERT_SET_SPEC
685 #undef VERT_COPY_SPEC
686 #undef VERT_SAVE_SPEC
687 #undef VERT_RESTORE_SPEC
688 #if HAVE_BACK_COLORS
689 #undef VERT_COPY_SPEC1
690 #endif
691 #else
692 #if HAVE_BACK_COLORS
693 #undef VERT_SET_SPEC
694 #endif
695 #endif
696
697 #if !HAVE_BACK_COLORS
698 #undef VERT_COPY_SPEC1
699 #undef VERT_COPY_RGBA1
700 #endif
701
702 #ifndef INSANE_VERTICES
703 #undef VERT_SET_Z
704 #undef VERT_Z_ADD
705 #endif