home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / natDisplay / natFastTrianglesDBn.E < prev    next >
Text File  |  1999-09-04  |  5KB  |  184 lines

  1. /*
  2.  * $Id: $
  3.  */
  4.  
  5. /*
  6.  * Mesa 3-D graphics library
  7.  * Version:  3.1
  8.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include "natFastTrianglesDBn8.E"
  26. #include "natFastTrianglesDBnD.E"
  27. #include "natFastTrianglesDBnG.E"
  28.  
  29. /**********************************************************************/
  30. /*****                 Optimized triangle rendering               *****/
  31. /**********************************************************************/
  32.  
  33. /* Smooth-shaded, z-less triangle, RGBA color. */
  34. void natSmoothCI32ZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  35.                        GLuint v2, GLuint pv)
  36. {
  37.   struct RastPort *rp;
  38.   GLuint *ItoP;
  39.  
  40.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  41.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  42.  
  43.   (void)pv;
  44. #define INTERP_Z    1
  45. #define INTERP_INDEX    1
  46. #define INNER_LOOP(LEFT, RIGHT, Y) {            \
  47.     GLshort i, len = RIGHT - LEFT;            \
  48.     for (i = 0; i < len; i++, zRow++) {            \
  49.       GLdepth z = FixedToDepth(ffz);            \
  50.       if (z < *zRow) {                    \
  51.         SetAPen(rp, GetRGBPLocal(FixedToInt(ffi)));    \
  52.         WritePixel(rp, i + LEFT, Y);            \
  53.         *zRow = z;                    \
  54.       }                            \
  55.       ffi += fdidx;                    \
  56.       ffz += fdzdx;                    \
  57.     }                            \
  58.   }
  59.  
  60. #include "../../tritemp.h"
  61. }
  62.  
  63. /* Flat-shaded, z-less triangle, RGBA color. */
  64. void natFlatCI32ZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  65.                      GLuint v2, GLuint pv)
  66. {
  67.   struct RastPort *rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  68.  
  69. #define INTERP_Z    1
  70. #define SETUP_CODE    SetAPen(rp, GetRGBP(((amigaMesaContext) ctx->DriverCtx), ctx->VB->IndexPtr->data[pvert]));
  71.  
  72. #define INNER_LOOP(LEFT, RIGHT, Y) {    \
  73.     GLshort i, len = RIGHT - LEFT;    \
  74.     for (i = 0; i < len; i++, zRow++) {    \
  75.       GLdepth z = FixedToDepth(ffz);    \
  76.       if (z < *zRow) {            \
  77.     WritePixel(rp, i + LEFT, Y);    \
  78.         *zRow = z;            \
  79.       }                    \
  80.       ffz += fdzdx;            \
  81.     }                    \
  82.   }
  83.  
  84. #include "../../tritemp.h"
  85. }
  86.  
  87. /* Smooth-shaded, z-less triangle, RGBA color. */
  88. void natSmoothCI32Triangle(GLcontext * ctx, GLuint v0, GLuint v1,
  89.                        GLuint v2, GLuint pv)
  90. {
  91.   struct RastPort *rp;
  92.   GLuint *ItoP;
  93.  
  94.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  95.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  96.  
  97.   (void)pv;
  98. #define INTERP_INDEX    1
  99. #define INNER_LOOP(LEFT, RIGHT, Y) {            \
  100.     GLshort i, len = RIGHT - LEFT;            \
  101.     for (i = 0; i < len; i++) {                \
  102.       SetAPen(rp, GetRGBPLocal(FixedToInt(ffi)));    \
  103.       WritePixel(rp, i + LEFT, Y);            \
  104.       ffi += fdidx;                    \
  105.     }                            \
  106.   }
  107.  
  108. #include "../../tritemp.h"
  109. }
  110.  
  111. /* Flat-shaded, z-less triangle, RGBA color. */
  112. void natFlatCI32Triangle(GLcontext * ctx, GLuint v0, GLuint v1,
  113.                      GLuint v2, GLuint pv)
  114. {
  115.   struct RastPort *rp;
  116.  
  117.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  118.  
  119. #define SETUP_CODE    SetAPen(rp, GetRGBP(((amigaMesaContext) ctx->DriverCtx), ctx->VB->IndexPtr->data[pvert]));
  120.  
  121. #define INNER_LOOP(LEFT, RIGHT, Y) {    \
  122.     GLshort len = RIGHT - LEFT;        \
  123.     while (--len >= 0)            \
  124.       WritePixel(rp, len + LEFT, Y);    \
  125.   }
  126.  
  127. #include "../../tritemp.h"
  128. }
  129.  
  130. /* Return pointer to an accelerated triangle function if possible. */
  131. triangle_func test_natChooseTriangleFunction(GLcontext * ctx)
  132. {
  133.   GLboolean RGBMode = ctx->Visual->RGBAflag;
  134.   palMode trueColor = ((amigaMesaContext)ctx->DriverCtx)->trueColor;
  135.  
  136.   if (ctx->Polygon.SmoothFlag)
  137.     return NULL;
  138.   if (ctx->Polygon.StippleFlag)
  139.     return NULL;
  140.   if (ctx->Texture.Enabled)
  141.     return NULL;
  142.  
  143.   if ((ctx->RasterMask == DEPTH_BIT) &&
  144.       (ctx->Depth.Func == GL_LESS) &&
  145.       (ctx->Depth.Mask)) {
  146.     if (ctx->Light.ShadeModel == GL_SMOOTH) {
  147.       if (RGBMode)
  148.     return IS_SHIFT(trueColor) ? nat8SmoothRGBAZTriangle :
  149.            IS_MATCH(trueColor) ? natGSmoothRGBAZTriangle :
  150.                      natDSmoothRGBAZTriangle;
  151.       else
  152.     return natSmoothCI32ZTriangle;
  153.     }
  154.     else {
  155.       if (RGBMode)
  156.     return IS_SHIFT(trueColor) ? nat8FlatRGBAZTriangle :
  157.            IS_MATCH(trueColor) ? natGFlatRGBAZTriangle :
  158.                      natDFlatRGBAZTriangle;
  159.       else
  160.     return natFlatCI32ZTriangle;
  161.     }
  162.   }
  163.   else if (ctx->RasterMask == 0) {
  164.     if (ctx->Light.ShadeModel == GL_SMOOTH) {
  165.       if (RGBMode)
  166.     return IS_SHIFT(trueColor) ? nat8SmoothRGBATriangle :
  167.            IS_MATCH(trueColor) ? natGSmoothRGBATriangle :
  168.                      natDSmoothRGBATriangle;
  169.       else
  170.     return natSmoothCI32Triangle;
  171.     }
  172.     else {
  173.       if (RGBMode)
  174.     return IS_SHIFT(trueColor) ? nat8FlatRGBATriangle :
  175.            IS_MATCH(trueColor) ? natGFlatRGBATriangle :
  176.                      natDFlatRGBATriangle;
  177.       else
  178.     return natFlatCI32Triangle;
  179.     }
  180.   }
  181.  
  182.   return NULL;
  183. }
  184.