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 / cybSpans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-12  |  12.8 KB  |  492 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. #include "cybSpans8.c"
  26. #include "cybSpansD.c"
  27. #include "cybSpansG.c"
  28.  
  29. /**********************************************************************/
  30. /*****        write spans of RGBA pixels                          *****/
  31. /**********************************************************************/
  32.  
  33. /* Write RGBA pixels to an RGBA (or permuted) buffer. */
  34. void cybWriteRGBASpan(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  35.               CONST GLubyte rgba[][4], const GLubyte mask[])
  36. {
  37.   amigaMesaContext amesa;
  38.   struct RastPort *rp;
  39.  
  40.   amesa = (amigaMesaContext) ctx->DriverCtx;
  41.   rp = amesa->rp;
  42.  
  43.   y = FIXy(y);
  44.   x = FIXx(x);
  45.   DEBUGOUT(1, "cybWriteRGBASpan(%d, %d, %d): ", n, x, y);
  46.  
  47.   if (!mask) {
  48.     DEBUGOUT(1, "nomask\n");
  49.     DEBUGOUT(2, " WritePixelArray(%d, %d, %d)\n", n, x, y);
  50.     MyWritePixelArray(rgba, 0, 0, 4 * n, rp, x, y, n, 1, RECTFMT_RGBA);
  51.   }
  52.   else {
  53.     GLshort i, ant = 0;
  54.     GLuint *il;
  55.  
  56.     il = (GLuint *) amesa->imageline;                        /* if imageline allocated then use fastversion */
  57.  
  58.     DEBUGOUT(1, "mask FAST\n");
  59.     for (i = 0; i < n; i++) {                            /* draw pixel (x[i],y[i]) */
  60.       if (*mask++) {
  61.     ant++;
  62.     *il++ = *iRGBAi;
  63.       }
  64.       else {
  65.     if (ant) {
  66.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  67.       MyWritePixelArray(il = (GLuint *)amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  68.       x += ant;
  69.       ant = 0;
  70.     }
  71.     else
  72.       x++;
  73.       }
  74.     }
  75.  
  76.     if (ant) {
  77.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  78.       MyWritePixelArray(amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  79.     }
  80.   }
  81. }
  82.  
  83. /* Write RGB pixels to an RGBA (or permuted) buffer. */
  84. void cybWriteRGBSpan(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  85.              CONST GLubyte rgb[][3], const GLubyte mask[])
  86. {
  87.   amigaMesaContext amesa;
  88.   struct RastPort *rp;
  89.  
  90.   amesa = (amigaMesaContext) ctx->DriverCtx;
  91.   rp = amesa->rp;
  92.  
  93.   y = FIXy(y);
  94.   x = FIXx(x);
  95.   DEBUGOUT(1, "cybWriteRGBSpan(%d, %d, %d): ", n, x, y);
  96.  
  97.   if (!mask) {
  98.     DEBUGOUT(1, "nomask\n");
  99.     DEBUGOUT(2, " WritePixelArray(%d, %d, %d)\n", n, x, y);
  100.     MyWritePixelArray(rgb, 0, 0, 3 * n, rp, x, y, n, 1, RECTFMT_RGB);
  101.   }
  102.   else {                                    /* if imageline allocated then use fastversion */
  103.     GLshort i, ant = 0;
  104.     GLuint *il;
  105.  
  106.     il = (GLuint *) amesa->imageline;                        /* if imageline allocated then use fastversion */
  107.  
  108.     RGBb--;                                    /* hacky RGBA to ARGB */
  109.     for (i = 0; i < n; i++) {                            /* draw pixel (x[i],y[i]) */
  110.       if (*mask++) {
  111.     ant++;
  112.     *il++ = *iRGBi;
  113.       }
  114.       else {
  115.     if (ant) {
  116.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  117.       MyWritePixelArray(il = (GLuint *)amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  118.       x += ant;
  119.       ant = 0;
  120.     }
  121.     else
  122.       x++;
  123.       }
  124.     }
  125.  
  126.     if (ant) {
  127.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  128.       MyWritePixelArray(amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  129.     }
  130.   }
  131. }
  132.  
  133. /* TODO: convert whole code to WriteLUTPixelArray */
  134. void cybWriteCI32Span(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  135.               const GLuint index[],
  136.               const GLubyte mask[])
  137. {
  138.   amigaMesaContext amesa;
  139.   GLuint *il;
  140.   GLuint *ItoP;
  141.   struct RastPort *rp;
  142.   GLshort i, ant = 0;
  143.  
  144.   amesa = (amigaMesaContext) ctx->DriverCtx;
  145.   ItoP = amesa->ItoP;
  146.   rp = amesa->rp;
  147.   il = (GLuint *) amesa->imageline;
  148.  
  149.   y = FIXy(y);
  150.   x = FIXx(x);
  151.   DEBUGOUT(1, "cybWriteCI32Span(%d, %d, %d)\n", n, x, y);
  152.  
  153.   if (!mask)
  154.     DEBUGOUT(0, "cybWriteCI32Span: called with no mask!\n");
  155. #if 0
  156.   if (!mask) {
  157.     /* TODO: check if this work */
  158.     PENCONVb--;                                    /* hacky RGBA to XRGB */
  159.     WriteLUTPixelArray(index, 0, 0, 1 * n, rp, ItoP, x, y, n, 1, CTABFMT_XRGB8);
  160.   }
  161.   else {
  162.     GLshort s = 0;
  163.  
  164.     PENCONVb--;                                    /* hacky RGBA to XRGB */
  165.     while (s < n) {
  166.       while (!*mask++ && s < n) {
  167.     s++;
  168.     x++;
  169.       } mask--;
  170.  
  171.       if (s < n) {
  172.     j = 0;
  173.     while (*mask++ && s < n) {
  174.       s++;
  175.       j++;
  176.     } mask--;
  177.     WriteLUTPixelArray(INDEXb + x, 0, 0, 1 * j, rp, ItoP, x, y, j, 1, CTABFMT_XRGB8);
  178.     DEBUGOUT(9, "  WriteLUTPixelArray(%d, %d, %d)\n", j, x, y);
  179.       }
  180.     }
  181.   }
  182. #endif
  183.     /*
  184.      * if imageline have been
  185.      * allocated then use fastversion 
  186.      */
  187.     for (i = 0; i < n; i++) {
  188.       /* draw pixel (x[i],y[i]) using index[i] */
  189.       if (*mask++) {
  190.     ant++;
  191.     *il++ = GetRGBPLocal(*iINDEXi);
  192.       }
  193.       else {
  194.     if (ant) {
  195.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  196.       MyWritePixelArray(il = (GLuint *)amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  197.       x += ant;
  198.       ant = 0;
  199.     }
  200.     else
  201.       x++;
  202.       }
  203.     }
  204.  
  205.     if (ant) {
  206.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  207.       MyWritePixelArray(amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  208.     }
  209. }
  210.  
  211. /* TODO: convert whole code to WriteLUTPixelArray */
  212. void cybWriteCI8Span(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  213.              const GLubyte index[],
  214.              const GLubyte mask[])
  215. {
  216.   amigaMesaContext amesa;
  217.   GLuint *il;
  218.   GLuint *ItoP;
  219.   struct RastPort *rp;
  220.   GLshort i, ant = 0;
  221.  
  222.   amesa = (amigaMesaContext) ctx->DriverCtx;
  223.   ItoP = amesa->ItoP;
  224.   rp = amesa->rp;
  225.   il = (GLuint *) amesa->imageline;
  226.  
  227.   y = FIXy(y);
  228.   x = FIXx(x);
  229.   DEBUGOUT(1, "cybWriteCI8Span(%d, %d, %d)\n", n, x, y);
  230.  
  231.   if (!mask)
  232.     DEBUGOUT(0, "cybWriteCI8Span: called with no mask!\n");
  233. #if 0
  234.   if (!mask) {
  235.     /* TODO: check if this work */
  236.     PENCONVb--;                                    /* hacky RGBA to XRGB */
  237.     WriteLUTPixelArray(index, 0, 0, 1 * n, rp, ItoP, x, y, n, 1, CTABFMT_XRGB8);
  238.   }
  239.   else {
  240.     GLshort s = 0;
  241.  
  242.     PENCONVb--;                                    /* hacky RGBA to XRGB */
  243.     while (s < n) {
  244.       while (!*mask++ && s < n) {
  245.     s++;
  246.     x++;
  247.       } mask--;
  248.  
  249.       if (s < n) {
  250.     j = 0;
  251.     while (*mask++ && s < n) {
  252.       s++;
  253.       j++;
  254.     } mask--;
  255.     WriteLUTPixelArray(INDEXb + x, 0, 0, 1 * j, rp, ItoP, x, y, j, 1, CTABFMT_XRGB8);
  256.     DEBUGOUT(9, "  WriteLUTPixelArray(%d, %d, %d)\n", j, x, y);
  257.       }
  258.     }
  259.   }
  260. #endif
  261.     /*
  262.      * if imageline have been
  263.      * allocated then use fastversion 
  264.      */
  265.     for (i = 0; i < n; i++) {
  266.       /* draw pixel (x[i],y[i]) using index[i] */
  267.       if (*mask++) {
  268.     ant++;
  269.     *il++ = GetRGBPLocal(*iINDEXb);
  270.       }
  271.       else {
  272.     if (ant) {
  273.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  274.       MyWritePixelArray(il = (GLuint *)amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  275.       x += ant;
  276.       ant = 0;
  277.     }
  278.     else
  279.       x++;
  280.       }
  281.     }
  282.  
  283.     if (ant) {
  284.       MyWritePixelArray(amesa->imageline, 0, 0, 4 * ant, rp, x, y, ant, 1, RECTFMT_RGBA);
  285.       DEBUGOUT(9, "  WritePixelArray(%d, %d, %d)\n", ant, x, y);
  286.     }
  287. }
  288.  
  289. void cybWriteMonoCISpan(const GLcontext * ctx, GLuint n, GLint x, GLint y, const GLubyte mask[])
  290. {
  291.   amigaMesaContext amesa;
  292.   struct RastPort *rp;
  293.   GLshort s, j;
  294.   GLuint col;
  295.  
  296.   amesa = (amigaMesaContext) ctx->DriverCtx;
  297.   rp = amesa->rp;
  298.  
  299.   y = FIXy(y);
  300.   x = FIXx(x);
  301.   DEBUGOUT(1, "cybWriteMonoCISpan(%d, %d, %d)\n", n, x, y);
  302.  
  303.   s = 0;
  304.   col = amesa->pixel >> 8;
  305.   while (s < n) {
  306.     while (!*mask++ && s < n) {
  307.       s++;
  308.       x++;
  309.     } mask--;
  310.  
  311.     if (s < n) {
  312.       j = 0;
  313.       while (*mask++ && s < n) {
  314.     s++;
  315.     j++;
  316.       } mask--;
  317.       FillPixelArray(rp, x, y, j, 1, col);
  318.       DEBUGOUT(9, "  FillPixelArray(%d, %d, %d)\n", j, x, y);
  319.     }
  320.   }
  321. }
  322.  
  323. /**********************************************************************/
  324. /*****        write spans of RGBA pixels doublebuffered           *****/
  325. /**********************************************************************/
  326.  
  327. void cybWriteRGBASpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  328.             CONST GLubyte rgba[][4], const GLubyte mask[])
  329. {
  330.   amigaMesaContext amesa;
  331.   GLuint *db;
  332.  
  333.   amesa = (amigaMesaContext) ctx->DriverCtx;
  334.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  335.  
  336.   DEBUGOUT(1, "cybWriteRGBASpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  337.  
  338.   /* Slower */
  339.   if (mask) {
  340.     /* draw pixel (x[i],y[i]) using index[i] */
  341.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, RGBAi++)
  342.       if (*mask++)
  343.     *db = *RGBAi;
  344.   }
  345.   else
  346.     /* draw pixel (x[i],y[i]) using index[i] */
  347.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  348.       *db++ = *RGBAi++;
  349. }
  350.  
  351. void cybWriteRGBSpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  352.                CONST GLubyte rgb[][3], const GLubyte mask[])
  353. {
  354.   amigaMesaContext amesa;
  355.   GLuint *db;
  356.  
  357.   amesa = (amigaMesaContext) ctx->DriverCtx;
  358.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  359.  
  360.   DEBUGOUT(1, "cybWriteRGBSpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  361.  
  362.   /* Slower */
  363.   if (mask) {
  364.     /* draw pixel (x[i],y[i]) using index[i] */
  365.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, RGBb += 3)
  366.       if (*mask++)
  367.     *db = *RGBi;                                /* hacky RGB to RGBA */
  368.   }
  369.   else
  370.     /* draw pixel (x[i],y[i]) using index[i] */
  371.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, RGBb += 3)
  372.       *db++ = *RGBi;                                /* hacky RGB to RGBA */
  373. }
  374.  
  375. void cybWriteCI32SpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  376.             const GLuint index[],
  377.             const GLubyte mask[])
  378. {
  379.   amigaMesaContext amesa;
  380.   GLuint *db;
  381.   GLuint *ItoP;
  382.  
  383.   amesa = (amigaMesaContext) ctx->DriverCtx;
  384.   ItoP = amesa->ItoP;
  385.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  386.  
  387.   DEBUGOUT(1, "cybWriteCI32SpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  388.  
  389.   /* Slower */
  390.   if (mask) {
  391.     /* draw pixel (x[i],y[i]) using index[i] */
  392.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, INDEXi++)
  393.       if (*mask++)
  394.     *db = GetRGBPLocal(*INDEXi);
  395.   }
  396.   else
  397.     /* draw pixel (x[i],y[i]) using index[i] */
  398.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  399.       *db++ = GetRGBPLocal(*INDEXi++);
  400. }
  401.  
  402. void cybWriteCI8SpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  403.                const GLubyte index[],
  404.                const GLubyte mask[])
  405. {
  406.   amigaMesaContext amesa;
  407.   GLuint *db;
  408.   GLuint *ItoP;
  409.  
  410.   amesa = (amigaMesaContext) ctx->DriverCtx;
  411.   ItoP = amesa->ItoP;
  412.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  413.  
  414.   DEBUGOUT(1, "cybWriteCI8SpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  415.  
  416.   /* Slower */
  417.   if (mask) {
  418.     /* draw pixel (x[i],y[i]) using index[i] */
  419.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, INDEXb++)
  420.       if (*mask++)
  421.     *db = GetRGBPLocal(*INDEXb);
  422.   }
  423.   else
  424.     /* draw pixel (x[i],y[i]) using index[i] */
  425.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  426.       *db++ = GetRGBPLocal(*INDEXb++);
  427. }
  428.  
  429. void cybWriteMonoCISpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y, const GLubyte mask[])
  430. {
  431.   amigaMesaContext amesa;
  432.   GLuint *db;
  433.   GLuint col;
  434.  
  435.   amesa = (amigaMesaContext) ctx->DriverCtx;
  436.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  437.  
  438.   DEBUGOUT(1, "cybWriteMonoCISpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  439.  
  440.   col = amesa->pixel;
  441.   /* Slower */
  442.   if (mask) {
  443.     /* draw pixel (x[i],y[i]) using index[i] */
  444.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++)
  445.       if (*mask++)
  446.     *db = col;
  447.   }
  448.   else
  449.     /* draw pixel (x[i],y[i]) using index[i] */
  450.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  451.       *db++ = col;
  452. }
  453.  
  454. /**********************************************************************/
  455. /*****        read spans of RGBA pixels                           *****/
  456. /**********************************************************************/
  457. /* Here we should check if the size of the colortable is <256 */
  458.  
  459. void cybReadRGBASpan(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  460.              GLubyte rgba[][4])
  461. {
  462.   amigaMesaContext amesa;
  463.  
  464.   amesa = (amigaMesaContext) ctx->DriverCtx;
  465.  
  466.   y = FIXy(y);
  467.   x = FIXx(x);
  468.   DEBUGOUT(1, "cybReadRGBASpan(%d, %d, %d)\n", n, x, y);
  469.  
  470.   DEBUGOUT(2, " ReadPixelArray(%d, %d, %d)\n", n, x, y);
  471.   MyReadPixelArray(rgba, 0, 0, n * 4, amesa->rp, x, y, n, 1, RECTFMT_RGBA);
  472. }
  473.  
  474. /**********************************************************************/
  475. /*****        read spans of RGBA pixels doublebuffered            *****/
  476. /**********************************************************************/
  477.  
  478. void cybReadRGBASpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  479.                GLubyte rgba[][4])
  480. {
  481.   amigaMesaContext amesa;
  482.   GLuint *db;
  483.  
  484.   amesa = (amigaMesaContext) ctx->DriverCtx;
  485.   db = dbRGBA(dbRGBAGet(amesa), x, y);
  486.  
  487.   DEBUGOUT(1, "cybReadRGBASpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  488.  
  489.   for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  490.     *RGBAi++ = *db++;
  491. }
  492.