ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

s_aatritemp.h
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.0.3
00004  *
00005  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 
00026 /*
00027  * Antialiased Triangle Rasterizer Template
00028  *
00029  * This file is #include'd to generate custom AA triangle rasterizers.
00030  * NOTE: this code hasn't been optimized yet.  That'll come after it
00031  * works correctly.
00032  *
00033  * The following macros may be defined to indicate what auxillary information
00034  * must be copmuted across the triangle:
00035  *    DO_Z         - if defined, compute Z values
00036  *    DO_RGBA      - if defined, compute RGBA values
00037  *    DO_INDEX     - if defined, compute color index values
00038  *    DO_ATTRIBS   - if defined, compute texcoords, varying, etc.
00039  */
00040 
00041 /*void triangle( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv )*/
00042 {
00043    const SWcontext *swrast = SWRAST_CONTEXT(ctx);
00044    const GLfloat *p0 = v0->attrib[FRAG_ATTRIB_WPOS];
00045    const GLfloat *p1 = v1->attrib[FRAG_ATTRIB_WPOS];
00046    const GLfloat *p2 = v2->attrib[FRAG_ATTRIB_WPOS];
00047    const SWvertex *vMin, *vMid, *vMax;
00048    GLint iyMin, iyMax;
00049    GLfloat yMin, yMax;
00050    GLboolean ltor;
00051    GLfloat majDx, majDy;  /* major (i.e. long) edge dx and dy */
00052    
00053    SWspan span;
00054    
00055 #ifdef DO_Z
00056    GLfloat zPlane[4];
00057 #endif
00058 #ifdef DO_RGBA
00059    GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];
00060 #endif
00061 #ifdef DO_INDEX
00062    GLfloat iPlane[4];
00063 #endif
00064 #if defined(DO_ATTRIBS)
00065    GLfloat attrPlane[FRAG_ATTRIB_MAX][4][4];
00066    GLfloat wPlane[4];  /* win[3] */
00067 #endif
00068    GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceCullSign;
00069    
00070    (void) swrast;
00071 
00072    INIT_SPAN(span, GL_POLYGON);
00073    span.arrayMask = SPAN_COVERAGE;
00074 
00075    /* determine bottom to top order of vertices */
00076    {
00077       GLfloat y0 = v0->attrib[FRAG_ATTRIB_WPOS][1];
00078       GLfloat y1 = v1->attrib[FRAG_ATTRIB_WPOS][1];
00079       GLfloat y2 = v2->attrib[FRAG_ATTRIB_WPOS][1];
00080       if (y0 <= y1) {
00081      if (y1 <= y2) {
00082         vMin = v0;   vMid = v1;   vMax = v2;   /* y0<=y1<=y2 */
00083      }
00084      else if (y2 <= y0) {
00085         vMin = v2;   vMid = v0;   vMax = v1;   /* y2<=y0<=y1 */
00086      }
00087      else {
00088         vMin = v0;   vMid = v2;   vMax = v1;  bf = -bf; /* y0<=y2<=y1 */
00089      }
00090       }
00091       else {
00092      if (y0 <= y2) {
00093         vMin = v1;   vMid = v0;   vMax = v2;  bf = -bf; /* y1<=y0<=y2 */
00094      }
00095      else if (y2 <= y1) {
00096         vMin = v2;   vMid = v1;   vMax = v0;  bf = -bf; /* y2<=y1<=y0 */
00097      }
00098      else {
00099         vMin = v1;   vMid = v2;   vMax = v0;   /* y1<=y2<=y0 */
00100      }
00101       }
00102    }
00103 
00104    majDx = vMax->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0];
00105    majDy = vMax->attrib[FRAG_ATTRIB_WPOS][1] - vMin->attrib[FRAG_ATTRIB_WPOS][1];
00106 
00107    /* front/back-face determination and cullling */
00108    {
00109       const GLfloat botDx = vMid->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0];
00110       const GLfloat botDy = vMid->attrib[FRAG_ATTRIB_WPOS][1] - vMin->attrib[FRAG_ATTRIB_WPOS][1];
00111       const GLfloat area = majDx * botDy - botDx * majDy;
00112       /* Do backface culling */
00113       if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area))
00114      return;
00115       ltor = (GLboolean) (area < 0.0F);
00116 
00117       span.facing = area * swrast->_BackfaceSign > 0.0F;
00118    }
00119 
00120    /* Plane equation setup:
00121     * We evaluate plane equations at window (x,y) coordinates in order
00122     * to compute color, Z, fog, texcoords, etc.  This isn't terribly
00123     * efficient but it's easy and reliable.
00124     */
00125 #ifdef DO_Z
00126    compute_plane(p0, p1, p2, p0[2], p1[2], p2[2], zPlane);
00127    span.arrayMask |= SPAN_Z;
00128 #endif
00129 #ifdef DO_RGBA
00130    if (ctx->Light.ShadeModel == GL_SMOOTH) {
00131       compute_plane(p0, p1, p2, v0->color[RCOMP], v1->color[RCOMP], v2->color[RCOMP], rPlane);
00132       compute_plane(p0, p1, p2, v0->color[GCOMP], v1->color[GCOMP], v2->color[GCOMP], gPlane);
00133       compute_plane(p0, p1, p2, v0->color[BCOMP], v1->color[BCOMP], v2->color[BCOMP], bPlane);
00134       compute_plane(p0, p1, p2, v0->color[ACOMP], v1->color[ACOMP], v2->color[ACOMP], aPlane);
00135    }
00136    else {
00137       constant_plane(v2->color[RCOMP], rPlane);
00138       constant_plane(v2->color[GCOMP], gPlane);
00139       constant_plane(v2->color[BCOMP], bPlane);
00140       constant_plane(v2->color[ACOMP], aPlane);
00141    }
00142    span.arrayMask |= SPAN_RGBA;
00143 #endif
00144 #ifdef DO_INDEX
00145    if (ctx->Light.ShadeModel == GL_SMOOTH) {
00146       compute_plane(p0, p1, p2, (GLfloat) v0->attrib[FRAG_ATTRIB_CI][0],
00147                     v1->attrib[FRAG_ATTRIB_CI][0], v2->attrib[FRAG_ATTRIB_CI][0], iPlane);
00148    }
00149    else {
00150       constant_plane(v2->attrib[FRAG_ATTRIB_CI][0], iPlane);
00151    }
00152    span.arrayMask |= SPAN_INDEX;
00153 #endif
00154 #if defined(DO_ATTRIBS)
00155    {
00156       const GLfloat invW0 = v0->attrib[FRAG_ATTRIB_WPOS][3];
00157       const GLfloat invW1 = v1->attrib[FRAG_ATTRIB_WPOS][3];
00158       const GLfloat invW2 = v2->attrib[FRAG_ATTRIB_WPOS][3];
00159       compute_plane(p0, p1, p2, invW0, invW1, invW2, wPlane);
00160       span.attrStepX[FRAG_ATTRIB_WPOS][3] = plane_dx(wPlane);
00161       span.attrStepY[FRAG_ATTRIB_WPOS][3] = plane_dy(wPlane);
00162       ATTRIB_LOOP_BEGIN
00163          GLuint c;
00164          if (swrast->_InterpMode[attr] == GL_FLAT) {
00165             for (c = 0; c < 4; c++) {
00166                constant_plane(v2->attrib[attr][c] * invW2, attrPlane[attr][c]);
00167             }
00168          }
00169          else {
00170             for (c = 0; c < 4; c++) {
00171                const GLfloat a0 = v0->attrib[attr][c] * invW0;
00172                const GLfloat a1 = v1->attrib[attr][c] * invW1;
00173                const GLfloat a2 = v2->attrib[attr][c] * invW2;
00174                compute_plane(p0, p1, p2, a0, a1, a2, attrPlane[attr][c]);
00175             }
00176          }
00177          for (c = 0; c < 4; c++) {
00178             span.attrStepX[attr][c] = plane_dx(attrPlane[attr][c]);
00179             span.attrStepY[attr][c] = plane_dy(attrPlane[attr][c]);
00180          }
00181       ATTRIB_LOOP_END
00182    }
00183 #endif
00184 
00185    /* Begin bottom-to-top scan over the triangle.
00186     * The long edge will either be on the left or right side of the
00187     * triangle.  We always scan from the long edge toward the shorter
00188     * edges, stopping when we find that coverage = 0.  If the long edge
00189     * is on the left we scan left-to-right.  Else, we scan right-to-left.
00190     */
00191    yMin = vMin->attrib[FRAG_ATTRIB_WPOS][1];
00192    yMax = vMax->attrib[FRAG_ATTRIB_WPOS][1];
00193    iyMin = (GLint) yMin;
00194    iyMax = (GLint) yMax + 1;
00195 
00196    if (ltor) {
00197       /* scan left to right */
00198       const GLfloat *pMin = vMin->attrib[FRAG_ATTRIB_WPOS];
00199       const GLfloat *pMid = vMid->attrib[FRAG_ATTRIB_WPOS];
00200       const GLfloat *pMax = vMax->attrib[FRAG_ATTRIB_WPOS];
00201       const GLfloat dxdy = majDx / majDy;
00202       const GLfloat xAdj = dxdy < 0.0F ? -dxdy : 0.0F;
00203       GLfloat x = pMin[0] - (yMin - iyMin) * dxdy;
00204       GLint iy;
00205       for (iy = iyMin; iy < iyMax; iy++, x += dxdy) {
00206          GLint ix, startX = (GLint) (x - xAdj);
00207          GLuint count;
00208          GLfloat coverage = 0.0F;
00209 
00210          /* skip over fragments with zero coverage */
00211          while (startX < MAX_WIDTH) {
00212             coverage = compute_coveragef(pMin, pMid, pMax, startX, iy);
00213             if (coverage > 0.0F)
00214                break;
00215             startX++;
00216          }
00217 
00218          /* enter interior of triangle */
00219          ix = startX;
00220 
00221 #if defined(DO_ATTRIBS)
00222          /* compute attributes at left-most fragment */
00223          span.attrStart[FRAG_ATTRIB_WPOS][3] = solve_plane(ix + 0.5, iy + 0.5, wPlane);
00224          ATTRIB_LOOP_BEGIN
00225             GLuint c;
00226             for (c = 0; c < 4; c++) {
00227                span.attrStart[attr][c] = solve_plane(ix + 0.5, iy + 0.5, attrPlane[attr][c]);
00228             }
00229          ATTRIB_LOOP_END
00230 #endif
00231 
00232          count = 0;
00233          while (coverage > 0.0F) {
00234             /* (cx,cy) = center of fragment */
00235             const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
00236             SWspanarrays *array = span.array;
00237 #ifdef DO_INDEX
00238             array->coverage[count] = (GLfloat) compute_coveragei(pMin, pMid, pMax, ix, iy);
00239 #else
00240             array->coverage[count] = coverage;
00241 #endif
00242 #ifdef DO_Z
00243             array->z[count] = (GLuint) solve_plane(cx, cy, zPlane);
00244 #endif
00245 #ifdef DO_RGBA
00246             array->rgba[count][RCOMP] = solve_plane_chan(cx, cy, rPlane);
00247             array->rgba[count][GCOMP] = solve_plane_chan(cx, cy, gPlane);
00248             array->rgba[count][BCOMP] = solve_plane_chan(cx, cy, bPlane);
00249             array->rgba[count][ACOMP] = solve_plane_chan(cx, cy, aPlane);
00250 #endif
00251 #ifdef DO_INDEX
00252             array->index[count] = (GLint) solve_plane(cx, cy, iPlane);
00253 #endif
00254             ix++;
00255             count++;
00256             coverage = compute_coveragef(pMin, pMid, pMax, ix, iy);
00257          }
00258          
00259          if (ix <= startX)
00260             continue;
00261          
00262          span.x = startX;
00263          span.y = iy;
00264          span.end = (GLuint) ix - (GLuint) startX;
00265 #if defined(DO_RGBA)
00266          _swrast_write_rgba_span(ctx, &span);
00267 #else
00268          _swrast_write_index_span(ctx, &span);
00269 #endif
00270       }
00271    }
00272    else {
00273       /* scan right to left */
00274       const GLfloat *pMin = vMin->attrib[FRAG_ATTRIB_WPOS];
00275       const GLfloat *pMid = vMid->attrib[FRAG_ATTRIB_WPOS];
00276       const GLfloat *pMax = vMax->attrib[FRAG_ATTRIB_WPOS];
00277       const GLfloat dxdy = majDx / majDy;
00278       const GLfloat xAdj = dxdy > 0 ? dxdy : 0.0F;
00279       GLfloat x = pMin[0] - (yMin - iyMin) * dxdy;
00280       GLint iy;
00281       for (iy = iyMin; iy < iyMax; iy++, x += dxdy) {
00282          GLint ix, left, startX = (GLint) (x + xAdj);
00283          GLuint count, n;
00284          GLfloat coverage = 0.0F;
00285          
00286          /* make sure we're not past the window edge */
00287          if (startX >= ctx->DrawBuffer->_Xmax) {
00288             startX = ctx->DrawBuffer->_Xmax - 1;
00289          }
00290 
00291          /* skip fragments with zero coverage */
00292          while (startX > 0) {
00293             coverage = compute_coveragef(pMin, pMax, pMid, startX, iy);
00294             if (coverage > 0.0F)
00295                break;
00296             startX--;
00297          }
00298          
00299          /* enter interior of triangle */
00300          ix = startX;
00301          count = 0;
00302          while (coverage > 0.0F) {
00303             /* (cx,cy) = center of fragment */
00304             const GLfloat cx = ix + 0.5F, cy = iy + 0.5F;
00305             SWspanarrays *array = span.array;
00306             ASSERT(ix >= 0);
00307 #ifdef DO_INDEX
00308             array->coverage[ix] = (GLfloat) compute_coveragei(pMin, pMax, pMid, ix, iy);
00309 #else
00310             array->coverage[ix] = coverage;
00311 #endif
00312 #ifdef DO_Z
00313             array->z[ix] = (GLuint) solve_plane(cx, cy, zPlane);
00314 #endif
00315 #ifdef DO_RGBA
00316             array->rgba[ix][RCOMP] = solve_plane_chan(cx, cy, rPlane);
00317             array->rgba[ix][GCOMP] = solve_plane_chan(cx, cy, gPlane);
00318             array->rgba[ix][BCOMP] = solve_plane_chan(cx, cy, bPlane);
00319             array->rgba[ix][ACOMP] = solve_plane_chan(cx, cy, aPlane);
00320 #endif
00321 #ifdef DO_INDEX
00322             array->index[ix] = (GLint) solve_plane(cx, cy, iPlane);
00323 #endif
00324             ix--;
00325             count++;
00326             coverage = compute_coveragef(pMin, pMax, pMid, ix, iy);
00327          }
00328          
00329 #if defined(DO_ATTRIBS)
00330          /* compute attributes at left-most fragment */
00331          span.attrStart[FRAG_ATTRIB_WPOS][3] = solve_plane(ix + 1.5, iy + 0.5, wPlane);
00332          ATTRIB_LOOP_BEGIN
00333             GLuint c;
00334             for (c = 0; c < 4; c++) {
00335                span.attrStart[attr][c] = solve_plane(ix + 1.5, iy + 0.5, attrPlane[attr][c]);
00336             }
00337          ATTRIB_LOOP_END
00338 #endif
00339 
00340          if (startX <= ix)
00341             continue;
00342 
00343          n = (GLuint) startX - (GLuint) ix;
00344 
00345          left = ix + 1;
00346 
00347          /* shift all values to the left */
00348          /* XXX this is temporary */
00349          {
00350             SWspanarrays *array = span.array;
00351             GLint j;
00352             for (j = 0; j < (GLint) n; j++) {
00353                array->coverage[j] = array->coverage[j + left];
00354 #ifdef DO_RGBA
00355                COPY_CHAN4(array->rgba[j], array->rgba[j + left]);
00356 #endif
00357 #ifdef DO_INDEX
00358                array->index[j] = array->index[j + left];
00359 #endif
00360 #ifdef DO_Z
00361                array->z[j] = array->z[j + left];
00362 #endif
00363             }
00364          }
00365 
00366          span.x = left;
00367          span.y = iy;
00368          span.end = n;
00369 #if defined(DO_RGBA)
00370          _swrast_write_rgba_span(ctx, &span);
00371 #else
00372          _swrast_write_index_span(ctx, &span);
00373 #endif
00374       }
00375    }
00376 }
00377 
00378 
00379 #undef DO_Z
00380 #undef DO_RGBA
00381 #undef DO_INDEX
00382 #undef DO_ATTRIBS
00383 #undef DO_OCCLUSION_TEST

Generated on Sat May 26 2012 04:19:30 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.