home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / AOS / cybDisplay.c < prev    next >
C/C++ Source or Header  |  1999-09-26  |  12KB  |  419 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.  * $Log:  $
  27.  */
  28.  
  29. #undef    NO_CONTEXT_AVAILABLE
  30. #include <AOS/amigamesa.h>
  31. #include "AOS/accessArray.h"
  32.  
  33. #define    MyWritePixelArray    WritePixelArray
  34. #define    MyReadPixelArray    ReadPixelArray
  35. #define    MyWriteLUTPixelArray    WriteLUTPixelArray
  36.  
  37. /**********************************************************************/
  38. /*****                Miscellaneous device driver funcs           *****/
  39. /**********************************************************************/
  40.  
  41. const char *cybRendererString(void)
  42. {
  43.   return "CyberGraphX standard\n";
  44. }
  45.  
  46. const char *cybRendererStringDB(void)
  47. {
  48.   return "CyberGraphX fast\n";
  49. }
  50.  
  51. void cybClearIndex(GLcontext * ctx, GLuint index)
  52. {
  53.   amigaMesaContext amesa;
  54.  
  55.   /*
  56.    * implement glClearIndex 
  57.    * usually just save the value in the context struct 
  58.    */
  59.  
  60.   amesa = (amigaMesaContext) ctx->DriverCtx;
  61.  
  62.   DEBUGOUT(1, "cybClearIndex(%d)\n", index);
  63.  
  64.   amesa->clearpixel = GetRGBP(amesa, index);
  65. }
  66.  
  67. void cybClearColor(GLcontext * ctx,
  68.            GLubyte r, GLubyte g, GLubyte b, GLubyte a)
  69. {
  70.   amigaMesaContext amesa;
  71.  
  72.   /*
  73.    * implement glClearColor 
  74.    * color components are floats in [0,1] 
  75.    * usually just save the value in the context struct 
  76.    *
  77.    * @@@ TODO FREE COLOR IF NOT USED 
  78.    */
  79.  
  80.   amesa = (amigaMesaContext) ctx->DriverCtx;
  81.  
  82.   DEBUGOUT(1, "cybClearColor(%d, %d, %d, %d)\n", r, g, b, a);
  83.  
  84.   amesa->clearpixel = MakeRGBP(amesa, (GLubyte) r, (GLubyte) g, (GLubyte) b, 0, 0);
  85. }
  86.  
  87. GLbitfield cybClear(GLcontext * ctx, GLbitfield mask, GLboolean all,
  88.             GLint x, GLint y, GLint width, GLint height)
  89. {
  90.   amigaMesaContext amesa;
  91.  
  92.   /*
  93.    * Clear the specified region of the color buffer using the clear color
  94.    * or index as specified by one of the two functions above.
  95.    * If all==GL_TRUE, clear whole buffer
  96.    */
  97.  
  98.   amesa = (amigaMesaContext) ctx->DriverCtx;
  99.  
  100.   DEBUGOUT(1, "cybClear(%d, %d, %d, %d, %d)\n", all, x, y, width, height);
  101.  
  102.   if (all) {
  103.     struct gl_viewport_attrib *vport = &ctx->Viewport;
  104.  
  105.     DEBUGOUT(2, " FillPixelArray(%d,%d,%d,%d);\n",
  106.          FIXx(vport->X),
  107.          FIXy(vport->Y) - vport->Height,
  108.          FIXx(vport->X) + vport->Width - 1,
  109.          FIXy(vport->Y) - 1);
  110.  
  111.     FillPixelArray(amesa->rp,
  112.            FIXx(vport->X),
  113.            FIXy(vport->Y) - vport->Height,
  114.            vport->Width,
  115.            vport->Height,
  116.            amesa->clearpixel >> 8);
  117.   }
  118.   else {
  119.     DEBUGOUT(2, " FillPixelArray(%d,%d,%d,%d);\n",
  120.          FIXx(x),
  121.          FIXy(y) - height,
  122.          FIXx(x) + width - 1,
  123.          FIXy(y) - 1);
  124.  
  125.     FillPixelArray(amesa->rp, FIXx(x),
  126.            FIXy(y) - height,
  127.            width,
  128.            height,
  129.            amesa->clearpixel >> 8);
  130.   }
  131.  
  132.   return mask & (~GL_COLOR_BUFFER_BIT);
  133. }
  134.  
  135. GLbitfield cybClearDB(GLcontext * ctx, GLbitfield mask, GLboolean all,
  136.               GLint x, GLint y, GLint width, GLint height)
  137. {
  138.   amigaMesaContext amesa;
  139.   GLuint *db;
  140.   GLuint col;
  141.  
  142.   /*
  143.    * Clear the specified region of the color buffer using the clear color
  144.    * or index as specified by one of the two functions above.
  145.    * If all==GL_TRUE, clear whole buffer
  146.    */
  147.  
  148.   amesa = (amigaMesaContext) ctx->DriverCtx;
  149.  
  150.   DEBUGOUT(1, "cybClearDB(%d, %d, %d, %d, %d)\n", all, x, y, width, height);
  151.  
  152.   col = amesa->clearpixel;
  153.   if (all) {
  154.     GLint size = (amesa->FixedWidth * amesa->FixedHeight);
  155.  
  156.   /*db = dbRGBA(dbRGBAGet(amesa), 0, 0);*/
  157.     db = (GLuint *)amesa->BackArray;                        /* really clear all (Fixed), not only Real */
  158.  
  159.     while (--size >= 0)
  160.       *db++ = col;
  161.   }
  162.   else {
  163.     GLshort x1, y1, x2, y2;
  164.  
  165.     y2 = y + width;
  166.     x2 = x + height;
  167.     db = dbRGBAGet(amesa);
  168.  
  169.     for (y1 = y; y1 < y2; y1++) {
  170.       GLuint *img = dbRGBA(db, y1, x);
  171.       for (x1 = x; x1 < x2; x1++)
  172.     *img++ = col;
  173.     }
  174.   }
  175.  
  176.   return mask & (~GL_COLOR_BUFFER_BIT);
  177. }
  178.  
  179. void cybSetIndex(GLcontext * ctx, GLuint index)
  180. {
  181.   amigaMesaContext amesa;
  182.  
  183.   /*
  184.    * Set the amesa color index. 
  185.    */
  186.  
  187.   amesa = (amigaMesaContext) ctx->DriverCtx;
  188.  
  189.   DEBUGOUT(1, "cybSetIndex(%d)\n", index);
  190.  
  191.   amesa->pixel = GetRGBP(amesa, index);
  192. }
  193.  
  194. void cybSetColor(GLcontext * ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a)
  195. {
  196.   amigaMesaContext amesa;
  197.  
  198.   /*
  199.    * Set the current RGBA color. 
  200.    * r is in 0..255.RedScale 
  201.    * g is in 0..255.GreenScale 
  202.    * b is in 0..255.BlueScale 
  203.    * a is in 0..255.AlphaScale 
  204.    */
  205.  
  206.   amesa = (amigaMesaContext) ctx->DriverCtx;
  207.  
  208.   DEBUGOUT(1, "cybSetColor(%d, %d, %d, %d)\n", r, g, b, a);
  209.  
  210.   amesa->pixel = MakeRGBP(amesa, (GLubyte) r, (GLubyte) g, (GLubyte) b, 0, 0);
  211. }
  212.  
  213. GLboolean cybIndexMask(GLcontext * ctx, GLuint mask)
  214. {
  215.   amigaMesaContext amesa;
  216.  
  217.   /*
  218.    * implement glIndexMask if possible, else return GL_FALSE 
  219.    */
  220.  
  221.   amesa = (amigaMesaContext) ctx->DriverCtx;
  222.  
  223.   DEBUGOUT(1, "cybIndexMask(0x%x)\n", mask);
  224.  
  225.   amesa->rp->Mask = (GLubyte) mask;
  226.  
  227.   return (GL_TRUE);
  228. }
  229.  
  230. GLboolean cybColorMask(GLcontext * ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask)
  231. {
  232.   amigaMesaContext amesa;
  233.  
  234.   /*
  235.    * implement glColorMask if possible, else return GL_FALSE 
  236.    */
  237.  
  238.   amesa = (amigaMesaContext) ctx->DriverCtx;
  239.  
  240.   DEBUGOUT(1, "cybColorMask()\n");
  241.  
  242.   if (rmask || gmask || bmask)
  243.     return GL_TRUE;
  244.  
  245.   return GL_FALSE;
  246. }
  247.  
  248. /*
  249.  * OPTIONAL FUNCTION: 
  250.  * Implements glLogicOp if possible.  Return GL_TRUE if the device driver
  251.  * can perform the operation, otherwise return GL_FALSE.  If GL_FALSE
  252.  * is returned, the logic op will be done in software by Mesa.
  253.  */
  254. GLboolean cybLogicOp(GLcontext * ctx, GLenum op)
  255. {
  256.   /* TODO: minterms etc. */
  257.   switch (op) {
  258.     case GL_CLEAR:
  259.     case GL_SET:
  260.     case GL_COPY:
  261.     case GL_COPY_INVERTED:
  262.     case GL_NOOP:
  263.     case GL_INVERT:
  264.     case GL_AND:
  265.     case GL_NAND:
  266.     case GL_OR:
  267.     case GL_NOR:
  268.     case GL_XOR:
  269.     case GL_EQUIV:
  270.     case GL_AND_REVERSE:
  271.     case GL_AND_INVERTED:
  272.     case GL_OR_REVERSE:
  273.     case GL_OR_INVERTED:
  274.     default:
  275.       break;
  276.   }
  277.  
  278.   return GL_FALSE;
  279. }
  280.  
  281. #include "cybDisplay/cybFastLines.c"
  282. #include "cybDisplay/cybFastPixels.c"
  283. #include "cybDisplay/cybFastPoints.c"
  284. #include "cybDisplay/cybFastTriangles.c"
  285.  
  286. #include "cybDisplay/cybSpans.c"
  287. #include "cybDisplay/cybPixel.c"
  288.  
  289. /**********************************************************************/
  290. /*****                  amiga/Mesa Private Functions              *****/
  291. /**********************************************************************/
  292. /*
  293.  * Initialize all the pointers in the DD struct.  Do this whenever   
  294.  * a new context is made current or we change buffers via setBuffer! 
  295.  */
  296. void cybStandardDDPointers(GLcontext * ctx)
  297. {
  298.   palMode trueColor = ((amigaMesaContext) ctx->DriverCtx)->trueColor;
  299.  
  300.   DEBUGOUT(1, "cybStandardDDPointers()\n");
  301.  
  302.   ctx->Driver.RendererString = cybRendererString;
  303.  
  304.   ctx->Driver.UpdateState = cybStandardDDPointers;
  305.   ctx->Driver.ClearIndex = cybClearIndex;
  306.   ctx->Driver.ClearColor = cybClearColor;
  307.   ctx->Driver.Clear = cybClear;
  308.  
  309.   ctx->Driver.Index = cybSetIndex;
  310.   ctx->Driver.Color = cybSetColor;
  311.  
  312.   ctx->Driver.IndexMask = cybIndexMask;
  313.   ctx->Driver.ColorMask = cybColorMask;
  314.   ctx->Driver.LogicOp = cybLogicOp;
  315.  
  316.   ctx->Driver.SetBuffer = cmnSetBuffer;
  317.   ctx->Driver.GetBufferSize = cmnStandardResize;
  318.  
  319.   ctx->Driver.RenderStart = cmnRenderStart;
  320.   ctx->Driver.RenderFinish = cmnRenderFinish;
  321.   ctx->Driver.Dither = NULL;
  322.   ctx->Driver.Flush = NULL;                            /* cmnFlush; */
  323.  
  324.   ctx->Driver.PointsFunc = cybChoosePointsFunction(ctx);
  325.   ctx->Driver.LineFunc = cybChooseLineFunction(ctx);
  326.   ctx->Driver.TriangleFunc = cybChooseTriangleFunction(ctx);
  327.   ctx->Driver.QuadFunc = cybChooseQuadFunction(ctx);
  328.   ctx->Driver.RectFunc = cybChooseRectFunction(ctx);
  329.  
  330.   ctx->Driver.DrawPixels = cybDirectDrawPixels;
  331.  
  332.   /* Pixel/span writing functions: */
  333.   ctx->Driver.WriteRGBASpan = cybWriteRGBASpan;
  334.   ctx->Driver.WriteRGBSpan = cybWriteRGBSpan;
  335.   ctx->Driver.WriteCI32Span = cybWriteCI32Span;
  336.   ctx->Driver.WriteCI8Span = cybWriteCI8Span;
  337.   ctx->Driver.WriteMonoRGBASpan = cybWriteMonoCISpan;
  338.   ctx->Driver.WriteMonoCISpan = cybWriteMonoCISpan;
  339.  
  340.   ctx->Driver.WriteRGBAPixels = cybWriteRGBAPixel;
  341.   ctx->Driver.WriteCI32Pixels = cybWriteCI32Pixel;
  342.   ctx->Driver.WriteMonoRGBAPixels = cybWriteMonoCIPixel;
  343.   ctx->Driver.WriteMonoCIPixels = cybWriteMonoCIPixel;
  344.  
  345.   /* Pixel/span reading functions: */
  346.   ctx->Driver.ReadRGBASpan = cybReadRGBASpan;
  347.   ctx->Driver.ReadCI32Span = IS_SHIFT(trueColor) ? cyb8ReadCI32Span :
  348.                  IS_MATCH(trueColor) ? cybGReadCI32Span :
  349.                            cybDReadCI32Span;
  350.  
  351.   ctx->Driver.ReadRGBAPixels = cybReadRGBAPixel;
  352.   ctx->Driver.ReadCI32Pixels = IS_SHIFT(trueColor) ? cyb8ReadCI32Pixel :
  353.                    IS_MATCH(trueColor) ? cybGReadCI32Pixel :
  354.                              cybDReadCI32Pixel;
  355. }
  356.  
  357. void cybFasterDDPointers(GLcontext * ctx)
  358. {
  359.   palMode trueColor = ((amigaMesaContext) ctx->DriverCtx)->trueColor;
  360.  
  361.   DEBUGOUT(1, "cybFasterDDPointers()\n");
  362.  
  363.   ctx->Driver.RendererString = cybRendererStringDB;
  364.  
  365.   ctx->Driver.UpdateState = cybFasterDDPointers;
  366.   ctx->Driver.ClearIndex = cybClearIndex;
  367.   ctx->Driver.ClearColor = cybClearColor;
  368.   ctx->Driver.Clear = cybClearDB;
  369.  
  370.   ctx->Driver.Index = cybSetIndex;
  371.   ctx->Driver.Color = cybSetColor;
  372.  
  373.   ctx->Driver.IndexMask = cybIndexMask;
  374.   ctx->Driver.ColorMask = cybColorMask;
  375.   ctx->Driver.LogicOp = cybLogicOp;
  376.  
  377.   ctx->Driver.SetBuffer = cmnSetBufferDB;
  378.   ctx->Driver.GetBufferSize = cmnStandardResizeDB;
  379.  
  380.   ctx->Driver.RenderStart = cmnRenderStartDB;
  381.   ctx->Driver.RenderFinish = cmnRenderFinishDB;
  382.   ctx->Driver.Dither = NULL;
  383.   ctx->Driver.Flush = cmnFlushDB;
  384.  
  385.   ctx->Driver.PointsFunc = cybChoosePointsFunctionDB(ctx);
  386.   ctx->Driver.LineFunc = cybChooseLineFunctionDB(ctx);
  387.   ctx->Driver.TriangleFunc = cybChooseTriangleFunctionDB(ctx);
  388.   ctx->Driver.QuadFunc = cybChooseQuadFunctionDB(ctx);
  389.   ctx->Driver.RectFunc = cybChooseRectFunctionDB(ctx);
  390.  
  391.   ctx->Driver.DrawPixels = cybDirectDrawPixelsDB;
  392.  
  393.   /* Pixel/span writing functions: */
  394.   ctx->Driver.WriteRGBASpan = cybWriteRGBASpanDB;
  395.   ctx->Driver.WriteRGBSpan = cybWriteRGBSpanDB;
  396.   ctx->Driver.WriteCI32Span = cybWriteCI32SpanDB;
  397.   ctx->Driver.WriteCI8Span = cybWriteCI8SpanDB;
  398.   ctx->Driver.WriteMonoRGBASpan = cybWriteMonoCISpanDB;                /* same  */
  399.   ctx->Driver.WriteMonoCISpan = cybWriteMonoCISpanDB;
  400.  
  401.   ctx->Driver.WriteRGBAPixels = cybWriteRGBAPixelDB;
  402.   ctx->Driver.WriteCI32Pixels = cybWriteCI32PixelDB;
  403.   ctx->Driver.WriteMonoRGBAPixels = cybWriteMonoCIPixelDB;            /* same  */
  404.   ctx->Driver.WriteMonoCIPixels = cybWriteMonoCIPixelDB;
  405.  
  406.   /* Pixel/span reading functions: */
  407.   ctx->Driver.ReadRGBASpan = cybReadRGBASpanDB;
  408.   ctx->Driver.ReadCI32Span = IS_SHIFT(trueColor) ? cyb8ReadCI32SpanDB :
  409.                  IS_MATCH(trueColor) ? cybGReadCI32SpanDB :
  410.                            cybDReadCI32SpanDB;
  411.  
  412.   ctx->Driver.ReadRGBAPixels = cybReadRGBAPixelDB;
  413.   ctx->Driver.ReadCI32Pixels = IS_SHIFT(trueColor) ? cyb8ReadCI32PixelDB :
  414.                    IS_MATCH(trueColor) ? cybGReadCI32PixelDB :
  415.                              cybDReadCI32PixelDB;
  416. }
  417.  
  418. #undef DEBUGPRINT
  419.