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