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