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