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 / cybDisplay / cybFastTrianglesDBn.E < prev    next >
Encoding:
Text File  |  1999-09-04  |  7.3 KB  |  254 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. /**********************************************************************/
  26. /*****                 Optimized triangle rendering               *****/
  27. /**********************************************************************/
  28.  
  29. /* Smooth-shaded, z-less triangle, RGBA color. */
  30. void cybSmoothRGBAZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  31.                      GLuint v2, GLuint pv)
  32. {
  33.   struct RastPort *rp;
  34.  
  35.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  36.  
  37.   (void)pv;
  38. #define INTERP_Z    1
  39. #define INTERP_RGB    1
  40. #undef    INTERP_ALPHA    /* alpha-channel is useless for amiga (currently) */
  41. #define INNER_LOOP(LEFT, RIGHT, Y) {                                    \
  42.     GLshort i, len = RIGHT - LEFT;                                    \
  43.     for (i = 0; i < len; i++, zRow++) {                                    \
  44.       GLdepth z = FixedToDepth(ffz);                                    \
  45.       if (z < *zRow) {                                        \
  46.     WriteRGBPixel(rp, i + LEFT, Y, TC_RGBA(FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb)) >> 8);\
  47.         *zRow = z;                                            \
  48.       }                                                    \
  49.       ffr += fdrdx;  ffg += fdgdx;  ffb += fdbdx; /* ffa += fdadx; */                    \
  50.       ffz += fdzdx;                                            \
  51.     }                                                    \
  52.   }
  53.  
  54. #include "../../tritemp.h"
  55. }
  56.  
  57. /* Smooth-shaded, z-less triangle, RGBA color. */
  58. void cybSmoothCI32ZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  59.                      GLuint v2, GLuint pv)
  60. {
  61.   struct RastPort *rp;
  62.   GLuint *ItoP;
  63.  
  64.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  65.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  66.  
  67.   (void)pv;
  68. #define INTERP_Z    1
  69. #define INTERP_INDEX    1
  70. #define INNER_LOOP(LEFT, RIGHT, Y) {                        \
  71.     GLshort i, len = RIGHT - LEFT;                        \
  72.     for (i = 0; i < len; i++, zRow++) {                        \
  73.       GLdepth z = FixedToDepth(ffz);                        \
  74.       if (z < *zRow) {                                \
  75.     WriteRGBPixel(rp, i + LEFT, Y, GetRGBPLocal(FixedToInt(ffi)) >> 8);    \
  76.         *zRow = z;                                \
  77.       }                                        \
  78.       ffi += fdidx;                                \
  79.       ffz += fdzdx;                                \
  80.     }                                        \
  81.   }
  82.  
  83. #include "../../tritemp.h"
  84. }
  85.  
  86. /* Flat-shaded, z-less triangle, RGBA color. */
  87. void cybFlatRGBAZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  88.                    GLuint v2, GLuint pv)
  89. {
  90.   struct RastPort *rp;
  91.  
  92.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  93.  
  94. #define INTERP_Z    1
  95. #define SETUP_CODE    GLuint pixel = TC_RGBA(VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]) >> 8;
  96.  
  97. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  98.     GLshort i, len = RIGHT - LEFT;        \
  99.     for (i = 0; i < len; i++, zRow++) {        \
  100.       GLdepth z = FixedToDepth(ffz);        \
  101.       if (z < *zRow) {                \
  102.     WriteRGBPixel(rp, i + LEFT, Y, pixel);    \
  103.         *zRow = z;                \
  104.       }                        \
  105.       ffz += fdzdx;                \
  106.     }                        \
  107.   }
  108.  
  109. #include "../../tritemp.h"
  110. }
  111.  
  112. /* Flat-shaded, z-less triangle, RGBA color. */
  113. void cybFlatCI32ZTriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  114.                    GLuint v2, GLuint pv)
  115. {
  116.   struct RastPort *rp;
  117.   GLuint *ItoP;
  118.  
  119.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  120.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  121.  
  122. #define INTERP_Z    1
  123. #define SETUP_CODE    GLuint pixel = GetRGBPLocal(VB->IndexPtr->data[pv][0]) >> 8;
  124.  
  125. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  126.     GLshort i, len = RIGHT - LEFT;        \
  127.     for (i = 0; i < len; i++, zRow++) {        \
  128.       GLdepth z = FixedToDepth(ffz);        \
  129.       if (z < *zRow) {                \
  130.     WriteRGBPixel(rp, i + LEFT, Y, pixel);    \
  131.         *zRow = z;                \
  132.       }                        \
  133.       ffz += fdzdx;                \
  134.     }                        \
  135.   }
  136.  
  137. #include "../../tritemp.h"
  138. }
  139.  
  140. /* Smooth-shaded, z-less triangle, RGBA color. */
  141. void cybSmoothRGBATriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  142.                      GLuint v2, GLuint pv)
  143. {
  144.   struct RastPort *rp;
  145.  
  146.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  147.  
  148.   (void)pv;
  149. #define INTERP_RGB    1
  150. #undef    INTERP_ALPHA    /* alpha-channel is useless for amiga (currently) */
  151. #define INNER_LOOP(LEFT, RIGHT, Y) {                                    \
  152.     GLshort i, len = RIGHT - LEFT;                                    \
  153.     for (i = 0; i < len; i++) {                                        \
  154.       WriteRGBPixel(rp, i + LEFT, Y, TC_RGBA(FixedToInt(ffr), FixedToInt(ffg), FixedToInt(ffb)) >> 8);    \
  155.       ffr += fdrdx;  ffg += fdgdx;  ffb += fdbdx; /* ffa += fdadx; */                    \
  156.     }                                                    \
  157.   }
  158.  
  159. #include "../../tritemp.h"
  160. }
  161.  
  162. /* Smooth-shaded, z-less triangle, RGBA color. */
  163. void cybSmoothCI32Triangle(GLcontext * ctx, GLuint v0, GLuint v1,
  164.                      GLuint v2, GLuint pv)
  165. {
  166.   struct RastPort *rp;
  167.   GLuint *ItoP;
  168.  
  169.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  170.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  171.  
  172.   (void)pv;
  173. #define INTERP_INDEX    1
  174. #define INNER_LOOP(LEFT, RIGHT, Y) {                        \
  175.     GLshort i, len = RIGHT - LEFT;                        \
  176.     for (i = 0; i < len; i++) {                            \
  177.       WriteRGBPixel(rp, i + LEFT, Y, GetRGBPLocal(FixedToInt(ffi)) >> 8);    \
  178.       ffi += fdidx;                                \
  179.     }                                        \
  180.   }
  181.  
  182. #include "../../tritemp.h"
  183. }
  184.  
  185. /* Flat-shaded, z-less triangle, RGBA color. */
  186. void cybFlatRGBATriangle(GLcontext * ctx, GLuint v0, GLuint v1,
  187.                    GLuint v2, GLuint pv)
  188. {
  189.   struct RastPort *rp;
  190.  
  191.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  192.  
  193. #define SETUP_CODE    GLuint pixel = TC_RGBA(VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]) >> 8;
  194.  
  195. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  196.     GLshort len = RIGHT - LEFT;            \
  197.     while (--len >= 0)                \
  198.       WriteRGBPixel(rp, len + LEFT, Y, pixel);    \
  199.   }
  200.  
  201. #include "../../tritemp.h"
  202. }
  203.  
  204. /* Flat-shaded, z-less triangle, RGBA color. */
  205. void cybFlatCI32Triangle(GLcontext * ctx, GLuint v0, GLuint v1,
  206.                    GLuint v2, GLuint pv)
  207. {
  208.   struct RastPort *rp;
  209.   GLuint *ItoP;
  210.  
  211.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp;
  212.   ItoP = ((amigaMesaContext) ctx->DriverCtx)->ItoP;
  213.  
  214. #define SETUP_CODE    GLuint pixel = GetRGBPLocal(VB->IndexPtr->data[pv][0]) >> 8;
  215.  
  216. #define INNER_LOOP(LEFT, RIGHT, Y) {        \
  217.     GLshort len = RIGHT - LEFT;            \
  218.     while (--len >= 0)                \
  219.       WriteRGBPixel(rp, len + LEFT, Y, pixel);    \
  220.   }
  221.  
  222. #include "../../tritemp.h"
  223. }
  224.  
  225. /* Return pointer to an accelerated triangle function if possible. */
  226. triangle_func test_cybChooseTriangleFunction(GLcontext * ctx)
  227. {
  228.   GLboolean rgbmode = ctx->Visual->RGBAflag;
  229.  
  230.   if (ctx->Polygon.SmoothFlag)
  231.     return NULL;
  232.   if (ctx->Polygon.StippleFlag)
  233.     return NULL;
  234.   if (ctx->Texture.Enabled)
  235.     return NULL;
  236.  
  237.   if (ctx->RasterMask == 0) {
  238.     if (ctx->Light.ShadeModel == GL_SMOOTH)
  239.       return rgbmode ? cybSmoothRGBATriangle : cybSmoothCI32Triangle;
  240.     else
  241.       return rgbmode ? cybFlatRGBATriangle : cybFlatCI32Triangle;
  242.   }
  243.   else if ((ctx->RasterMask == DEPTH_BIT) &&
  244.        (ctx->Depth.Func == GL_LESS) &&
  245.        (ctx->Depth.Mask)) {
  246.     if (ctx->Light.ShadeModel == GL_SMOOTH)
  247.       return rgbmode ? cybSmoothRGBAZTriangle : cybSmoothCI32ZTriangle;
  248.     else
  249.       return rgbmode ? cybFlatRGBAZTriangle : cybFlatCI32ZTriangle;
  250.   }
  251.  
  252.   return NULL;
  253. }
  254.