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_linetemp.h
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.0
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  * Line Rasterizer Template
00028  *
00029  * This file is #include'd to generate custom line rasterizers.
00030  *
00031  * The following macros may be defined to indicate what auxillary information
00032  * must be interplated along the line:
00033  *    INTERP_Z        - if defined, interpolate Z values
00034  *    INTERP_RGBA     - if defined, interpolate RGBA values
00035  *    INTERP_INDEX    - if defined, interpolate color index values
00036  *    INTERP_ATTRIBS  - if defined, interpolate attribs (texcoords, varying, etc)
00037  *
00038  * When one can directly address pixels in the color buffer the following
00039  * macros can be defined and used to directly compute pixel addresses during
00040  * rasterization (see pixelPtr):
00041  *    PIXEL_TYPE          - the datatype of a pixel (GLubyte, GLushort, GLuint)
00042  *    BYTES_PER_ROW       - number of bytes per row in the color buffer
00043  *    PIXEL_ADDRESS(X,Y)  - returns the address of pixel at (X,Y) where
00044  *                          Y==0 at bottom of screen and increases upward.
00045  *
00046  * Similarly, for direct depth buffer access, this type is used for depth
00047  * buffer addressing:
00048  *    DEPTH_TYPE          - either GLushort or GLuint
00049  *
00050  * Optionally, one may provide one-time setup code
00051  *    SETUP_CODE    - code which is to be executed once per line
00052  *
00053  * To actually "plot" each pixel the PLOT macro must be defined...
00054  *    PLOT(X,Y) - code to plot a pixel.  Example:
00055  *                if (Z < *zPtr) {
00056  *                   *zPtr = Z;
00057  *                   color = pack_rgb( FixedToInt(r0), FixedToInt(g0),
00058  *                                     FixedToInt(b0) );
00059  *                   put_pixel( X, Y, color );
00060  *                }
00061  *
00062  * This code was designed for the origin to be in the lower-left corner.
00063  *
00064  */
00065 
00066 
00067 static void
00068 NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
00069 {
00070    const SWcontext *swrast = SWRAST_CONTEXT(ctx);
00071    SWspan span;
00072    GLuint interpFlags = 0;
00073    GLint x0 = (GLint) vert0->attrib[FRAG_ATTRIB_WPOS][0];
00074    GLint x1 = (GLint) vert1->attrib[FRAG_ATTRIB_WPOS][0];
00075    GLint y0 = (GLint) vert0->attrib[FRAG_ATTRIB_WPOS][1];
00076    GLint y1 = (GLint) vert1->attrib[FRAG_ATTRIB_WPOS][1];
00077    GLint dx, dy;
00078    GLint numPixels;
00079    GLint xstep, ystep;
00080 #if defined(DEPTH_TYPE)
00081    const GLint depthBits = ctx->DrawBuffer->Visual.depthBits;
00082    const GLint fixedToDepthShift = depthBits <= 16 ? FIXED_SHIFT : 0;
00083    struct gl_renderbuffer *zrb = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
00084 #define FixedToDepth(F)  ((F) >> fixedToDepthShift)
00085    GLint zPtrXstep, zPtrYstep;
00086    DEPTH_TYPE *zPtr;
00087 #elif defined(INTERP_Z)
00088    const GLint depthBits = ctx->DrawBuffer->Visual.depthBits;
00089 /*ctx->Visual.depthBits;*/
00090 #endif
00091 #ifdef PIXEL_ADDRESS
00092    PIXEL_TYPE *pixelPtr;
00093    GLint pixelXstep, pixelYstep;
00094 #endif
00095 
00096 #ifdef SETUP_CODE
00097    SETUP_CODE
00098 #endif
00099 
00100    (void) swrast;
00101 
00102    /* Cull primitives with malformed coordinates.
00103     */
00104    {
00105       GLfloat tmp = vert0->attrib[FRAG_ATTRIB_WPOS][0] + vert0->attrib[FRAG_ATTRIB_WPOS][1]
00106                   + vert1->attrib[FRAG_ATTRIB_WPOS][0] + vert1->attrib[FRAG_ATTRIB_WPOS][1];
00107       if (IS_INF_OR_NAN(tmp))
00108      return;
00109    }
00110 
00111    /*
00112    printf("%s():\n", __FUNCTION__);
00113    printf(" (%f, %f, %f) -> (%f, %f, %f)\n",
00114           vert0->attrib[FRAG_ATTRIB_WPOS][0],
00115           vert0->attrib[FRAG_ATTRIB_WPOS][1],
00116           vert0->attrib[FRAG_ATTRIB_WPOS][2],
00117           vert1->attrib[FRAG_ATTRIB_WPOS][0],
00118           vert1->attrib[FRAG_ATTRIB_WPOS][1],
00119           vert1->attrib[FRAG_ATTRIB_WPOS][2]);
00120    printf(" (%d, %d, %d) -> (%d, %d, %d)\n",
00121           vert0->color[0], vert0->color[1], vert0->color[2], 
00122           vert1->color[0], vert1->color[1], vert1->color[2]);
00123    printf(" (%d, %d, %d) -> (%d, %d, %d)\n",
00124           vert0->specular[0], vert0->specular[1], vert0->specular[2], 
00125           vert1->specular[0], vert1->specular[1], vert1->specular[2]);
00126    */
00127 
00128 /*
00129  * Despite being clipped to the view volume, the line's window coordinates
00130  * may just lie outside the window bounds.  That is, if the legal window
00131  * coordinates are [0,W-1][0,H-1], it's possible for x==W and/or y==H.
00132  * This quick and dirty code nudges the endpoints inside the window if
00133  * necessary.
00134  */
00135 #ifdef CLIP_HACK
00136    {
00137       GLint w = ctx->DrawBuffer->Width;
00138       GLint h = ctx->DrawBuffer->Height;
00139       if ((x0==w) | (x1==w)) {
00140          if ((x0==w) & (x1==w))
00141            return;
00142          x0 -= x0==w;
00143          x1 -= x1==w;
00144       }
00145       if ((y0==h) | (y1==h)) {
00146          if ((y0==h) & (y1==h))
00147            return;
00148          y0 -= y0==h;
00149          y1 -= y1==h;
00150       }
00151    }
00152 #endif
00153 
00154    dx = x1 - x0;
00155    dy = y1 - y0;
00156    if (dx == 0 && dy == 0)
00157       return;
00158 
00159    /*
00160    printf("%s %d,%d  %g %g %g %g  %g %g %g %g\n", __FUNCTION__, dx, dy,
00161           vert0->attrib[FRAG_ATTRIB_COL1][0],
00162           vert0->attrib[FRAG_ATTRIB_COL1][1],
00163           vert0->attrib[FRAG_ATTRIB_COL1][2],
00164           vert0->attrib[FRAG_ATTRIB_COL1][3],
00165           vert1->attrib[FRAG_ATTRIB_COL1][0],
00166           vert1->attrib[FRAG_ATTRIB_COL1][1],
00167           vert1->attrib[FRAG_ATTRIB_COL1][2],
00168           vert1->attrib[FRAG_ATTRIB_COL1][3]);
00169    */
00170 
00171 #ifdef DEPTH_TYPE
00172    zPtr = (DEPTH_TYPE *) zrb->GetPointer(ctx, zrb, x0, y0);
00173 #endif
00174 #ifdef PIXEL_ADDRESS
00175    pixelPtr = (PIXEL_TYPE *) PIXEL_ADDRESS(x0,y0);
00176 #endif
00177 
00178    if (dx<0) {
00179       dx = -dx;   /* make positive */
00180       xstep = -1;
00181 #ifdef DEPTH_TYPE
00182       zPtrXstep = -((GLint)sizeof(DEPTH_TYPE));
00183 #endif
00184 #ifdef PIXEL_ADDRESS
00185       pixelXstep = -((GLint)sizeof(PIXEL_TYPE));
00186 #endif
00187    }
00188    else {
00189       xstep = 1;
00190 #ifdef DEPTH_TYPE
00191       zPtrXstep = ((GLint)sizeof(DEPTH_TYPE));
00192 #endif
00193 #ifdef PIXEL_ADDRESS
00194       pixelXstep = ((GLint)sizeof(PIXEL_TYPE));
00195 #endif
00196    }
00197 
00198    if (dy<0) {
00199       dy = -dy;   /* make positive */
00200       ystep = -1;
00201 #ifdef DEPTH_TYPE
00202       zPtrYstep = -((GLint) (ctx->DrawBuffer->Width * sizeof(DEPTH_TYPE)));
00203 #endif
00204 #ifdef PIXEL_ADDRESS
00205       pixelYstep = BYTES_PER_ROW;
00206 #endif
00207    }
00208    else {
00209       ystep = 1;
00210 #ifdef DEPTH_TYPE
00211       zPtrYstep = (GLint) (ctx->DrawBuffer->Width * sizeof(DEPTH_TYPE));
00212 #endif
00213 #ifdef PIXEL_ADDRESS
00214       pixelYstep = -(BYTES_PER_ROW);
00215 #endif
00216    }
00217 
00218    ASSERT(dx >= 0);
00219    ASSERT(dy >= 0);
00220 
00221    numPixels = MAX2(dx, dy);
00222 
00223    /*
00224     * Span setup: compute start and step values for all interpolated values.
00225     */
00226 #ifdef INTERP_RGBA
00227    interpFlags |= SPAN_RGBA;
00228    if (ctx->Light.ShadeModel == GL_SMOOTH) {
00229       span.red   = ChanToFixed(vert0->color[0]);
00230       span.green = ChanToFixed(vert0->color[1]);
00231       span.blue  = ChanToFixed(vert0->color[2]);
00232       span.alpha = ChanToFixed(vert0->color[3]);
00233       span.redStep   = (ChanToFixed(vert1->color[0]) - span.red  ) / numPixels;
00234       span.greenStep = (ChanToFixed(vert1->color[1]) - span.green) / numPixels;
00235       span.blueStep  = (ChanToFixed(vert1->color[2]) - span.blue ) / numPixels;
00236       span.alphaStep = (ChanToFixed(vert1->color[3]) - span.alpha) / numPixels;
00237    }
00238    else {
00239       span.red   = ChanToFixed(vert1->color[0]);
00240       span.green = ChanToFixed(vert1->color[1]);
00241       span.blue  = ChanToFixed(vert1->color[2]);
00242       span.alpha = ChanToFixed(vert1->color[3]);
00243       span.redStep   = 0;
00244       span.greenStep = 0;
00245       span.blueStep  = 0;
00246       span.alphaStep = 0;
00247    }
00248 #endif
00249 #ifdef INTERP_INDEX
00250    interpFlags |= SPAN_INDEX;
00251    if (ctx->Light.ShadeModel == GL_SMOOTH) {
00252       span.index = FloatToFixed(vert0->attrib[FRAG_ATTRIB_CI][0]);
00253       span.indexStep = FloatToFixed(  vert1->attrib[FRAG_ATTRIB_CI][0]
00254                                     - vert0->attrib[FRAG_ATTRIB_CI][0]) / numPixels;
00255    }
00256    else {
00257       span.index = FloatToFixed(vert1->attrib[FRAG_ATTRIB_CI][0]);
00258       span.indexStep = 0;
00259    }
00260 #endif
00261 #if defined(INTERP_Z) || defined(DEPTH_TYPE)
00262    interpFlags |= SPAN_Z;
00263    {
00264       if (depthBits <= 16) {
00265          span.z = FloatToFixed(vert0->attrib[FRAG_ATTRIB_WPOS][2]) + FIXED_HALF;
00266          span.zStep = FloatToFixed(  vert1->attrib[FRAG_ATTRIB_WPOS][2]
00267                                    - vert0->attrib[FRAG_ATTRIB_WPOS][2]) / numPixels;
00268       }
00269       else {
00270          /* don't use fixed point */
00271          span.z = (GLuint) vert0->attrib[FRAG_ATTRIB_WPOS][2];
00272          span.zStep = (GLint) ((  vert1->attrib[FRAG_ATTRIB_WPOS][2]
00273                                 - vert0->attrib[FRAG_ATTRIB_WPOS][2]) / numPixels);
00274       }
00275    }
00276 #endif
00277 #if defined(INTERP_ATTRIBS)
00278    {
00279       const GLfloat invLen = 1.0F / numPixels;
00280       const GLfloat invw0 = vert0->attrib[FRAG_ATTRIB_WPOS][3];
00281       const GLfloat invw1 = vert1->attrib[FRAG_ATTRIB_WPOS][3];
00282 
00283       span.attrStart[FRAG_ATTRIB_WPOS][3] = invw0;
00284       span.attrStepX[FRAG_ATTRIB_WPOS][3] = (invw1 - invw0) * invLen;
00285       span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0;
00286 
00287       ATTRIB_LOOP_BEGIN
00288          if (swrast->_InterpMode[attr] == GL_FLAT) {
00289             COPY_4V(span.attrStart[attr], vert1->attrib[attr]);
00290             ASSIGN_4V(span.attrStepX[attr], 0.0, 0.0, 0.0, 0.0);
00291          }
00292          else {
00293             GLuint c;
00294             for (c = 0; c < 4; c++) {
00295                float da;
00296                span.attrStart[attr][c] = invw0 * vert0->attrib[attr][c];
00297                da = (invw1 * vert1->attrib[attr][c]) - span.attrStart[attr][c];
00298                span.attrStepX[attr][c] = da * invLen;
00299             }
00300          }
00301          ASSIGN_4V(span.attrStepY[attr], 0.0, 0.0, 0.0, 0.0);
00302       ATTRIB_LOOP_END
00303    }
00304 #endif
00305 
00306    INIT_SPAN(span, GL_LINE);
00307    span.end = numPixels;
00308    span.interpMask = interpFlags;
00309    span.arrayMask = SPAN_XY;
00310 
00311    span.facing = swrast->PointLineFacing;
00312 
00313 
00314    /*
00315     * Draw
00316     */
00317 
00318    if (dx > dy) {
00319       /*** X-major line ***/
00320       GLint i;
00321       GLint errorInc = dy+dy;
00322       GLint error = errorInc-dx;
00323       GLint errorDec = error-dx;
00324 
00325       for (i = 0; i < dx; i++) {
00326 #ifdef DEPTH_TYPE
00327          GLuint Z = FixedToDepth(span.z);
00328 #endif
00329 #ifdef PLOT
00330          PLOT( x0, y0 );
00331 #else
00332          span.array->x[i] = x0;
00333          span.array->y[i] = y0;
00334 #endif
00335          x0 += xstep;
00336 #ifdef DEPTH_TYPE
00337          zPtr = (DEPTH_TYPE *) ((GLubyte*) zPtr + zPtrXstep);
00338          span.z += span.zStep;
00339 #endif
00340 #ifdef PIXEL_ADDRESS
00341          pixelPtr = (PIXEL_TYPE*) ((GLubyte*) pixelPtr + pixelXstep);
00342 #endif
00343          if (error < 0) {
00344             error += errorInc;
00345          }
00346          else {
00347             error += errorDec;
00348             y0 += ystep;
00349 #ifdef DEPTH_TYPE
00350             zPtr = (DEPTH_TYPE *) ((GLubyte*) zPtr + zPtrYstep);
00351 #endif
00352 #ifdef PIXEL_ADDRESS
00353             pixelPtr = (PIXEL_TYPE*) ((GLubyte*) pixelPtr + pixelYstep);
00354 #endif
00355          }
00356       }
00357    }
00358    else {
00359       /*** Y-major line ***/
00360       GLint i;
00361       GLint errorInc = dx+dx;
00362       GLint error = errorInc-dy;
00363       GLint errorDec = error-dy;
00364 
00365       for (i=0;i<dy;i++) {
00366 #ifdef DEPTH_TYPE
00367          GLuint Z = FixedToDepth(span.z);
00368 #endif
00369 #ifdef PLOT
00370          PLOT( x0, y0 );
00371 #else
00372          span.array->x[i] = x0;
00373          span.array->y[i] = y0;
00374 #endif
00375          y0 += ystep;
00376 #ifdef DEPTH_TYPE
00377          zPtr = (DEPTH_TYPE *) ((GLubyte*) zPtr + zPtrYstep);
00378          span.z += span.zStep;
00379 #endif
00380 #ifdef PIXEL_ADDRESS
00381          pixelPtr = (PIXEL_TYPE*) ((GLubyte*) pixelPtr + pixelYstep);
00382 #endif
00383          if (error<0) {
00384             error += errorInc;
00385          }
00386          else {
00387             error += errorDec;
00388             x0 += xstep;
00389 #ifdef DEPTH_TYPE
00390             zPtr = (DEPTH_TYPE *) ((GLubyte*) zPtr + zPtrXstep);
00391 #endif
00392 #ifdef PIXEL_ADDRESS
00393             pixelPtr = (PIXEL_TYPE*) ((GLubyte*) pixelPtr + pixelXstep);
00394 #endif
00395          }
00396       }
00397    }
00398 
00399 #ifdef RENDER_SPAN
00400    RENDER_SPAN( span );
00401 #endif
00402 
00403    (void)span;
00404 
00405 }
00406 
00407 
00408 #undef NAME
00409 #undef INTERP_Z
00410 #undef INTERP_RGBA
00411 #undef INTERP_ATTRIBS
00412 #undef INTERP_INDEX
00413 #undef PIXEL_ADDRESS
00414 #undef PIXEL_TYPE
00415 #undef DEPTH_TYPE
00416 #undef BYTES_PER_ROW
00417 #undef SETUP_CODE
00418 #undef PLOT
00419 #undef CLIP_HACK
00420 #undef FixedToDepth
00421 #undef RENDER_SPAN

Generated on Fri May 25 2012 04:18:51 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.