460{
463
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483#define GENERAL_CLIP \
484 if (INCOUNT<3) return 0; \
485 previ = INCOUNT-1; \
486 prevj = INLIST[previ]; \
487 OUTCOUNT = 0; \
488 for (curri=0;curri<INCOUNT;curri++) { \
489 currj = INLIST[curri]; \
490 if (INSIDE(currj)) { \
491 if (INSIDE(prevj)) { \
492 \
493 OUTLIST[OUTCOUNT] = currj; \
494 OUTCOUNT++; \
495 } \
496 else { \
497 \
498 COMPUTE_INTERSECTION( currj, prevj, VB->Free ) \
499 \
500 if (t>0.0) { \
501 \
502 if (ctx->ClipMask) \
503 ctx->ClipInterpAuxFunc( ctx, CLIP_SPACE, VB->Free, t, currj, prevj ); \
504 VB->Edgeflag[VB->Free] = VB->Edgeflag[prevj]; \
505 \
506 OUTLIST[OUTCOUNT] = VB->Free; \
507 VB->Free++; \
508 if (VB->Free==VB_SIZE) VB->Free = 1; \
509 OUTCOUNT++; \
510 } \
511 \
512 OUTLIST[OUTCOUNT] = currj; \
513 OUTCOUNT++; \
514 } \
515 } \
516 else { \
517 if (INSIDE(prevj)) { \
518 \
519 COMPUTE_INTERSECTION( prevj, currj, VB->Free ) \
520 \
521 if (t>0.0) { \
522 \
523 if (ctx->ClipMask) \
524 ctx->ClipInterpAuxFunc( ctx, CLIP_SPACE, VB->Free, t, prevj, currj ); \
525 VB->Edgeflag[VB->Free] = VB->Edgeflag[prevj]; \
526 \
527 OUTLIST[OUTCOUNT] = VB->Free; \
528 VB->Free++; \
529 if (VB->Free==VB_SIZE) VB->Free = 1; \
530 OUTCOUNT++; \
531 } \
532 } \
533 \
534 } \
535 \
536 previ = curri; \
537 prevj = currj; \
538 \
539 if (OUTCOUNT>=VB_SIZE-1) { \
540 \
541 if (OUTLIST==vlist2) { \
542 \
543 int i; \
544 for (i=0;i<VB_SIZE;i++) { \
545 vlist[i] = OUTLIST[i]; \
546 } \
547 } \
548 return VB_SIZE-1; \
549 } \
550 }
551
552
553#define X(I) coord[I][0]
554#define Y(I) coord[I][1]
555#define Z(I) coord[I][2]
556#define W(I) coord[I][3]
557
558
559
560
561#define INCOUNT n
562#define OUTCOUNT n2
563#define INLIST vlist
564#define OUTLIST vlist2
565#define INSIDE(K) (X(K) <= W(K))
566
567#define COMPUTE_INTERSECTION( in, out, new ) \
568 dx = X(out) - X(in); \
569 dw = W(out) - W(in); \
570 t = (X(in)-W(in)) / (dw-dx); \
571 neww = W(in) + t * dw; \
572 X(new) = neww; \
573 Y(new) = Y(in) + t * (Y(out) - Y(in)); \
574 Z(new) = Z(in) + t * (Z(out) - Z(in)); \
575 W(new) = neww;
576
578
579#undef INCOUNT
580#undef OUTCOUNT
581#undef INLIST
582#undef OUTLIST
583#undef INSIDE
584#undef COMPUTE_INTERSECTION
585
586
587
588
589
590#define INCOUNT n2
591#define OUTCOUNT n
592#define INLIST vlist2
593#define OUTLIST vlist
594#define INSIDE(K) (X(K) >= -W(K))
595#define COMPUTE_INTERSECTION( in, out, new ) \
596 dx = X(out)-X(in); \
597 dw = W(out)-W(in); \
598 t = -(X(in)+W(in)) / (dw+dx); \
599 neww = W(in) + t * dw; \
600 X(new) = -neww; \
601 Y(new) = Y(in) + t * (Y(out) - Y(in)); \
602 Z(new) = Z(in) + t * (Z(out) - Z(in)); \
603 W(new) = neww;
604
606
607#undef INCOUNT
608#undef OUTCOUNT
609#undef INLIST
610#undef OUTLIST
611#undef INSIDE
612#undef COMPUTE_INTERSECTION
613
614
615
616
617
618#define INCOUNT n
619#define OUTCOUNT n2
620#define INLIST vlist
621#define OUTLIST vlist2
622#define INSIDE(K) (Y(K) <= W(K))
623#define COMPUTE_INTERSECTION( in, out, new ) \
624 dy = Y(out)-Y(in); \
625 dw = W(out)-W(in); \
626 t = (Y(in)-W(in)) / (dw-dy); \
627 neww = W(in) + t * dw; \
628 X(new) = X(in) + t * (X(out) - X(in)); \
629 Y(new) = neww; \
630 Z(new) = Z(in) + t * (Z(out) - Z(in)); \
631 W(new) = neww;
632
634
635#undef INCOUNT
636#undef OUTCOUNT
637#undef INLIST
638#undef OUTLIST
639#undef INSIDE
640#undef COMPUTE_INTERSECTION
641
642
643
644
645
646#define INCOUNT n2
647#define OUTCOUNT n
648#define INLIST vlist2
649#define OUTLIST vlist
650#define INSIDE(K) (Y(K) >= -W(K))
651#define COMPUTE_INTERSECTION( in, out, new ) \
652 dy = Y(out)-Y(in); \
653 dw = W(out)-W(in); \
654 t = -(Y(in)+W(in)) / (dw+dy); \
655 neww = W(in) + t * dw; \
656 X(new) = X(in) + t * (X(out) - X(in)); \
657 Y(new) = -neww; \
658 Z(new) = Z(in) + t * (Z(out) - Z(in)); \
659 W(new) = neww;
660
662
663#undef INCOUNT
664#undef OUTCOUNT
665#undef INLIST
666#undef OUTLIST
667#undef INSIDE
668#undef COMPUTE_INTERSECTION
669
670
671
672
673
674
675#define INCOUNT n
676#define OUTCOUNT n2
677#define INLIST vlist
678#define OUTLIST vlist2
679#define INSIDE(K) (Z(K) <= W(K))
680#define COMPUTE_INTERSECTION( in, out, new ) \
681 dz = Z(out)-Z(in); \
682 dw = W(out)-W(in); \
683 t = (Z(in)-W(in)) / (dw-dz); \
684 neww = W(in) + t * dw; \
685 X(new) = X(in) + t * (X(out) - X(in)); \
686 Y(new) = Y(in) + t * (Y(out) - Y(in)); \
687 Z(new) = neww; \
688 W(new) = neww;
689
691
692#undef INCOUNT
693#undef OUTCOUNT
694#undef INLIST
695#undef OUTLIST
696#undef INSIDE
697#undef COMPUTE_INTERSECTION
698
699
700
701
702
703#define INCOUNT n2
704#define OUTCOUNT n
705#define INLIST vlist2
706#define OUTLIST vlist
707#define INSIDE(K) (Z(K) >= -W(K))
708#define COMPUTE_INTERSECTION( in, out, new ) \
709 dz = Z(out)-Z(in); \
710 dw = W(out)-W(in); \
711 t = -(Z(in)+W(in)) / (dw+dz); \
712 neww = W(in) + t * dw; \
713 X(new) = X(in) + t * (X(out) - X(in)); \
714 Y(new) = Y(in) + t * (Y(out) - Y(in)); \
715 Z(new) = -neww; \
716 W(new) = neww;
717
719
720#undef INCOUNT
721#undef INLIST
722#undef OUTLIST
723#undef INSIDE
724#undef COMPUTE_INTERSECTION
725
726
728
729#undef GENERAL_CLIP
730#undef OUTCOUNT
731}