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_lines.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.1
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 #include "main/glheader.h"
00027 #include "main/context.h"
00028 #include "main/colormac.h"
00029 #include "main/macros.h"
00030 #include "s_aaline.h"
00031 #include "s_context.h"
00032 #include "s_depth.h"
00033 #include "s_feedback.h"
00034 #include "s_lines.h"
00035 #include "s_span.h"
00036 
00037 
00038 /*
00039  * Init the mask[] array to implement a line stipple.
00040  */
00041 static void
00042 compute_stipple_mask( GLcontext *ctx, GLuint len, GLubyte mask[] )
00043 {
00044    SWcontext *swrast = SWRAST_CONTEXT(ctx);
00045    GLuint i;
00046 
00047    for (i = 0; i < len; i++) {
00048       GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf;
00049       if ((1 << bit) & ctx->Line.StipplePattern) {
00050          mask[i] = GL_TRUE;
00051       }
00052       else {
00053          mask[i] = GL_FALSE;
00054       }
00055       swrast->StippleCounter++;
00056    }
00057 }
00058 
00059 
00060 /*
00061  * To draw a wide line we can simply redraw the span N times, side by side.
00062  */
00063 static void
00064 draw_wide_line( GLcontext *ctx, SWspan *span, GLboolean xMajor )
00065 {
00066    const GLint width = (GLint) CLAMP(ctx->Line.Width,
00067                                      ctx->Const.MinLineWidth,
00068                                      ctx->Const.MaxLineWidth);
00069    GLint start;
00070 
00071    ASSERT(span->end < MAX_WIDTH);
00072 
00073    if (width & 1)
00074       start = width / 2;
00075    else
00076       start = width / 2 - 1;
00077 
00078    if (xMajor) {
00079       GLint *y = span->array->y;
00080       GLuint i;
00081       GLint w;
00082       for (w = 0; w < width; w++) {
00083          if (w == 0) {
00084             for (i = 0; i < span->end; i++)
00085                y[i] -= start;
00086          }
00087          else {
00088             for (i = 0; i < span->end; i++)
00089                y[i]++;
00090          }
00091          if (ctx->Visual.rgbMode)
00092             _swrast_write_rgba_span(ctx, span);
00093          else
00094             _swrast_write_index_span(ctx, span);
00095       }
00096    }
00097    else {
00098       GLint *x = span->array->x;
00099       GLuint i;
00100       GLint w;
00101       for (w = 0; w < width; w++) {
00102          if (w == 0) {
00103             for (i = 0; i < span->end; i++)
00104                x[i] -= start;
00105          }
00106          else {
00107             for (i = 0; i < span->end; i++)
00108                x[i]++;
00109          }
00110          if (ctx->Visual.rgbMode)
00111             _swrast_write_rgba_span(ctx, span);
00112          else
00113             _swrast_write_index_span(ctx, span);
00114       }
00115    }
00116 }
00117 
00118 
00119 
00120 /**********************************************************************/
00121 /*****                    Rasterization                           *****/
00122 /**********************************************************************/
00123 
00124 /* Simple color index line (no stipple, width=1, no Z, no fog, no tex)*/
00125 #define NAME simple_no_z_ci_line
00126 #define INTERP_INDEX
00127 #define RENDER_SPAN(span) _swrast_write_index_span(ctx, &span)
00128 #include "s_linetemp.h"
00129 
00130 /* Simple RGBA index line (no stipple, width=1, no Z, no fog, no tex)*/
00131 #define NAME simple_no_z_rgba_line
00132 #define INTERP_RGBA
00133 #define RENDER_SPAN(span) _swrast_write_rgba_span(ctx, &span);
00134 #include "s_linetemp.h"
00135 
00136 
00137 /* Z, fog, wide, stipple color index line */
00138 #define NAME ci_line
00139 #define INTERP_INDEX
00140 #define INTERP_Z
00141 #define INTERP_ATTRIBS /* for fog */
00142 #define RENDER_SPAN(span)                   \
00143    if (ctx->Line.StippleFlag) {                 \
00144       span.arrayMask |= SPAN_MASK;              \
00145       compute_stipple_mask(ctx, span.end, span.array->mask);    \
00146    }                                \
00147    if (ctx->Line.Width > 1.0) {                 \
00148       draw_wide_line(ctx, &span, (GLboolean)(dx > dy));     \
00149    }                                \
00150    else {                           \
00151       _swrast_write_index_span(ctx, &span);         \
00152    }
00153 #include "s_linetemp.h"
00154 
00155 
00156 /* Z, fog, wide, stipple RGBA line */
00157 #define NAME rgba_line
00158 #define INTERP_RGBA
00159 #define INTERP_Z
00160 #define RENDER_SPAN(span)                   \
00161    if (ctx->Line.StippleFlag) {                 \
00162       span.arrayMask |= SPAN_MASK;              \
00163       compute_stipple_mask(ctx, span.end, span.array->mask);    \
00164    }                                \
00165    if (ctx->Line.Width > 1.0) {                 \
00166       draw_wide_line(ctx, &span, (GLboolean)(dx > dy));     \
00167    }                                \
00168    else {                           \
00169       _swrast_write_rgba_span(ctx, &span);          \
00170    }
00171 #include "s_linetemp.h"
00172 
00173 
00174 /* General-purpose line (any/all features). */
00175 #define NAME general_line
00176 #define INTERP_RGBA
00177 #define INTERP_Z
00178 #define INTERP_ATTRIBS
00179 #define RENDER_SPAN(span)                   \
00180    if (ctx->Line.StippleFlag) {                 \
00181       span.arrayMask |= SPAN_MASK;              \
00182       compute_stipple_mask(ctx, span.end, span.array->mask);    \
00183    }                                \
00184    if (ctx->Line.Width > 1.0) {                 \
00185       draw_wide_line(ctx, &span, (GLboolean)(dx > dy));     \
00186    }                                \
00187    else {                           \
00188       _swrast_write_rgba_span(ctx, &span);          \
00189    }
00190 #include "s_linetemp.h"
00191 
00192 
00193 
00194 void
00195 _swrast_add_spec_terms_line(GLcontext *ctx,
00196                             const SWvertex *v0, const SWvertex *v1)
00197 {
00198    SWvertex *ncv0 = (SWvertex *)v0;
00199    SWvertex *ncv1 = (SWvertex *)v1;
00200    GLfloat rSum, gSum, bSum;
00201    GLchan cSave[2][4];
00202 
00203    /* save original colors */
00204    COPY_CHAN4(cSave[0], ncv0->color);
00205    COPY_CHAN4(cSave[1], ncv1->color);
00206    /* sum v0 */
00207    rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
00208    gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
00209    bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
00210    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
00211    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
00212    UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
00213    /* sum v1 */
00214    rSum = CHAN_TO_FLOAT(ncv1->color[0]) + ncv1->attrib[FRAG_ATTRIB_COL1][0];
00215    gSum = CHAN_TO_FLOAT(ncv1->color[1]) + ncv1->attrib[FRAG_ATTRIB_COL1][1];
00216    bSum = CHAN_TO_FLOAT(ncv1->color[2]) + ncv1->attrib[FRAG_ATTRIB_COL1][2];
00217    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[0], rSum);
00218    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[1], gSum);
00219    UNCLAMPED_FLOAT_TO_CHAN(ncv1->color[2], bSum);
00220    /* draw */
00221    SWRAST_CONTEXT(ctx)->SpecLine( ctx, ncv0, ncv1 );
00222    /* restore original colors */
00223    COPY_CHAN4( ncv0->attrib[FRAG_ATTRIB_COL0], cSave[0] );
00224    COPY_CHAN4( ncv1->attrib[FRAG_ATTRIB_COL0], cSave[1] );
00225 }
00226 
00227 
00228 
00229 #ifdef DEBUG
00230 
00231 /* record the current line function name */
00232 static const char *lineFuncName = NULL;
00233 
00234 #define USE(lineFunc)                   \
00235 do {                                    \
00236     lineFuncName = #lineFunc;           \
00237     /*_mesa_printf("%s\n", lineFuncName);*/   \
00238     swrast->Line = lineFunc;            \
00239 } while (0)
00240 
00241 #else
00242 
00243 #define USE(lineFunc)  swrast->Line = lineFunc
00244 
00245 #endif
00246 
00247 
00248 
00256 void
00257 _swrast_choose_line( GLcontext *ctx )
00258 {
00259    SWcontext *swrast = SWRAST_CONTEXT(ctx);
00260    const GLboolean rgbmode = ctx->Visual.rgbMode;
00261    GLboolean specular = (ctx->Fog.ColorSumEnabled ||
00262                          (ctx->Light.Enabled &&
00263                           ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR));
00264 
00265    if (ctx->RenderMode == GL_RENDER) {
00266       if (ctx->Line.SmoothFlag) {
00267          /* antialiased lines */
00268          _swrast_choose_aa_line_function(ctx);
00269          ASSERT(swrast->Line);
00270       }
00271       else if (ctx->Texture._EnabledCoordUnits
00272                || ctx->FragmentProgram._Current
00273                || swrast->_FogEnabled
00274                || specular) {
00275          USE(general_line);
00276       }
00277       else if (ctx->Depth.Test
00278                || ctx->Line.Width != 1.0
00279                || ctx->Line.StippleFlag) {
00280          /* no texture, but Z, fog, width>1, stipple, etc. */
00281          if (rgbmode)
00282 #if CHAN_BITS == 32
00283             USE(general_line);
00284 #else
00285             USE(rgba_line);
00286 #endif
00287          else
00288             USE(ci_line);
00289       }
00290       else {
00291          ASSERT(!ctx->Depth.Test);
00292          ASSERT(ctx->Line.Width == 1.0);
00293          /* simple lines */
00294          if (rgbmode)
00295             USE(simple_no_z_rgba_line);
00296          else
00297             USE(simple_no_z_ci_line);
00298       }
00299    }
00300    else if (ctx->RenderMode == GL_FEEDBACK) {
00301       USE(_swrast_feedback_line);
00302    }
00303    else {
00304       ASSERT(ctx->RenderMode == GL_SELECT);
00305       USE(_swrast_select_line);
00306    }
00307 }

Generated on Sat May 26 2012 04:19:32 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.