home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / swrast_setup / ss_triangle.cpp < prev    next >
C/C++ Source or Header  |  2002-12-19  |  133KB  |  3,243 lines

  1. /* $Id: ss_triangle.c,v 1.20 2002/10/29 22:25:57 brianp Exp $ */
  2.  
  3. #include "glheader.h"
  4. #include "colormac.h"
  5. #include "macros.h"
  6. #include "mtypes.h"
  7.  
  8. #include "tnl/t_context.h"
  9.  
  10. #include "ss_triangle.h"
  11. #include "ss_context.h"
  12.  
  13. #define SS_RGBA_BIT         0x1
  14. #define SS_OFFSET_BIT      0x2
  15. #define SS_TWOSIDE_BIT     0x4
  16. #define SS_UNFILLED_BIT            0x8
  17. #define SS_MAX_TRIFUNC      0x10
  18.  
  19. static triangle_func tri_tab[SS_MAX_TRIFUNC];
  20. static quad_func     quad_tab[SS_MAX_TRIFUNC];
  21.  
  22.  
  23.  
  24. /* static  */
  25. void
  26.  _swsetup_render_line_tri( GLcontext *ctx,
  27.                                      GLuint e0, GLuint e1, GLuint e2,
  28.                                       GLuint facing )
  29. {
  30.    SScontext *swsetup = ((SScontext *)ctx->swsetup_context);
  31.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  32.    GLubyte *ef = VB->EdgeFlag;
  33.    SWvertex *verts = swsetup->verts;
  34.    SWvertex *v0 = &verts[e0];
  35.    SWvertex *v1 = &verts[e1];
  36.    SWvertex *v2 = &verts[e2];
  37.    GLchan c[2][4];
  38.    GLchan s[2][4];
  39.    GLuint i[2];
  40.  
  41.    /* cull testing */
  42.    if (ctx->Polygon.CullFlag) {
  43.       if (facing == 1 && ctx->Polygon.CullFaceMode != 0x0404)
  44.          return;
  45.       if (facing == 0 && ctx->Polygon.CullFaceMode != 0x0405)
  46.          return;
  47.    }
  48.  
  49.    if (ctx->_TriangleCaps & 0x1) {
  50.       do { (c[0])[0] = (v0->color)[0]; (c[0])[1] = (v0->color)[1]; (c[0])[2] = (v0->color)[2]; (c[0])[3] = (v0->color)[3]; } while (0);
  51.       do { (c[1])[0] = (v1->color)[0]; (c[1])[1] = (v1->color)[1]; (c[1])[2] = (v1->color)[2]; (c[1])[3] = (v1->color)[3]; } while (0);
  52.       do { (s[0])[0] = (v0->specular)[0]; (s[0])[1] = (v0->specular)[1]; (s[0])[2] = (v0->specular)[2]; (s[0])[3] = (v0->specular)[3]; } while (0);
  53.       do { (s[1])[0] = (v1->specular)[0]; (s[1])[1] = (v1->specular)[1]; (s[1])[2] = (v1->specular)[2]; (s[1])[3] = (v1->specular)[3]; } while (0);
  54.       i[0] = v0->index;
  55.       i[1] = v1->index;
  56.  
  57.       do { (v0->color)[0] = (v2->color)[0]; (v0->color)[1] = (v2->color)[1]; (v0->color)[2] = (v2->color)[2]; (v0->color)[3] = (v2->color)[3]; } while (0);
  58.       do { (v1->color)[0] = (v2->color)[0]; (v1->color)[1] = (v2->color)[1]; (v1->color)[2] = (v2->color)[2]; (v1->color)[3] = (v2->color)[3]; } while (0);
  59.       do { (v0->specular)[0] = (v2->specular)[0]; (v0->specular)[1] = (v2->specular)[1]; (v0->specular)[2] = (v2->specular)[2]; (v0->specular)[3] = (v2->specular)[3]; } while (0);
  60.       do { (v1->specular)[0] = (v2->specular)[0]; (v1->specular)[1] = (v2->specular)[1]; (v1->specular)[2] = (v2->specular)[2]; (v1->specular)[3] = (v2->specular)[3]; } while (0);
  61.       v0->index = v2->index;
  62.       v1->index = v2->index;
  63.    }
  64.  
  65.    if (swsetup->render_prim == 0x0009) {
  66.       if (ef[e2]) _swrast_Line( ctx, v2, v0 );
  67.       if (ef[e0]) _swrast_Line( ctx, v0, v1 );
  68.       if (ef[e1]) _swrast_Line( ctx, v1, v2 );
  69.    } else {
  70.       if (ef[e0]) _swrast_Line( ctx, v0, v1 );
  71.       if (ef[e1]) _swrast_Line( ctx, v1, v2 );
  72.       if (ef[e2]) _swrast_Line( ctx, v2, v0 );
  73.    }
  74.  
  75.    if (ctx->_TriangleCaps & 0x1) {
  76.       do { (v0->color)[0] = (c[0])[0]; (v0->color)[1] = (c[0])[1]; (v0->color)[2] = (c[0])[2]; (v0->color)[3] = (c[0])[3]; } while (0);
  77.       do { (v1->color)[0] = (c[1])[0]; (v1->color)[1] = (c[1])[1]; (v1->color)[2] = (c[1])[2]; (v1->color)[3] = (c[1])[3]; } while (0);
  78.       do { (v0->specular)[0] = (s[0])[0]; (v0->specular)[1] = (s[0])[1]; (v0->specular)[2] = (s[0])[2]; (v0->specular)[3] = (s[0])[3]; } while (0);
  79.       do { (v1->specular)[0] = (s[1])[0]; (v1->specular)[1] = (s[1])[1]; (v1->specular)[2] = (s[1])[2]; (v1->specular)[3] = (s[1])[3]; } while (0);
  80.       v0->index = i[0];
  81.       v1->index = i[1];
  82.    }
  83. }
  84.  
  85. /* static */
  86.  void _swsetup_render_point_tri( GLcontext *ctx,
  87.                                       GLuint e0, GLuint e1, GLuint e2,
  88.                                        GLuint facing )
  89. {
  90.    SScontext *swsetup = ((SScontext *)ctx->swsetup_context);
  91.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  92.    GLubyte *ef = VB->EdgeFlag;
  93.    SWvertex *verts = swsetup->verts;
  94.    SWvertex *v0 = &verts[e0];
  95.    SWvertex *v1 = &verts[e1];
  96.    SWvertex *v2 = &verts[e2];
  97.    GLchan c[2][4];
  98.    GLchan s[2][4];
  99.    GLuint i[2];
  100.  
  101.    /* cull testing */
  102.    if (ctx->Polygon.CullFlag) {
  103.       if (facing == 1 && ctx->Polygon.CullFaceMode != 0x0404)
  104.          return;
  105.       if (facing == 0 && ctx->Polygon.CullFaceMode != 0x0405)
  106.          return;
  107.    }
  108.  
  109.    if (ctx->_TriangleCaps & 0x1) {
  110.       do { (c[0])[0] = (v0->color)[0]; (c[0])[1] = (v0->color)[1]; (c[0])[2] = (v0->color)[2]; (c[0])[3] = (v0->color)[3]; } while (0);
  111.       do { (c[1])[0] = (v1->color)[0]; (c[1])[1] = (v1->color)[1]; (c[1])[2] = (v1->color)[2]; (c[1])[3] = (v1->color)[3]; } while (0);
  112.       do { (s[0])[0] = (v0->specular)[0]; (s[0])[1] = (v0->specular)[1]; (s[0])[2] = (v0->specular)[2]; (s[0])[3] = (v0->specular)[3]; } while (0);
  113.       do { (s[1])[0] = (v1->specular)[0]; (s[1])[1] = (v1->specular)[1]; (s[1])[2] = (v1->specular)[2]; (s[1])[3] = (v1->specular)[3]; } while (0);
  114.       i[0] = v0->index;
  115.       i[1] = v1->index;
  116.  
  117.       do { (v0->color)[0] = (v2->color)[0]; (v0->color)[1] = (v2->color)[1]; (v0->color)[2] = (v2->color)[2]; (v0->color)[3] = (v2->color)[3]; } while (0);
  118.       do { (v1->color)[0] = (v2->color)[0]; (v1->color)[1] = (v2->color)[1]; (v1->color)[2] = (v2->color)[2]; (v1->color)[3] = (v2->color)[3]; } while (0);
  119.       do { (v0->specular)[0] = (v2->specular)[0]; (v0->specular)[1] = (v2->specular)[1]; (v0->specular)[2] = (v2->specular)[2]; (v0->specular)[3] = (v2->specular)[3]; } while (0);
  120.       do { (v1->specular)[0] = (v2->specular)[0]; (v1->specular)[1] = (v2->specular)[1]; (v1->specular)[2] = (v2->specular)[2]; (v1->specular)[3] = (v2->specular)[3]; } while (0);
  121.       v0->index = v2->index;
  122.       v1->index = v2->index;
  123.    }
  124.  
  125.    if (ef[e0]) _swrast_Point( ctx, v0 );
  126.    if (ef[e1]) _swrast_Point( ctx, v1 );
  127.    if (ef[e2]) _swrast_Point( ctx, v2 );
  128.  
  129.    if (ctx->_TriangleCaps & 0x1) {
  130.       do { (v0->color)[0] = (c[0])[0]; (v0->color)[1] = (c[0])[1]; (v0->color)[2] = (c[0])[2]; (v0->color)[3] = (c[0])[3]; } while (0);
  131.       do { (v1->color)[0] = (c[1])[0]; (v1->color)[1] = (c[1])[1]; (v1->color)[2] = (c[1])[2]; (v1->color)[3] = (c[1])[3]; } while (0);
  132.       do { (v0->specular)[0] = (s[0])[0]; (v0->specular)[1] = (s[0])[1]; (v0->specular)[2] = (s[0])[2]; (v0->specular)[3] = (s[0])[3]; } while (0);
  133.       do { (v1->specular)[0] = (s[1])[0]; (v1->specular)[1] = (s[1])[1]; (v1->specular)[2] = (s[1])[2]; (v1->specular)[3] = (s[1])[3]; } while (0);
  134.       v0->index = i[0];
  135.       v1->index = i[1];
  136.    }
  137.    _swrast_flush(ctx);
  138. }
  139.  
  140.  
  141. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  142.  
  143. /*
  144.  * Mesa 3-D graphics library
  145.  * Version:  5.0
  146.  *
  147.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  148.  *
  149.  * Permission is hereby granted, free of charge, to any person obtaining a
  150.  * copy of this software and associated documentation files (the "Software"),
  151.  * to deal in the Software without restriction, including without limitation
  152.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  153.  * and/or sell copies of the Software, and to permit persons to whom the
  154.  * Software is furnished to do so, subject to the following conditions:
  155.  *
  156.  * The above copyright notice and this permission notice shall be included
  157.  * in all copies or substantial portions of the Software.
  158.  *
  159.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  160.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  161.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  162.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  163.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  164.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  165.  *
  166.  * Authors:
  167.  *    Keith Whitwell <keith@tungstengraphics.com>
  168.  */
  169.  
  170.  
  171. static void triangle(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  172. {
  173.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  174.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  175.    SWvertex *v[3];
  176.    GLfloat z[3];
  177.    GLfloat offset;
  178.    GLenum mode = 0x1B02;
  179.    GLuint facing = 0;
  180.  
  181.    v[0] = &verts[e0];
  182.    v[1] = &verts[e1];
  183.    v[2] = &verts[e2];
  184.  
  185.  
  186.    if ((0) & (0x4 | 0x2 | 0x8))
  187.    {
  188.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  189.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  190.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  191.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  192.       GLfloat cc  = ex*fy - ey*fx;
  193.  
  194.       if ((0) & (0x4 | 0x8))
  195.       {
  196.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  197.          if (ctx->Stencil.TestTwoSide)
  198.             ctx->_Facing = facing; /* for 2-sided stencil test */
  199.  
  200.         if ((0) & 0x8)
  201.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  202.  
  203.         if (facing == 1) {
  204.            if ((0) & 0x4) {
  205.               if ((0) & 0x1) {
  206.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  207.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  208.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  209.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  210.                  if (VB->SecondaryColorPtr[1]) {
  211.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  212.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  213.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  214.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  215.                  }
  216.               } else {
  217.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  218.                  (v[0]->index = vbindex[e0]);
  219.                  (v[1]->index = vbindex[e1]);
  220.                  (v[2]->index = vbindex[e2]);
  221.               }
  222.            }
  223.         }
  224.       }
  225.  
  226.       if ((0) & 0x2)
  227.       {
  228.         offset = ctx->Polygon.OffsetUnits;
  229.         z[0] = v[0]->win[2];
  230.         z[1] = v[1]->win[2];
  231.         z[2] = v[2]->win[2];
  232.         if (cc * cc > 1e-16) {
  233.            GLfloat ez = z[0] - z[2];
  234.            GLfloat fz = z[1] - z[2];
  235.            GLfloat a = ey*fz - ez*fy;
  236.            GLfloat b = ez*fx - ex*fz;
  237.            GLfloat ic = 1.0F / cc;
  238.            GLfloat ac = a * ic;
  239.            GLfloat bc = b * ic;
  240.            if (ac < 0.0F) ac = -ac;
  241.            if (bc < 0.0F) bc = -bc;
  242.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  243.         }
  244.          offset *= ctx->MRD;
  245.          /*printf("offset %g\n", offset);*/
  246.       }
  247.    }
  248.  
  249.    if (mode == 0x1B00) {
  250.       if (((0) & 0x2) && ctx->Polygon.OffsetPoint) {
  251.         v[0]->win[2] += offset;
  252.         v[1]->win[2] += offset;
  253.         v[2]->win[2] += offset;
  254.       }
  255.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  256.    } else if (mode == 0x1B01) {
  257.       if (((0) & 0x2) && ctx->Polygon.OffsetLine) {
  258.         v[0]->win[2] += offset;
  259.         v[1]->win[2] += offset;
  260.         v[2]->win[2] += offset;
  261.       }
  262.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  263.    } else {
  264.       if (((0) & 0x2) && ctx->Polygon.OffsetFill) {
  265.         v[0]->win[2] += offset;
  266.         v[1]->win[2] += offset;
  267.         v[2]->win[2] += offset;
  268.       }
  269.  _mesa_debug(ctx, "triangle call  _swrast_Triangle\n");
  270.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  271.  _mesa_debug(ctx, "triangle  return  _swrast_Triangle\n");
  272.    }
  273.  
  274.    if ((0) & 0x2) {
  275.       v[0]->win[2] = z[0];
  276.       v[1]->win[2] = z[1];
  277.       v[2]->win[2] = z[2];
  278.    }
  279.  
  280.    if ((0) & 0x4) {
  281.       if (facing == 1) {
  282.         if ((0) & 0x1) {
  283.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  284.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  285.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  286.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  287.            if (VB->SecondaryColorPtr[0]) {
  288.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  289.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  290.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  291.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  292.            }
  293.         } else {
  294.            GLuint *vbindex = VB->IndexPtr[0]->data;
  295.            (v[0]->index = vbindex[e0]);
  296.            (v[1]->index = vbindex[e1]);
  297.            (v[2]->index = vbindex[e2]);
  298.         }
  299.       }
  300.    }
  301. }
  302.  
  303.  
  304.  
  305. /* Need to fixup edgeflags when decomposing to triangles:
  306.  */
  307. static void _Optlink quadfunc( GLcontext *ctx, GLuint v0,
  308.                       GLuint v1, GLuint v2, GLuint v3 )
  309. {
  310.    if ((0) & 0x8) {
  311.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  312.       GLubyte ef1 = VB->EdgeFlag[v1];
  313.       GLubyte ef3 = VB->EdgeFlag[v3];
  314.       VB->EdgeFlag[v1] = 0;
  315.       triangle( ctx, v0, v1, v3 );
  316.       VB->EdgeFlag[v1] = ef1;
  317.       VB->EdgeFlag[v3] = 0;
  318.       triangle( ctx, v1, v2, v3 );
  319.       VB->EdgeFlag[v3] = ef3;
  320.    } else {
  321.       triangle( ctx, v0, v1, v3 );
  322.       triangle( ctx, v1, v2, v3 );
  323.    }
  324. }
  325.  
  326.  
  327.  
  328.  
  329. static void init( void )
  330. {
  331.    tri_tab[(0)] = triangle;
  332.    quad_tab[(0)] = quadfunc;
  333. }
  334.  
  335.  
  336.  
  337. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  338.  
  339. /*
  340.  * Mesa 3-D graphics library
  341.  * Version:  5.0
  342.  *
  343.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  344.  *
  345.  * Permission is hereby granted, free of charge, to any person obtaining a
  346.  * copy of this software and associated documentation files (the "Software"),
  347.  * to deal in the Software without restriction, including without limitation
  348.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  349.  * and/or sell copies of the Software, and to permit persons to whom the
  350.  * Software is furnished to do so, subject to the following conditions:
  351.  *
  352.  * The above copyright notice and this permission notice shall be included
  353.  * in all copies or substantial portions of the Software.
  354.  *
  355.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  356.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  357.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  358.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  359.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  360.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  361.  *
  362.  * Authors:
  363.  *    Keith Whitwell <keith@tungstengraphics.com>
  364.  */
  365.  
  366.  
  367. static void triangle_offset(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  368. {
  369.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  370.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  371.    SWvertex *v[3];
  372.    GLfloat z[3];
  373.    GLfloat offset;
  374.    GLenum mode = 0x1B02;
  375.    GLuint facing = 0;
  376.  
  377.    v[0] = &verts[e0];
  378.    v[1] = &verts[e1];
  379.    v[2] = &verts[e2];
  380.  
  381.  
  382.    if ((0x2) & (0x4 | 0x2 | 0x8))
  383.    {
  384.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  385.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  386.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  387.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  388.       GLfloat cc  = ex*fy - ey*fx;
  389.  
  390.       if ((0x2) & (0x4 | 0x8))
  391.       {
  392.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  393.          if (ctx->Stencil.TestTwoSide)
  394.             ctx->_Facing = facing; /* for 2-sided stencil test */
  395.  
  396.         if ((0x2) & 0x8)
  397.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  398.  
  399.         if (facing == 1) {
  400.            if ((0x2) & 0x4) {
  401.               if ((0x2) & 0x1) {
  402.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  403.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  404.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  405.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  406.                  if (VB->SecondaryColorPtr[1]) {
  407.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  408.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  409.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  410.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  411.                  }
  412.               } else {
  413.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  414.                  (v[0]->index = vbindex[e0]);
  415.                  (v[1]->index = vbindex[e1]);
  416.                  (v[2]->index = vbindex[e2]);
  417.               }
  418.            }
  419.         }
  420.       }
  421.  
  422.       if ((0x2) & 0x2)
  423.       {
  424.         offset = ctx->Polygon.OffsetUnits;
  425.         z[0] = v[0]->win[2];
  426.         z[1] = v[1]->win[2];
  427.         z[2] = v[2]->win[2];
  428.         if (cc * cc > 1e-16) {
  429.            GLfloat ez = z[0] - z[2];
  430.            GLfloat fz = z[1] - z[2];
  431.            GLfloat a = ey*fz - ez*fy;
  432.            GLfloat b = ez*fx - ex*fz;
  433.            GLfloat ic = 1.0F / cc;
  434.            GLfloat ac = a * ic;
  435.            GLfloat bc = b * ic;
  436.            if (ac < 0.0F) ac = -ac;
  437.            if (bc < 0.0F) bc = -bc;
  438.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  439.         }
  440.          offset *= ctx->MRD;
  441.          /*printf("offset %g\n", offset);*/
  442.       }
  443.    }
  444.  
  445.    if (mode == 0x1B00) {
  446.       if (((0x2) & 0x2) && ctx->Polygon.OffsetPoint) {
  447.         v[0]->win[2] += offset;
  448.         v[1]->win[2] += offset;
  449.         v[2]->win[2] += offset;
  450.       }
  451.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  452.    } else if (mode == 0x1B01) {
  453.       if (((0x2) & 0x2) && ctx->Polygon.OffsetLine) {
  454.         v[0]->win[2] += offset;
  455.         v[1]->win[2] += offset;
  456.         v[2]->win[2] += offset;
  457.       }
  458.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  459.    } else {
  460.       if (((0x2) & 0x2) && ctx->Polygon.OffsetFill) {
  461.         v[0]->win[2] += offset;
  462.         v[1]->win[2] += offset;
  463.         v[2]->win[2] += offset;
  464.       }
  465.  _mesa_debug(ctx, "triangle_offset call  _swrast_Triangle\n");
  466.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  467.  _mesa_debug(ctx, "triangle_offset return  _swrast_Triangle\n");
  468.    }
  469.  
  470.    if ((0x2) & 0x2) {
  471.       v[0]->win[2] = z[0];
  472.       v[1]->win[2] = z[1];
  473.       v[2]->win[2] = z[2];
  474.    }
  475.  
  476.    if ((0x2) & 0x4) {
  477.       if (facing == 1) {
  478.         if ((0x2) & 0x1) {
  479.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  480.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  481.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  482.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  483.            if (VB->SecondaryColorPtr[0]) {
  484.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  485.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  486.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  487.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  488.            }
  489.         } else {
  490.            GLuint *vbindex = VB->IndexPtr[0]->data;
  491.            (v[0]->index = vbindex[e0]);
  492.            (v[1]->index = vbindex[e1]);
  493.            (v[2]->index = vbindex[e2]);
  494.         }
  495.       }
  496.    }
  497. }
  498.  
  499.  
  500.  
  501. /* Need to fixup edgeflags when decomposing to triangles:
  502.  */
  503. static void  _Optlink quadfunc_offset( GLcontext *ctx, GLuint v0,
  504.                       GLuint v1, GLuint v2, GLuint v3 )
  505. {
  506.    if ((0x2) & 0x8) {
  507.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  508.       GLubyte ef1 = VB->EdgeFlag[v1];
  509.       GLubyte ef3 = VB->EdgeFlag[v3];
  510.       VB->EdgeFlag[v1] = 0;
  511.       triangle_offset( ctx, v0, v1, v3 );
  512.       VB->EdgeFlag[v1] = ef1;
  513.       VB->EdgeFlag[v3] = 0;
  514.       triangle_offset( ctx, v1, v2, v3 );
  515.       VB->EdgeFlag[v3] = ef3;
  516.    } else {
  517.       triangle_offset( ctx, v0, v1, v3 );
  518.       triangle_offset( ctx, v1, v2, v3 );
  519.    }
  520. }
  521.  
  522.  
  523.  
  524.  
  525. static void init_offset( void )
  526. {
  527.    tri_tab[(0x2)] = triangle_offset;
  528.    quad_tab[(0x2)] = quadfunc_offset;
  529. }
  530.  
  531.  
  532.  
  533. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  534.  
  535. /*
  536.  * Mesa 3-D graphics library
  537.  * Version:  5.0
  538.  *
  539.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  540.  *
  541.  * Permission is hereby granted, free of charge, to any person obtaining a
  542.  * copy of this software and associated documentation files (the "Software"),
  543.  * to deal in the Software without restriction, including without limitation
  544.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  545.  * and/or sell copies of the Software, and to permit persons to whom the
  546.  * Software is furnished to do so, subject to the following conditions:
  547.  *
  548.  * The above copyright notice and this permission notice shall be included
  549.  * in all copies or substantial portions of the Software.
  550.  *
  551.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  552.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  553.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  554.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  555.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  556.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  557.  *
  558.  * Authors:
  559.  *    Keith Whitwell <keith@tungstengraphics.com>
  560.  */
  561.  
  562.  
  563. static void triangle_twoside(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  564. {
  565.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  566.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  567.    SWvertex *v[3];
  568.    GLfloat z[3];
  569.    GLfloat offset;
  570.    GLenum mode = 0x1B02;
  571.    GLuint facing = 0;
  572.  
  573.    v[0] = &verts[e0];
  574.    v[1] = &verts[e1];
  575.    v[2] = &verts[e2];
  576.  
  577.  
  578.    if ((0x4) & (0x4 | 0x2 | 0x8))
  579.    {
  580.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  581.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  582.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  583.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  584.       GLfloat cc  = ex*fy - ey*fx;
  585.  
  586.       if ((0x4) & (0x4 | 0x8))
  587.       {
  588.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  589.          if (ctx->Stencil.TestTwoSide)
  590.             ctx->_Facing = facing; /* for 2-sided stencil test */
  591.  
  592.         if ((0x4) & 0x8)
  593.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  594.  
  595.         if (facing == 1) {
  596.            if ((0x4) & 0x4) {
  597.               if ((0x4) & 0x1) {
  598.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  599.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  600.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  601.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  602.                  if (VB->SecondaryColorPtr[1]) {
  603.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  604.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  605.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  606.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  607.                  }
  608.               } else {
  609.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  610.                  (v[0]->index = vbindex[e0]);
  611.                  (v[1]->index = vbindex[e1]);
  612.                  (v[2]->index = vbindex[e2]);
  613.               }
  614.            }
  615.         }
  616.       }
  617.  
  618.       if ((0x4) & 0x2)
  619.       {
  620.         offset = ctx->Polygon.OffsetUnits;
  621.         z[0] = v[0]->win[2];
  622.         z[1] = v[1]->win[2];
  623.         z[2] = v[2]->win[2];
  624.         if (cc * cc > 1e-16) {
  625.            GLfloat ez = z[0] - z[2];
  626.            GLfloat fz = z[1] - z[2];
  627.            GLfloat a = ey*fz - ez*fy;
  628.            GLfloat b = ez*fx - ex*fz;
  629.            GLfloat ic = 1.0F / cc;
  630.            GLfloat ac = a * ic;
  631.            GLfloat bc = b * ic;
  632.            if (ac < 0.0F) ac = -ac;
  633.            if (bc < 0.0F) bc = -bc;
  634.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  635.         }
  636.          offset *= ctx->MRD;
  637.          /*printf("offset %g\n", offset);*/
  638.       }
  639.    }
  640.  
  641.    if (mode == 0x1B00) {
  642.       if (((0x4) & 0x2) && ctx->Polygon.OffsetPoint) {
  643.         v[0]->win[2] += offset;
  644.         v[1]->win[2] += offset;
  645.         v[2]->win[2] += offset;
  646.       }
  647.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  648.    } else if (mode == 0x1B01) {
  649.       if (((0x4) & 0x2) && ctx->Polygon.OffsetLine) {
  650.         v[0]->win[2] += offset;
  651.         v[1]->win[2] += offset;
  652.         v[2]->win[2] += offset;
  653.       }
  654.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  655.    } else {
  656.       if (((0x4) & 0x2) && ctx->Polygon.OffsetFill) {
  657.         v[0]->win[2] += offset;
  658.         v[1]->win[2] += offset;
  659.         v[2]->win[2] += offset;
  660.       }
  661.  _mesa_debug(ctx, "triangle_twoside call  _swrast_Triangle\n");
  662.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  663.  _mesa_debug(ctx, "triangle_twoside return  _swrast_Triangle\n");
  664.    }
  665.  
  666.    if ((0x4) & 0x2) {
  667.       v[0]->win[2] = z[0];
  668.       v[1]->win[2] = z[1];
  669.       v[2]->win[2] = z[2];
  670.    }
  671.  
  672.    if ((0x4) & 0x4) {
  673.       if (facing == 1) {
  674.         if ((0x4) & 0x1) {
  675.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  676.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  677.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  678.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  679.            if (VB->SecondaryColorPtr[0]) {
  680.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  681.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  682.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  683.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  684.            }
  685.         } else {
  686.            GLuint *vbindex = VB->IndexPtr[0]->data;
  687.            (v[0]->index = vbindex[e0]);
  688.            (v[1]->index = vbindex[e1]);
  689.            (v[2]->index = vbindex[e2]);
  690.         }
  691.       }
  692.    }
  693. }
  694.  
  695.  
  696.  
  697. /* Need to fixup edgeflags when decomposing to triangles:
  698.  */
  699. static void  _Optlink  quadfunc_twoside( GLcontext *ctx, GLuint v0,
  700.                       GLuint v1, GLuint v2, GLuint v3 )
  701. {
  702.    if ((0x4) & 0x8) {
  703.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  704.       GLubyte ef1 = VB->EdgeFlag[v1];
  705.       GLubyte ef3 = VB->EdgeFlag[v3];
  706.       VB->EdgeFlag[v1] = 0;
  707.       triangle_twoside( ctx, v0, v1, v3 );
  708.       VB->EdgeFlag[v1] = ef1;
  709.       VB->EdgeFlag[v3] = 0;
  710.       triangle_twoside( ctx, v1, v2, v3 );
  711.       VB->EdgeFlag[v3] = ef3;
  712.    } else {
  713.       triangle_twoside( ctx, v0, v1, v3 );
  714.       triangle_twoside( ctx, v1, v2, v3 );
  715.    }
  716. }
  717.  
  718.  
  719.  
  720.  
  721. static void init_twoside( void )
  722. {
  723.    tri_tab[(0x4)] = triangle_twoside;
  724.    quad_tab[(0x4)] = quadfunc_twoside;
  725. }
  726.  
  727.  
  728.  
  729. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  730.  
  731. /*
  732.  * Mesa 3-D graphics library
  733.  * Version:  5.0
  734.  *
  735.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  736.  *
  737.  * Permission is hereby granted, free of charge, to any person obtaining a
  738.  * copy of this software and associated documentation files (the "Software"),
  739.  * to deal in the Software without restriction, including without limitation
  740.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  741.  * and/or sell copies of the Software, and to permit persons to whom the
  742.  * Software is furnished to do so, subject to the following conditions:
  743.  *
  744.  * The above copyright notice and this permission notice shall be included
  745.  * in all copies or substantial portions of the Software.
  746.  *
  747.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  748.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  749.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  750.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  751.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  752.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  753.  *
  754.  * Authors:
  755.  *    Keith Whitwell <keith@tungstengraphics.com>
  756.  */
  757.  
  758.  
  759. static void triangle_offset_twoside(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  760. {
  761.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  762.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  763.    SWvertex *v[3];
  764.    GLfloat z[3];
  765.    GLfloat offset;
  766.    GLenum mode = 0x1B02;
  767.    GLuint facing = 0;
  768.  
  769.    v[0] = &verts[e0];
  770.    v[1] = &verts[e1];
  771.    v[2] = &verts[e2];
  772.  
  773.  
  774.    if ((0x2|0x4) & (0x4 | 0x2 | 0x8))
  775.    {
  776.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  777.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  778.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  779.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  780.       GLfloat cc  = ex*fy - ey*fx;
  781.  
  782.       if ((0x2|0x4) & (0x4 | 0x8))
  783.       {
  784.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  785.          if (ctx->Stencil.TestTwoSide)
  786.             ctx->_Facing = facing; /* for 2-sided stencil test */
  787.  
  788.         if (facing == 1) {
  789.            if ((0x2|0x4) & 0x4) {
  790.               if ((0x2|0x4) & 0x1) {
  791.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  792.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  793.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  794.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  795.                  if (VB->SecondaryColorPtr[1]) {
  796.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  797.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  798.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  799.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  800.                  }
  801.               } else {
  802.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  803.                  (v[0]->index = vbindex[e0]);
  804.                  (v[1]->index = vbindex[e1]);
  805.                  (v[2]->index = vbindex[e2]);
  806.               }
  807.            }
  808.         }
  809.       }
  810.  
  811.       if ((0x2|0x4) & 0x2)
  812.       {
  813.         offset = ctx->Polygon.OffsetUnits;
  814.         z[0] = v[0]->win[2];
  815.         z[1] = v[1]->win[2];
  816.         z[2] = v[2]->win[2];
  817.         if (cc * cc > 1e-16) {
  818.            GLfloat ez = z[0] - z[2];
  819.            GLfloat fz = z[1] - z[2];
  820.            GLfloat a = ey*fz - ez*fy;
  821.            GLfloat b = ez*fx - ex*fz;
  822.            GLfloat ic = 1.0F / cc;
  823.            GLfloat ac = a * ic;
  824.            GLfloat bc = b * ic;
  825.            if (ac < 0.0F) ac = -ac;
  826.            if (bc < 0.0F) bc = -bc;
  827.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  828.         }
  829.          offset *= ctx->MRD;
  830.          /*printf("offset %g\n", offset);*/
  831.       }
  832.    }
  833.  
  834.    if (mode == 0x1B00) {
  835.       if (((0x2|0x4) & 0x2) && ctx->Polygon.OffsetPoint) {
  836.         v[0]->win[2] += offset;
  837.         v[1]->win[2] += offset;
  838.         v[2]->win[2] += offset;
  839.       }
  840.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  841.    } else if (mode == 0x1B01) {
  842.       if (((0x2|0x4) & 0x2) && ctx->Polygon.OffsetLine) {
  843.         v[0]->win[2] += offset;
  844.         v[1]->win[2] += offset;
  845.         v[2]->win[2] += offset;
  846.       }
  847.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  848.    } else {
  849.       if (((0x2|0x4) & 0x2) && ctx->Polygon.OffsetFill) {
  850.         v[0]->win[2] += offset;
  851.         v[1]->win[2] += offset;
  852.         v[2]->win[2] += offset;
  853.       }
  854.  _mesa_debug(ctx, "triangle_offset_twoside call  _swrast_Triangle\n");
  855.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  856.  _mesa_debug(ctx, "triangle_offset_twoside return  _swrast_Triangle\n");
  857.    }
  858.  
  859.    if ((0x2|0x4) & 0x2) {
  860.       v[0]->win[2] = z[0];
  861.       v[1]->win[2] = z[1];
  862.       v[2]->win[2] = z[2];
  863.    }
  864.  
  865.    if ((0x2|0x4) & 0x4) {
  866.       if (facing == 1) {
  867.            GLuint *vbindex = VB->IndexPtr[0]->data;
  868.            (v[0]->index = vbindex[e0]);
  869.            (v[1]->index = vbindex[e1]);
  870.            (v[2]->index = vbindex[e2]);
  871.       }
  872.    }
  873. }
  874.  
  875.  
  876.  
  877. /* Need to fixup edgeflags when decomposing to triangles:
  878.  */
  879. static void _Optlink quadfunc_offset_twoside( GLcontext *ctx, GLuint v0,
  880.                       GLuint v1, GLuint v2, GLuint v3 )
  881. {
  882.       triangle_offset_twoside( ctx, v0, v1, v3 );
  883.       triangle_offset_twoside( ctx, v1, v2, v3 );
  884. }
  885.  
  886.  
  887.  
  888.  
  889. static void init_offset_twoside( void )
  890. {
  891.    tri_tab[(0x2|0x4)] = triangle_offset_twoside;
  892.    quad_tab[(0x2|0x4)] = quadfunc_offset_twoside;
  893. }
  894.  
  895.  
  896.  
  897. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  898.  
  899. /*
  900.  * Mesa 3-D graphics library
  901.  * Version:  5.0
  902.  *
  903.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  904.  *
  905.  * Permission is hereby granted, free of charge, to any person obtaining a
  906.  * copy of this software and associated documentation files (the "Software"),
  907.  * to deal in the Software without restriction, including without limitation
  908.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  909.  * and/or sell copies of the Software, and to permit persons to whom the
  910.  * Software is furnished to do so, subject to the following conditions:
  911.  *
  912.  * The above copyright notice and this permission notice shall be included
  913.  * in all copies or substantial portions of the Software.
  914.  *
  915.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  916.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  917.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  918.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  919.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  920.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  921.  *
  922.  * Authors:
  923.  *    Keith Whitwell <keith@tungstengraphics.com>
  924.  */
  925.  
  926.  
  927. static void triangle_unfilled(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  928. {
  929.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  930.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  931.    SWvertex *v[3];
  932.    GLfloat z[3];
  933.    GLfloat offset;
  934.    GLenum mode = 0x1B02;
  935.    GLuint facing = 0;
  936.  
  937.    v[0] = &verts[e0];
  938.    v[1] = &verts[e1];
  939.    v[2] = &verts[e2];
  940.  
  941.  
  942.    if ((0x8) & (0x4 | 0x2 | 0x8))
  943.    {
  944.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  945.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  946.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  947.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  948.       GLfloat cc  = ex*fy - ey*fx;
  949.  
  950.       if ((0x8) & (0x4 | 0x8))
  951.       {
  952.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  953.          if (ctx->Stencil.TestTwoSide)
  954.             ctx->_Facing = facing; /* for 2-sided stencil test */
  955.  
  956.         if ((0x8) & 0x8)
  957.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  958.  
  959.         if (facing == 1) {
  960.            if ((0x8) & 0x4) {
  961.               if ((0x8) & 0x1) {
  962.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  963.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  964.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  965.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  966.                  if (VB->SecondaryColorPtr[1]) {
  967.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  968.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  969.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  970.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  971.                  }
  972.               } else {
  973.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  974.                  (v[0]->index = vbindex[e0]);
  975.                  (v[1]->index = vbindex[e1]);
  976.                  (v[2]->index = vbindex[e2]);
  977.               }
  978.            }
  979.         }
  980.       }
  981.  
  982.       if ((0x8) & 0x2)
  983.       {
  984.         offset = ctx->Polygon.OffsetUnits;
  985.         z[0] = v[0]->win[2];
  986.         z[1] = v[1]->win[2];
  987.         z[2] = v[2]->win[2];
  988.         if (cc * cc > 1e-16) {
  989.            GLfloat ez = z[0] - z[2];
  990.            GLfloat fz = z[1] - z[2];
  991.            GLfloat a = ey*fz - ez*fy;
  992.            GLfloat b = ez*fx - ex*fz;
  993.            GLfloat ic = 1.0F / cc;
  994.            GLfloat ac = a * ic;
  995.            GLfloat bc = b * ic;
  996.            if (ac < 0.0F) ac = -ac;
  997.            if (bc < 0.0F) bc = -bc;
  998.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  999.         }
  1000.          offset *= ctx->MRD;
  1001.          /*printf("offset %g\n", offset);*/
  1002.       }
  1003.    }
  1004.  
  1005.    if (mode == 0x1B00) {
  1006.       if (((0x8) & 0x2) && ctx->Polygon.OffsetPoint) {
  1007.         v[0]->win[2] += offset;
  1008.         v[1]->win[2] += offset;
  1009.         v[2]->win[2] += offset;
  1010.       }
  1011.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1012.    } else if (mode == 0x1B01) {
  1013.       if (((0x8) & 0x2) && ctx->Polygon.OffsetLine) {
  1014.         v[0]->win[2] += offset;
  1015.         v[1]->win[2] += offset;
  1016.         v[2]->win[2] += offset;
  1017.       }
  1018.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1019.    } else {
  1020.       if (((0x8) & 0x2) && ctx->Polygon.OffsetFill) {
  1021.         v[0]->win[2] += offset;
  1022.         v[1]->win[2] += offset;
  1023.         v[2]->win[2] += offset;
  1024.       }
  1025.  _mesa_debug(ctx, "triangle_unfilled call  _swrast_Triangle\n");
  1026.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1027.  _mesa_debug(ctx, "triangle_unfilled return  _swrast_Triangle\n");
  1028.    }
  1029.  
  1030.    if ((0x8) & 0x2) {
  1031.       v[0]->win[2] = z[0];
  1032.       v[1]->win[2] = z[1];
  1033.       v[2]->win[2] = z[2];
  1034.    }
  1035.  
  1036.    if ((0x8) & 0x4) {
  1037.       if (facing == 1) {
  1038.         if ((0x8) & 0x1) {
  1039.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  1040.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1041.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1042.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1043.            if (VB->SecondaryColorPtr[0]) {
  1044.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  1045.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1046.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1047.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1048.            }
  1049.         } else {
  1050.            GLuint *vbindex = VB->IndexPtr[0]->data;
  1051.            (v[0]->index = vbindex[e0]);
  1052.            (v[1]->index = vbindex[e1]);
  1053.            (v[2]->index = vbindex[e2]);
  1054.         }
  1055.       }
  1056.    }
  1057. }
  1058.  
  1059.  
  1060.  
  1061. /* Need to fixup edgeflags when decomposing to triangles:
  1062.  */
  1063. static void  _Optlink  quadfunc_unfilled( GLcontext *ctx, GLuint v0,
  1064.                       GLuint v1, GLuint v2, GLuint v3 )
  1065. {
  1066.    if ((0x8) & 0x8) {
  1067.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1068.       GLubyte ef1 = VB->EdgeFlag[v1];
  1069.       GLubyte ef3 = VB->EdgeFlag[v3];
  1070.       VB->EdgeFlag[v1] = 0;
  1071.       triangle_unfilled( ctx, v0, v1, v3 );
  1072.       VB->EdgeFlag[v1] = ef1;
  1073.       VB->EdgeFlag[v3] = 0;
  1074.       triangle_unfilled( ctx, v1, v2, v3 );
  1075.       VB->EdgeFlag[v3] = ef3;
  1076.    } else {
  1077.       triangle_unfilled( ctx, v0, v1, v3 );
  1078.       triangle_unfilled( ctx, v1, v2, v3 );
  1079.    }
  1080. }
  1081.  
  1082.  
  1083.  
  1084.  
  1085. static void init_unfilled( void )
  1086. {
  1087.    tri_tab[(0x8)] = triangle_unfilled;
  1088.    quad_tab[(0x8)] = quadfunc_unfilled;
  1089. }
  1090.  
  1091.  
  1092.  
  1093. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  1094.  
  1095. /*
  1096.  * Mesa 3-D graphics library
  1097.  * Version:  5.0
  1098.  *
  1099.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  1100.  *
  1101.  * Permission is hereby granted, free of charge, to any person obtaining a
  1102.  * copy of this software and associated documentation files (the "Software"),
  1103.  * to deal in the Software without restriction, including without limitation
  1104.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1105.  * and/or sell copies of the Software, and to permit persons to whom the
  1106.  * Software is furnished to do so, subject to the following conditions:
  1107.  *
  1108.  * The above copyright notice and this permission notice shall be included
  1109.  * in all copies or substantial portions of the Software.
  1110.  *
  1111.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1112.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1113.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  1114.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  1115.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1116.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1117.  *
  1118.  * Authors:
  1119.  *    Keith Whitwell <keith@tungstengraphics.com>
  1120.  */
  1121.  
  1122.  
  1123. static void triangle_offset_unfilled(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  1124. {
  1125.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1126.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  1127.    SWvertex *v[3];
  1128.    GLfloat z[3];
  1129.    GLfloat offset;
  1130.    GLenum mode = 0x1B02;
  1131.    GLuint facing = 0;
  1132.  
  1133.    v[0] = &verts[e0];
  1134.    v[1] = &verts[e1];
  1135.    v[2] = &verts[e2];
  1136.  
  1137.  
  1138.    if ((0x2|0x8) & (0x4 | 0x2 | 0x8))
  1139.    {
  1140.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  1141.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  1142.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  1143.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  1144.       GLfloat cc  = ex*fy - ey*fx;
  1145.  
  1146.       if ((0x2|0x8) & (0x4 | 0x8))
  1147.       {
  1148.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  1149.          if (ctx->Stencil.TestTwoSide)
  1150.             ctx->_Facing = facing; /* for 2-sided stencil test */
  1151.  
  1152.         if ((0x2|0x8) & 0x8)
  1153.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  1154.  
  1155.         if (facing == 1) {
  1156.            if ((0x2|0x8) & 0x4) {
  1157.               if ((0x2|0x8) & 0x1) {
  1158.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  1159.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1160.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1161.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1162.                  if (VB->SecondaryColorPtr[1]) {
  1163.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  1164.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1165.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1166.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1167.                  }
  1168.               } else {
  1169.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  1170.                  (v[0]->index = vbindex[e0]);
  1171.                  (v[1]->index = vbindex[e1]);
  1172.                  (v[2]->index = vbindex[e2]);
  1173.               }
  1174.            }
  1175.         }
  1176.       }
  1177.  
  1178.       if ((0x2|0x8) & 0x2)
  1179.       {
  1180.         offset = ctx->Polygon.OffsetUnits;
  1181.         z[0] = v[0]->win[2];
  1182.         z[1] = v[1]->win[2];
  1183.         z[2] = v[2]->win[2];
  1184.         if (cc * cc > 1e-16) {
  1185.            GLfloat ez = z[0] - z[2];
  1186.            GLfloat fz = z[1] - z[2];
  1187.            GLfloat a = ey*fz - ez*fy;
  1188.            GLfloat b = ez*fx - ex*fz;
  1189.            GLfloat ic = 1.0F / cc;
  1190.            GLfloat ac = a * ic;
  1191.            GLfloat bc = b * ic;
  1192.            if (ac < 0.0F) ac = -ac;
  1193.            if (bc < 0.0F) bc = -bc;
  1194.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  1195.         }
  1196.          offset *= ctx->MRD;
  1197.          /*printf("offset %g\n", offset);*/
  1198.       }
  1199.    }
  1200.  
  1201.    if (mode == 0x1B00) {
  1202.       if (((0x2|0x8) & 0x2) && ctx->Polygon.OffsetPoint) {
  1203.         v[0]->win[2] += offset;
  1204.         v[1]->win[2] += offset;
  1205.         v[2]->win[2] += offset;
  1206.       }
  1207.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1208.    } else if (mode == 0x1B01) {
  1209.       if (((0x2|0x8) & 0x2) && ctx->Polygon.OffsetLine) {
  1210.         v[0]->win[2] += offset;
  1211.         v[1]->win[2] += offset;
  1212.         v[2]->win[2] += offset;
  1213.       }
  1214.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1215.    } else {
  1216.       if (((0x2|0x8) & 0x2) && ctx->Polygon.OffsetFill) {
  1217.         v[0]->win[2] += offset;
  1218.         v[1]->win[2] += offset;
  1219.         v[2]->win[2] += offset;
  1220.       }
  1221.  _mesa_debug(ctx, "triangle_offset_unfilled call _swrast_Triangle\n");
  1222.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1223.  _mesa_debug(ctx, "triangle_offset_unfilled return  _swrast_Triangle\n");
  1224.    }
  1225.  
  1226.    if ((0x2|0x8) & 0x2) {
  1227.       v[0]->win[2] = z[0];
  1228.       v[1]->win[2] = z[1];
  1229.       v[2]->win[2] = z[2];
  1230.    }
  1231.  
  1232.    if ((0x2|0x8) & 0x4) {
  1233.       if (facing == 1) {
  1234.         if ((0x2|0x8) & 0x1) {
  1235.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  1236.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1237.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1238.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1239.            if (VB->SecondaryColorPtr[0]) {
  1240.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  1241.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1242.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1243.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1244.            }
  1245.         } else {
  1246.            GLuint *vbindex = VB->IndexPtr[0]->data;
  1247.            (v[0]->index = vbindex[e0]);
  1248.            (v[1]->index = vbindex[e1]);
  1249.            (v[2]->index = vbindex[e2]);
  1250.         }
  1251.       }
  1252.    }
  1253. }
  1254.  
  1255.  
  1256.  
  1257. /* Need to fixup edgeflags when decomposing to triangles:
  1258.  */
  1259. static void  _Optlink quadfunc_offset_unfilled( GLcontext *ctx, GLuint v0,
  1260.                       GLuint v1, GLuint v2, GLuint v3 )
  1261. {
  1262.    if ((0x2|0x8) & 0x8) {
  1263.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1264.       GLubyte ef1 = VB->EdgeFlag[v1];
  1265.       GLubyte ef3 = VB->EdgeFlag[v3];
  1266.       VB->EdgeFlag[v1] = 0;
  1267.       triangle_offset_unfilled( ctx, v0, v1, v3 );
  1268.       VB->EdgeFlag[v1] = ef1;
  1269.       VB->EdgeFlag[v3] = 0;
  1270.       triangle_offset_unfilled( ctx, v1, v2, v3 );
  1271.       VB->EdgeFlag[v3] = ef3;
  1272.    } else {
  1273.       triangle_offset_unfilled( ctx, v0, v1, v3 );
  1274.       triangle_offset_unfilled( ctx, v1, v2, v3 );
  1275.    }
  1276. }
  1277.  
  1278.  
  1279.  
  1280.  
  1281. static void init_offset_unfilled( void )
  1282. {
  1283.    tri_tab[(0x2|0x8)] = triangle_offset_unfilled;
  1284.    quad_tab[(0x2|0x8)] = quadfunc_offset_unfilled;
  1285. }
  1286.  
  1287.  
  1288.  
  1289. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  1290.  
  1291. /*
  1292.  * Mesa 3-D graphics library
  1293.  * Version:  5.0
  1294.  *
  1295.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  1296.  *
  1297.  * Permission is hereby granted, free of charge, to any person obtaining a
  1298.  * copy of this software and associated documentation files (the "Software"),
  1299.  * to deal in the Software without restriction, including without limitation
  1300.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1301.  * and/or sell copies of the Software, and to permit persons to whom the
  1302.  * Software is furnished to do so, subject to the following conditions:
  1303.  *
  1304.  * The above copyright notice and this permission notice shall be included
  1305.  * in all copies or substantial portions of the Software.
  1306.  *
  1307.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1308.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1309.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  1310.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  1311.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1312.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1313.  *
  1314.  * Authors:
  1315.  *    Keith Whitwell <keith@tungstengraphics.com>
  1316.  */
  1317.  
  1318.  
  1319. static void triangle_twoside_unfilled(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  1320. {
  1321.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1322.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  1323.    SWvertex *v[3];
  1324.    GLfloat z[3];
  1325.    GLfloat offset;
  1326.    GLenum mode = 0x1B02;
  1327.    GLuint facing = 0;
  1328.  
  1329.    v[0] = &verts[e0];
  1330.    v[1] = &verts[e1];
  1331.    v[2] = &verts[e2];
  1332.  
  1333.  
  1334.    if ((0x4|0x8) & (0x4 | 0x2 | 0x8))
  1335.    {
  1336.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  1337.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  1338.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  1339.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  1340.       GLfloat cc  = ex*fy - ey*fx;
  1341.  
  1342.       if ((0x4|0x8) & (0x4 | 0x8))
  1343.       {
  1344.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  1345.          if (ctx->Stencil.TestTwoSide)
  1346.             ctx->_Facing = facing; /* for 2-sided stencil test */
  1347.  
  1348.         if ((0x4|0x8) & 0x8)
  1349.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  1350.  
  1351.         if (facing == 1) {
  1352.            if ((0x4|0x8) & 0x4) {
  1353.               if ((0x4|0x8) & 0x1) {
  1354.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  1355.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1356.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1357.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1358.                  if (VB->SecondaryColorPtr[1]) {
  1359.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  1360.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1361.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1362.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1363.                  }
  1364.               } else {
  1365.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  1366.                  (v[0]->index = vbindex[e0]);
  1367.                  (v[1]->index = vbindex[e1]);
  1368.                  (v[2]->index = vbindex[e2]);
  1369.               }
  1370.            }
  1371.         }
  1372.       }
  1373.  
  1374.       if ((0x4|0x8) & 0x2)
  1375.       {
  1376.         offset = ctx->Polygon.OffsetUnits;
  1377.         z[0] = v[0]->win[2];
  1378.         z[1] = v[1]->win[2];
  1379.         z[2] = v[2]->win[2];
  1380.         if (cc * cc > 1e-16) {
  1381.            GLfloat ez = z[0] - z[2];
  1382.            GLfloat fz = z[1] - z[2];
  1383.            GLfloat a = ey*fz - ez*fy;
  1384.            GLfloat b = ez*fx - ex*fz;
  1385.            GLfloat ic = 1.0F / cc;
  1386.            GLfloat ac = a * ic;
  1387.            GLfloat bc = b * ic;
  1388.            if (ac < 0.0F) ac = -ac;
  1389.            if (bc < 0.0F) bc = -bc;
  1390.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  1391.         }
  1392.          offset *= ctx->MRD;
  1393.          /*printf("offset %g\n", offset);*/
  1394.       }
  1395.    }
  1396.  
  1397.    if (mode == 0x1B00) {
  1398.       if (((0x4|0x8) & 0x2) && ctx->Polygon.OffsetPoint) {
  1399.         v[0]->win[2] += offset;
  1400.         v[1]->win[2] += offset;
  1401.         v[2]->win[2] += offset;
  1402.       }
  1403.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1404.    } else if (mode == 0x1B01) {
  1405.       if (((0x4|0x8) & 0x2) && ctx->Polygon.OffsetLine) {
  1406.         v[0]->win[2] += offset;
  1407.         v[1]->win[2] += offset;
  1408.         v[2]->win[2] += offset;
  1409.       }
  1410.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1411.    } else {
  1412.       if (((0x4|0x8) & 0x2) && ctx->Polygon.OffsetFill) {
  1413.         v[0]->win[2] += offset;
  1414.         v[1]->win[2] += offset;
  1415.         v[2]->win[2] += offset;
  1416.       }
  1417.  _mesa_debug(ctx, "triangle_twoside_unfilled call  _swrast_Triangle\n");
  1418.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1419.  _mesa_debug(ctx, "triangle_twoside_unfilled return  _swrast_Triangle\n");
  1420.    }
  1421.  
  1422.    if ((0x4|0x8) & 0x2) {
  1423.       v[0]->win[2] = z[0];
  1424.       v[1]->win[2] = z[1];
  1425.       v[2]->win[2] = z[2];
  1426.    }
  1427.  
  1428.    if ((0x4|0x8) & 0x4) {
  1429.       if (facing == 1) {
  1430.         if ((0x4|0x8) & 0x1) {
  1431.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  1432.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1433.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1434.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1435.            if (VB->SecondaryColorPtr[0]) {
  1436.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  1437.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1438.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1439.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1440.            }
  1441.         } else {
  1442.            GLuint *vbindex = VB->IndexPtr[0]->data;
  1443.            (v[0]->index = vbindex[e0]);
  1444.            (v[1]->index = vbindex[e1]);
  1445.            (v[2]->index = vbindex[e2]);
  1446.         }
  1447.       }
  1448.    }
  1449. }
  1450.  
  1451.  
  1452.  
  1453. /* Need to fixup edgeflags when decomposing to triangles:
  1454.  */
  1455. static void  _Optlink  quadfunc_twoside_unfilled( GLcontext *ctx, GLuint v0,
  1456.                       GLuint v1, GLuint v2, GLuint v3 )
  1457. {
  1458.    if ((0x4|0x8) & 0x8) {
  1459.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1460.       GLubyte ef1 = VB->EdgeFlag[v1];
  1461.       GLubyte ef3 = VB->EdgeFlag[v3];
  1462.       VB->EdgeFlag[v1] = 0;
  1463.       triangle_twoside_unfilled( ctx, v0, v1, v3 );
  1464.       VB->EdgeFlag[v1] = ef1;
  1465.       VB->EdgeFlag[v3] = 0;
  1466.       triangle_twoside_unfilled( ctx, v1, v2, v3 );
  1467.       VB->EdgeFlag[v3] = ef3;
  1468.    } else {
  1469.       triangle_twoside_unfilled( ctx, v0, v1, v3 );
  1470.       triangle_twoside_unfilled( ctx, v1, v2, v3 );
  1471.    }
  1472. }
  1473.  
  1474.  
  1475.  
  1476.  
  1477. static void init_twoside_unfilled( void )
  1478. {
  1479.    tri_tab[(0x4|0x8)] = triangle_twoside_unfilled;
  1480.    quad_tab[(0x4|0x8)] = quadfunc_twoside_unfilled;
  1481. }
  1482.  
  1483.  
  1484.  
  1485. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  1486.  
  1487. /*
  1488.  * Mesa 3-D graphics library
  1489.  * Version:  5.0
  1490.  *
  1491.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  1492.  *
  1493.  * Permission is hereby granted, free of charge, to any person obtaining a
  1494.  * copy of this software and associated documentation files (the "Software"),
  1495.  * to deal in the Software without restriction, including without limitation
  1496.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1497.  * and/or sell copies of the Software, and to permit persons to whom the
  1498.  * Software is furnished to do so, subject to the following conditions:
  1499.  *
  1500.  * The above copyright notice and this permission notice shall be included
  1501.  * in all copies or substantial portions of the Software.
  1502.  *
  1503.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1504.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1505.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  1506.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  1507.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1508.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1509.  *
  1510.  * Authors:
  1511.  *    Keith Whitwell <keith@tungstengraphics.com>
  1512.  */
  1513.  
  1514.  
  1515. static void triangle_offset_twoside_unfilled(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  1516. {
  1517.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1518.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  1519.    SWvertex *v[3];
  1520.    GLfloat z[3];
  1521.    GLfloat offset;
  1522.    GLenum mode = 0x1B02;
  1523.    GLuint facing = 0;
  1524.  
  1525.    v[0] = &verts[e0];
  1526.    v[1] = &verts[e1];
  1527.    v[2] = &verts[e2];
  1528.  
  1529.  
  1530.    if ((0x2|0x4|0x8) & (0x4 | 0x2 | 0x8))
  1531.    {
  1532.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  1533.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  1534.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  1535.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  1536.       GLfloat cc  = ex*fy - ey*fx;
  1537.  
  1538.       if ((0x2|0x4|0x8) & (0x4 | 0x8))
  1539.       {
  1540.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  1541.          if (ctx->Stencil.TestTwoSide)
  1542.             ctx->_Facing = facing; /* for 2-sided stencil test */
  1543.  
  1544.         if ((0x2|0x4|0x8) & 0x8)
  1545.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  1546.  
  1547.         if (facing == 1) {
  1548.            if ((0x2|0x4|0x8) & 0x4) {
  1549.               if ((0x2|0x4|0x8) & 0x1) {
  1550.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  1551.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1552.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1553.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1554.                  if (VB->SecondaryColorPtr[1]) {
  1555.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  1556.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1557.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1558.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1559.                  }
  1560.               } else {
  1561.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  1562.                  (v[0]->index = vbindex[e0]);
  1563.                  (v[1]->index = vbindex[e1]);
  1564.                  (v[2]->index = vbindex[e2]);
  1565.               }
  1566.            }
  1567.         }
  1568.       }
  1569.  
  1570.       if ((0x2|0x4|0x8) & 0x2)
  1571.       {
  1572.         offset = ctx->Polygon.OffsetUnits;
  1573.         z[0] = v[0]->win[2];
  1574.         z[1] = v[1]->win[2];
  1575.         z[2] = v[2]->win[2];
  1576.         if (cc * cc > 1e-16) {
  1577.            GLfloat ez = z[0] - z[2];
  1578.            GLfloat fz = z[1] - z[2];
  1579.            GLfloat a = ey*fz - ez*fy;
  1580.            GLfloat b = ez*fx - ex*fz;
  1581.            GLfloat ic = 1.0F / cc;
  1582.            GLfloat ac = a * ic;
  1583.            GLfloat bc = b * ic;
  1584.            if (ac < 0.0F) ac = -ac;
  1585.            if (bc < 0.0F) bc = -bc;
  1586.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  1587.         }
  1588.          offset *= ctx->MRD;
  1589.          /*printf("offset %g\n", offset);*/
  1590.       }
  1591.    }
  1592.  
  1593.    if (mode == 0x1B00) {
  1594.       if (((0x2|0x4|0x8) & 0x2) && ctx->Polygon.OffsetPoint) {
  1595.         v[0]->win[2] += offset;
  1596.         v[1]->win[2] += offset;
  1597.         v[2]->win[2] += offset;
  1598.       }
  1599.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1600.    } else if (mode == 0x1B01) {
  1601.       if (((0x2|0x4|0x8) & 0x2) && ctx->Polygon.OffsetLine) {
  1602.         v[0]->win[2] += offset;
  1603.         v[1]->win[2] += offset;
  1604.         v[2]->win[2] += offset;
  1605.       }
  1606.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1607.    } else {
  1608.       if (((0x2|0x4|0x8) & 0x2) && ctx->Polygon.OffsetFill) {
  1609.         v[0]->win[2] += offset;
  1610.         v[1]->win[2] += offset;
  1611.         v[2]->win[2] += offset;
  1612.       }
  1613.  _mesa_debug(ctx, "triangle_offset_twoside_unfilled call  _swrast_Triangle\n");
  1614.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1615.  _mesa_debug(ctx, "triangle_offset_twoside_unfilled return  _swrast_Triangle\n");
  1616.    }
  1617.  
  1618.    if ((0x2|0x4|0x8) & 0x2) {
  1619.       v[0]->win[2] = z[0];
  1620.       v[1]->win[2] = z[1];
  1621.       v[2]->win[2] = z[2];
  1622.    }
  1623.  
  1624.    if ((0x2|0x4|0x8) & 0x4) {
  1625.       if (facing == 1) {
  1626.         if ((0x2|0x4|0x8) & 0x1) {
  1627.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  1628.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1629.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1630.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1631.            if (VB->SecondaryColorPtr[0]) {
  1632.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  1633.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1634.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1635.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1636.            }
  1637.         } else {
  1638.            GLuint *vbindex = VB->IndexPtr[0]->data;
  1639.            (v[0]->index = vbindex[e0]);
  1640.            (v[1]->index = vbindex[e1]);
  1641.            (v[2]->index = vbindex[e2]);
  1642.         }
  1643.       }
  1644.    }
  1645. }
  1646.  
  1647.  
  1648.  
  1649. /* Need to fixup edgeflags when decomposing to triangles:
  1650.  */
  1651. static void _Optlink quadfunc_offset_twoside_unfilled( GLcontext *ctx, GLuint v0,
  1652.                       GLuint v1, GLuint v2, GLuint v3 )
  1653. {
  1654.    if ((0x2|0x4|0x8) & 0x8) {
  1655.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1656.       GLubyte ef1 = VB->EdgeFlag[v1];
  1657.       GLubyte ef3 = VB->EdgeFlag[v3];
  1658.       VB->EdgeFlag[v1] = 0;
  1659.       triangle_offset_twoside_unfilled( ctx, v0, v1, v3 );
  1660.       VB->EdgeFlag[v1] = ef1;
  1661.       VB->EdgeFlag[v3] = 0;
  1662.       triangle_offset_twoside_unfilled( ctx, v1, v2, v3 );
  1663.       VB->EdgeFlag[v3] = ef3;
  1664.    } else {
  1665.       triangle_offset_twoside_unfilled( ctx, v0, v1, v3 );
  1666.       triangle_offset_twoside_unfilled( ctx, v1, v2, v3 );
  1667.    }
  1668. }
  1669.  
  1670.  
  1671.  
  1672.  
  1673. static void init_offset_twoside_unfilled( void )
  1674. {
  1675.    tri_tab[(0x2|0x4|0x8)] = triangle_offset_twoside_unfilled;
  1676.    quad_tab[(0x2|0x4|0x8)] = quadfunc_offset_twoside_unfilled;
  1677. }
  1678.  
  1679. #if 0
  1680.  
  1681. static void triangle_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  1682. {
  1683.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1684.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  1685.    SWvertex *v[3];
  1686.    GLfloat z[3];
  1687.    GLfloat offset;
  1688.    GLenum mode = 0x1B02;
  1689.    GLuint facing = 0;
  1690.  
  1691.    v[0] = &verts[e0];
  1692.    v[1] = &verts[e1];
  1693.    v[2] = &verts[e2];
  1694.  
  1695.  
  1696.    if ((0|0x1) & (0x4 | 0x2 | 0x8))
  1697.    {
  1698.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  1699.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  1700.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  1701.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  1702.       GLfloat cc  = ex*fy - ey*fx;
  1703.  
  1704.       if ((0|0x1) & (0x4 | 0x8))
  1705.       {
  1706.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  1707.          if (ctx->Stencil.TestTwoSide)
  1708.             ctx->_Facing = facing; /* for 2-sided stencil test */
  1709.  
  1710.         if ((0|0x1) & 0x8)
  1711.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  1712.  
  1713.         if (facing == 1) {
  1714.            if ((0|0x1) & 0x4) {
  1715.               if ((0|0x1) & 0x1) {
  1716.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  1717.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1718.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1719.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1720.                  if (VB->SecondaryColorPtr[1]) {
  1721.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  1722.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1723.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1724.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1725.                  }
  1726.               } else {
  1727.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  1728.                  (v[0]->index = vbindex[e0]);
  1729.                  (v[1]->index = vbindex[e1]);
  1730.                  (v[2]->index = vbindex[e2]);
  1731.               }
  1732.            }
  1733.         }
  1734.       }
  1735.  
  1736.       if ((0|0x1) & 0x2)
  1737.       {
  1738.         offset = ctx->Polygon.OffsetUnits;
  1739.         z[0] = v[0]->win[2];
  1740.         z[1] = v[1]->win[2];
  1741.         z[2] = v[2]->win[2];
  1742.         if (cc * cc > 1e-16) {
  1743.            GLfloat ez = z[0] - z[2];
  1744.            GLfloat fz = z[1] - z[2];
  1745.            GLfloat a = ey*fz - ez*fy;
  1746.            GLfloat b = ez*fx - ex*fz;
  1747.            GLfloat ic = 1.0F / cc;
  1748.            GLfloat ac = a * ic;
  1749.            GLfloat bc = b * ic;
  1750.            if (ac < 0.0F) ac = -ac;
  1751.            if (bc < 0.0F) bc = -bc;
  1752.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  1753.         }
  1754.          offset *= ctx->MRD;
  1755.          /*printf("offset %g\n", offset);*/
  1756.       }
  1757.    }
  1758.  
  1759.    if (mode == 0x1B00) {
  1760.       if (((0|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  1761.         v[0]->win[2] += offset;
  1762.         v[1]->win[2] += offset;
  1763.         v[2]->win[2] += offset;
  1764.       }
  1765.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1766.    } else if (mode == 0x1B01) {
  1767.       if (((0|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  1768.         v[0]->win[2] += offset;
  1769.         v[1]->win[2] += offset;
  1770.         v[2]->win[2] += offset;
  1771.       }
  1772.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1773.    } else {
  1774.       if (((0|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  1775.         v[0]->win[2] += offset;
  1776.         v[1]->win[2] += offset;
  1777.         v[2]->win[2] += offset;
  1778.       }
  1779.  _mesa_debug(ctx, "triangle_rgba call  _swrast_Triangle\n");
  1780.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1781.  _mesa_debug(ctx, "triangle_rgba return  _swrast_Triangle\n");
  1782.    }
  1783.  
  1784.    if ((0|0x1) & 0x2) {
  1785.       v[0]->win[2] = z[0];
  1786.       v[1]->win[2] = z[1];
  1787.       v[2]->win[2] = z[2];
  1788.    }
  1789.  
  1790.    if ((0|0x1) & 0x4) {
  1791.       if (facing == 1) {
  1792.         if ((0|0x1) & 0x1) {
  1793.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  1794.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1795.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1796.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1797.            if (VB->SecondaryColorPtr[0]) {
  1798.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  1799.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1800.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1801.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1802.            }
  1803.         } else {
  1804.            GLuint *vbindex = VB->IndexPtr[0]->data;
  1805.            (v[0]->index = vbindex[e0]);
  1806.            (v[1]->index = vbindex[e1]);
  1807.            (v[2]->index = vbindex[e2]);
  1808.         }
  1809.       }
  1810.    }
  1811. }
  1812. #else
  1813. void triangle_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 );
  1814.  
  1815. #endif
  1816.  
  1817.  
  1818. #if 0
  1819.  
  1820. /* Need to fixup edgeflags when decomposing to triangles:
  1821.  */
  1822. /* static */
  1823.  
  1824. void quadfunc_rgba( GLcontext *ctx, GLuint v0,
  1825.                       GLuint v1, GLuint v2, GLuint v3 )
  1826. {
  1827.    if ((0|0x1) & 0x8) {
  1828.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1829.       GLubyte ef1 = VB->EdgeFlag[v1];
  1830.       GLubyte ef3 = VB->EdgeFlag[v3];
  1831.       VB->EdgeFlag[v1] = 0;
  1832.       triangle_rgba( ctx, v0, v1, v3 );
  1833.       VB->EdgeFlag[v1] = ef1;
  1834.       VB->EdgeFlag[v3] = 0;
  1835.       triangle_rgba( ctx, v1, v2, v3 );
  1836.       VB->EdgeFlag[v3] = ef3;
  1837.    } else {
  1838.       _mesa_debug(ctx, __FUNCTION__ " %i,%i,%i,%i\n",v0,v1,v2,v3);
  1839.       triangle_rgba( ctx, v0, v1, v3 );
  1840.       triangle_rgba( ctx, v1, v2, v3 );
  1841.    }
  1842. }
  1843. #else
  1844.  
  1845. extern void _Optlink quadfunc_rgba( GLcontext *ctx, GLuint v0,
  1846.                       GLuint v1, GLuint v2, GLuint v3 );
  1847.  
  1848. #endif
  1849.  
  1850.  
  1851. static void init_rgba( void )
  1852. {
  1853.    tri_tab[(0|0x1)] = triangle_rgba;
  1854.    quad_tab[(0|0x1)] = quadfunc_rgba;
  1855. }
  1856.  
  1857.  
  1858.  
  1859. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  1860.  
  1861. /*
  1862.  * Mesa 3-D graphics library
  1863.  * Version:  5.0
  1864.  *
  1865.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  1866.  *
  1867.  * Permission is hereby granted, free of charge, to any person obtaining a
  1868.  * copy of this software and associated documentation files (the "Software"),
  1869.  * to deal in the Software without restriction, including without limitation
  1870.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1871.  * and/or sell copies of the Software, and to permit persons to whom the
  1872.  * Software is furnished to do so, subject to the following conditions:
  1873.  *
  1874.  * The above copyright notice and this permission notice shall be included
  1875.  * in all copies or substantial portions of the Software.
  1876.  *
  1877.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1878.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1879.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  1880.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  1881.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1882.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1883.  *
  1884.  * Authors:
  1885.  *    Keith Whitwell <keith@tungstengraphics.com>
  1886.  */
  1887.  
  1888.  
  1889. static void triangle_offset_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  1890. {
  1891.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  1892.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  1893.    SWvertex *v[3];
  1894.    GLfloat z[3];
  1895.    GLfloat offset;
  1896.    GLenum mode = 0x1B02;
  1897.    GLuint facing = 0;
  1898.  
  1899.    v[0] = &verts[e0];
  1900.    v[1] = &verts[e1];
  1901.    v[2] = &verts[e2];
  1902.  
  1903.  
  1904.    if ((0x2|0x1) & (0x4 | 0x2 | 0x8))
  1905.    {
  1906.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  1907.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  1908.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  1909.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  1910.       GLfloat cc  = ex*fy - ey*fx;
  1911.  
  1912.       if ((0x2|0x1) & (0x4 | 0x8))
  1913.       {
  1914.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  1915.          if (ctx->Stencil.TestTwoSide)
  1916.             ctx->_Facing = facing; /* for 2-sided stencil test */
  1917.  
  1918.         if ((0x2|0x1) & 0x8)
  1919.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  1920.  
  1921.         if (facing == 1) {
  1922.            if ((0x2|0x1) & 0x4) {
  1923.               if ((0x2|0x1) & 0x1) {
  1924.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  1925.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  1926.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  1927.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  1928.                  if (VB->SecondaryColorPtr[1]) {
  1929.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  1930.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  1931.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  1932.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  1933.                  }
  1934.               } else {
  1935.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  1936.                  (v[0]->index = vbindex[e0]);
  1937.                  (v[1]->index = vbindex[e1]);
  1938.                  (v[2]->index = vbindex[e2]);
  1939.               }
  1940.            }
  1941.         }
  1942.       }
  1943.  
  1944.       if ((0x2|0x1) & 0x2)
  1945.       {
  1946.         offset = ctx->Polygon.OffsetUnits;
  1947.         z[0] = v[0]->win[2];
  1948.         z[1] = v[1]->win[2];
  1949.         z[2] = v[2]->win[2];
  1950.         if (cc * cc > 1e-16) {
  1951.            GLfloat ez = z[0] - z[2];
  1952.            GLfloat fz = z[1] - z[2];
  1953.            GLfloat a = ey*fz - ez*fy;
  1954.            GLfloat b = ez*fx - ex*fz;
  1955.            GLfloat ic = 1.0F / cc;
  1956.            GLfloat ac = a * ic;
  1957.            GLfloat bc = b * ic;
  1958.            if (ac < 0.0F) ac = -ac;
  1959.            if (bc < 0.0F) bc = -bc;
  1960.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  1961.         }
  1962.          offset *= ctx->MRD;
  1963.          /*printf("offset %g\n", offset);*/
  1964.       }
  1965.    }
  1966.  
  1967.    if (mode == 0x1B00) {
  1968.       if (((0x2|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  1969.         v[0]->win[2] += offset;
  1970.         v[1]->win[2] += offset;
  1971.         v[2]->win[2] += offset;
  1972.       }
  1973.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  1974.    } else if (mode == 0x1B01) {
  1975.       if (((0x2|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  1976.         v[0]->win[2] += offset;
  1977.         v[1]->win[2] += offset;
  1978.         v[2]->win[2] += offset;
  1979.       }
  1980.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  1981.    } else {
  1982.       if (((0x2|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  1983.         v[0]->win[2] += offset;
  1984.         v[1]->win[2] += offset;
  1985.         v[2]->win[2] += offset;
  1986.       }
  1987.  _mesa_debug(ctx, "triangle_offset_rgba call  _swrast_Triangle\n");
  1988.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  1989.  _mesa_debug(ctx, "triangle_offset_rgba return  _swrast_Triangle\n");
  1990.    }
  1991.  
  1992.    if ((0x2|0x1) & 0x2) {
  1993.       v[0]->win[2] = z[0];
  1994.       v[1]->win[2] = z[1];
  1995.       v[2]->win[2] = z[2];
  1996.    }
  1997.  
  1998.    if ((0x2|0x1) & 0x4) {
  1999.       if (facing == 1) {
  2000.         if ((0x2|0x1) & 0x1) {
  2001.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2002.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2003.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2004.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2005.            if (VB->SecondaryColorPtr[0]) {
  2006.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2007.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2008.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2009.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2010.            }
  2011.         } else {
  2012.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2013.            (v[0]->index = vbindex[e0]);
  2014.            (v[1]->index = vbindex[e1]);
  2015.            (v[2]->index = vbindex[e2]);
  2016.         }
  2017.       }
  2018.    }
  2019. }
  2020.  
  2021.  
  2022.  
  2023. /* Need to fixup edgeflags when decomposing to triangles:
  2024.  */
  2025. static void _Optlink quadfunc_offset_rgba( GLcontext *ctx, GLuint v0,
  2026.                       GLuint v1, GLuint v2, GLuint v3 )
  2027. {
  2028.    if ((0x2|0x1) & 0x8) {
  2029.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2030.       GLubyte ef1 = VB->EdgeFlag[v1];
  2031.       GLubyte ef3 = VB->EdgeFlag[v3];
  2032.       VB->EdgeFlag[v1] = 0;
  2033.       triangle_offset_rgba( ctx, v0, v1, v3 );
  2034.       VB->EdgeFlag[v1] = ef1;
  2035.       VB->EdgeFlag[v3] = 0;
  2036.       triangle_offset_rgba( ctx, v1, v2, v3 );
  2037.       VB->EdgeFlag[v3] = ef3;
  2038.    } else {
  2039.       triangle_offset_rgba( ctx, v0, v1, v3 );
  2040.       triangle_offset_rgba( ctx, v1, v2, v3 );
  2041.    }
  2042. }
  2043.  
  2044.  
  2045.  
  2046.  
  2047. static void init_offset_rgba( void )
  2048. {
  2049.    tri_tab[(0x2|0x1)] = triangle_offset_rgba;
  2050.    quad_tab[(0x2|0x1)] = quadfunc_offset_rgba;
  2051. }
  2052.  
  2053.  
  2054.  
  2055. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  2056.  
  2057. /*
  2058.  * Mesa 3-D graphics library
  2059.  * Version:  5.0
  2060.  *
  2061.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  2062.  *
  2063.  * Permission is hereby granted, free of charge, to any person obtaining a
  2064.  * copy of this software and associated documentation files (the "Software"),
  2065.  * to deal in the Software without restriction, including without limitation
  2066.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2067.  * and/or sell copies of the Software, and to permit persons to whom the
  2068.  * Software is furnished to do so, subject to the following conditions:
  2069.  *
  2070.  * The above copyright notice and this permission notice shall be included
  2071.  * in all copies or substantial portions of the Software.
  2072.  *
  2073.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2074.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2075.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  2076.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2077.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2078.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2079.  *
  2080.  * Authors:
  2081.  *    Keith Whitwell <keith@tungstengraphics.com>
  2082.  */
  2083.  
  2084.  
  2085. static void triangle_twoside_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2086. {
  2087.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2088.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  2089.    SWvertex *v[3];
  2090.    GLfloat z[3];
  2091.    GLfloat offset;
  2092.    GLenum mode = 0x1B02;
  2093.    GLuint facing = 0;
  2094.  
  2095.    v[0] = &verts[e0];
  2096.    v[1] = &verts[e1];
  2097.    v[2] = &verts[e2];
  2098.  
  2099.  
  2100.    if ((0x4|0x1) & (0x4 | 0x2 | 0x8))
  2101.    {
  2102.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  2103.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  2104.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  2105.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  2106.       GLfloat cc  = ex*fy - ey*fx;
  2107.  
  2108.       if ((0x4|0x1) & (0x4 | 0x8))
  2109.       {
  2110.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  2111.          if (ctx->Stencil.TestTwoSide)
  2112.             ctx->_Facing = facing; /* for 2-sided stencil test */
  2113.  
  2114.         if ((0x4|0x1) & 0x8)
  2115.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  2116.  
  2117.         if (facing == 1) {
  2118.            if ((0x4|0x1) & 0x4) {
  2119.               if ((0x4|0x1) & 0x1) {
  2120.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  2121.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2122.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2123.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2124.                  if (VB->SecondaryColorPtr[1]) {
  2125.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  2126.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2127.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2128.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2129.                  }
  2130.               } else {
  2131.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  2132.                  (v[0]->index = vbindex[e0]);
  2133.                  (v[1]->index = vbindex[e1]);
  2134.                  (v[2]->index = vbindex[e2]);
  2135.               }
  2136.            }
  2137.         }
  2138.       }
  2139.  
  2140.       if ((0x4|0x1) & 0x2)
  2141.       {
  2142.         offset = ctx->Polygon.OffsetUnits;
  2143.         z[0] = v[0]->win[2];
  2144.         z[1] = v[1]->win[2];
  2145.         z[2] = v[2]->win[2];
  2146.         if (cc * cc > 1e-16) {
  2147.            GLfloat ez = z[0] - z[2];
  2148.            GLfloat fz = z[1] - z[2];
  2149.            GLfloat a = ey*fz - ez*fy;
  2150.            GLfloat b = ez*fx - ex*fz;
  2151.            GLfloat ic = 1.0F / cc;
  2152.            GLfloat ac = a * ic;
  2153.            GLfloat bc = b * ic;
  2154.            if (ac < 0.0F) ac = -ac;
  2155.            if (bc < 0.0F) bc = -bc;
  2156.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  2157.         }
  2158.          offset *= ctx->MRD;
  2159.          /*printf("offset %g\n", offset);*/
  2160.       }
  2161.    }
  2162.  
  2163.    if (mode == 0x1B00) {
  2164.       if (((0x4|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  2165.         v[0]->win[2] += offset;
  2166.         v[1]->win[2] += offset;
  2167.         v[2]->win[2] += offset;
  2168.       }
  2169.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  2170.    } else if (mode == 0x1B01) {
  2171.       if (((0x4|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  2172.         v[0]->win[2] += offset;
  2173.         v[1]->win[2] += offset;
  2174.         v[2]->win[2] += offset;
  2175.       }
  2176.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  2177.    } else {
  2178.       if (((0x4|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  2179.         v[0]->win[2] += offset;
  2180.         v[1]->win[2] += offset;
  2181.         v[2]->win[2] += offset;
  2182.       }
  2183. // _mesa_debug(ctx, "triangle_twoside_rgba call  _swrast_Triangle\n");
  2184.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  2185. // _mesa_debug(ctx, "triangle_twoside_rgba call  _swrast_Triangle\n");
  2186.    }
  2187.  
  2188.    if ((0x4|0x1) & 0x2) {
  2189.       v[0]->win[2] = z[0];
  2190.       v[1]->win[2] = z[1];
  2191.       v[2]->win[2] = z[2];
  2192.    }
  2193.  
  2194.    if ((0x4|0x1) & 0x4) {
  2195.       if (facing == 1) {
  2196.         if ((0x4|0x1) & 0x1) {
  2197.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2198.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2199.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2200.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2201.            if (VB->SecondaryColorPtr[0]) {
  2202.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2203.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2204.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2205.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2206.            }
  2207.         } else {
  2208.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2209.            (v[0]->index = vbindex[e0]);
  2210.            (v[1]->index = vbindex[e1]);
  2211.            (v[2]->index = vbindex[e2]);
  2212.         }
  2213.       }
  2214.    }
  2215. }
  2216.  
  2217.  
  2218.  
  2219. /* Need to fixup edgeflags when decomposing to triangles:
  2220.  */
  2221. static void  _Optlink  quadfunc_twoside_rgba( GLcontext *ctx, GLuint v0,
  2222.                       GLuint v1, GLuint v2, GLuint v3 )
  2223. {
  2224.    if ((0x4|0x1) & 0x8) {
  2225.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2226.       GLubyte ef1 = VB->EdgeFlag[v1];
  2227.       GLubyte ef3 = VB->EdgeFlag[v3];
  2228.       VB->EdgeFlag[v1] = 0;
  2229.       triangle_twoside_rgba( ctx, v0, v1, v3 );
  2230.       VB->EdgeFlag[v1] = ef1;
  2231.       VB->EdgeFlag[v3] = 0;
  2232.       triangle_twoside_rgba( ctx, v1, v2, v3 );
  2233.       VB->EdgeFlag[v3] = ef3;
  2234.    } else {
  2235.       triangle_twoside_rgba( ctx, v0, v1, v3 );
  2236.       triangle_twoside_rgba( ctx, v1, v2, v3 );
  2237.    }
  2238. }
  2239.  
  2240.  
  2241.  
  2242.  
  2243. static void init_twoside_rgba( void )
  2244. {
  2245.    tri_tab[(0x4|0x1)] = triangle_twoside_rgba;
  2246.    quad_tab[(0x4|0x1)] = quadfunc_twoside_rgba;
  2247. }
  2248.  
  2249.  
  2250.  
  2251. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  2252.  
  2253. /*
  2254.  * Mesa 3-D graphics library
  2255.  * Version:  5.0
  2256.  *
  2257.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  2258.  *
  2259.  * Permission is hereby granted, free of charge, to any person obtaining a
  2260.  * copy of this software and associated documentation files (the "Software"),
  2261.  * to deal in the Software without restriction, including without limitation
  2262.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2263.  * and/or sell copies of the Software, and to permit persons to whom the
  2264.  * Software is furnished to do so, subject to the following conditions:
  2265.  *
  2266.  * The above copyright notice and this permission notice shall be included
  2267.  * in all copies or substantial portions of the Software.
  2268.  *
  2269.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2270.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2271.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  2272.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2273.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2274.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2275.  *
  2276.  * Authors:
  2277.  *    Keith Whitwell <keith@tungstengraphics.com>
  2278.  */
  2279.  
  2280.  
  2281. static void triangle_offset_twoside_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2282. {
  2283.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2284.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  2285.    SWvertex *v[3];
  2286.    GLfloat z[3];
  2287.    GLfloat offset;
  2288.    GLenum mode = 0x1B02;
  2289.    GLuint facing = 0;
  2290.  
  2291.    v[0] = &verts[e0];
  2292.    v[1] = &verts[e1];
  2293.    v[2] = &verts[e2];
  2294.  
  2295.  
  2296.    if ((0x2|0x4|0x1) & (0x4 | 0x2 | 0x8))
  2297.    {
  2298.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  2299.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  2300.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  2301.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  2302.       GLfloat cc  = ex*fy - ey*fx;
  2303.  
  2304.       if ((0x2|0x4|0x1) & (0x4 | 0x8))
  2305.       {
  2306.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  2307.          if (ctx->Stencil.TestTwoSide)
  2308.             ctx->_Facing = facing; /* for 2-sided stencil test */
  2309.  
  2310.         if ((0x2|0x4|0x1) & 0x8)
  2311.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  2312.  
  2313.         if (facing == 1) {
  2314.            if ((0x2|0x4|0x1) & 0x4) {
  2315.               if ((0x2|0x4|0x1) & 0x1) {
  2316.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  2317.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2318.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2319.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2320.                  if (VB->SecondaryColorPtr[1]) {
  2321.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  2322.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2323.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2324.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2325.                  }
  2326.               } else {
  2327.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  2328.                  (v[0]->index = vbindex[e0]);
  2329.                  (v[1]->index = vbindex[e1]);
  2330.                  (v[2]->index = vbindex[e2]);
  2331.               }
  2332.            }
  2333.         }
  2334.       }
  2335.  
  2336.       if ((0x2|0x4|0x1) & 0x2)
  2337.       {
  2338.         offset = ctx->Polygon.OffsetUnits;
  2339.         z[0] = v[0]->win[2];
  2340.         z[1] = v[1]->win[2];
  2341.         z[2] = v[2]->win[2];
  2342.         if (cc * cc > 1e-16) {
  2343.            GLfloat ez = z[0] - z[2];
  2344.            GLfloat fz = z[1] - z[2];
  2345.            GLfloat a = ey*fz - ez*fy;
  2346.            GLfloat b = ez*fx - ex*fz;
  2347.            GLfloat ic = 1.0F / cc;
  2348.            GLfloat ac = a * ic;
  2349.            GLfloat bc = b * ic;
  2350.            if (ac < 0.0F) ac = -ac;
  2351.            if (bc < 0.0F) bc = -bc;
  2352.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  2353.         }
  2354.          offset *= ctx->MRD;
  2355.          /*printf("offset %g\n", offset);*/
  2356.       }
  2357.    }
  2358.  
  2359.    if (mode == 0x1B00) {
  2360.       if (((0x2|0x4|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  2361.         v[0]->win[2] += offset;
  2362.         v[1]->win[2] += offset;
  2363.         v[2]->win[2] += offset;
  2364.       }
  2365.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  2366.    } else if (mode == 0x1B01) {
  2367.       if (((0x2|0x4|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  2368.         v[0]->win[2] += offset;
  2369.         v[1]->win[2] += offset;
  2370.         v[2]->win[2] += offset;
  2371.       }
  2372.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  2373.    } else {
  2374.       if (((0x2|0x4|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  2375.         v[0]->win[2] += offset;
  2376.         v[1]->win[2] += offset;
  2377.         v[2]->win[2] += offset;
  2378.       }
  2379.  _mesa_debug(ctx, "triangle_offset_twoside_rgba call  _swrast_Triangle\n");
  2380.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  2381.  _mesa_debug(ctx, "triangle_offset_twoside_rgba return  _swrast_Triangle\n");
  2382.    }
  2383.  
  2384.    if ((0x2|0x4|0x1) & 0x2) {
  2385.       v[0]->win[2] = z[0];
  2386.       v[1]->win[2] = z[1];
  2387.       v[2]->win[2] = z[2];
  2388.    }
  2389.  
  2390.    if ((0x2|0x4|0x1) & 0x4) {
  2391.       if (facing == 1) {
  2392.         if ((0x2|0x4|0x1) & 0x1) {
  2393.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2394.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2395.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2396.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2397.            if (VB->SecondaryColorPtr[0]) {
  2398.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2399.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2400.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2401.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2402.            }
  2403.         } else {
  2404.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2405.            (v[0]->index = vbindex[e0]);
  2406.            (v[1]->index = vbindex[e1]);
  2407.            (v[2]->index = vbindex[e2]);
  2408.         }
  2409.       }
  2410.    }
  2411. }
  2412.  
  2413.  
  2414.  
  2415. /* Need to fixup edgeflags when decomposing to triangles:
  2416.  */
  2417. static void _Optlink quadfunc_offset_twoside_rgba( GLcontext *ctx, GLuint v0,
  2418.                       GLuint v1, GLuint v2, GLuint v3 )
  2419. {
  2420.    if ((0x2|0x4|0x1) & 0x8) {
  2421.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2422.       GLubyte ef1 = VB->EdgeFlag[v1];
  2423.       GLubyte ef3 = VB->EdgeFlag[v3];
  2424.       VB->EdgeFlag[v1] = 0;
  2425.       triangle_offset_twoside_rgba( ctx, v0, v1, v3 );
  2426.       VB->EdgeFlag[v1] = ef1;
  2427.       VB->EdgeFlag[v3] = 0;
  2428.       triangle_offset_twoside_rgba( ctx, v1, v2, v3 );
  2429.       VB->EdgeFlag[v3] = ef3;
  2430.    } else {
  2431.       triangle_offset_twoside_rgba( ctx, v0, v1, v3 );
  2432.       triangle_offset_twoside_rgba( ctx, v1, v2, v3 );
  2433.    }
  2434. }
  2435.  
  2436.  
  2437.  
  2438.  
  2439. static void init_offset_twoside_rgba( void )
  2440. {
  2441.    tri_tab[(0x2|0x4|0x1)] = triangle_offset_twoside_rgba;
  2442.    quad_tab[(0x2|0x4|0x1)] = quadfunc_offset_twoside_rgba;
  2443. }
  2444.  
  2445.  
  2446.  
  2447. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  2448.  
  2449. /*
  2450.  * Mesa 3-D graphics library
  2451.  * Version:  5.0
  2452.  *
  2453.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  2454.  *
  2455.  * Permission is hereby granted, free of charge, to any person obtaining a
  2456.  * copy of this software and associated documentation files (the "Software"),
  2457.  * to deal in the Software without restriction, including without limitation
  2458.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2459.  * and/or sell copies of the Software, and to permit persons to whom the
  2460.  * Software is furnished to do so, subject to the following conditions:
  2461.  *
  2462.  * The above copyright notice and this permission notice shall be included
  2463.  * in all copies or substantial portions of the Software.
  2464.  *
  2465.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2466.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2467.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  2468.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2469.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2470.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2471.  *
  2472.  * Authors:
  2473.  *    Keith Whitwell <keith@tungstengraphics.com>
  2474.  */
  2475.  
  2476.  
  2477. static void triangle_unfilled_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2478. {
  2479.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2480.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  2481.    SWvertex *v[3];
  2482.    GLfloat z[3];
  2483.    GLfloat offset;
  2484.    GLenum mode = 0x1B02;
  2485.    GLuint facing = 0;
  2486.  
  2487.    v[0] = &verts[e0];
  2488.    v[1] = &verts[e1];
  2489.    v[2] = &verts[e2];
  2490.  
  2491.  
  2492.    if ((0x8|0x1) & (0x4 | 0x2 | 0x8))
  2493.    {
  2494.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  2495.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  2496.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  2497.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  2498.       GLfloat cc  = ex*fy - ey*fx;
  2499.  
  2500.       if ((0x8|0x1) & (0x4 | 0x8))
  2501.       {
  2502.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  2503.          if (ctx->Stencil.TestTwoSide)
  2504.             ctx->_Facing = facing; /* for 2-sided stencil test */
  2505.  
  2506.         if ((0x8|0x1) & 0x8)
  2507.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  2508.  
  2509.         if (facing == 1) {
  2510.            if ((0x8|0x1) & 0x4) {
  2511.               if ((0x8|0x1) & 0x1) {
  2512.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  2513.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2514.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2515.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2516.                  if (VB->SecondaryColorPtr[1]) {
  2517.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  2518.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2519.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2520.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2521.                  }
  2522.               } else {
  2523.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  2524.                  (v[0]->index = vbindex[e0]);
  2525.                  (v[1]->index = vbindex[e1]);
  2526.                  (v[2]->index = vbindex[e2]);
  2527.               }
  2528.            }
  2529.         }
  2530.       }
  2531.  
  2532.       if ((0x8|0x1) & 0x2)
  2533.       {
  2534.         offset = ctx->Polygon.OffsetUnits;
  2535.         z[0] = v[0]->win[2];
  2536.         z[1] = v[1]->win[2];
  2537.         z[2] = v[2]->win[2];
  2538.         if (cc * cc > 1e-16) {
  2539.            GLfloat ez = z[0] - z[2];
  2540.            GLfloat fz = z[1] - z[2];
  2541.            GLfloat a = ey*fz - ez*fy;
  2542.            GLfloat b = ez*fx - ex*fz;
  2543.            GLfloat ic = 1.0F / cc;
  2544.            GLfloat ac = a * ic;
  2545.            GLfloat bc = b * ic;
  2546.            if (ac < 0.0F) ac = -ac;
  2547.            if (bc < 0.0F) bc = -bc;
  2548.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  2549.         }
  2550.          offset *= ctx->MRD;
  2551.          /*printf("offset %g\n", offset);*/
  2552.       }
  2553.    }
  2554.  
  2555.    if (mode == 0x1B00) {
  2556.       if (((0x8|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  2557.         v[0]->win[2] += offset;
  2558.         v[1]->win[2] += offset;
  2559.         v[2]->win[2] += offset;
  2560.       }
  2561.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  2562.    } else if (mode == 0x1B01) {
  2563.       if (((0x8|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  2564.         v[0]->win[2] += offset;
  2565.         v[1]->win[2] += offset;
  2566.         v[2]->win[2] += offset;
  2567.       }
  2568.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  2569.    } else {
  2570.       if (((0x8|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  2571.         v[0]->win[2] += offset;
  2572.         v[1]->win[2] += offset;
  2573.         v[2]->win[2] += offset;
  2574.       }
  2575.  _mesa_debug(ctx, "triangle_unfilled_rgba call  _swrast_Triangle\n");
  2576.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  2577.  _mesa_debug(ctx, "triangle_unfilled_rgba return  _swrast_Triangle\n");
  2578.    }
  2579.  
  2580.    if ((0x8|0x1) & 0x2) {
  2581.       v[0]->win[2] = z[0];
  2582.       v[1]->win[2] = z[1];
  2583.       v[2]->win[2] = z[2];
  2584.    }
  2585.  
  2586.    if ((0x8|0x1) & 0x4) {
  2587.       if (facing == 1) {
  2588.         if ((0x8|0x1) & 0x1) {
  2589.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2590.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2591.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2592.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2593.            if (VB->SecondaryColorPtr[0]) {
  2594.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2595.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2596.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2597.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2598.            }
  2599.         } else {
  2600.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2601.            (v[0]->index = vbindex[e0]);
  2602.            (v[1]->index = vbindex[e1]);
  2603.            (v[2]->index = vbindex[e2]);
  2604.         }
  2605.       }
  2606.    }
  2607. }
  2608.  
  2609.  
  2610.  
  2611. /* Need to fixup edgeflags when decomposing to triangles:
  2612.  */
  2613. static void  _Optlink  quadfunc_unfilled_rgba( GLcontext *ctx, GLuint v0,
  2614.                       GLuint v1, GLuint v2, GLuint v3 )
  2615. {
  2616.    if ((0x8|0x1) & 0x8) {
  2617.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2618.       GLubyte ef1 = VB->EdgeFlag[v1];
  2619.       GLubyte ef3 = VB->EdgeFlag[v3];
  2620.       VB->EdgeFlag[v1] = 0;
  2621.       triangle_unfilled_rgba( ctx, v0, v1, v3 );
  2622.       VB->EdgeFlag[v1] = ef1;
  2623.       VB->EdgeFlag[v3] = 0;
  2624.       triangle_unfilled_rgba( ctx, v1, v2, v3 );
  2625.       VB->EdgeFlag[v3] = ef3;
  2626.    } else {
  2627.       triangle_unfilled_rgba( ctx, v0, v1, v3 );
  2628.       triangle_unfilled_rgba( ctx, v1, v2, v3 );
  2629.    }
  2630. }
  2631.  
  2632.  
  2633.  
  2634.  
  2635. static void init_unfilled_rgba( void )
  2636. {
  2637.    tri_tab[(0x8|0x1)] = triangle_unfilled_rgba;
  2638.    quad_tab[(0x8|0x1)] = quadfunc_unfilled_rgba;
  2639. }
  2640.  
  2641.  
  2642.  
  2643. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  2644.  
  2645. /*
  2646.  * Mesa 3-D graphics library
  2647.  * Version:  5.0
  2648.  *
  2649.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  2650.  *
  2651.  * Permission is hereby granted, free of charge, to any person obtaining a
  2652.  * copy of this software and associated documentation files (the "Software"),
  2653.  * to deal in the Software without restriction, including without limitation
  2654.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2655.  * and/or sell copies of the Software, and to permit persons to whom the
  2656.  * Software is furnished to do so, subject to the following conditions:
  2657.  *
  2658.  * The above copyright notice and this permission notice shall be included
  2659.  * in all copies or substantial portions of the Software.
  2660.  *
  2661.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2662.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2663.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  2664.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2665.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2666.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2667.  *
  2668.  * Authors:
  2669.  *    Keith Whitwell <keith@tungstengraphics.com>
  2670.  */
  2671.  
  2672.  
  2673. static void triangle_offset_unfilled_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2674. {
  2675.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2676.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  2677.    SWvertex *v[3];
  2678.    GLfloat z[3];
  2679.    GLfloat offset;
  2680.    GLenum mode = 0x1B02;
  2681.    GLuint facing = 0;
  2682.  
  2683.    v[0] = &verts[e0];
  2684.    v[1] = &verts[e1];
  2685.    v[2] = &verts[e2];
  2686.  
  2687.  
  2688.    if ((0x2|0x8|0x1) & (0x4 | 0x2 | 0x8))
  2689.    {
  2690.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  2691.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  2692.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  2693.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  2694.       GLfloat cc  = ex*fy - ey*fx;
  2695.  
  2696.       if ((0x2|0x8|0x1) & (0x4 | 0x8))
  2697.       {
  2698.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  2699.          if (ctx->Stencil.TestTwoSide)
  2700.             ctx->_Facing = facing; /* for 2-sided stencil test */
  2701.  
  2702.         if ((0x2|0x8|0x1) & 0x8)
  2703.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  2704.  
  2705.         if (facing == 1) {
  2706.            if ((0x2|0x8|0x1) & 0x4) {
  2707.               if ((0x2|0x8|0x1) & 0x1) {
  2708.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  2709.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2710.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2711.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2712.                  if (VB->SecondaryColorPtr[1]) {
  2713.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  2714.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2715.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2716.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2717.                  }
  2718.               } else {
  2719.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  2720.                  (v[0]->index = vbindex[e0]);
  2721.                  (v[1]->index = vbindex[e1]);
  2722.                  (v[2]->index = vbindex[e2]);
  2723.               }
  2724.            }
  2725.         }
  2726.       }
  2727.  
  2728.       if ((0x2|0x8|0x1) & 0x2)
  2729.       {
  2730.         offset = ctx->Polygon.OffsetUnits;
  2731.         z[0] = v[0]->win[2];
  2732.         z[1] = v[1]->win[2];
  2733.         z[2] = v[2]->win[2];
  2734.         if (cc * cc > 1e-16) {
  2735.            GLfloat ez = z[0] - z[2];
  2736.            GLfloat fz = z[1] - z[2];
  2737.            GLfloat a = ey*fz - ez*fy;
  2738.            GLfloat b = ez*fx - ex*fz;
  2739.            GLfloat ic = 1.0F / cc;
  2740.            GLfloat ac = a * ic;
  2741.            GLfloat bc = b * ic;
  2742.            if (ac < 0.0F) ac = -ac;
  2743.            if (bc < 0.0F) bc = -bc;
  2744.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  2745.         }
  2746.          offset *= ctx->MRD;
  2747.          /*printf("offset %g\n", offset);*/
  2748.       }
  2749.    }
  2750.  
  2751.    if (mode == 0x1B00) {
  2752.       if (((0x2|0x8|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  2753.         v[0]->win[2] += offset;
  2754.         v[1]->win[2] += offset;
  2755.         v[2]->win[2] += offset;
  2756.       }
  2757.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  2758.    } else if (mode == 0x1B01) {
  2759.       if (((0x2|0x8|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  2760.         v[0]->win[2] += offset;
  2761.         v[1]->win[2] += offset;
  2762.         v[2]->win[2] += offset;
  2763.       }
  2764.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  2765.    } else {
  2766.       if (((0x2|0x8|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  2767.         v[0]->win[2] += offset;
  2768.         v[1]->win[2] += offset;
  2769.         v[2]->win[2] += offset;
  2770.       }
  2771.  _mesa_debug(ctx, "triangle_offset_unfilled_rgba call  _swrast_Triangle\n");
  2772.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  2773.  _mesa_debug(ctx, "triangle_offset_unfilled_rgba return  _swrast_Triangle\n");
  2774.    }
  2775.  
  2776.    if ((0x2|0x8|0x1) & 0x2) {
  2777.       v[0]->win[2] = z[0];
  2778.       v[1]->win[2] = z[1];
  2779.       v[2]->win[2] = z[2];
  2780.    }
  2781.  
  2782.    if ((0x2|0x8|0x1) & 0x4) {
  2783.       if (facing == 1) {
  2784.         if ((0x2|0x8|0x1) & 0x1) {
  2785.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2786.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2787.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2788.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2789.            if (VB->SecondaryColorPtr[0]) {
  2790.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2791.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2792.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2793.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2794.            }
  2795.         } else {
  2796.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2797.            (v[0]->index = vbindex[e0]);
  2798.            (v[1]->index = vbindex[e1]);
  2799.            (v[2]->index = vbindex[e2]);
  2800.         }
  2801.       }
  2802.    }
  2803. }
  2804.  
  2805.  
  2806.  
  2807. /* Need to fixup edgeflags when decomposing to triangles:
  2808.  */
  2809. static void  _Optlink  quadfunc_offset_unfilled_rgba( GLcontext *ctx, GLuint v0,
  2810.                       GLuint v1, GLuint v2, GLuint v3 )
  2811. {
  2812.    if ((0x2|0x8|0x1) & 0x8) {
  2813.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2814.       GLubyte ef1 = VB->EdgeFlag[v1];
  2815.       GLubyte ef3 = VB->EdgeFlag[v3];
  2816.       VB->EdgeFlag[v1] = 0;
  2817.       triangle_offset_unfilled_rgba( ctx, v0, v1, v3 );
  2818.       VB->EdgeFlag[v1] = ef1;
  2819.       VB->EdgeFlag[v3] = 0;
  2820.       triangle_offset_unfilled_rgba( ctx, v1, v2, v3 );
  2821.       VB->EdgeFlag[v3] = ef3;
  2822.    } else {
  2823.       triangle_offset_unfilled_rgba( ctx, v0, v1, v3 );
  2824.       triangle_offset_unfilled_rgba( ctx, v1, v2, v3 );
  2825.    }
  2826. }
  2827.  
  2828.  
  2829.  
  2830.  
  2831. static void init_offset_unfilled_rgba( void )
  2832. {
  2833.    tri_tab[(0x2|0x8|0x1)] = triangle_offset_unfilled_rgba;
  2834.    quad_tab[(0x2|0x8|0x1)] = quadfunc_offset_unfilled_rgba;
  2835. }
  2836.  
  2837.  
  2838.  
  2839. static void triangle_twoside_unfilled_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2840. {
  2841.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2842.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  2843.    SWvertex *v[3];
  2844.    GLfloat z[3];
  2845.    GLfloat offset;
  2846.    GLenum mode = 0x1B02;
  2847.    GLuint facing = 0;
  2848.  
  2849.    v[0] = &verts[e0];
  2850.    v[1] = &verts[e1];
  2851.    v[2] = &verts[e2];
  2852.  
  2853.  
  2854.    if ((0x4|0x8|0x1) & (0x4 | 0x2 | 0x8))
  2855.    {
  2856.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  2857.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  2858.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  2859.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  2860.       GLfloat cc  = ex*fy - ey*fx;
  2861.  
  2862.       if ((0x4|0x8|0x1) & (0x4 | 0x8))
  2863.       {
  2864.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  2865.          if (ctx->Stencil.TestTwoSide)
  2866.             ctx->_Facing = facing; /* for 2-sided stencil test */
  2867.  
  2868.         if ((0x4|0x8|0x1) & 0x8)
  2869.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  2870.  
  2871.         if (facing == 1) {
  2872.            if ((0x4|0x8|0x1) & 0x4) {
  2873.               if ((0x4|0x8|0x1) & 0x1) {
  2874.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  2875.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2876.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2877.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2878.                  if (VB->SecondaryColorPtr[1]) {
  2879.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  2880.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2881.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2882.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2883.                  }
  2884.               } else {
  2885.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  2886.                  (v[0]->index = vbindex[e0]);
  2887.                  (v[1]->index = vbindex[e1]);
  2888.                  (v[2]->index = vbindex[e2]);
  2889.               }
  2890.            }
  2891.         }
  2892.       }
  2893.  
  2894.    }
  2895.  
  2896.     v[0]->win[2] += offset;
  2897.     v[1]->win[2] += offset;
  2898.     v[2]->win[2] += offset;
  2899. // _mesa_debug(ctx, "triangle_twoside_unfilled_rgba call  _swrast_Triangle\n");
  2900.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  2901. // _mesa_debug(ctx, "triangle_twoside_unfilled_rgba return  _swrast_Triangle\n");
  2902.  
  2903.    if ((0x4|0x8|0x1) & 0x2) {
  2904.       v[0]->win[2] = z[0];
  2905.       v[1]->win[2] = z[1];
  2906.       v[2]->win[2] = z[2];
  2907.    }
  2908.  
  2909.    if ((0x4|0x8|0x1) & 0x4) {
  2910.       if (facing == 1) {
  2911.         if ((0x4|0x8|0x1) & 0x1) {
  2912.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  2913.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  2914.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  2915.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  2916.            if (VB->SecondaryColorPtr[0]) {
  2917.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  2918.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  2919.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  2920.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  2921.            }
  2922.         } else {
  2923.            GLuint *vbindex = VB->IndexPtr[0]->data;
  2924.            (v[0]->index = vbindex[e0]);
  2925.            (v[1]->index = vbindex[e1]);
  2926.            (v[2]->index = vbindex[e2]);
  2927.         }
  2928.       }
  2929.    }
  2930. }
  2931.  
  2932.  
  2933.  
  2934. /* Need to fixup edgeflags when decomposing to triangles:
  2935.  */
  2936. static void  _Optlink  quadfunc_twoside_unfilled_rgba( GLcontext *ctx, GLuint v0,
  2937.                       GLuint v1, GLuint v2, GLuint v3 )
  2938. {
  2939.    if ((0x4|0x8|0x1) & 0x8) {
  2940.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2941.       GLubyte ef1 = VB->EdgeFlag[v1];
  2942.       GLubyte ef3 = VB->EdgeFlag[v3];
  2943.       VB->EdgeFlag[v1] = 0;
  2944.       triangle_twoside_unfilled_rgba( ctx, v0, v1, v3 );
  2945.       VB->EdgeFlag[v1] = ef1;
  2946.       VB->EdgeFlag[v3] = 0;
  2947.       triangle_twoside_unfilled_rgba( ctx, v1, v2, v3 );
  2948.       VB->EdgeFlag[v3] = ef3;
  2949.    } else {
  2950.       triangle_twoside_unfilled_rgba( ctx, v0, v1, v3 );
  2951.       triangle_twoside_unfilled_rgba( ctx, v1, v2, v3 );
  2952.    }
  2953. }
  2954.  
  2955.  
  2956.  
  2957.  
  2958. static void init_twoside_unfilled_rgba( void )
  2959. {
  2960.    tri_tab[(0x4|0x8|0x1)] = triangle_twoside_unfilled_rgba;
  2961.    quad_tab[(0x4|0x8|0x1)] = quadfunc_twoside_unfilled_rgba;
  2962. }
  2963.  
  2964.  
  2965.  
  2966. /* $Id: ss_tritmp.h,v 1.20 2002/11/13 15:04:29 brianp Exp $ */
  2967.  
  2968. /*
  2969.  * Mesa 3-D graphics library
  2970.  * Version:  5.0
  2971.  *
  2972.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  2973.  *
  2974.  * Permission is hereby granted, free of charge, to any person obtaining a
  2975.  * copy of this software and associated documentation files (the "Software"),
  2976.  * to deal in the Software without restriction, including without limitation
  2977.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  2978.  * and/or sell copies of the Software, and to permit persons to whom the
  2979.  * Software is furnished to do so, subject to the following conditions:
  2980.  *
  2981.  * The above copyright notice and this permission notice shall be included
  2982.  * in all copies or substantial portions of the Software.
  2983.  *
  2984.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2985.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2986.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  2987.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  2988.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2989.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2990.  *
  2991.  * Authors:
  2992.  *    Keith Whitwell <keith@tungstengraphics.com>
  2993.  */
  2994.  
  2995.  
  2996. static void triangle_offset_twoside_unfilled_rgba(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
  2997. {
  2998.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  2999.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  3000.    SWvertex *v[3];
  3001.    GLfloat z[3];
  3002.    GLfloat offset;
  3003.    GLenum mode = 0x1B02;
  3004.    GLuint facing = 0;
  3005.  
  3006.    v[0] = &verts[e0];
  3007.    v[1] = &verts[e1];
  3008.    v[2] = &verts[e2];
  3009.  
  3010.  
  3011.    if ((0x2|0x4|0x8|0x1) & (0x4 | 0x2 | 0x8))
  3012.    {
  3013.       GLfloat ex = v[0]->win[0] - v[2]->win[0];
  3014.       GLfloat ey = v[0]->win[1] - v[2]->win[1];
  3015.       GLfloat fx = v[1]->win[0] - v[2]->win[0];
  3016.       GLfloat fy = v[1]->win[1] - v[2]->win[1];
  3017.       GLfloat cc  = ex*fy - ey*fx;
  3018.  
  3019.       if ((0x2|0x4|0x8|0x1) & (0x4 | 0x8))
  3020.       {
  3021.         facing = (cc < 0.0) ^ ctx->Polygon._FrontBit;
  3022.          if (ctx->Stencil.TestTwoSide)
  3023.             ctx->_Facing = facing; /* for 2-sided stencil test */
  3024.  
  3025.         if ((0x2|0x4|0x8|0x1) & 0x8)
  3026.            mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode;
  3027.  
  3028.         if (facing == 1) {
  3029.            if ((0x2|0x4|0x8|0x1) & 0x4) {
  3030.               if ((0x2|0x4|0x8|0x1) & 0x1) {
  3031.                  GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[1]->Ptr;
  3032.                  do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  3033.                  do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  3034.                  do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  3035.                  if (VB->SecondaryColorPtr[1]) {
  3036.                     GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[1]->Ptr;
  3037.                     do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  3038.                     do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  3039.                     do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  3040.                  }
  3041.               } else {
  3042.                  GLuint *vbindex = VB->IndexPtr[1]->data;
  3043.                  (v[0]->index = vbindex[e0]);
  3044.                  (v[1]->index = vbindex[e1]);
  3045.                  (v[2]->index = vbindex[e2]);
  3046.               }
  3047.            }
  3048.         }
  3049.       }
  3050.  
  3051.       if ((0x2|0x4|0x8|0x1) & 0x2)
  3052.       {
  3053.         offset = ctx->Polygon.OffsetUnits;
  3054.         z[0] = v[0]->win[2];
  3055.         z[1] = v[1]->win[2];
  3056.         z[2] = v[2]->win[2];
  3057.         if (cc * cc > 1e-16) {
  3058.            GLfloat ez = z[0] - z[2];
  3059.            GLfloat fz = z[1] - z[2];
  3060.            GLfloat a = ey*fz - ez*fy;
  3061.            GLfloat b = ez*fx - ex*fz;
  3062.            GLfloat ic = 1.0F / cc;
  3063.            GLfloat ac = a * ic;
  3064.            GLfloat bc = b * ic;
  3065.            if (ac < 0.0F) ac = -ac;
  3066.            if (bc < 0.0F) bc = -bc;
  3067.            offset += ( (ac)>(bc) ? (ac) : (bc) ) * ctx->Polygon.OffsetFactor;
  3068.         }
  3069.          offset *= ctx->MRD;
  3070.          /*printf("offset %g\n", offset);*/
  3071.       }
  3072.    }
  3073.  
  3074.    if (mode == 0x1B00) {
  3075.       if (((0x2|0x4|0x8|0x1) & 0x2) && ctx->Polygon.OffsetPoint) {
  3076.         v[0]->win[2] += offset;
  3077.         v[1]->win[2] += offset;
  3078.         v[2]->win[2] += offset;
  3079.       }
  3080.       _swsetup_render_point_tri( ctx, e0, e1, e2, facing );
  3081.    } else if (mode == 0x1B01) {
  3082.       if (((0x2|0x4|0x8|0x1) & 0x2) && ctx->Polygon.OffsetLine) {
  3083.         v[0]->win[2] += offset;
  3084.         v[1]->win[2] += offset;
  3085.         v[2]->win[2] += offset;
  3086.       }
  3087.       _swsetup_render_line_tri( ctx, e0, e1, e2, facing );
  3088.    } else {
  3089.       if (((0x2|0x4|0x8|0x1) & 0x2) && ctx->Polygon.OffsetFill) {
  3090.         v[0]->win[2] += offset;
  3091.         v[1]->win[2] += offset;
  3092.         v[2]->win[2] += offset;
  3093.       }
  3094.  _mesa_debug(ctx, "triangle_offset_twoside_unfilled_rgba call  _swrast_Triangle\n");
  3095.       _swrast_Triangle( ctx, v[0], v[1], v[2] );
  3096.  _mesa_debug(ctx, "triangle_offset_twoside_unfilled_rgba return  _swrast_Triangle\n");
  3097.    }
  3098.  
  3099.    if ((0x2|0x4|0x8|0x1) & 0x2) {
  3100.       v[0]->win[2] = z[0];
  3101.       v[1]->win[2] = z[1];
  3102.       v[2]->win[2] = z[2];
  3103.    }
  3104.  
  3105.    if ((0x2|0x4|0x8|0x1) & 0x4) {
  3106.       if (facing == 1) {
  3107.         if ((0x2|0x4|0x8|0x1) & 0x1) {
  3108.            GLchan (*vbcolor)[4] = (GLchan (*)[4])VB->ColorPtr[0]->Ptr;
  3109.            do { (v[0]->color)[0] = (vbcolor[e0])[0]; (v[0]->color)[1] = (vbcolor[e0])[1]; (v[0]->color)[2] = (vbcolor[e0])[2]; (v[0]->color)[3] = (vbcolor[e0])[3]; } while (0);
  3110.            do { (v[1]->color)[0] = (vbcolor[e1])[0]; (v[1]->color)[1] = (vbcolor[e1])[1]; (v[1]->color)[2] = (vbcolor[e1])[2]; (v[1]->color)[3] = (vbcolor[e1])[3]; } while (0);
  3111.            do { (v[2]->color)[0] = (vbcolor[e2])[0]; (v[2]->color)[1] = (vbcolor[e2])[1]; (v[2]->color)[2] = (vbcolor[e2])[2]; (v[2]->color)[3] = (vbcolor[e2])[3]; } while (0);
  3112.            if (VB->SecondaryColorPtr[0]) {
  3113.               GLchan (*vbspec)[4] = (GLchan (*)[4])VB->SecondaryColorPtr[0]->Ptr;
  3114.               do { (v[0]->specular)[0] = (vbspec[e0])[0]; (v[0]->specular)[1] = (vbspec[e0])[1]; (v[0]->specular)[2] = (vbspec[e0])[2]; } while (0);
  3115.               do { (v[1]->specular)[0] = (vbspec[e1])[0]; (v[1]->specular)[1] = (vbspec[e1])[1]; (v[1]->specular)[2] = (vbspec[e1])[2]; } while (0);
  3116.               do { (v[2]->specular)[0] = (vbspec[e2])[0]; (v[2]->specular)[1] = (vbspec[e2])[1]; (v[2]->specular)[2] = (vbspec[e2])[2]; } while (0);
  3117.            }
  3118.         } else {
  3119.            GLuint *vbindex = VB->IndexPtr[0]->data;
  3120.            (v[0]->index = vbindex[e0]);
  3121.            (v[1]->index = vbindex[e1]);
  3122.            (v[2]->index = vbindex[e2]);
  3123.         }
  3124.       }
  3125.    }
  3126. }
  3127.  
  3128.  
  3129.  
  3130. /* Need to fixup edgeflags when decomposing to triangles:
  3131.  */
  3132. static void _Optlink quadfunc_offset_twoside_unfilled_rgba( GLcontext *ctx, GLuint v0,
  3133.                       GLuint v1, GLuint v2, GLuint v3 )
  3134. {
  3135.    if ((0x2|0x4|0x8|0x1) & 0x8) {
  3136.       struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  3137.       GLubyte ef1 = VB->EdgeFlag[v1];
  3138.       GLubyte ef3 = VB->EdgeFlag[v3];
  3139.       VB->EdgeFlag[v1] = 0;
  3140.       triangle_offset_twoside_unfilled_rgba( ctx, v0, v1, v3 );
  3141.       VB->EdgeFlag[v1] = ef1;
  3142.       VB->EdgeFlag[v3] = 0;
  3143.       triangle_offset_twoside_unfilled_rgba( ctx, v1, v2, v3 );
  3144.       VB->EdgeFlag[v3] = ef3;
  3145.    } else {
  3146.       triangle_offset_twoside_unfilled_rgba( ctx, v0, v1, v3 );
  3147.       triangle_offset_twoside_unfilled_rgba( ctx, v1, v2, v3 );
  3148.    }
  3149. }
  3150.  
  3151.  
  3152.  
  3153.  
  3154. static void init_offset_twoside_unfilled_rgba( void )
  3155. {
  3156.    tri_tab[(0x2|0x4|0x8|0x1)] = triangle_offset_twoside_unfilled_rgba;
  3157.    quad_tab[(0x2|0x4|0x8|0x1)] = quadfunc_offset_twoside_unfilled_rgba;
  3158. }
  3159.  
  3160.  
  3161.  
  3162.  
  3163. void _swsetup_trifuncs_init( GLcontext *ctx )
  3164. {
  3165.    (void) ctx;
  3166.  
  3167.    init();
  3168.    init_offset();
  3169.    init_twoside();
  3170.    init_offset_twoside();
  3171.    init_unfilled();
  3172.    init_offset_unfilled();
  3173.    init_twoside_unfilled();
  3174.    init_offset_twoside_unfilled();
  3175.  
  3176.    init_rgba();
  3177.    init_offset_rgba();
  3178.    init_twoside_rgba();
  3179.    init_offset_twoside_rgba();
  3180.    init_unfilled_rgba();
  3181.    init_offset_unfilled_rgba();
  3182.    init_twoside_unfilled_rgba();
  3183.    init_offset_twoside_unfilled_rgba();
  3184. }
  3185.  
  3186.  
  3187. static void swsetup_points( GLcontext *ctx, GLuint first, GLuint last )
  3188. {
  3189.    struct vertex_buffer *VB = &((TNLcontext *)(ctx->swtnl_context))->vb;
  3190.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  3191.    GLuint i;
  3192.  
  3193.    if (VB->Elts) {
  3194.       for (i = first; i < last; i++)
  3195.         if (VB->ClipMask[VB->Elts[i]] == 0)
  3196.            _swrast_Point( ctx, &verts[VB->Elts[i]] );
  3197.    }
  3198.    else {
  3199.       for (i = first; i < last; i++)
  3200.         if (VB->ClipMask[i] == 0)
  3201.            _swrast_Point( ctx, &verts[i] );
  3202.    }
  3203. }
  3204.  
  3205. static void swsetup_line( GLcontext *ctx, GLuint v0, GLuint v1 )
  3206. {
  3207.    SWvertex *verts = ((SScontext *)ctx->swsetup_context)->verts;
  3208.    _swrast_Line( ctx, &verts[v0], &verts[v1] );
  3209. }
  3210.  
  3211.  
  3212.  
  3213. void _swsetup_choose_trifuncs( GLcontext *ctx )
  3214. {
  3215.    TNLcontext *tnl = ((TNLcontext *)(ctx->swtnl_context));
  3216.    GLuint ind = 0;
  3217.  
  3218.    if (ctx->Polygon.OffsetPoint ||
  3219.        ctx->Polygon.OffsetLine ||
  3220.        ctx->Polygon.OffsetFill)
  3221.       ind |= 0x2;
  3222.  
  3223.    if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
  3224.       ind |= 0x4;
  3225.  
  3226.    /* We piggyback the two-sided stencil front/back determination on the
  3227.     * unfilled triangle path.
  3228.     */
  3229.    if ((ctx->_TriangleCaps & 0x10) ||
  3230.        (ctx->Stencil.Enabled && ctx->Stencil.TestTwoSide))
  3231.       ind |= 0x8;
  3232.  
  3233.    if (ctx->Visual.rgbMode)
  3234.       ind |= 0x1;
  3235.  
  3236.    tnl->Driver.Render.Triangle = tri_tab[ind];
  3237.    tnl->Driver.Render.Quad = quad_tab[ind];
  3238.    tnl->Driver.Render.Line = swsetup_line;
  3239.    tnl->Driver.Render.Points = swsetup_points;
  3240.  
  3241.    ctx->_Facing = 0;
  3242. }
  3243.