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 / cybFastLinesDBn.E < prev    next >
Encoding:
Text File  |  1999-09-04  |  7.3 KB  |  252 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 line rendering                 *****/
  27. /**********************************************************************/
  28.  
  29. /* Draw a flat-shaded, RGB line into an osmesa buffer. */
  30. void cybFlatRGBALine(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  31. {
  32.   struct RastPort *rp;
  33.   GLuint pixel;
  34.  
  35.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  36.   pixel = TC_RGBA(ctx->VB->ColorPtr->data[pvert][0], ctx->VB->ColorPtr->data[pvert][1], ctx->VB->ColorPtr->data[pvert][2]) >> 8;
  37.  
  38. #define INTERP_XY    1
  39. #define CLIP_HACK    1
  40. #define PLOT(X,Y)    WriteRGBPixel(rp, X, Y, pixel)
  41.  
  42. #include "../../linetemp.h"
  43. }
  44.  
  45. /* Draw a flat-shaded, RGB line into an osmesa buffer. */
  46. void cybFlatCI32Line(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  47. {
  48.   struct RastPort *rp;
  49.   GLuint pixel;
  50.  
  51.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  52.   pixel = GetRGBP(((amigaMesaContext) ctx->DriverCtx), ctx->VB->IndexPtr->data[pvert])
  53.  
  54. #define INTERP_XY    1
  55. #define CLIP_HACK    1
  56. #define PLOT(X,Y)    WriteRGBPixel(rp, X, Y, pixel)
  57.  
  58. #include "../../linetemp.h"
  59. }
  60.  
  61. /* Draw a flat-shaded, Z-less, RGB line into an osmesa buffer. */
  62. void cybFlatRGBAZLine(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  63. {
  64.   struct RastPort *rp;
  65.   GLuint pixel;
  66.  
  67.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  68.   pixel = TC_RGBA(ctx->VB->ColorPtr->data[pvert][0], ctx->VB->ColorPtr->data[pvert][1], ctx->VB->ColorPtr->data[pvert][2]) >> 8;
  69.  
  70. #define INTERP_XY    1
  71. #define INTERP_Z    1
  72. #define CLIP_HACK    1
  73. #define PLOT(X,Y)            \
  74.   if (Z < *zPtr) {            \
  75.     WriteRGBPixel(rp, X, Y, pixel);    \
  76.     *zPtr = Z;                \
  77.   }
  78.  
  79. #include "../../linetemp.h"
  80. }
  81.  
  82. /* Draw a flat-shaded, Z-less, RGB line into an osmesa buffer. */
  83. void cybFlatCI32ZLine(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  84. {
  85.   struct RastPort *rp;
  86.   GLuint pixel;
  87.  
  88.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  89.   pixel = GetRGBP(((amigaMesaContext) ctx->DriverCtx), ctx->VB->IndexPtr->data[pvert])
  90.  
  91. #define INTERP_XY    1
  92. #define INTERP_Z    1
  93. #define CLIP_HACK    1
  94. #define PLOT(X,Y)            \
  95.   if (Z < *zPtr) {            \
  96.     WriteRGBPixel(rp, X, Y, pixel);    \
  97.     *zPtr = Z;                \
  98.   }
  99.  
  100. #include "../../linetemp.h"
  101. }
  102.  
  103. /* Draw a flat-shaded, alpha-blended, RGB line into an osmesa buffer. */
  104. void cybFlatBlendRGBALine(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  105. {
  106.   struct RastPort *rp;
  107.   GLuint *db;
  108.   struct vertex_buffer *VB;
  109.   GLint avalue, msavalue, rvalue, gvalue, bvalue;
  110.  
  111.   db = dbRGBAGet(((amigaMesaContext) ctx->DriverCtx));
  112.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  113.   VB = ctx->VB;
  114.   avalue = VB->ColorPtr->data[pvert][3];
  115.   msavalue = 255 - avalue;
  116.   rvalue = VB->ColorPtr->data[pvert][0] * avalue;
  117.   gvalue = VB->ColorPtr->data[pvert][1] * avalue;
  118.   bvalue = VB->ColorPtr->data[pvert][2] * avalue;
  119.  
  120. #define INTERP_XY    1
  121. #define CLIP_HACK    1
  122. #define PLOT(X,Y) {                                    \
  123.     GLubyte *ptr4 = (GLubyte *)dbRGBA(db, X, Y);                    \
  124.     WriteRGBPixel(rp, X, Y, TC_RGBA(((*ptr4++ * msavalue + rvalue) >> 8),        \
  125.                     ((*ptr4++ * msavalue + gvalue) >> 8),        \
  126.                     ((*ptr4   * msavalue + bvalue) >> 8)) >> 8);    \
  127.   }
  128.  
  129. #include "../../linetemp.h"
  130. }
  131.  
  132. /* Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. */
  133. void cybFlatBlendRGBAZLine(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  134. {
  135.   struct RastPort *rp;
  136.   GLuint *db;
  137.   struct vertex_buffer *VB;
  138.   GLint avalue, msavalue, rvalue, gvalue, bvalue;
  139.  
  140.   db = dbRGBAGet(((amigaMesaContext) ctx->DriverCtx));
  141.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  142.   VB = ctx->VB;
  143.   avalue = VB->ColorPtr->data[pvert][3];
  144.   msavalue = 255 - avalue;
  145.   rvalue = VB->ColorPtr->data[pvert][0] * avalue;
  146.   gvalue = VB->ColorPtr->data[pvert][1] * avalue;
  147.   bvalue = VB->ColorPtr->data[pvert][2] * avalue;
  148.  
  149. #define INTERP_XY    1
  150. #define INTERP_Z    1
  151. #define CLIP_HACK    1
  152. #define PLOT(X,Y)                                    \
  153.   if (Z < *zPtr) {                                    \
  154.     GLubyte *ptr4 = (GLubyte *)dbRGBA(db, X, Y);                    \
  155.     WriteRGBPixel(rp, X, Y, TC_RGBA(((*ptr4++ * msavalue + rvalue) >> 8),        \
  156.                     ((*ptr4++ * msavalue + gvalue) >> 8),        \
  157.                     ((*ptr4   * msavalue + bvalue) >> 8)) >> 8);    \
  158.   }
  159.  
  160. #include "../../linetemp.h"
  161. }
  162.  
  163. /* Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. */
  164. void cybFlatBlendRGBAZLineWrite(GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pvert)
  165. {
  166.   struct RastPort *rp;
  167.   GLuint *db;
  168.   struct vertex_buffer *VB;
  169.   GLint avalue, msavalue, rvalue, gvalue, bvalue;
  170.  
  171.   db = dbRGBAGet(((amigaMesaContext) ctx->DriverCtx));
  172.   rp = ((amigaMesaContext) ctx->DriverCtx)->rp
  173.   VB = ctx->VB;
  174.   avalue = VB->ColorPtr->data[pvert][3];
  175.   msavalue = 255 - avalue;
  176.   rvalue = VB->ColorPtr->data[pvert][0] * avalue;
  177.   gvalue = VB->ColorPtr->data[pvert][1] * avalue;
  178.   bvalue = VB->ColorPtr->data[pvert][2] * avalue;
  179.  
  180. #define INTERP_XY    1
  181. #define INTERP_Z    1
  182. #define CLIP_HACK    1
  183. #define PLOT(X,Y)                                    \
  184.   if (Z < *zPtr) {                                    \
  185.     GLubyte *ptr4 = (GLubyte *)dbRGBA(db, X, Y);                    \
  186.     WriteRGBPixel(rp, X, Y, TC_RGBA(((*ptr4++ * msavalue + rvalue) >> 8),        \
  187.                     ((*ptr4++ * msavalue + gvalue) >> 8),        \
  188.                     ((*ptr4   * msavalue + bvalue) >> 8)) >> 8);    \
  189.     *zPtr = Z;                                        \
  190.   }
  191.  
  192. #include "../../linetemp.h"
  193. }
  194.  
  195. /*
  196.  * Analyze context state to see if we can provide a fast line drawing
  197.  * function, like those in lines.c.  Otherwise, return NULL.
  198.  */
  199. line_func test_cybChooseLineFunction(GLcontext * ctx)
  200. {
  201.   GLboolean rgbmode = ctx->Visual->RGBAflag;
  202.  
  203.   if (ctx->Line.SmoothFlag)
  204.     return NULL;
  205.   if (ctx->Texture.Enabled)
  206.     return NULL;
  207.   if (ctx->Light.ShadeModel != GL_FLAT)
  208.     return NULL;
  209.   if (ctx->Line.Width != 1.0F)
  210.     return NULL;
  211.   if (ctx->Line.StippleFlag)
  212.     return NULL;
  213.  
  214.   switch (ctx->RasterMask) {
  215.     case 0:
  216.       if (rgbmode)
  217.     return cybFlatRGBALine;
  218.       else
  219.     return cybFlatCI32Line;
  220.       break;
  221.     case DEPTH_BIT:
  222.       if ((ctx->Depth.Func == GL_LESS) &&
  223.       (ctx->Depth.Mask))
  224.     if (rgbmode)
  225.       return cybFlatRGBAZLine;
  226.     else
  227.       return cybFlatCI32ZLine;
  228.       break;
  229.     case BLEND_BIT:
  230.       if ((ctx->Color.BlendSrc == GL_SRC_ALPHA) &&
  231.       (ctx->Color.BlendDst == GL_ONE_MINUS_SRC_ALPHA) &&
  232.       (ctx->Color.BlendEquation == GL_FUNC_ADD_EXT))
  233.     return cybFlatBlendRGBALine;
  234.       break;
  235.     case DEPTH_BIT | BLEND_BIT:
  236.       if ((ctx->Depth.Func == GL_LESS) &&
  237.       (ctx->Color.BlendSrc == GL_SRC_ALPHA) &&
  238.       (ctx->Color.BlendDst == GL_ONE_MINUS_SRC_ALPHA) &&
  239.       (ctx->Color.BlendEquation == GL_FUNC_ADD_EXT)) {
  240.     if (ctx->Depth.Mask)
  241.       return cybFlatBlendRGBAZLineWrite;
  242.     else
  243.       return cybFlatBlendRGBAZLine;
  244.       }
  245.       break;
  246.     default:
  247.       break;
  248.   }
  249.  
  250.   return NULL;
  251. }
  252.