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

ss_triangle.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  * Authors:
00025  *    Keith Whitwell <keith@tungstengraphics.com>
00026  */
00027 
00028 #include "main/glheader.h"
00029 #include "main/colormac.h"
00030 #include "main/macros.h"
00031 #include "main/mtypes.h"
00032 
00033 #include "tnl/t_context.h"
00034 
00035 #include "ss_triangle.h"
00036 #include "ss_context.h"
00037 
00038 #define SS_RGBA_BIT         0x1
00039 #define SS_OFFSET_BIT       0x2
00040 #define SS_TWOSIDE_BIT      0x4
00041 #define SS_UNFILLED_BIT     0x8
00042 #define SS_MAX_TRIFUNC      0x10
00043 
00044 static tnl_triangle_func tri_tab[SS_MAX_TRIFUNC];
00045 static tnl_quad_func     quad_tab[SS_MAX_TRIFUNC];
00046 
00047 
00048 static void _swsetup_render_line_tri( GLcontext *ctx,
00049                       GLuint e0, GLuint e1, GLuint e2,
00050                                       GLuint facing )
00051 {
00052    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00053    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
00054    GLubyte *ef = VB->EdgeFlag;
00055    SWvertex *verts = swsetup->verts;
00056    SWvertex *v0 = &verts[e0];
00057    SWvertex *v1 = &verts[e1];
00058    SWvertex *v2 = &verts[e2];
00059    GLchan c[2][4];
00060    GLfloat s[2][4];
00061    GLfloat i[2];
00062 
00063    /* cull testing */
00064    if (ctx->Polygon.CullFlag) {
00065       if (facing == 1 && ctx->Polygon.CullFaceMode != GL_FRONT)
00066          return;
00067       if (facing == 0 && ctx->Polygon.CullFaceMode != GL_BACK)
00068          return;
00069    }
00070 
00071    _swrast_SetFacing(ctx, facing);
00072 
00073    if (ctx->Light.ShadeModel == GL_FLAT) {
00074       COPY_CHAN4(c[0], v0->color);
00075       COPY_CHAN4(c[1], v1->color);
00076       COPY_4V(s[0], v0->attrib[FRAG_ATTRIB_COL1]);
00077       COPY_4V(s[1], v1->attrib[FRAG_ATTRIB_COL1]);
00078       i[0] = v0->attrib[FRAG_ATTRIB_CI][0];
00079       i[1] = v1->attrib[FRAG_ATTRIB_CI][0];
00080 
00081       COPY_CHAN4(v0->color, v2->color);
00082       COPY_CHAN4(v1->color, v2->color);
00083       COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
00084       COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
00085       v0->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
00086       v1->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
00087    }
00088 
00089    if (swsetup->render_prim == GL_POLYGON) {
00090       if (ef[e2]) _swrast_Line( ctx, v2, v0 );
00091       if (ef[e0]) _swrast_Line( ctx, v0, v1 );
00092       if (ef[e1]) _swrast_Line( ctx, v1, v2 );
00093    } else {
00094       if (ef[e0]) _swrast_Line( ctx, v0, v1 );
00095       if (ef[e1]) _swrast_Line( ctx, v1, v2 );
00096       if (ef[e2]) _swrast_Line( ctx, v2, v0 );
00097    }
00098 
00099    if (ctx->Light.ShadeModel == GL_FLAT) {
00100       COPY_CHAN4(v0->color, c[0]);
00101       COPY_CHAN4(v1->color, c[1]);
00102       COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], s[0]);
00103       COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], s[1]);
00104       v0->attrib[FRAG_ATTRIB_CI][0] = i[0];
00105       v1->attrib[FRAG_ATTRIB_CI][0] = i[1];
00106    }
00107 }
00108 
00109 static void _swsetup_render_point_tri( GLcontext *ctx,
00110                        GLuint e0, GLuint e1, GLuint e2,
00111                                        GLuint facing )
00112 {
00113    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00114    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
00115    GLubyte *ef = VB->EdgeFlag;
00116    SWvertex *verts = swsetup->verts;
00117    SWvertex *v0 = &verts[e0];
00118    SWvertex *v1 = &verts[e1];
00119    SWvertex *v2 = &verts[e2];
00120    GLchan c[2][4];
00121    GLfloat s[2][4];
00122    GLfloat i[2];
00123 
00124    /* cull testing */
00125    if (ctx->Polygon.CullFlag) {
00126       if (facing == 1 && ctx->Polygon.CullFaceMode != GL_FRONT)
00127          return;
00128       if (facing == 0 && ctx->Polygon.CullFaceMode != GL_BACK)
00129          return;
00130    }
00131 
00132    _swrast_SetFacing(ctx, facing);
00133 
00134    if (ctx->Light.ShadeModel == GL_FLAT) {
00135       /* save colors/indexes for v0, v1 vertices */
00136       COPY_CHAN4(c[0], v0->color);
00137       COPY_CHAN4(c[1], v1->color);
00138       COPY_4V(s[0], v0->attrib[FRAG_ATTRIB_COL1]);
00139       COPY_4V(s[1], v1->attrib[FRAG_ATTRIB_COL1]);
00140       i[0] = v0->attrib[FRAG_ATTRIB_CI][0];
00141       i[1] = v1->attrib[FRAG_ATTRIB_CI][0];
00142 
00143       /* copy v2 color/indexes to v0, v1 indexes */
00144       COPY_CHAN4(v0->color, v2->color);
00145       COPY_CHAN4(v1->color, v2->color);
00146       COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
00147       COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], v2->attrib[FRAG_ATTRIB_COL1]);
00148       v0->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
00149       v1->attrib[FRAG_ATTRIB_CI][0] = v2->attrib[FRAG_ATTRIB_CI][0];
00150    }
00151 
00152    if (ef[e0]) _swrast_Point( ctx, v0 );
00153    if (ef[e1]) _swrast_Point( ctx, v1 );
00154    if (ef[e2]) _swrast_Point( ctx, v2 );
00155 
00156    if (ctx->Light.ShadeModel == GL_FLAT) {
00157       /* restore v0, v1 colores/indexes */
00158       COPY_CHAN4(v0->color, c[0]);
00159       COPY_CHAN4(v1->color, c[1]);
00160       COPY_4V(v0->attrib[FRAG_ATTRIB_COL1], s[0]);
00161       COPY_4V(v1->attrib[FRAG_ATTRIB_COL1], s[1]);
00162       v0->attrib[FRAG_ATTRIB_CI][0] = i[0];
00163       v1->attrib[FRAG_ATTRIB_CI][0] = i[1];
00164    }
00165    _swrast_flush(ctx);
00166 }
00167 
00168 #define SS_COLOR(a,b) UNCLAMPED_FLOAT_TO_RGBA_CHAN(a,b)
00169 #define SS_SPEC(a,b) UNCLAMPED_FLOAT_TO_RGB_CHAN(a,b)
00170 #define SS_IND(a,b) (a = b)
00171 
00172 #define IND (0)
00173 #define TAG(x) x
00174 #include "ss_tritmp.h"
00175 
00176 #define IND (SS_OFFSET_BIT)
00177 #define TAG(x) x##_offset
00178 #include "ss_tritmp.h"
00179 
00180 #define IND (SS_TWOSIDE_BIT)
00181 #define TAG(x) x##_twoside
00182 #include "ss_tritmp.h"
00183 
00184 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT)
00185 #define TAG(x) x##_offset_twoside
00186 #include "ss_tritmp.h"
00187 
00188 #define IND (SS_UNFILLED_BIT)
00189 #define TAG(x) x##_unfilled
00190 #include "ss_tritmp.h"
00191 
00192 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT)
00193 #define TAG(x) x##_offset_unfilled
00194 #include "ss_tritmp.h"
00195 
00196 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
00197 #define TAG(x) x##_twoside_unfilled
00198 #include "ss_tritmp.h"
00199 
00200 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT)
00201 #define TAG(x) x##_offset_twoside_unfilled
00202 #include "ss_tritmp.h"
00203 
00204 #define IND (0|SS_RGBA_BIT)
00205 #define TAG(x) x##_rgba
00206 #include "ss_tritmp.h"
00207 
00208 #define IND (SS_OFFSET_BIT|SS_RGBA_BIT)
00209 #define TAG(x) x##_offset_rgba
00210 #include "ss_tritmp.h"
00211 
00212 #define IND (SS_TWOSIDE_BIT|SS_RGBA_BIT)
00213 #define TAG(x) x##_twoside_rgba
00214 #include "ss_tritmp.h"
00215 
00216 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_RGBA_BIT)
00217 #define TAG(x) x##_offset_twoside_rgba
00218 #include "ss_tritmp.h"
00219 
00220 #define IND (SS_UNFILLED_BIT|SS_RGBA_BIT)
00221 #define TAG(x) x##_unfilled_rgba
00222 #include "ss_tritmp.h"
00223 
00224 #define IND (SS_OFFSET_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
00225 #define TAG(x) x##_offset_unfilled_rgba
00226 #include "ss_tritmp.h"
00227 
00228 #define IND (SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
00229 #define TAG(x) x##_twoside_unfilled_rgba
00230 #include "ss_tritmp.h"
00231 
00232 #define IND (SS_OFFSET_BIT|SS_TWOSIDE_BIT|SS_UNFILLED_BIT|SS_RGBA_BIT)
00233 #define TAG(x) x##_offset_twoside_unfilled_rgba
00234 #include "ss_tritmp.h"
00235 
00236 
00237 void _swsetup_trifuncs_init( GLcontext *ctx )
00238 {
00239    (void) ctx;
00240 
00241    init();
00242    init_offset();
00243    init_twoside();
00244    init_offset_twoside();
00245    init_unfilled();
00246    init_offset_unfilled();
00247    init_twoside_unfilled();
00248    init_offset_twoside_unfilled();
00249 
00250    init_rgba();
00251    init_offset_rgba();
00252    init_twoside_rgba();
00253    init_offset_twoside_rgba();
00254    init_unfilled_rgba();
00255    init_offset_unfilled_rgba();
00256    init_twoside_unfilled_rgba();
00257    init_offset_twoside_unfilled_rgba();
00258 }
00259 
00260 
00261 static void swsetup_points( GLcontext *ctx, GLuint first, GLuint last )
00262 {
00263    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
00264    SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
00265    GLuint i;
00266 
00267    if (VB->Elts) {
00268       for (i = first; i < last; i++)
00269      if (VB->ClipMask[VB->Elts[i]] == 0)
00270         _swrast_Point( ctx, &verts[VB->Elts[i]] );
00271    }
00272    else {
00273       for (i = first; i < last; i++)
00274      if (VB->ClipMask[i] == 0)
00275         _swrast_Point( ctx, &verts[i] );
00276    }
00277 }
00278 
00279 static void swsetup_line( GLcontext *ctx, GLuint v0, GLuint v1 )
00280 {
00281    SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
00282    _swrast_Line( ctx, &verts[v0], &verts[v1] );
00283 }
00284 
00285 
00286 
00287 void _swsetup_choose_trifuncs( GLcontext *ctx )
00288 {
00289    TNLcontext *tnl = TNL_CONTEXT(ctx);
00290    GLuint ind = 0;
00291 
00292    if (ctx->Polygon.OffsetPoint ||
00293        ctx->Polygon.OffsetLine ||
00294        ctx->Polygon.OffsetFill)
00295       ind |= SS_OFFSET_BIT;
00296 
00297    if ((ctx->Light.Enabled && ctx->Light.Model.TwoSide) ||
00298        (ctx->VertexProgram._Current && ctx->VertexProgram.TwoSideEnabled))
00299       ind |= SS_TWOSIDE_BIT;
00300 
00301    /* We piggyback the two-sided stencil front/back determination on the
00302     * unfilled triangle path.
00303     */
00304    if (ctx->Polygon.FrontMode != GL_FILL ||
00305        ctx->Polygon.BackMode != GL_FILL ||
00306        (ctx->Stencil.Enabled && ctx->Stencil._TestTwoSide))
00307       ind |= SS_UNFILLED_BIT;
00308 
00309    if (ctx->Visual.rgbMode)
00310       ind |= SS_RGBA_BIT;
00311 
00312    tnl->Driver.Render.Triangle = tri_tab[ind];
00313    tnl->Driver.Render.Quad = quad_tab[ind];
00314    tnl->Driver.Render.Line = swsetup_line;
00315    tnl->Driver.Render.Points = swsetup_points;
00316 }

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