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 / natDisplay / natSpans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-12  |  8.8 KB  |  322 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 "natSpans8.c"
  26. #include "natSpansD.c"
  27. #include "natSpansG.c"
  28.  
  29. /**********************************************************************/
  30. /*****        write spans of RGBA pixels                          *****/
  31. /**********************************************************************/
  32.  
  33. void natWriteCI32Span(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  34.               const GLuint index[],
  35.               const GLubyte mask[])
  36. {
  37.   amigaMesaContext amesa;
  38.   GLubyte *il;
  39.   GLuint *ItoP;
  40.   struct RastPort *rp;
  41.   GLshort i, ant = 0;                                /*  allocated then use fastversion  */
  42.  
  43.   amesa = (amigaMesaContext) ctx->DriverCtx;
  44.   ItoP = amesa->ItoP;
  45.   rp = amesa->rp;
  46.   il = amesa->imageline;                            /*  if imageline and temporary rastport have been */
  47.  
  48.   y = FIXy(y);
  49.   x = FIXx(x);
  50.   DEBUGOUT(1, "natWriteCI32Span(%d, %d, %d):\n", n, x, y);
  51.  
  52.   for (i = 0; i < n; i++) {                            /*  draw pixel (x[i],y[i]) using index[i]  */
  53.     if (*mask++) {
  54.       ant++;
  55.       *il++ = GetRGBPLocal(*iINDEXi);
  56.     }
  57.     else {
  58.       if (ant) {
  59.     DEBUGOUT(9, "  MyWritePixelLine8(%d, %d, %d)\n", ant, x, y);
  60.     MyWritePixelLine8(rp, x, y, ant, il = amesa->imageline, amesa->temprp);
  61.     x += ant;
  62.     ant = 0;
  63.       }
  64.       else
  65.     x++;
  66.     }
  67.   }
  68.  
  69.   if (ant) {
  70.     DEBUGOUT(9, "  MyWritePixelLine8(%d, %d, %d)\n", ant, x, y);
  71.     MyWritePixelLine8(rp, x, y, ant, amesa->imageline, amesa->temprp);
  72.   }
  73. }
  74.  
  75. void natWriteCI8Span(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  76.              const GLubyte index[],
  77.              const GLubyte mask[])
  78. {
  79.   amigaMesaContext amesa;
  80.   GLubyte *il;
  81.   GLuint *ItoP;
  82.   struct RastPort *rp;
  83.   GLshort ant = 0, i;                                /*  allocated then use fastversion  */
  84.  
  85.   amesa = (amigaMesaContext) ctx->DriverCtx;
  86.   ItoP = amesa->ItoP;
  87.   rp = amesa->rp;
  88.   il = amesa->imageline;                            /*  if imageline and temporary rastport have been */
  89.  
  90.   y = FIXy(y);
  91.   x = FIXx(x);
  92.   DEBUGOUT(1, "natWriteCI8Span(%d, %d, %d): ", n, x, y);
  93.  
  94.   for (i = 0; i < n; i++) {                            /*  draw pixel (x[i],y[i]) using index[i]  */
  95.     if (*mask++) {
  96.       ant++;
  97.       *il++ = GetRGBPLocal(*iINDEXb);
  98.     }
  99.     else {
  100.       if (ant) {
  101.     DEBUGOUT(9, "  MyWritePixelLine8(%d, %d, %d)\n", n, x, y);
  102.     MyWritePixelLine8(rp, x, y, ant, il = amesa->imageline, amesa->temprp);
  103.     x += ant;
  104.     ant = 0;
  105.       }
  106.       else
  107.     x++;
  108.     }
  109.   }
  110.  
  111.   if (ant) {
  112.     DEBUGOUT(9, "  MyWritePixelLine8(%d, %d, %d)\n", n, x, y);
  113.     MyWritePixelLine8(rp, x, y, ant, amesa->imageline, amesa->temprp);
  114.   }
  115. }
  116.  
  117. void natWriteMonoCISpan(const GLcontext * ctx, GLuint n, GLint x, GLint y, const GLubyte mask[])
  118. {
  119.   amigaMesaContext amesa;
  120.   struct RastPort *rp;
  121.   GLshort s;
  122.  
  123.   amesa = (amigaMesaContext) ctx->DriverCtx;
  124.   rp = amesa->rp;
  125.  
  126.   y = FIXy(y);
  127.   x = FIXx(x);
  128.   DEBUGOUT(1, "natWriteMonoCISpan(%d, %d, %d): \n", n, x, y);
  129.  
  130.   s = 0;
  131.   SetAPen(rp, amesa->pixel);
  132.   while (s < n) {
  133.     while (!*mask++ && s < n) {
  134.       s++;
  135.       x++;
  136.     } mask--;
  137.  
  138.     if (s < n) {
  139.       DEBUGOUT(9, "  Move(%d, %d)\n", x, y);
  140.       Move(rp, x, y);
  141.       while (*mask++ && s < n) {
  142.     s++;
  143.     x++;
  144.       } mask--;
  145.       DEBUGOUT(9, "  Draw(%d, %d)\n", x - 1, y);
  146.       Draw(rp, x - 1, y);
  147.     }
  148.   }
  149. }
  150.  
  151. /**********************************************************************/
  152. /*****        write spans of RGBA pixels doublebuffered           *****/
  153. /**********************************************************************/
  154.  
  155. void natWriteCI32SpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  156.             const GLuint index[],
  157.             const GLubyte mask[])
  158. {
  159.   amigaMesaContext amesa;
  160.   GLubyte *db;
  161.   GLuint *ItoP;
  162.  
  163.   amesa = (amigaMesaContext) ctx->DriverCtx;
  164.   db = dbPen(dbPenGet(amesa), x, y);
  165.   ItoP = amesa->ItoP;
  166.  
  167.   DEBUGOUT(1, "natWriteCI32SpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  168.  
  169.   if (!mask) {
  170.     /* draw pixel (x[i],y[i]) using index[i] */
  171.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  172.       *db++ = GetRGBPLocal(*INDEXi++);
  173.   }
  174.   else
  175.     /* draw pixel (x[i],y[i]) using index[i] */
  176.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, INDEXi++)        /* Slower */
  177.       if (*mask++)
  178.     *db = GetRGBPLocal(*INDEXi);
  179. }
  180.  
  181. void natWriteCI8SpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  182.                const GLubyte index[],
  183.                const GLubyte mask[])
  184. {
  185.  
  186.   amigaMesaContext amesa;
  187.   GLubyte *db;
  188.   GLuint *ItoP;
  189.  
  190.   amesa = (amigaMesaContext) ctx->DriverCtx;
  191.   db = dbPen(dbPenGet(amesa), x, y);
  192.   ItoP = amesa->ItoP;
  193.  
  194.   DEBUGOUT(1, "natWriteCI8SpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  195.  
  196.   if (!mask) {
  197.     /* draw pixel (x[i],y[i]) using index[i] */
  198.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  199.       *db++ = GetRGBPLocal(*INDEXb++);
  200.   }
  201.   else
  202.     /* draw pixel (x[i],y[i]) using index[i] */
  203.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++, INDEXb++)        /* Slower */
  204.       if (*mask++)
  205.     *db = GetRGBPLocal(*INDEXb);
  206. }
  207.  
  208. void natWriteMonoCISpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  209.               const GLubyte mask[])
  210. {
  211.   amigaMesaContext amesa;
  212.   GLubyte *db;
  213.   GLubyte col;
  214.  
  215.   amesa = (amigaMesaContext) ctx->DriverCtx;
  216.   db = dbPen(dbPenGet(amesa), x, y);
  217.  
  218.   DEBUGOUT(1, "natWriteMonoCISpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  219.  
  220.   col = amesa->pixel;
  221.   if (!mask) {
  222.     /* draw pixel (x[i],y[i]) using index[i] */
  223.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)                /* Slower */
  224.       *db++ = col;
  225.   }
  226.   else
  227.     /* draw pixel (x[i],y[i]) using index[i] */
  228.     for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--, db++)
  229.       if (*mask++)
  230.     *db = col;
  231. }
  232.  
  233. /**********************************************************************/
  234. /*****        read spans of RGBA pixels doublebuffered            *****/
  235. /**********************************************************************/
  236.  
  237. void natReadRGBASpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  238.                GLubyte rgba[][4])
  239. {
  240.   /* TODO: samples-old/accum have problems with something, maybe this (check it) */
  241. #if 0
  242.   amigaMesaContext amesa;
  243.   GLubyte *db;
  244.   GLuint *PtoI;
  245.  
  246.   amesa = (amigaMesaContext) ctx->DriverCtx;
  247.   db = dbPen(dbPenGet(amesa), x, y);
  248.   PtoI = amesa->PtoI;
  249.  
  250.   DEBUGOUT(1, "natReadRGBASpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  251.  
  252.   for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  253.     *RGBAi++ = GetIndexLocal(*db++) & 0xFFFFFF00;                /* clear alpha? */
  254. #endif
  255. }
  256.  
  257. void natReadCI32SpanDB(const GLcontext * ctx, GLuint n, GLint x, GLint y, GLuint index[])
  258. {
  259.   amigaMesaContext amesa;
  260.   GLubyte *db;
  261.   GLuint *PtoI;
  262.  
  263.   amesa = (amigaMesaContext) ctx->DriverCtx;
  264.   db = dbPen(dbPenGet(amesa), x, y);
  265.   PtoI = amesa->PtoI;
  266.  
  267.   DEBUGOUT(1, "natReadCI32SpanDB(%d, %d, %d)\n", n, FIXx(x), FIXy(y));
  268.  
  269.   for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  270.     *INDEXi++ = GetIndexLocal(*db++) & 0x000000FF;                /* clear rgb! */
  271. }
  272.  
  273. /**********************************************************************/
  274. /*****        read spans of RGBA pixels                           *****/
  275. /**********************************************************************/
  276.  
  277. void natReadCI32Span(const GLcontext * ctx, GLuint n, GLint x, GLint y, GLuint index[])
  278. {
  279.   amigaMesaContext amesa;
  280.   struct RastPort *rp;
  281.   GLubyte *il;
  282.   GLuint *PtoI;
  283.  
  284.   amesa = (amigaMesaContext) ctx->DriverCtx;
  285.   PtoI = amesa->PtoI;
  286.   rp = amesa->rp;
  287.   il = amesa->imageline;
  288.  
  289.   y = FIXy(y);
  290.   x = FIXx(x);
  291.   DEBUGOUT(1, "natReadCI32Span(%d, %d, %d)\n", n, x, y);
  292.  
  293.   DEBUGOUT(8, "  MyReadPixelLine8(%d, %d, %d)\n", n, x, y);
  294.   MyReadPixelLine8(rp, x, y, n, il, amesa->temprp);
  295.   for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  296.     *INDEXi++ = GetIndexLocal(*il++) & 0x000000FF;                /* clear rgb! */
  297. }
  298.  
  299. void natReadRGBASpan(const GLcontext * ctx, GLuint n, GLint x, GLint y,
  300.              GLubyte rgba[][4])
  301. {
  302.   amigaMesaContext amesa;
  303.   struct RastPort *rp;
  304.   GLubyte *il;
  305.   GLuint *PtoI;
  306.  
  307.   amesa = (amigaMesaContext) ctx->DriverCtx;
  308.   PtoI = amesa->PtoI;
  309.   rp = amesa->rp;
  310.   il = amesa->imageline;
  311.  
  312.   y = FIXy(y);
  313.   x = FIXx(x);
  314.   DEBUGOUT(1, "natReadRGBASpan(%d, %d, %d)\n", n, x, y);
  315.  
  316.   /* bug in egcs (spilled register) */
  317.   DEBUGOUT(8, "  MyReadPixelLine8(%d, %d, %d)\n", n, x, y);
  318.   MyReadPixelLine8(rp, x, y, n, il, amesa->temprp);
  319.   for (--(GLshort)n; (GLshort)n >= 0; (GLshort)n--)
  320.     *RGBAi++ = GetIndexLocal(*il++) & 0xFFFFFF00;                /* clear alpha? */
  321. }
  322.