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_tritmp.h
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 
00033 static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
00034 {
00035    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
00036    SScontext *swsetup = SWSETUP_CONTEXT(ctx);
00037    SWvertex *verts = SWSETUP_CONTEXT(ctx)->verts;
00038    SWvertex *v[3];
00039    GLfloat z[3];
00040    GLfloat offset, oz0, oz1, oz2;
00041    GLenum mode = GL_FILL;
00042    GLuint facing = 0;
00043    GLchan saved_color[3][4];
00044    GLfloat saved_col0[3][4];
00045    GLfloat saved_spec[3][4];
00046    GLfloat saved_index[3];
00047 
00048    v[0] = &verts[e0];
00049    v[1] = &verts[e1];
00050    v[2] = &verts[e2];
00051 
00052    if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT))
00053    {
00054       GLfloat ex = v[0]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
00055       GLfloat ey = v[0]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
00056       GLfloat fx = v[1]->attrib[FRAG_ATTRIB_WPOS][0] - v[2]->attrib[FRAG_ATTRIB_WPOS][0];
00057       GLfloat fy = v[1]->attrib[FRAG_ATTRIB_WPOS][1] - v[2]->attrib[FRAG_ATTRIB_WPOS][1];
00058       GLfloat cc  = ex*fy - ey*fx;
00059 
00060       if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT))
00061       {
00062      facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
00063 
00064      if (IND & SS_UNFILLED_BIT)
00065         mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
00066 
00067      if (facing == 1) {
00068         if (IND & SS_TWOSIDE_BIT) {
00069            if (IND & SS_RGBA_BIT) {
00070                   if (VB->ColorPtr[1]) {
00071                      GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
00072 
00073                      if (swsetup->intColors) {
00074                         COPY_CHAN4(saved_color[0], v[0]->color);
00075                         COPY_CHAN4(saved_color[1], v[1]->color);
00076                         COPY_CHAN4(saved_color[2], v[2]->color);
00077                      }
00078                      else {
00079                         COPY_4V(saved_col0[0], v[0]->attrib[FRAG_ATTRIB_COL0]);
00080                         COPY_4V(saved_col0[1], v[1]->attrib[FRAG_ATTRIB_COL0]);
00081                         COPY_4V(saved_col0[2], v[2]->attrib[FRAG_ATTRIB_COL0]);
00082                      }
00083 
00084                      if (VB->ColorPtr[1]->stride) {
00085                         if (swsetup->intColors) {
00086                            SS_COLOR(v[0]->color, vbcolor[e0]);
00087                            SS_COLOR(v[1]->color, vbcolor[e1]);
00088                            SS_COLOR(v[2]->color, vbcolor[e2]);
00089                         }
00090                         else {
00091                            COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], vbcolor[e0]);
00092                            COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], vbcolor[e1]);
00093                            COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], vbcolor[e2]);
00094                         }
00095                      }
00096                      else {
00097                         /* flat shade */
00098                         if (swsetup->intColors) {
00099                            SS_COLOR(v[0]->color, vbcolor[0]);
00100                            SS_COLOR(v[1]->color, vbcolor[0]);
00101                            SS_COLOR(v[2]->color, vbcolor[0]);
00102                         }
00103                         else {
00104                            COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
00105                            COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
00106                            COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], vbcolor[0]);
00107                         }
00108                      }
00109                   }
00110 
00111           if (VB->SecondaryColorPtr[1]) {
00112              GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
00113 
00114              COPY_4V(saved_spec[0], v[0]->attrib[FRAG_ATTRIB_COL1]);
00115              COPY_4V(saved_spec[1], v[1]->attrib[FRAG_ATTRIB_COL1]);
00116              COPY_4V(saved_spec[2], v[2]->attrib[FRAG_ATTRIB_COL1]);
00117 
00118              if (VB->SecondaryColorPtr[1]->stride) {
00119             SS_SPEC(v[0]->attrib[FRAG_ATTRIB_COL1], vbspec[e0]);
00120             SS_SPEC(v[1]->attrib[FRAG_ATTRIB_COL1], vbspec[e1]);
00121             SS_SPEC(v[2]->attrib[FRAG_ATTRIB_COL1], vbspec[e2]);
00122              }
00123              else {
00124             SS_SPEC(v[0]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
00125             SS_SPEC(v[1]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
00126             SS_SPEC(v[2]->attrib[FRAG_ATTRIB_COL1], vbspec[0]);
00127              }
00128           }
00129            } else {
00130           GLfloat *vbindex = (GLfloat *)VB->IndexPtr[1]->data;
00131           saved_index[0] = v[0]->attrib[FRAG_ATTRIB_CI][0];
00132           saved_index[1] = v[1]->attrib[FRAG_ATTRIB_CI][0];
00133           saved_index[2] = v[2]->attrib[FRAG_ATTRIB_CI][0];
00134           
00135           SS_IND(v[0]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e0]);
00136           SS_IND(v[1]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e1]);
00137           SS_IND(v[2]->attrib[FRAG_ATTRIB_CI][0], (GLuint) vbindex[e2]);
00138            }
00139         }
00140      }
00141       }
00142 
00143       if (IND & SS_OFFSET_BIT) {
00144          const GLfloat max = ctx->DrawBuffer->_DepthMaxF;
00145          /* save original Z values (restored later) */
00146      z[0] = v[0]->attrib[FRAG_ATTRIB_WPOS][2];
00147      z[1] = v[1]->attrib[FRAG_ATTRIB_WPOS][2];
00148      z[2] = v[2]->attrib[FRAG_ATTRIB_WPOS][2];
00149          /* Note that Z values are already scaled to [0,65535] (for example)
00150           * so no MRD value is used here.
00151           */
00152      offset = ctx->Polygon.OffsetUnits;
00153      if (cc * cc > 1e-16) {
00154         const GLfloat ez = z[0] - z[2];
00155         const GLfloat fz = z[1] - z[2];
00156         const GLfloat oneOverArea = 1.0F / cc;
00157         const GLfloat dzdx = FABSF((ey * fz - ez * fy) * oneOverArea);
00158         const GLfloat dzdy = FABSF((ez * fx - ex * fz) * oneOverArea);
00159         offset += MAX2(dzdx, dzdy) * ctx->Polygon.OffsetFactor;
00160      }
00161          /* new Z values */
00162          oz0 = CLAMP(v[0]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max);
00163          oz1 = CLAMP(v[1]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max);
00164          oz2 = CLAMP(v[2]->attrib[FRAG_ATTRIB_WPOS][2] + offset, 0.0, max);
00165       }
00166    }
00167 
00168    if (mode == GL_POINT) {
00169       if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetPoint) {
00170      v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
00171      v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
00172      v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
00173       }
00174       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
00175    } else if (mode == GL_LINE) {
00176       if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetLine) {
00177      v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
00178      v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
00179      v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
00180       }
00181       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
00182    } else {
00183       if ((IND & SS_OFFSET_BIT) && ctx->Polygon.OffsetFill) {
00184      v[0]->attrib[FRAG_ATTRIB_WPOS][2] = oz0;
00185      v[1]->attrib[FRAG_ATTRIB_WPOS][2] = oz1;
00186      v[2]->attrib[FRAG_ATTRIB_WPOS][2] = oz2;
00187       }
00188       _swrast_Triangle( ctx, v[0], v[1], v[2] );
00189    }
00190 
00191    /*
00192     * Restore original vertex colors, etc.
00193     */
00194    if (IND & SS_OFFSET_BIT) {
00195       v[0]->attrib[FRAG_ATTRIB_WPOS][2] = z[0];
00196       v[1]->attrib[FRAG_ATTRIB_WPOS][2] = z[1];
00197       v[2]->attrib[FRAG_ATTRIB_WPOS][2] = z[2];
00198    }
00199 
00200    if (IND & SS_TWOSIDE_BIT) {
00201       if (facing == 1) {
00202      if (IND & SS_RGBA_BIT) {
00203             if (VB->ColorPtr[1]) {
00204                if (swsetup->intColors) {
00205                   COPY_CHAN4(v[0]->color, saved_color[0]);
00206                   COPY_CHAN4(v[1]->color, saved_color[1]);
00207                   COPY_CHAN4(v[2]->color, saved_color[2]);
00208                }
00209                else {
00210                   COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL0], saved_col0[0]);
00211                   COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL0], saved_col0[1]);
00212                   COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL0], saved_col0[2]);
00213                }
00214             }
00215 
00216         if (VB->SecondaryColorPtr[1]) {
00217            COPY_4V(v[0]->attrib[FRAG_ATTRIB_COL1], saved_spec[0]);
00218            COPY_4V(v[1]->attrib[FRAG_ATTRIB_COL1], saved_spec[1]);
00219            COPY_4V(v[2]->attrib[FRAG_ATTRIB_COL1], saved_spec[2]);
00220         }
00221      } else {
00222         v[0]->attrib[FRAG_ATTRIB_CI][0] = saved_index[0];
00223         v[1]->attrib[FRAG_ATTRIB_CI][0] = saved_index[1];
00224         v[2]->attrib[FRAG_ATTRIB_CI][0] = saved_index[2];
00225      }
00226       }
00227    }
00228 }
00229 
00230 
00231 
00232 /* Need to fixup edgeflags when decomposing to triangles:
00233  */
00234 static void TAG(quadfunc)( GLcontext *ctx, GLuint v0,
00235                GLuint v1, GLuint v2, GLuint v3 )
00236 {
00237    if (IND & SS_UNFILLED_BIT) {
00238       struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
00239       if (VB->EdgeFlag) { /* XXX this test shouldn't be needed (bug 12614) */
00240          GLubyte ef1 = VB->EdgeFlag[v1];
00241          GLubyte ef3 = VB->EdgeFlag[v3];
00242          VB->EdgeFlag[v1] = 0;
00243          TAG(triangle)( ctx, v0, v1, v3 );
00244          VB->EdgeFlag[v1] = ef1;
00245          VB->EdgeFlag[v3] = 0;
00246          TAG(triangle)( ctx, v1, v2, v3 );
00247          VB->EdgeFlag[v3] = ef3;
00248       }
00249    } else {
00250       TAG(triangle)( ctx, v0, v1, v3 );
00251       TAG(triangle)( ctx, v1, v2, v3 );
00252    }
00253 }
00254 
00255 
00256 
00257 
00258 static void TAG(init)( void )
00259 {
00260    tri_tab[IND] = TAG(triangle);
00261    quad_tab[IND] = TAG(quadfunc);
00262 }
00263 
00264 
00265 #undef IND
00266 #undef TAG

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.