home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / mmesai.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  20.9 KB  |  290 lines

  1. /****************************************************************************
  2. *
  3. *                      Mesa bindings for SciTech MGL
  4. *
  5. *                   Copyright (C) 1996 SciTech Software.
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $Workfile:   mmesai.c  $
  9. * Version:      $Revision:   1.1  $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  Any
  13. *
  14. * Description:  Include file defining macros to implement many of the
  15. *               optimized rendering functions for the MGL Mesa driver.
  16. *
  17. * This library is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU Library General Public
  19. * License as published by the Free Software Foundation; either
  20. * version 2 of the License, or (at your option) any later version.
  21. *
  22. * This library is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  25. * Library General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Library General Public
  28. * License along with this library; if not, write to the Free
  29. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. * $Date:   06 Apr 1997 14:40:00  $ $Author:   KendallB  $
  32. *
  33. ****************************************************************************/
  34.  
  35. /**********************************************************************/
  36. /*****            Write spans of pixels                           *****/
  37. /**********************************************************************/
  38.  
  39. #define IMPLEMENT_WRITE_SPAN(DEPTH,FMT,TYPE)                                \
  40. void _mmesa_write_span_##DEPTH##_##FMT (GLcontext *ctx,GLuint n, GLint x,   \
  41.     GLint y,GLubyte red[], GLubyte green[],GLubyte blue[],GLubyte alpha[],  \
  42.     GLubyte mask[])                                                         \
  43. {                                                                           \
  44.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                         \
  45.     if (mask) {                                                             \
  46.         while (n >= 8) {                                                    \
  47.             if (mask[0]) d[0] = PACK_COLOR_##FMT(red[0],green[0],blue[0]);  \
  48.             if (mask[1]) d[1] = PACK_COLOR_##FMT(red[1],green[1],blue[1]);  \
  49.             if (mask[2]) d[2] = PACK_COLOR_##FMT(red[2],green[2],blue[2]);  \
  50.             if (mask[3]) d[3] = PACK_COLOR_##FMT(red[3],green[3],blue[3]);  \
  51.             if (mask[4]) d[4] = PACK_COLOR_##FMT(red[4],green[4],blue[4]);  \
  52.             if (mask[5]) d[5] = PACK_COLOR_##FMT(red[5],green[5],blue[5]);  \
  53.             if (mask[6]) d[6] = PACK_COLOR_##FMT(red[6],green[6],blue[6]);  \
  54.             if (mask[7]) d[7] = PACK_COLOR_##FMT(red[7],green[7],blue[7]);  \
  55.             d += 8; red += 8; green += 8; blue += 8; mask += 8; n -= 8;     \
  56.             }                                                               \
  57.         while (n--) {                                                       \
  58.             if (mask[0]) d[0] = PACK_COLOR_##FMT(red[0],green[0],blue[0]);  \
  59.             d++; red++; green++; blue++; mask++;                            \
  60.             }                                                               \
  61.         }                                                                   \
  62.     else {                                                                  \
  63.         while (n >= 8) {                                                    \
  64.             d[0] = PACK_COLOR_##FMT(red[0],green[0],blue[0]);               \
  65.             d[1] = PACK_COLOR_##FMT(red[1],green[1],blue[1]);               \
  66.             d[2] = PACK_COLOR_##FMT(red[2],green[2],blue[2]);               \
  67.             d[3] = PACK_COLOR_##FMT(red[3],green[3],blue[3]);               \
  68.             d[4] = PACK_COLOR_##FMT(red[4],green[4],blue[4]);               \
  69.             d[5] = PACK_COLOR_##FMT(red[5],green[5],blue[5]);               \
  70.             d[6] = PACK_COLOR_##FMT(red[6],green[6],blue[6]);               \
  71.             d[7] = PACK_COLOR_##FMT(red[7],green[7],blue[7]);               \
  72.             d += 8; red += 8; green += 8; blue += 8; n -= 8;                \
  73.             }                                                               \
  74.         while (n--) {                                                       \
  75.             d[0] = PACK_COLOR_##FMT(red[0],green[0],blue[0]);               \
  76.             d++; red++; green++; blue++;                                    \
  77.             }                                                               \
  78.         }                                                                   \
  79. }
  80.  
  81. #define IMPLEMENT_WRITE_SPAN_DITHER(DEPTH,FMT,TYPE)                                 \
  82. void _mmesa_write_span_##DEPTH##_##FMT(GLcontext *ctx,GLuint n, GLint x,            \
  83.     GLint y,GLubyte red[], GLubyte green[],GLubyte blue[],GLubyte alpha[],          \
  84.     GLubyte mask[])                                                                 \
  85. {                                                                                   \
  86.     TYPE *d;                                                                        \
  87.     y = FLIP(y);                                                                    \
  88.     d = PACKED##DEPTH##_pixelAddr(x,y);                                             \
  89.     if (mask) {                                                                     \
  90.         while (n >= 4) {                                                            \
  91.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,red[0],green[0],blue[0]);        \
  92.             if (mask[1]) PACK_COLOR_##FMT(d[1],x+1,y,red[1],green[1],blue[1]);      \
  93.             if (mask[2]) PACK_COLOR_##FMT(d[2],x+2,y,red[2],green[2],blue[2]);      \
  94.             if (mask[3]) PACK_COLOR_##FMT(d[3],x+3,y,red[3],green[3],blue[3]);      \
  95.             d += 4; red += 4; green += 4; blue += 4; mask += 4; x += 4; n -= 4;     \
  96.             }                                                                       \
  97.         while (n--) {                                                               \
  98.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,red[0],green[0],blue[0]);        \
  99.             d++; red++; green++; blue++; mask++; x++;                               \
  100.             }                                                                       \
  101.         }                                                                           \
  102.     else {                                                                          \
  103.         while (n >= 4) {                                                            \
  104.             PACK_COLOR_##FMT(d[0],x,y,red[0],green[0],blue[0]);                     \
  105.             PACK_COLOR_##FMT(d[1],x+1,y,red[1],green[1],blue[1]);                   \
  106.             PACK_COLOR_##FMT(d[2],x+2,y,red[2],green[2],blue[2]);                   \
  107.             PACK_COLOR_##FMT(d[3],x+3,y,red[3],green[3],blue[3]);                   \
  108.             d += 4; red += 4; green += 4; blue += 4; x += 4; n -= 4;                \
  109.             }                                                                       \
  110.         while (n--) {                                                               \
  111.             PACK_COLOR_##FMT(d[0],x,y,red[0],green[0],blue[0]);                     \
  112.             d++; red++; green++; blue++; x++;                                       \
  113.             }                                                                       \
  114.         }                                                                           \
  115. }
  116.  
  117. #define IMPLEMENT_WRITE_SPAN_MONO(DEPTH,TYPE)                               \
  118. void _mmesa_write_span_mono_##DEPTH (GLcontext *ctx,GLuint n,GLint x,       \
  119.     GLint y,GLubyte mask[])                                                 \
  120. {                                                                           \
  121.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                         \
  122.     while (n >= 8) {                                                        \
  123.         if (mask[0]) d[0] = (TYPE)RC.color;                                 \
  124.         if (mask[1]) d[1] = (TYPE)RC.color;                                 \
  125.         if (mask[2]) d[2] = (TYPE)RC.color;                                 \
  126.         if (mask[3]) d[3] = (TYPE)RC.color;                                 \
  127.         if (mask[4]) d[4] = (TYPE)RC.color;                                 \
  128.         if (mask[5]) d[5] = (TYPE)RC.color;                                 \
  129.         if (mask[6]) d[6] = (TYPE)RC.color;                                 \
  130.         if (mask[7]) d[7] = (TYPE)RC.color;                                 \
  131.         d += 8; mask += 8; n -= 8;                                          \
  132.         }                                                                   \
  133.     while (n--) {                                                           \
  134.         if (mask[0]) d[0] = (TYPE)RC.color;                                 \
  135.         d++; mask++;                                                        \
  136.         }                                                                   \
  137. }
  138.  
  139. #define IMPLEMENT_WRITE_SPAN_MONO_DITHER(DEPTH,FMT,TYPE)                        \
  140. void _mmesa_write_span_mono_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,   \
  141.     GLint y,GLubyte mask[])                                                     \
  142. {                                                                               \
  143.     HALFTONE_VARS_##DEPTH;                                                      \
  144.     TYPE *d;                                                                    \
  145.     y = FLIP(y);                                                                \
  146.     d = PACKED##DEPTH##_pixelAddr(x,y);                                         \
  147.     SETUP_##FMT(y,RC.red,RC.green,RC.blue);                                     \
  148.     while (n >= 4) {                                                            \
  149.         if (mask[0]) PACK_COLOR2_##FMT(d[0],x);                                 \
  150.         if (mask[1]) PACK_COLOR2_##FMT(d[1],x+1);                               \
  151.         if (mask[2]) PACK_COLOR2_##FMT(d[2],x+2);                               \
  152.         if (mask[3]) PACK_COLOR2_##FMT(d[3],x+3);                               \
  153.         d += 4; mask += 4; x += 4; n -= 4;                                      \
  154.         }                                                                       \
  155.     while (n--) {                                                               \
  156.         if (mask[0]) PACK_COLOR2_##FMT(d[0],x);                                 \
  157.         d++; mask++; x++;                                                       \
  158.         }                                                                       \
  159. }
  160.  
  161. /**********************************************************************/
  162. /*****              Write arrays of pixels                        *****/
  163. /**********************************************************************/
  164.  
  165. #define IMPLEMENT_WRITE_PIXELS(DEPTH,FMT,TYPE)                                                                  \
  166. void _mmesa_write_pixels_##DEPTH##_##FMT (GLcontext *ctx,GLuint n, GLint x[],                                   \
  167.     GLint y[],GLubyte r[], GLubyte g[],GLubyte b[],                                                             \
  168.     GLubyte a[],GLubyte mask[])                                                                                 \
  169. {                                                                                                               \
  170.     while (n >= 4) {                                                                                            \
  171.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = PACK_COLOR_##FMT(r[0],g[0],b[0]);   \
  172.         if (mask[1]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]))) = PACK_COLOR_##FMT(r[1],g[1],b[1]);   \
  173.         if (mask[2]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]))) = PACK_COLOR_##FMT(r[2],g[2],b[2]);   \
  174.         if (mask[3]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]))) = PACK_COLOR_##FMT(r[3],g[3],b[3]);   \
  175.         r += 4; g += 4; b += 4; mask += 4; x+= 4; y += 4; n -= 4;                                               \
  176.         }                                                                                                       \
  177.     while (n--) {                                                                                               \
  178.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = PACK_COLOR_##FMT(r[0],g[0],b[0]);   \
  179.         r++; g++; b++; mask++; x++; y++;                                                                        \
  180.         }                                                                                                       \
  181. }                                                                                                               
  182.  
  183. #define IMPLEMENT_WRITE_PIXELS_DITHER(DEPTH,FMT,TYPE)                           \
  184. void _mmesa_write_pixels_##DEPTH##_##FMT(GLcontext *ctx,GLuint n, GLint x[],    \
  185.     GLint y[],GLubyte r[], GLubyte g[],GLubyte b[],                             \
  186.     GLubyte a[],GLubyte mask[])                                                 \
  187. {                                                                               \
  188.     while (n--) {                                                               \
  189.         if (mask[0]) {                                                          \
  190.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  191.             PACK_COLOR_##FMT(d[0],x[0],FLIP(y[0]),r[0],g[0],b[0]);              \
  192.             }                                                                   \
  193.         r++; g++; b++; mask++; x++; y++;                                        \
  194.         }                                                                       \
  195. }                                                                               
  196.  
  197. #define IMPLEMENT_WRITE_PIXELS_MONO(DEPTH,TYPE)                                             \
  198. void _mmesa_write_pixels_mono_##DEPTH (GLcontext *ctx,GLuint n,GLint x[],                   \
  199.     GLint y[],GLubyte mask[])                                                               \
  200. {                                                                                           \
  201.     while (n >= 4) {                                                                        \
  202.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = (TYPE)RC.color; \
  203.         if (mask[1]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]))) = (TYPE)RC.color; \
  204.         if (mask[2]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]))) = (TYPE)RC.color; \
  205.         if (mask[3]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]))) = (TYPE)RC.color; \
  206.         mask += 4; x+= 4; y += 4; n -= 4;                                                   \
  207.         }                                                                                   \
  208.     while (n--) {                                                                           \
  209.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = (TYPE)RC.color; \
  210.         mask++; x++; y++;                                                                   \
  211.         }                                                                                   \
  212. }
  213.  
  214. #define IMPLEMENT_WRITE_PIXELS_MONO_DITHER(DEPTH,FMT,TYPE)                          \
  215. void _mmesa_write_pixels_mono_##DEPTH##_##FMT(GLcontext *ctx,GLuint n,GLint x[],    \
  216.     GLint y[],GLubyte mask[])                                                       \
  217. {                                                                                   \
  218.     while (n--) {                                                                   \
  219.         if (mask[0]) {                                                              \
  220.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));                   \
  221.             PACK_COLOR_##FMT(d[0],x[0],FLIP(y[0]),RC.red,RC.green,RC.blue);         \
  222.             }                                                                       \
  223.         mask++; x++; y++;                                                           \
  224.         }                                                                           \
  225. }
  226.  
  227. /**********************************************************************/
  228. /*****                 Read spans of pixels                       *****/
  229. /**********************************************************************/
  230.  
  231. #define IMPLEMENT_READ_SPAN(DEPTH,FMT,TYPE)                                         \
  232. void _mmesa_read_span_##DEPTH##_##FMT(GLcontext *ctx,GLuint n, GLint x, GLint y,    \
  233.     GLubyte red[], GLubyte green[],GLubyte blue[], GLubyte alpha[])                 \
  234. {                                                                                   \
  235.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                                 \
  236.     while (n >= 8) {                                                                \
  237.         UNPACK_COLOR_##FMT(d[0],red[0],green[0],blue[0]);                           \
  238.         UNPACK_COLOR_##FMT(d[1],red[1],green[1],blue[1]);                           \
  239.         UNPACK_COLOR_##FMT(d[2],red[2],green[2],blue[2]);                           \
  240.         UNPACK_COLOR_##FMT(d[3],red[3],green[3],blue[3]);                           \
  241.         UNPACK_COLOR_##FMT(d[4],red[4],green[4],blue[4]);                           \
  242.         UNPACK_COLOR_##FMT(d[5],red[5],green[5],blue[5]);                           \
  243.         UNPACK_COLOR_##FMT(d[6],red[6],green[6],blue[6]);                           \
  244.         UNPACK_COLOR_##FMT(d[7],red[7],green[7],blue[7]);                           \
  245.         d += 8; red += 8; green += 8; blue += 8; n -= 8;                            \
  246.         }                                                                           \
  247.     while (n--) {                                                                   \
  248.         UNPACK_COLOR_##FMT(d[0],red[0],green[0],blue[0]);                           \
  249.         d++; red++; green++; blue++;                                                \
  250.         }                                                                           \
  251. }
  252.  
  253. /**********************************************************************/
  254. /*****                   Read arrays of pixels                    *****/
  255. /**********************************************************************/
  256.  
  257. #define IMPLEMENT_READ_PIXELS(DEPTH,FMT,TYPE)                                   \
  258. void _mmesa_read_pixels_##DEPTH##_##FMT (GLcontext *ctx,GLuint n, GLint x[],    \
  259.     GLint y[],GLubyte red[], GLubyte green[],GLubyte blue[],                    \
  260.     GLubyte alpha[],GLubyte mask[])                                             \
  261. {                                                                               \
  262.     while (n >= 4) {                                                            \
  263.         if (mask[0]) {                                                          \
  264.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  265.             UNPACK_COLOR_##FMT(d[0],red[0],green[0],blue[0]);                   \
  266.             }                                                                   \
  267.         if (mask[1]) {                                                          \
  268.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]));               \
  269.             UNPACK_COLOR_##FMT(d[1],red[1],green[1],blue[1]);                   \
  270.             }                                                                   \
  271.         if (mask[2]) {                                                          \
  272.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]));               \
  273.             UNPACK_COLOR_##FMT(d[2],red[2],green[2],blue[2]);                   \
  274.             }                                                                   \
  275.         if (mask[3]) {                                                          \
  276.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]));               \
  277.             UNPACK_COLOR_##FMT(d[3],red[3],green[3],blue[3]);                   \
  278.             }                                                                   \
  279.         red += 4; green += 4; blue += 4; mask += 4; x += 4; y += 4; n -= 4;     \
  280.         }                                                                       \
  281.     while (n--) {                                                               \
  282.         if (mask[0]) {                                                          \
  283.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  284.             UNPACK_COLOR_##FMT(d[0],red[0],green[0],blue[0]);                   \
  285.             }                                                                   \
  286.         red++; green++; blue++; mask++; x++; y++;                               \
  287.         }                                                                       \
  288. }
  289.  
  290.