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