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 / natFastTriangles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-24  |  7.2 KB  |  258 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 "natFastTrianglesDBn.c"
  27. #include "natFastTrianglesDB.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 natFastTriangleFunction(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, "natFastLineFunction\n");
  52.  
  53.   if (!TstF(amesa->visual->flags, VISUAL_RGBMODE))
  54.     SetAPen(rp, GetRGBP(amesa, VB->IndexPtr->data[pv]));
  55.   else
  56.     SetAPen(rp, PL_RGBA(amesa, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], 0, 0));
  57.  
  58.   x = FIXx((int)(VB->Win.data[v0][0]));
  59.   y = FIXy((int)(VB->Win.data[v0][1]));
  60.   DEBUGOUT(8, " AreaMove(%d, %d)\n", x, y);
  61.   AreaMove(rp, x, y);
  62.  
  63.   x = FIXx((int)(VB->Win.data[v1][0]));
  64.   y = FIXy((int)(VB->Win.data[v1][1]));
  65.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  66.   AreaDraw(rp, x, y);
  67.  
  68.   x = FIXx((int)(VB->Win.data[v2][0]));
  69.   y = FIXy((int)(VB->Win.data[v2][1]));
  70.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  71.   AreaDraw(rp, x, y);
  72.  
  73.   AreaEnd(rp);
  74. }
  75.  
  76. triangle_func natChooseTriangleFunction(GLcontext * ctx)
  77. {
  78.   /*
  79.    * Examine the current rendering state and return a pointer to a 
  80.    * fast polygon-rendering function if possible. 
  81.    */
  82.  
  83.   DEBUGOUT(1, "natChooseTriangleFunction()\n");
  84.  
  85.   if (!IS_DITHER((amigaMesaContext) ctx->DriverCtx) &&
  86.       (ctx->Line.Width == 1.0) &&
  87.       (!ctx->Line.SmoothFlag) &&
  88.       (!ctx->Line.StippleFlag) &&
  89.       (ctx->Light.ShadeModel == GL_FLAT) &&
  90.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  91.       (!ctx->Texture.Enabled))
  92.     return natFastTriangleFunction;
  93. #ifdef    TRYTEST
  94.   if (preset.tryTest)
  95.     return test_natChooseTriangleFunction(ctx);
  96. #endif
  97.  
  98. #if 0
  99.   DEBUGOUT(0, "Line.Width = %g\nLine.SmoothFlag = %d\nLine.StippleFlag = %d\nLight.ShadeModel = %x\nRasterMask = %x\nTexture.Enabled = %d\n",
  100.       ctx->Line.Width, ctx->Line.SmoothFlag, ctx->Line.StippleFlag, ctx->Light.ShadeModel, ctx->RasterMask, ctx->Texture.Enabled);
  101. #endif
  102.  
  103.   return NULL;
  104. }
  105.  
  106. triangle_func natChooseTriangleFunctionDB(GLcontext * ctx)
  107. {
  108.   DEBUGOUT(1, "natChooseTriangleFunctionDB()\n");
  109.  
  110. #ifdef    TRYTEST
  111.   if (preset.tryTest)
  112.     return test_natChooseTriangleFunctionDB(ctx);
  113. #endif
  114.  
  115.   return NULL;
  116. }
  117.  
  118. void natFastQuadFunction(GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv)
  119. {
  120.   amigaMesaContext amesa;
  121.   struct RastPort *rp;
  122.   struct vertex_buffer *VB;
  123.   int x, y;
  124.  
  125.   amesa = (amigaMesaContext) ctx->DriverCtx;
  126.   VB = ctx->VB;
  127.   rp = amesa->rp;
  128.  
  129.   DEBUGOUT(1, "natFastQuadFunction\n");
  130.  
  131.   if (!TstF(amesa->visual->flags, VISUAL_RGBMODE))
  132.     SetAPen(rp, GetRGBP(amesa, VB->IndexPtr->data[pv]));
  133.   else
  134.     SetAPen(rp, PL_RGBA(amesa, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], 0, 0));
  135.  
  136.   x = FIXx((int)(VB->Win.data[v0][0]));
  137.   y = FIXy((int)(VB->Win.data[v0][1]));
  138.   DEBUGOUT(8, " AreaMove(%d, %d)\n", x, y);
  139.   AreaMove(rp, x, y);
  140.  
  141.   x = FIXx((int)(VB->Win.data[v1][0]));
  142.   y = FIXy((int)(VB->Win.data[v1][1]));
  143.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  144.   AreaDraw(rp, x, y);
  145.  
  146.   x = FIXx((int)(VB->Win.data[v2][0]));
  147.   y = FIXy((int)(VB->Win.data[v2][1]));
  148.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  149.   AreaDraw(rp, x, y);
  150.  
  151.   x = FIXx((int)(VB->Win.data[v3][0]));
  152.   y = FIXy((int)(VB->Win.data[v3][1]));
  153.   DEBUGOUT(8, " AreaDraw(%d, %d)\n", x, y);
  154.   AreaDraw(rp, x, y);
  155.  
  156.   AreaEnd(rp);
  157. }
  158.  
  159. quad_func natChooseQuadFunction(GLcontext * ctx)
  160. {
  161.   /*
  162.    * Examine the current rendering state and return a pointer to a 
  163.    * fast polygon-rendering function if possible. 
  164.    */
  165.  
  166.   DEBUGOUT(1, "natChooseQuadFunction()\n");
  167.  
  168.   if (!IS_DITHER((amigaMesaContext) ctx->DriverCtx) &&
  169.       (ctx->Line.Width == 1.0) &&
  170.       (!ctx->Line.SmoothFlag) &&
  171.       (!ctx->Line.StippleFlag) &&
  172.       (ctx->Light.ShadeModel == GL_FLAT) &&
  173.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  174.       (!ctx->Texture.Enabled))
  175.     return natFastQuadFunction;
  176. #ifdef    TRYTEST
  177.   if (preset.tryTest)
  178.     return test_natChooseQuadFunction(ctx);
  179. #endif
  180.  
  181. #if 0
  182.   DEBUGOUT(0, "Line.Width = %g\nLine.SmoothFlag = %d\nLine.StippleFlag = %d\nLight.ShadeModel = %x\nRasterMask = %x\nTexture.Enabled = %d\n",
  183.       ctx->Line.Width, ctx->Line.SmoothFlag, ctx->Line.StippleFlag, ctx->Light.ShadeModel, ctx->RasterMask, ctx->Texture.Enabled);
  184. #endif
  185.  
  186.   return NULL;
  187. }
  188.  
  189. quad_func natChooseQuadFunctionDB(GLcontext * ctx)
  190. {
  191.   DEBUGOUT(1, "natChooseQuadFunctionDB()\n");
  192.  
  193. #ifdef    TRYTEST
  194.   if (preset.tryTest)
  195.     return test_natChooseQuadFunctionDB(ctx);
  196. #endif
  197.  
  198.   return NULL;
  199. }
  200.  
  201. void natFastRectFunction(GLcontext * ctx, GLint x, GLint y, GLint width, GLint height)
  202. {
  203.   amigaMesaContext amesa;
  204.   struct RastPort *rp;
  205.  
  206.   amesa = (amigaMesaContext) ctx->DriverCtx;
  207.  
  208.   DEBUGOUT(1, "natFastRectFunction()\n");
  209.  
  210.   SetAPen(amesa->rp, amesa->pixel);
  211.   RectFill(amesa->rp, FIXx(x),
  212.               FIXy(y) - height,
  213.               FIXx(x) + width - 1,
  214.               FIXy(y) - 1);
  215. }
  216.  
  217. rect_func natChooseRectFunction(GLcontext * ctx)
  218. {
  219.   /*
  220.    * Examine the current rendering state and return a pointer to a 
  221.    * fast polygon-rendering function if possible. 
  222.    */
  223.  
  224.   DEBUGOUT(1, "natChooseRectFunction()\n");
  225.  
  226.   if (!IS_DITHER((amigaMesaContext) ctx->DriverCtx) &&
  227.       (ctx->Line.Width == 1.0) &&
  228.       (!ctx->Line.SmoothFlag) &&
  229.       (!ctx->Line.StippleFlag) &&
  230.       (ctx->Light.ShadeModel == GL_FLAT) &&
  231.       (ctx->RasterMask == 0) &&                            /* what means rastermask really? */
  232.       (!ctx->Texture.Enabled))
  233.     return natFastRectFunction;
  234. #ifdef    TRYTEST
  235.   if (preset.tryTest)
  236.     return test_natChooseRectFunction(ctx);
  237. #endif
  238.  
  239. #if 0
  240.   DEBUGOUT(0, "Line.Width = %g\nLine.SmoothFlag = %d\nLine.StippleFlag = %d\nLight.ShadeModel = %x\nRasterMask = %x\nTexture.Enabled = %d\n",
  241.       ctx->Line.Width, ctx->Line.SmoothFlag, ctx->Line.StippleFlag, ctx->Light.ShadeModel, ctx->RasterMask, ctx->Texture.Enabled);
  242. #endif
  243.  
  244.   return NULL;
  245. }
  246.  
  247. rect_func natChooseRectFunctionDB(GLcontext * ctx)
  248. {
  249.   DEBUGOUT(1, "natChooseRectFunctionDB()\n");
  250.  
  251. #ifdef    TRYTEST
  252.   if (preset.tryTest)
  253.     return test_natChooseRectFunctionDB(ctx);
  254. #endif
  255.  
  256.   return NULL;
  257. }
  258.