home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-3_1.lha / src / AOS / natDisplay / natFastTrianglesDB.E < prev    next >
Encoding:
Text File  |  1999-09-04  |  5.3 KB  |  192 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 "natFastTrianglesDB8.E"
  26. #include "natFastTrianglesDBD.E"
  27. #include "natFastTrianglesDBG.E"
  28.  
  29. /**********************************************************************/
  30. /*****                 Optimized triangle rendering               *****/
  31. /**********************************************************************/
  32.  
  33. /* Smooth-shaded, z-less triangle, RGBA color. */
  34. void natSmoothCI32ZTriangleDB(GLcontext * ctx, GLuint v0, GLuint v1,
  35.                        GLuint v2, GLuint pv)
  36. {
  37.   GLubyte *db;
  38.   GLuint *ItoP;
  39.  
  40.   db = dbPenGet(((amigaMesaContext) ctx->DriverCtx));
  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.     GLubyte *img = dbPen(db, LEFT, Y);       \
  49.     for (i = 0; i < len; i++, img++, zRow++) {    \
  50.       GLdepth z = FixedToDepth(ffz);        \
  51.       if (z < *zRow) {                \
  52.         *img = GetRGBPLocal(FixedToInt(ffi));    \
  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 natFlatCI32ZTriangleDB(GLcontext * ctx, GLuint v0, GLuint v1,
  65.                      GLuint v2, GLuint pv)
  66. {
  67.   GLubyte *db;
  68.   GLuint *ItoP;
  69.  
  70.   db = dbPenGet(((amigaMesaContext) ctx->DriverCtx));
  71.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  72.  
  73. #define INTERP_Z    1
  74. #define SETUP_CODE    GLuint pixel = GetRGBPLocal(VB->IndexPtr->data[pv][0]);
  75.  
  76. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  77.     GLshort i, len = RIGHT - LEFT;        \
  78.     GLubyte *img = dbPen(db, LEFT, Y);       \
  79.     for (i = 0; i < len; i++, img++, zRow++) {    \
  80.       GLdepth z = FixedToDepth(ffz);        \
  81.       if (z < *zRow) {                \
  82.         *img = pixel;                \
  83.         *zRow = z;                \
  84.       }                        \
  85.       ffz += fdzdx;                \
  86.     }                        \
  87.   }
  88.  
  89. #include "../../tritemp.h"
  90. }
  91.  
  92. /* Smooth-shaded, z-less triangle, RGBA color. */
  93. void natSmoothCI32TriangleDB(GLcontext * ctx, GLuint v0, GLuint v1,
  94.                        GLuint v2, GLuint pv)
  95. {
  96.   GLubyte *db;
  97.   GLuint *ItoP;
  98.  
  99.   db = dbPenGet(((amigaMesaContext) ctx->DriverCtx));
  100.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  101.  
  102.   (void)pv;
  103. #define INTERP_INDEX    1
  104. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  105.     GLshort len = RIGHT - LEFT;            \
  106.     GLubyte *img = dbPen(db, LEFT, Y);       \
  107.     while (--len >= 0)                \
  108.       *img++ = GetRGBPLocal(FixedToInt(ffi));    \
  109.       ffi += fdidx;                \
  110.     }                        \
  111.   }
  112.  
  113. #include "../../tritemp.h"
  114. }
  115.  
  116. /* Flat-shaded, z-less triangle, RGBA color. */
  117. void natFlatCI32TriangleDB(GLcontext * ctx, GLuint v0, GLuint v1,
  118.                      GLuint v2, GLuint pv)
  119. {
  120.   GLubyte *db;
  121.   GLuint *ItoP;
  122.  
  123.   db = dbPenGet(((amigaMesaContext) ctx->DriverCtx));
  124.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  125.  
  126. #define SETUP_CODE    GLuint pixel = GetRGBPLocal(VB->IndexPtr->data[pv][0]);
  127.  
  128. #define INNER_LOOP(LEFT, RIGHT, Y) {    \
  129.     GLshort len = RIGHT - LEFT;        \
  130.     GLubyte *img = dbPen(db, LEFT, Y);  \
  131.     while (--len >= 0)            \
  132.       *img++ = pixel;            \
  133.   }
  134.  
  135. #include "../../tritemp.h"
  136. }
  137.  
  138. /* Return pointer to an accelerated triangle function if possible. */
  139. triangle_func test_natChooseTriangleFunctionDB(GLcontext * ctx)
  140. {
  141.   GLboolean RGBMode = ctx->Visual->RGBAflag;
  142.   palMode trueColor = ((amigaMesaContext)ctx->DriverCtx)->trueColor;
  143.  
  144.   if (ctx->Polygon.SmoothFlag)
  145.     return NULL;
  146.   if (ctx->Polygon.StippleFlag)
  147.     return NULL;
  148.   if (ctx->Texture.Enabled)
  149.     return NULL;
  150.  
  151.   if ((ctx->RasterMask == DEPTH_BIT) &&
  152.       (ctx->Depth.Func == GL_LESS) &&
  153.       (ctx->Depth.Mask)) {
  154.     if (ctx->Light.ShadeModel == GL_SMOOTH) {
  155.       if (RGBMode)
  156.     return IS_SHIFT(trueColor) ? nat8SmoothRGBAZTriangleDB :
  157.            IS_MATCH(trueColor) ? natGSmoothRGBAZTriangleDB :
  158.                      natDSmoothRGBAZTriangleDB;
  159.       else
  160.     return natSmoothCI32ZTriangleDB;
  161.     }
  162.     else {
  163.       if (RGBMode)
  164.     return IS_SHIFT(trueColor) ? nat8FlatRGBAZTriangleDB :
  165.            IS_MATCH(trueColor) ? natGFlatRGBAZTriangleDB :
  166.                      natDFlatRGBAZTriangleDB;
  167.       else
  168.     return natFlatCI32ZTriangleDB;
  169.     }
  170.   }
  171.   else if (ctx->RasterMask == 0) {
  172.     if (ctx->Light.ShadeModel == GL_SMOOTH) {
  173.       if (RGBMode)
  174.     return IS_SHIFT(trueColor) ? nat8SmoothRGBATriangleDB :
  175.            IS_MATCH(trueColor) ? natGSmoothRGBATriangleDB :
  176.                      natDSmoothRGBATriangleDB;
  177.       else
  178.     return natSmoothCI32TriangleDB;
  179.     }
  180.     else {
  181.       if (RGBMode)
  182.     return IS_SHIFT(trueColor) ? nat8FlatRGBATriangleDB :
  183.            IS_MATCH(trueColor) ? natGFlatRGBATriangleDB :
  184.                      natDFlatRGBATriangleDB;
  185.       else
  186.     return natFlatCI32TriangleDB;
  187.     }
  188.   }
  189.  
  190.   return NULL;
  191. }
  192.