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 / cybFastTriangles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-23  |  6.5 KB  |  248 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. #ifdef    TRYTEST
  26. #include "cybFastTrianglesDBn.c"
  27. #include "cybFastTrianglesDB.c"
  28. #endif
  29.  
  30. /**********************************************************************/
  31. /*****            Accelerated point, line, polygon rendering      *****/
  32. /**********************************************************************/
  33.  
  34. /*
  35.  * Draw a filled polygon of a single color. If there is hardware/OS support
  36.  * for polygon drawing use that here.   Otherwise, call a function in
  37.  * polygon.c to do the drawing.
  38.  */
  39.  
  40. void cybFastTriangleFunction(GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv)
  41. {
  42.   amigaMesaContext amesa;
  43.   struct RastPort *rp;
  44.   struct vertex_buffer *VB;
  45.   int x, y;
  46.  
  47.   amesa = (amigaMesaContext) ctx->DriverCtx;
  48.   VB = ctx->VB;
  49.   rp = amesa->rp;
  50.  
  51.   DEBUGOUT(1, "cybFastLineFunction\n");
  52.  
  53.   /* TODO: this is not the optimal case,
  54.    * we should allocate the color here to
  55.    * get the _exact_ color out of the allocated
  56.    * pen
  57.    */
  58.   if (!(amesa->visual->flags & VISUAL_RGBMODE))
  59.     SetAPen(rp, GetRGBP(amesa, VB->IndexPtr->data[pv]));
  60.   else
  61.     SetAPen(rp, PL_RGBA(amesa, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], 0, 0));
  62.  
  63.   x = FIXx((int)(VB->Win.data[v0][0]));
  64.   y = FIXy((int)(VB->Win.data[v0][1]));
  65.   DEBUGOUT(8, " AreaMove(%d, %d)\n", x, y);
  66.   AreaMove(rp, x, y);
  67.  
  68.   x = FIXx((int)(VB->Win.data[v1][0]));
  69.   y = FIXy((int)(VB->Win.data[v1][1]));
  70.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  71.   AreaDraw(rp, x, y);
  72.  
  73.   x = FIXx((int)(VB->Win.data[v2][0]));
  74.   y = FIXy((int)(VB->Win.data[v2][1]));
  75.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  76.   AreaDraw(rp, x, y);
  77.  
  78.   AreaEnd(rp);
  79. }
  80.  
  81. triangle_func cybChooseTriangleFunction(GLcontext * ctx)
  82. {
  83.   /*
  84.    * Examine the current rendering state and return a pointer to a 
  85.    * fast polygon-rendering function if possible. 
  86.    */
  87.   DEBUGOUT(1, "cybChooseTriangleFunction\n");
  88.  
  89.   if ((ctx->Line.Width == 1.0) &&
  90.       (!ctx->Line.SmoothFlag) &&
  91.       (!ctx->Line.StippleFlag) &&
  92.       (ctx->Light.ShadeModel == GL_FLAT) &&
  93.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  94.       (!ctx->Texture.Enabled))
  95.     return cybFastTriangleFunction;
  96. #ifdef    TRYTEST
  97.   if (preset.tryTest)
  98.     return test_cybChooseTriangleFunction(ctx);
  99. #endif
  100.  
  101.   return NULL;
  102. }
  103.  
  104. triangle_func cybChooseTriangleFunctionDB(GLcontext * ctx)
  105. {
  106.   DEBUGOUT(1, "cybChooseTriangleFunctionDB()\n");
  107.  
  108. #ifdef    TRYTEST
  109.   if (preset.tryTest)
  110.     return test_cybChooseTriangleFunctionDB(ctx);
  111. #endif
  112.  
  113.   return NULL;
  114. }
  115.  
  116. void cybFastQuadFunction(GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  117. {
  118.   amigaMesaContext amesa;
  119.   struct RastPort *rp;
  120.   struct vertex_buffer *VB;
  121.   int x, y;
  122.  
  123.   amesa = (amigaMesaContext) ctx->DriverCtx;
  124.   VB = ctx->VB;
  125.   rp = amesa->rp;
  126.  
  127.   DEBUGOUT(1, "cybFastLineFunction\n");
  128.  
  129.   /* TODO: this is not the optimal case,
  130.    * we should allocate the color here to
  131.    * get the _exact_ color out of the allocated
  132.    * pen
  133.    */
  134.   if (!(amesa->visual->flags & VISUAL_RGBMODE))
  135.     SetAPen(rp, GetRGBP(amesa, VB->IndexPtr->data[pv]));
  136.   else
  137.     SetAPen(rp, PL_RGBA(amesa, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], 0, 0));
  138.  
  139.   x = FIXx((int)(VB->Win.data[v0][0]));
  140.   y = FIXy((int)(VB->Win.data[v0][1]));
  141.   DEBUGOUT(8, " AreaMove(%d, %d)\n", x, y);
  142.   AreaMove(rp, x, y);
  143.  
  144.   x = FIXx((int)(VB->Win.data[v1][0]));
  145.   y = FIXy((int)(VB->Win.data[v1][1]));
  146.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  147.   AreaDraw(rp, x, y);
  148.  
  149.   x = FIXx((int)(VB->Win.data[v2][0]));
  150.   y = FIXy((int)(VB->Win.data[v2][1]));
  151.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  152.   AreaDraw(rp, x, y);
  153.  
  154.   x = FIXx((int)(VB->Win.data[v3][0]));
  155.   y = FIXy((int)(VB->Win.data[v3][1]));
  156.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  157.   AreaDraw(rp, x, y);
  158.  
  159.   AreaEnd(rp);
  160. }
  161.  
  162. quad_func cybChooseQuadFunction(GLcontext * ctx)
  163. {
  164.   /*
  165.    * Examine the current rendering state and return a pointer to a 
  166.    * fast polygon-rendering function if possible. 
  167.    */
  168.   DEBUGOUT(1, "cybChooseQuadFunction\n");
  169.  
  170.   if ((ctx->Line.Width == 1.0) &&
  171.       (!ctx->Line.SmoothFlag) &&
  172.       (!ctx->Line.StippleFlag) &&
  173.       (ctx->Light.ShadeModel == GL_FLAT) &&
  174.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  175.       (!ctx->Texture.Enabled))
  176.     return cybFastQuadFunction;
  177. #ifdef    TRYTEST
  178.   if (preset.tryTest)
  179.     return test_cybChooseQuadFunction(ctx);
  180. #endif
  181.  
  182.   return NULL;
  183. }
  184.  
  185. quad_func cybChooseQuadFunctionDB(GLcontext * ctx)
  186. {
  187.   DEBUGOUT(1, "cybChooseQuadFunctionDB()\n");
  188.  
  189. #ifdef    TRYTEST
  190.   if (preset.tryTest)
  191.     return test_cybChooseQuadFunctionDB(ctx);
  192. #endif
  193.  
  194.   return NULL;
  195. }
  196.  
  197. void cybFastRectFunction(GLcontext * ctx, GLint x, GLint y, GLint width, GLint height)
  198. {
  199.   amigaMesaContext amesa;
  200.   struct RastPort *rp;
  201.  
  202.   amesa = (amigaMesaContext) ctx->DriverCtx;
  203.   rp = amesa->rp;
  204.  
  205.   DEBUGOUT(1, "cybFastLineFunction()\n");
  206.  
  207.   FillPixelArray(amesa->rp, FIXx(x),
  208.                 FIXy(y) - height,
  209.                 width,
  210.                 height,
  211.                 amesa->pixel >> 8);
  212. }
  213.  
  214. rect_func cybChooseRectFunction(GLcontext * ctx)
  215. {
  216.   /*
  217.    * Examine the current rendering state and return a pointer to a 
  218.    * fast polygon-rendering function if possible. 
  219.    */
  220.   DEBUGOUT(1, "cybChooseRectFunction\n");
  221.  
  222.   if ((ctx->Line.Width == 1.0) &&
  223.       (!ctx->Line.SmoothFlag) &&
  224.       (!ctx->Line.StippleFlag) &&
  225.       (ctx->Light.ShadeModel == GL_FLAT) &&
  226.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  227.       (!ctx->Texture.Enabled))
  228.     return cybFastRectFunction;
  229. #ifdef    TRYTEST
  230.   if (preset.tryTest)
  231.     return test_cybChooseRectFunction(ctx);
  232. #endif
  233.  
  234.   return NULL;
  235. }
  236.  
  237. rect_func cybChooseRectFunctionDB(GLcontext * ctx)
  238. {
  239.   DEBUGOUT(1, "cybChooseRectFunctionDB()\n");
  240.  
  241. #ifdef    TRYTEST
  242.   if (preset.tryTest)
  243.     return test_cybChooseRectFunctionDB(ctx);
  244. #endif
  245.  
  246.   return NULL;
  247. }
  248.