Ignore:
Timestamp:
May 21, 2000, 10:57:14 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/clip_funcs.h

    r2938 r3582  
    1 /* $Id: clip_funcs.h,v 1.1 2000-02-29 00:48:26 sandervl Exp $ */
     1/* $Id: clip_funcs.h,v 1.2 2000-05-21 20:15:38 jeroen Exp $ */
    22
    33/*
     
    3030
    3131static GLuint TAG(userclip_line)( struct vertex_buffer *VB,
    32                                   GLuint *i, GLuint *j );
     32                                  GLuint *i, GLuint *j );
    3333static GLuint TAG(userclip_polygon)( struct vertex_buffer *VB,
    34                                      GLuint n, GLuint vlist[] );
     34                                     GLuint n, GLuint vlist[] );
    3535
    3636
     
    3939 */
    4040static GLuint TAG(viewclip_line)( struct vertex_buffer *VB,
    41                                   GLuint *i, GLuint *j,
    42                                   GLubyte mask )
     41                                  GLuint *i, GLuint *j,
     42                                  GLubyte mask )
    4343{
    4444   GLfloat (*coord)[4] = VB->ClipPtr->data;
     
    5555 * macros apprpriately.
    5656 */
    57 #define GENERAL_CLIP                                    \
    58    if (mask & PLANE) {                                  \
    59       GLuint flagI = INSIDE( ii );                      \
    60       GLuint flagJ = INSIDE( jj );                      \
    61                                                         \
    62       if (!(flagI|flagJ))                               \
    63          return 0;                                      \
    64                                                         \
    65       if (flagI ^ flagJ) {                              \
    66          COMPUTE_INTERSECTION( jj, ii, vb_free );       \
    67          interp( VB, vb_free, t, jj, ii);               \
    68                                                         \
    69          if (flagI) {                                   \
    70             VB->ClipMask[jj] |= PLANE;                  \
    71             jj = vb_free;                               \
    72          } else {                                       \
    73             VB->ClipMask[ii] |= PLANE;                  \
    74             ii = vb_free;                               \
    75          }                                              \
    76                                                         \
    77          VB->ClipMask[vb_free++] = 0;                   \
    78       }                                                 \
     57#define GENERAL_CLIP                                    \
     58   if (mask & PLANE) {                                  \
     59      GLuint flagI = INSIDE( ii );                      \
     60      GLuint flagJ = INSIDE( jj );                      \
     61                                                        \
     62      if (!(flagI|flagJ))                               \
     63         return 0;                                      \
     64                                                        \
     65      if (flagI ^ flagJ) {                              \
     66         COMPUTE_INTERSECTION( jj, ii, vb_free );       \
     67         interp( VB, vb_free, t, jj, ii);               \
     68                                                        \
     69         if (flagI) {                                   \
     70            VB->ClipMask[jj] |= PLANE;                  \
     71            jj = vb_free;                               \
     72         } else {                                       \
     73            VB->ClipMask[ii] |= PLANE;                  \
     74            ii = vb_free;                               \
     75         }                                              \
     76                                                        \
     77         VB->ClipMask[vb_free++] = 0;                   \
     78      }                                                 \
    7979   }
    8080
     
    8585   if (mask & CLIP_USER_BIT) {
    8686      if ( TAG(userclip_line)( VB, &ii, &jj ) == 0 )
    87         return 0;
     87        return 0;
    8888   }
    8989
     
    107107
    108108      for (i = 0; i < n; i++) {
    109         j = vlist[i];
    110         if (j >= start) {
    111             if (W(j) != 0.0F) {
    112                GLfloat wInv = 1.0F / W(j);
    113                win[j][0] = X(j) * wInv * sx + tx;
    114                win[j][1] = Y(j) * wInv * sy + ty;
    115                win[j][2] = Z(j) * wInv * sz + tz;
    116                win[j][3] = wInv;
    117             } else {
    118                win[j][0] = win[j][1] = win[j][2] = 0.0F;
    119                win[j][3] = 1.0F;
    120             }
    121         }
     109        j = vlist[i];
     110        if (j >= start) {
     111            if (W(j) != 0.0F) {
     112               GLfloat wInv = 1.0F / W(j);
     113               win[j][0] = X(j) * wInv * sx + tx;
     114               win[j][1] = Y(j) * wInv * sy + ty;
     115               win[j][2] = Z(j) * wInv * sz + tz;
     116               win[j][3] = wInv;
     117            } else {
     118               win[j][0] = win[j][1] = win[j][2] = 0.0F;
     119               win[j][3] = 1.0F;
     120            }
     121        }
    122122      }
    123123   }
     
    138138 */
    139139static GLuint TAG(viewclip_polygon)( struct vertex_buffer *VB,
    140                                      GLuint n, GLuint vlist[],
    141                                      GLubyte mask )
     140                                     GLuint n, GLuint vlist[],
     141                                     GLubyte mask )
    142142{
    143143   GLfloat (*coord)[4] = VB->ClipPtr->data;
     
    151151   if (mask & CLIP_ALL_BITS) {
    152152
    153 #define GENERAL_CLIP                                                    \
    154    if (mask & PLANE) {                                                  \
    155       GLuint prevj = inlist[n-1];                                       \
    156       GLuint prevflag = INSIDE(prevj);                                  \
    157       GLuint outcount = 0;                                              \
    158       GLuint ef_state = 3;                                              \
    159       GLuint i;                                                         \
    160                                                                         \
    161                                                                         \
    162       for (i = 0; i < n; i++) {                                         \
    163          GLuint j = inlist[i];                                          \
    164          GLuint flag = INSIDE(j);                                       \
    165                                                                         \
    166          if (flag ^ prevflag) {                                         \
    167             if (flag) {                                                 \
    168                /* Coming back in                                        \
    169                 */                                                      \
    170                COMPUTE_INTERSECTION( j, prevj, vb_free );               \
    171                interp( VB, vb_free, t, j, prevj );                      \
    172                                                                         \
    173                if (IND&CLIP_TAB_EDGEFLAG)                               \
    174                   VB->EdgeFlagPtr->data[vb_free] =                      \
    175                      VB->EdgeFlagPtr->data[prevj] & ef_state;           \
    176                                                                         \
    177                                                                         \
    178             } else {                                                    \
    179                /* Going out of bounds                                   \
    180                 */                                                      \
    181                COMPUTE_INTERSECTION( prevj, j, vb_free );               \
    182                interp( VB, vb_free, t, prevj, j );                      \
    183                                                                         \
    184                if (IND&CLIP_TAB_EDGEFLAG)                               \
    185                   VB->EdgeFlagPtr->data[vb_free] = 1;                   \
    186             }                                                           \
    187                                                                         \
    188             outlist[outcount++] = vb_free;                              \
    189             VB->ClipMask[vb_free++] = 0;                                \
    190          }                                                              \
    191                                                                         \
    192          if (flag) {                                                    \
    193             outlist[outcount++] = j;                                    \
    194          } else {                                                       \
    195             VB->ClipMask[j] |= (PLANE&CLIP_ALL_BITS); /* don't setup */ \
    196          }                                                              \
    197          prevj = j;                                                     \
    198          prevflag = flag;                                               \
    199          ef_state = 1;                                                  \
    200       }                                                                 \
    201                                                                         \
    202       if (outcount < 3)                                                 \
    203          return 0;                                                      \
    204       else {                                                            \
    205          GLuint *tmp = inlist;                                          \
    206          inlist = outlist;                                              \
    207          outlist = tmp;                                                 \
    208          n = outcount;                                                  \
    209       }                                                                 \
     153#define GENERAL_CLIP                                                    \
     154   if (mask & PLANE) {                                                  \
     155      GLuint prevj = inlist[0];                                         \
     156      GLuint prevflag = INSIDE(prevj);                                  \
     157      GLuint outcount = 0;                                              \
     158      GLuint i;                                                         \
     159                                                                        \
     160      inlist[n] = inlist[0];                                            \
     161                                                                        \
     162      for (i = 1; i < n+1; i++) {                                       \
     163         GLuint j = inlist[i];                                          \
     164         GLuint flag = INSIDE(j);                                       \
     165                                                                        \
     166         if (prevflag) {                                                \
     167            outlist[outcount++] = prevj;                                \
     168         } else {                                                       \
     169            VB->ClipMask[prevj] |= (PLANE&CLIP_ALL_BITS);               \
     170         }                                                              \
     171                                                                        \
     172         if (flag ^ prevflag) {                                         \
     173            if (flag) {                                                 \
     174               /* Coming back in                                        \
     175                */                                                      \
     176               COMPUTE_INTERSECTION( j, prevj, vb_free );               \
     177               interp( VB, vb_free, t, j, prevj );                      \
     178                                                                        \
     179               if (IND&CLIP_TAB_EDGEFLAG)                               \
     180                  VB->EdgeFlagPtr->data[vb_free] =                      \
     181                     VB->EdgeFlagPtr->data[prevj];                      \
     182                                                                        \
     183                                                                        \
     184            } else {                                                    \
     185               /* Going out of bounds                                   \
     186                */                                                      \
     187               COMPUTE_INTERSECTION( prevj, j, vb_free );               \
     188               interp( VB, vb_free, t, prevj, j );                      \
     189                                                                        \
     190               if (IND&CLIP_TAB_EDGEFLAG) {                             \
     191                  VB->EdgeFlagPtr->data[vb_free] = 3;                   \
     192               }                                                        \
     193            }                                                           \
     194                                                                        \
     195            if (IND&CLIP_TAB_EDGEFLAG) {                                \
     196               /* Demote trailing edge to internal edge.                \
     197                */                                                      \
     198               if (outcount &&                                          \
     199                   (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2))  \
     200                  VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1;       \
     201            }                                                           \
     202                                                                        \
     203            outlist[outcount++] = vb_free;                              \
     204            VB->ClipMask[vb_free++] = 0;                                \
     205         }                                                              \
     206                                                                        \
     207         prevj = j;                                                     \
     208         prevflag = flag;                                               \
     209      }                                                                 \
     210                                                                        \
     211      if (outcount < 3)                                                 \
     212         return 0;                                                      \
     213      else {                                                            \
     214         GLuint *tmp = inlist;                                          \
     215         inlist = outlist;                                              \
     216         outlist = tmp;                                                 \
     217         n = outcount;                                                  \
     218      }                                                                 \
    210219   }
    211220
     
    214223
    215224      if (inlist != vlist)
    216         for (i = 0 ; i < n ; i++)
    217             vlist[i] = inlist[i];
     225        for (i = 0 ; i < n ; i++)
     226            vlist[i] = inlist[i];
    218227   }
    219228
     
    241250
    242251      for (i = 0; i < n; i++) {
    243         GLuint j = vlist[i];
    244         if (j >= first) {
    245             if (W(j) != 0.0F) {
    246                GLfloat wInv = 1.0F / W(j);
    247                win[j][0] = X(j) * wInv * sx + tx;
    248                win[j][1] = Y(j) * wInv * sy + ty;
    249                win[j][2] = Z(j) * wInv * sz + tz;
    250                win[j][3] = wInv;
    251             } else {
    252                win[j][0] = win[j][1] = win[j][2] = 0.0;
    253                win[j][3] = 1.0F;
    254             }
    255         }
     252        GLuint j = vlist[i];
     253        if (j >= first) {
     254            if (W(j) != 0.0F) {
     255               GLfloat wInv = 1.0F / W(j);
     256               win[j][0] = X(j) * wInv * sx + tx;
     257               win[j][1] = Y(j) * wInv * sy + ty;
     258               win[j][2] = Z(j) * wInv * sz + tz;
     259               win[j][3] = wInv;
     260            } else {
     261               win[j][0] = win[j][1] = win[j][2] = 0.0;
     262               win[j][3] = 1.0F;
     263            }
     264        }
    256265      }
    257266   }
     
    271280
    272281static GLuint TAG(userclip_line)( struct vertex_buffer *VB,
    273                                   GLuint *i, GLuint *j )
     282                                  GLuint *i, GLuint *j )
    274283{
    275284   GLcontext *ctx = VB->ctx;
     
    283292   for (p=0;p<MAX_CLIP_PLANES;p++) {
    284293      if (ctx->Transform.ClipEnabled[p]) {
    285         GLfloat a = ctx->Transform.ClipUserPlane[p][0];
    286         GLfloat b = ctx->Transform.ClipUserPlane[p][1];
    287         GLfloat c = ctx->Transform.ClipUserPlane[p][2];
    288         GLfloat d = ctx->Transform.ClipUserPlane[p][3];
    289 
    290         GLfloat dpI = d*W(ii) + c*Z(ii) + b*Y(ii) + a*X(ii);
    291         GLfloat dpJ = d*W(jj) + c*Z(jj) + b*Y(jj) + a*X(jj);
     294        GLfloat a = ctx->Transform.ClipUserPlane[p][0];
     295        GLfloat b = ctx->Transform.ClipUserPlane[p][1];
     296        GLfloat c = ctx->Transform.ClipUserPlane[p][2];
     297        GLfloat d = ctx->Transform.ClipUserPlane[p][3];
     298
     299        GLfloat dpI = d*W(ii) + c*Z(ii) + b*Y(ii) + a*X(ii);
     300        GLfloat dpJ = d*W(jj) + c*Z(jj) + b*Y(jj) + a*X(jj);
    292301
    293302         GLuint flagI = OUTSIDE( dpI );
    294303         GLuint flagJ = OUTSIDE( dpJ );
    295304
    296         if (flagI & flagJ)
    297             return 0;
    298 
    299         if (flagI ^ flagJ) {
    300             GLfloat t = -dpI/(dpJ-dpI);
    301 
    302             INTERP_SZ( t, coord, vb_free, ii, jj, SIZE );
    303             interp( VB, vb_free, t, ii, jj );
    304 
    305             if (flagI) {
    306                VB->ClipMask[ii] |= CLIP_USER_BIT;
    307                ii = vb_free;
    308             } else {
    309                VB->ClipMask[jj] |= CLIP_USER_BIT;
    310                jj = vb_free;
    311             }
    312        
    313             VB->ClipMask[vb_free++] = 0;
     305        if (flagI & flagJ)
     306            return 0;
     307
     308        if (flagI ^ flagJ) {
     309            GLfloat t = -dpI/(dpJ-dpI);
     310
     311            INTERP_SZ( t, coord, vb_free, ii, jj, SIZE );
     312            interp( VB, vb_free, t, ii, jj );
     313
     314            if (flagI) {
     315               VB->ClipMask[ii] |= CLIP_USER_BIT;
     316               ii = vb_free;
     317            } else {
     318               VB->ClipMask[jj] |= CLIP_USER_BIT;
     319               jj = vb_free;
     320            }
     321
     322            VB->ClipMask[vb_free++] = 0;
    314323         }
    315324      }
     
    324333
    325334static GLuint TAG(userclip_polygon)( struct vertex_buffer *VB,
    326                                      GLuint n, GLuint vlist[] )
     335                                     GLuint n, GLuint vlist[] )
    327336{
    328337   GLcontext *ctx = VB->ctx;
     
    336345   for (p=0;p<MAX_CLIP_PLANES;p++) {
    337346      if (ctx->Transform.ClipEnabled[p]) {
    338          register float a = ctx->Transform.ClipUserPlane[p][0];
    339          register float b = ctx->Transform.ClipUserPlane[p][1];
    340          register float c = ctx->Transform.ClipUserPlane[p][2];
    341          register float d = ctx->Transform.ClipUserPlane[p][3];
    342 
    343          /* initialize prev to be last in the input list */
    344          GLuint prevj = inlist[n - 1];
    345          GLfloat dpJ = d*W(prevj) + c*Z(prevj) + b*Y(prevj) + a*X(prevj);
    346          GLuint flagJ = INSIDE(dpJ);
    347          GLuint outcount = 0;
    348          GLuint curri;
    349 
    350          for (curri=0;curri<n;curri++) {
    351             GLuint currj = inlist[curri];
    352             GLfloat dpI = d*W(currj) + c*Z(currj) + b*Y(currj) + a*X(currj);
     347         register float a = ctx->Transform.ClipUserPlane[p][0];
     348         register float b = ctx->Transform.ClipUserPlane[p][1];
     349         register float c = ctx->Transform.ClipUserPlane[p][2];
     350         register float d = ctx->Transform.ClipUserPlane[p][3];
     351
     352         /* initialize prev to be last in the input list */
     353         GLuint prevj = inlist[0];
     354         GLfloat dpJ = d*W(prevj) + c*Z(prevj) + b*Y(prevj) + a*X(prevj);
     355         GLuint flagJ = INSIDE(dpJ);
     356         GLuint outcount = 0;
     357         GLuint curri;
     358
     359         inlist[n] = inlist[0];
     360
     361
     362         for (curri=1;curri<n+1;curri++) {
     363            GLuint currj = inlist[curri];
     364            GLfloat dpI = d*W(currj) + c*Z(currj) + b*Y(currj) + a*X(currj);
    353365            GLuint flagI = INSIDE(dpI);
    354366
    355             if (flagI ^ flagJ) {
    356                GLfloat t;
    357                GLuint in;
    358                GLuint out;
    359 
    360                if (flagI) {
    361                   out = prevj;
     367            if (flagJ) {
     368               outlist[outcount++] = prevj;
     369            } else {
     370               VB->ClipMask[prevj] |= CLIP_USER_BIT;
     371            }
     372
     373            if (flagI ^ flagJ) {
     374               GLfloat t;
     375               GLuint in;
     376               GLuint out;
     377
     378               if (flagI) {
     379                  out = prevj;
    362380                  in = currj;
    363381                  t = dpI/(dpI-dpJ);
    364382
    365                   if (IND&CLIP_TAB_EDGEFLAG)
    366                      VB->EdgeFlagPtr->data[vb_free] =
    367                         VB->EdgeFlagPtr->data[prevj];
    368                } else {
    369                   in = prevj;
     383                  if (IND&CLIP_TAB_EDGEFLAG)
     384                     VB->EdgeFlagPtr->data[vb_free] =
     385                        VB->EdgeFlagPtr->data[prevj];
     386               } else {
     387                  in = prevj;
    370388                  out = currj;
    371389                  t = dpJ/(dpJ-dpI);
    372390
    373                   if (IND&CLIP_TAB_EDGEFLAG)
    374                      VB->EdgeFlagPtr->data[vb_free] = 1;
    375                }               
    376        
    377                INTERP_SZ( t, coord, vb_free, in, out, SIZE );
    378                interp( VB, vb_free, t, in, out);
    379                outlist[outcount++] = vb_free;
    380                VB->ClipMask[vb_free++] = 0;
     391                  if (IND&CLIP_TAB_EDGEFLAG)
     392                     VB->EdgeFlagPtr->data[vb_free] = 1;
     393               }
     394
     395               if (IND&CLIP_TAB_EDGEFLAG) {
     396                  /* Demote trailing edge to internal edge.
     397                   */
     398                  if (outcount &&
     399                      (VB->EdgeFlagPtr->data[outlist[outcount-1]] & 0x2))
     400                     VB->EdgeFlagPtr->data[outlist[outcount-1]] = 1;
     401               }
     402
     403               INTERP_SZ( t, coord, vb_free, in, out, SIZE );
     404               interp( VB, vb_free, t, in, out);
     405               outlist[outcount++] = vb_free;
     406               VB->ClipMask[vb_free++] = 0;
    381407            }
    382408
    383             if (flagI) {
    384                outlist[outcount++] = currj;
    385             } else {
    386                VB->ClipMask[currj] |= CLIP_USER_BIT;
    387             }
    388 
    389             prevj = currj;
    390             flagJ = flagI;
    391             dpJ = dpI;
     409            prevj = currj;
     410            flagJ = flagI;
     411            dpJ = dpI;
    392412         }
    393413
    394         if (outcount < 3)
    395             return 0;
    396         else {
     414        if (outcount < 3)
     415            return 0;
     416        else {
    397417            GLuint *tmp;
    398418            tmp = inlist;
     
    408428      GLuint i;
    409429      for (i = 0 ; i < n ; i++)
    410         vlist[i] = inlist[i];
     430        vlist[i] = inlist[i];
    411431   }
    412432
Note: See TracChangeset for help on using the changeset viewer.