home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / natDisplay.c < prev    next >
C/C++ Source or Header  |  1999-09-26  |  12KB  |  420 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. #undef    NO_CONTEXT_AVAILABLE
  26. #include <AOS/amigamesa.h>
  27. #include "AOS/accessArray.h"
  28.  
  29. #define    MyWritePixelLine8    WritePixelLine8
  30. #define    MyReadPixelLine8    ReadPixelLine8
  31.  
  32. /**********************************************************************/
  33. /*****                Miscellaneous device driver funcs           *****/
  34. /**********************************************************************/
  35.  
  36. const char *natRendererString(void)
  37. {
  38.   return "Native standard\n";
  39. }
  40.  
  41. const char *natRendererStringDB(void)
  42. {
  43.   return "Native fast\n";
  44. }
  45.  
  46. void natClearIndex(GLcontext * ctx, GLuint index)
  47. {
  48.   amigaMesaContext amesa;
  49.  
  50.   /*
  51.    * implement glClearIndex 
  52.    * usually just save the value in the context struct 
  53.    */
  54.   amesa = (amigaMesaContext) ctx->DriverCtx;
  55.  
  56.   DEBUGOUT(1, "natClearIndex(%d)\n", index);
  57.  
  58.   /* RGBP (same as RGBA if P is ignored, same as CI8 if RGB is ignored) */
  59.   amesa->clearpixel = GetRGBP(amesa, index);
  60. }
  61.  
  62. void natClearColor(GLcontext * ctx,
  63.            GLubyte r, GLubyte g, GLubyte b, GLubyte a)
  64. {
  65.   amigaMesaContext amesa;
  66.  
  67.   /*
  68.    * implement glClearColor 
  69.    * color components are floats in [0,1] 
  70.    * usually just save the value in the context struct 
  71.    *
  72.    * @@@ TODO FREE COLOR IF NOT USED 
  73.    */
  74.   amesa = (amigaMesaContext) ctx->DriverCtx;
  75.  
  76.   DEBUGOUT(1, "natClearColor(%d, %d, %d, %d)\n", r, g, b, a);
  77.  
  78.   /* TODO: make a pattern of 2*16 size and fill        *
  79.    * the area with the pattern istead of this color    */
  80.   amesa->clearpixel = MakeRGBP(amesa, (GLubyte) r, (GLubyte) g, (GLubyte) b, 0, 0);
  81. }
  82.  
  83. GLbitfield natClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
  84.             GLint x, GLint y, GLint width, GLint height)
  85. {
  86.   amigaMesaContext amesa;
  87.  
  88.   /*
  89.    * Clear the specified region of the color buffer using the clear color
  90.    * or index as specified by one of the two functions above.
  91.    * If all==GL_TRUE, clear whole buffer
  92.    */
  93.  
  94.   amesa = (amigaMesaContext) ctx->DriverCtx;
  95.  
  96.   DEBUGOUT(1, "natClear(%d, %d, %d, %d, %d)\n", all, FIXx(x), FIXy(y), width, height);
  97.  
  98.   SetAPen(amesa->rp, amesa->clearpixel);
  99.   if (all) {
  100.     struct gl_viewport_attrib *vport = &ctx->Viewport;
  101.  
  102.     DEBUGOUT(8, " RectFill(%d,%d,%d,%d);\n",
  103.          FIXx(vport->X),
  104.          FIXy(vport->Y) - vport->Height,
  105.          FIXx(vport->X) + vport->Width - 1,
  106.          FIXy(vport->Y) - 1);
  107.  
  108.     RectFill(amesa->rp, FIXx(vport->X),
  109.          FIXy(vport->Y) - vport->Height,
  110.          FIXx(vport->X) + vport->Width - 1,
  111.          FIXy(vport->Y) - 1);
  112.   }
  113.   else {
  114.     DEBUGOUT(8, " RectFill(%d,%d,%d,%d);\n",
  115.          FIXx(x),
  116.          FIXy(y) - height,
  117.          FIXx(x) + width - 1,
  118.          FIXy(y) - 1);
  119.  
  120.     RectFill(amesa->rp, FIXx(x),
  121.          FIXy(y) - height,
  122.          FIXx(x) + width - 1,
  123.          FIXy(y) - 1);
  124.   }
  125.  
  126.   return mask & (~GL_COLOR_BUFFER_BIT);
  127. }
  128.  
  129. GLbitfield natClearDB(GLcontext * ctx, GLbitfield mask, GLboolean all,
  130.               GLint x, GLint y, GLint width, GLint height)
  131. {
  132.   amigaMesaContext amesa;
  133.   GLubyte *db;
  134.   GLubyte col;
  135.  
  136.   /*
  137.    * Clear the specified region of the color buffer using the clear color
  138.    * or index as specified by one of the two functions above.
  139.    * If all==GL_TRUE, clear whole buffer
  140.    */
  141.  
  142.   amesa = (amigaMesaContext) ctx->DriverCtx;
  143.   col = amesa->clearpixel;
  144.  
  145.   DEBUGOUT(1, "natClearDB(%d, %d, %d, %d, %d)\n", all, FIXx(x), FIXy(y), width, height);
  146.  
  147.   if (all) {
  148.     GLint size = amesa->FixedWidth * amesa->FixedHeight;
  149.  
  150.   /*db = dbPen(dbPenGet(amesa), 0, 0);*/
  151.     db = amesa->BackArray;                            /* really clear all (Fixed), not only Real */
  152.     while (--size >= 0)
  153.       *db++ = col;
  154.   }
  155.   else {
  156.     GLshort x1, y1, x2, y2;
  157.  
  158.     y2 = y + width;
  159.     x2 = x + height;
  160.     db = dbPenGet(amesa);
  161.  
  162.     for (y1 = y; y1 < y2; y1++) {
  163.       GLubyte *img = dbPen(db, y1, x);
  164.       for (x1 = x; x1 < x2; x1++)
  165.     *img++ = col;
  166.     }
  167.   }
  168.  
  169.   return mask & (~GL_COLOR_BUFFER_BIT);
  170. }
  171.  
  172. void natSetIndex(GLcontext * ctx, GLuint index)
  173. {
  174.   amigaMesaContext amesa;
  175.  
  176.   /*
  177.    * Set the amesa color index. 
  178.    */
  179.  
  180.   amesa = (amigaMesaContext) ctx->DriverCtx;
  181.  
  182.   DEBUGOUT(1, "natSetIndex(%d)\n", index);
  183.  
  184.   /* RGBP (same as RGBA if P is ignored, same as CI8 if RGB is ignored) */
  185.   amesa->pixel = GetRGBP(amesa, index);
  186. }
  187.  
  188. void natSetColor(GLcontext * ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
  189. {
  190.   amigaMesaContext amesa;
  191.  
  192.   /*
  193.    * Set the current RGBA color. 
  194.    * r is in 0..255.RedScale 
  195.    * g is in 0..255.GreenScale 
  196.    * b is in 0..255.BlueScale 
  197.    * a is in 0..255.AlphaScale 
  198.    */
  199.  
  200.   amesa = (amigaMesaContext) ctx->DriverCtx;
  201.  
  202.   DEBUGOUT(1, "natSetColor(%d, %d, %d, %d)\n", r, g, b, a);
  203.  
  204.   /* MonoCI functions need the rgb-value in case of dithering */
  205.   amesa->pixel = MakeRGBP(amesa, (GLubyte) r, (GLubyte) g, (GLubyte) b, 0, 0);
  206. }
  207.  
  208. GLboolean natIndexMask(GLcontext * ctx, GLuint mask)
  209. {
  210.   amigaMesaContext amesa;
  211.  
  212.   /*
  213.    * implement glIndexMask if possible, else return GL_FALSE 
  214.    */
  215.  
  216.   amesa = (amigaMesaContext) ctx->DriverCtx;
  217.  
  218.   DEBUGOUT(1, "natIndexMask(0x%x)\n", mask);
  219.  
  220.   amesa->rp->Mask = (GLubyte) mask;
  221.  
  222.   return (GL_TRUE);
  223. }
  224.  
  225. GLboolean natColorMask(GLcontext * ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
  226. {
  227.   amigaMesaContext amesa;
  228.  
  229.   /*
  230.    * implement glColorMask if possible, else return GL_FALSE 
  231.    */
  232.  
  233.   amesa = (amigaMesaContext) ctx->DriverCtx;
  234.  
  235.   DEBUGOUT(1, "natColorMask()\n");
  236.  
  237.   if (rmask || gmask || bmask)
  238.     return GL_TRUE;
  239.  
  240.   return GL_FALSE;
  241. }
  242.  
  243. /*
  244.  * OPTIONAL FUNCTION: 
  245.  * Implements glLogicOp if possible.  Return GL_TRUE if the device driver
  246.  * can perform the operation, otherwise return GL_FALSE.  If GL_FALSE
  247.  * is returned, the logic op will be done in software by Mesa.
  248.  */
  249. GLboolean natLogicOp(GLcontext * ctx, GLenum op)
  250. {
  251.   /* TODO: minterms etc. */
  252.   switch (op) {
  253.     case GL_CLEAR:
  254.     case GL_SET:
  255.     case GL_COPY:
  256.     case GL_COPY_INVERTED:
  257.     case GL_NOOP:
  258.     case GL_INVERT:
  259.     case GL_AND:
  260.     case GL_NAND:
  261.     case GL_OR:
  262.     case GL_NOR:
  263.     case GL_XOR:
  264.     case GL_EQUIV:
  265.     case GL_AND_REVERSE:
  266.     case GL_AND_INVERTED:
  267.     case GL_OR_REVERSE:
  268.     case GL_OR_INVERTED:
  269.     default:
  270.       break;
  271.   }
  272.  
  273.   return (GL_FALSE);
  274. }
  275.  
  276. #include "natDisplay/natFastLines.c"
  277. #include "natDisplay/natFastPoints.c"
  278. #include "natDisplay/natFastPixels.c"
  279. #include "natDisplay/natFastTriangles.c"
  280.  
  281. #include "natDisplay/natSpans.c"
  282. #include "natDisplay/natPixel.c"
  283.  
  284. /**********************************************************************/
  285. /*****                  amiga/Mesa Private Functions              *****/
  286. /**********************************************************************/
  287. /*
  288.  * Initialize all the pointers in the DD struct.  Do this whenever   
  289.  * a new context is made current or we change buffers via setBuffer! 
  290.  */
  291. void natStandardDDPointers(GLcontext * ctx)
  292. {
  293.   palMode trueColor = ((amigaMesaContext) ctx->DriverCtx)->trueColor;
  294.  
  295.   DEBUGOUT(1, "natStandardDDPointers()\n");
  296.  
  297.   ctx->Driver.RendererString = natRendererString;
  298.  
  299.   ctx->Driver.UpdateState = natStandardDDPointers;
  300.   ctx->Driver.ClearIndex = natClearIndex;
  301.   ctx->Driver.ClearColor = natClearColor;
  302.   ctx->Driver.Clear = natClear;
  303.  
  304.   ctx->Driver.Index = natSetIndex;
  305.   ctx->Driver.Color = natSetColor;
  306.  
  307.   ctx->Driver.IndexMask = natIndexMask;
  308.   ctx->Driver.ColorMask = natColorMask;
  309.  
  310.   ctx->Driver.SetBuffer = cmnSetBuffer;
  311.   ctx->Driver.GetBufferSize = cmnStandardResize;
  312.  
  313.   ctx->Driver.RenderStart = cmnRenderStart;
  314.   ctx->Driver.RenderFinish = cmnRenderFinish;
  315.   ctx->Driver.Dither = cmnDither;
  316.   ctx->Driver.Flush = NULL;                            /* cmnFlush; */
  317.  
  318.   ctx->Driver.PointsFunc = natChoosePointsFunction(ctx);
  319.   ctx->Driver.LineFunc = natChooseLineFunction(ctx);
  320.   ctx->Driver.TriangleFunc = natChooseTriangleFunction(ctx);
  321.   ctx->Driver.QuadFunc = natChooseQuadFunction(ctx);
  322.   ctx->Driver.RectFunc = natChooseRectFunction(ctx);
  323.  
  324.   ctx->Driver.DrawPixels = NULL;
  325.  
  326.   /* Pixel/span writing functions: */
  327.   ctx->Driver.WriteRGBASpan = IS_SHIFT(trueColor) ? nat8WriteRGBASpan :
  328.                   IS_MATCH(trueColor) ? natGWriteRGBASpan :
  329.                             natDWriteRGBASpan;
  330.   ctx->Driver.WriteRGBSpan = IS_SHIFT(trueColor) ? nat8WriteRGBSpan :
  331.                  IS_MATCH(trueColor) ? natGWriteRGBSpan :
  332.                            natDWriteRGBSpan;
  333.   ctx->Driver.WriteCI32Span = natWriteCI32Span;
  334.   ctx->Driver.WriteCI8Span = natWriteCI8Span;
  335.   ctx->Driver.WriteMonoRGBASpan =
  336.   ctx->Driver.WriteMonoCISpan = IS_DITHER(trueColor) ? natDWriteMonoCISpan :
  337.                                natWriteMonoCISpan;
  338.  
  339.   ctx->Driver.WriteRGBAPixels = IS_SHIFT(trueColor) ? nat8WriteRGBAPixel :
  340.                     IS_MATCH(trueColor) ? natGWriteRGBAPixel :
  341.                               natDWriteRGBAPixel;
  342.   ctx->Driver.WriteCI32Pixels = natWriteCI32Pixel;
  343.   ctx->Driver.WriteMonoRGBAPixels =
  344.   ctx->Driver.WriteMonoCIPixels = IS_DITHER(trueColor) ? natDWriteMonoCIPixel :
  345.                              natWriteMonoCIPixel;
  346.  
  347.   /* Pixel/span reading functions: */
  348.   ctx->Driver.ReadRGBASpan = natReadRGBASpan;
  349.   ctx->Driver.ReadCI32Span = natReadCI32Span;
  350.  
  351.   ctx->Driver.ReadRGBAPixels = natReadRGBAPixel;
  352.   ctx->Driver.ReadCI32Pixels = natReadCI32Pixel;
  353. }
  354.  
  355. void natFasterDDPointers(GLcontext * ctx)
  356. {
  357.   palMode trueColor = ((amigaMesaContext) ctx->DriverCtx)->trueColor;
  358.  
  359.   DEBUGOUT(1, "natFasterDDPointers()\n");
  360.  
  361.   ctx->Driver.RendererString = natRendererStringDB;
  362.  
  363.   ctx->Driver.UpdateState = natFasterDDPointers;
  364.   ctx->Driver.ClearIndex = natClearIndex;
  365.   ctx->Driver.ClearColor = natClearColor;
  366.   ctx->Driver.Clear = natClearDB;
  367.  
  368.   ctx->Driver.Index = natSetIndex;
  369.   ctx->Driver.Color = natSetColor;
  370.  
  371.   ctx->Driver.IndexMask = natIndexMask;
  372.   ctx->Driver.ColorMask = natColorMask;
  373.  
  374.   ctx->Driver.SetBuffer = cmnSetBufferDB;
  375.   ctx->Driver.GetBufferSize = cmnStandardResizeDB;
  376.  
  377.   ctx->Driver.RenderStart = cmnRenderStartDB;
  378.   ctx->Driver.RenderFinish = cmnRenderFinishDB;
  379.   ctx->Driver.Dither = cmnDitherDB;
  380.   ctx->Driver.Flush = cmnFlushDB;
  381.  
  382.   ctx->Driver.PointsFunc = natChoosePointsFunctionDB(ctx);
  383.   ctx->Driver.LineFunc = natChooseLineFunctionDB(ctx);
  384.   ctx->Driver.TriangleFunc = natChooseTriangleFunctionDB(ctx);
  385.   ctx->Driver.QuadFunc = natChooseQuadFunctionDB(ctx);
  386.   ctx->Driver.RectFunc = natChooseRectFunctionDB(ctx);
  387.  
  388.   ctx->Driver.DrawPixels = NULL;
  389.  
  390.   /* Pixel/span writing functions: */
  391.   ctx->Driver.WriteRGBASpan = IS_SHIFT(trueColor) ? nat8WriteRGBASpanDB :
  392.                   IS_MATCH(trueColor) ? natGWriteRGBASpanDB :
  393.                             natDWriteRGBASpanDB;
  394.   ctx->Driver.WriteRGBSpan = IS_SHIFT(trueColor) ? nat8WriteRGBSpanDB :
  395.                  IS_MATCH(trueColor) ? natGWriteRGBSpanDB :
  396.                            natDWriteRGBSpanDB;
  397.   ctx->Driver.WriteCI32Span = natWriteCI32SpanDB;
  398.   ctx->Driver.WriteCI8Span = natWriteCI8SpanDB;
  399.   ctx->Driver.WriteMonoRGBASpan =
  400.   ctx->Driver.WriteMonoCISpan = IS_DITHER(trueColor) ? natDWriteMonoCISpanDB :
  401.                                natWriteMonoCISpanDB;
  402.  
  403.   ctx->Driver.WriteRGBAPixels = IS_SHIFT(trueColor) ? nat8WriteRGBAPixelDB :
  404.                     IS_MATCH(trueColor) ? natGWriteRGBAPixelDB :
  405.                               natDWriteRGBAPixelDB;
  406.   ctx->Driver.WriteCI32Pixels = natWriteCI32PixelDB;
  407.   ctx->Driver.WriteMonoRGBAPixels =
  408.   ctx->Driver.WriteMonoCIPixels = IS_DITHER(trueColor) ? natDWriteMonoCIPixelDB :
  409.                              natWriteMonoCIPixelDB;
  410.  
  411.   /* Pixel/span reading functions: */
  412.   ctx->Driver.ReadRGBASpan = natReadRGBASpanDB;
  413.   ctx->Driver.ReadCI32Span = natReadCI32SpanDB;
  414.  
  415.   ctx->Driver.ReadRGBAPixels = natReadRGBAPixelDB;
  416.   ctx->Driver.ReadCI32Pixels = natReadCI32PixelDB;
  417. }
  418.  
  419. #undef DEBUGPRINT
  420.