home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesa5.zip / mesa5src.zip / swrast / s_spantemp.h < prev    next >
Text File  |  2002-11-28  |  10KB  |  365 lines

  1. /* $Id: s_spantemp.h,v 1.2 2002/11/28 15:56:06 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  5.1
  6.  *
  7.  * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
  8.  *
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  *
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  *
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * Templates for the span/pixel-array write/read functions called via
  30.  * swrast.  This is intended for memory-based framebuffers (like OSMesa).
  31.  *
  32.  * Define the following macros before including this file:
  33.  *   NAME(PREFIX)  to generate the function name
  34.  *   SPAN_VARS  to declare any local variables
  35.  *   INIT_PIXEL_PTR(P, X, Y)  to initialize a pointer to a pixel
  36.  *   INC_PIXEL_PTR(P)  to increment a pixel pointer by one pixel
  37.  *   STORE_RGB_PIXEL(P, R, G, B)  to store RGB values in  pixel P
  38.  *   STORE_RGBA_PIXEL(P, R, G, B, A)  to store RGBA values in pixel P
  39.  *   FETCH_RGBA_PIXEL(R, G, B, A, P)  to fetch RGBA values from pixel P
  40.  * For color index mode:
  41.  *   STORE_CI_PIXEL(P, CI)  to store a color index in pixel P
  42.  *   FETCH_CI_PIXEL(CI, P)  to fetch a pixel index from pixel P
  43.  */
  44.  
  45.  
  46. #ifdef STORE_RGBA_PIXEL
  47.  
  48. static void
  49. NAME(write_rgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  50.                        CONST GLchan rgba[][4], const GLubyte mask[] )
  51. {
  52. #ifdef SPAN_VARS
  53.    SPAN_VARS
  54. #endif
  55.    GLuint i;
  56.    INIT_PIXEL_PTR(pixel, x, y);
  57.    if (mask) {
  58.       for (i = 0; i < n; i++) {
  59.          if (mask[i]) {
  60.             STORE_RGBA_PIXEL(pixel, rgba[i][RCOMP], rgba[i][GCOMP],
  61.                              rgba[i][BCOMP], rgba[i][ACOMP]);
  62.          }
  63.          INC_PIXEL_PTR(pixel);
  64.       }
  65.    }
  66.    else {
  67.       for (i = 0; i < n; i++) {
  68.          STORE_RGBA_PIXEL(pixel, rgba[i][RCOMP], rgba[i][GCOMP],
  69.                           rgba[i][BCOMP], rgba[i][ACOMP]);
  70.          INC_PIXEL_PTR(pixel);
  71.       }
  72.    }
  73. }
  74.  
  75. static void
  76. NAME(write_rgb_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  77.                       CONST GLchan rgb[][3], const GLubyte mask[] )
  78. {
  79. #ifdef SPAN_VARS
  80.    SPAN_VARS
  81. #endif
  82.    GLuint i;
  83.    INIT_PIXEL_PTR(pixel, x, y);
  84.    if (mask) {
  85.       for (i = 0; i < n; i++) {
  86.          if (mask[i]) {
  87.             STORE_RGB_PIXEL(pixel, rgb[i][RCOMP], rgb[i][GCOMP],
  88.                             rgb[i][BCOMP]);
  89.          }
  90.          INC_PIXEL_PTR(pixel);
  91.       }
  92.    }
  93.    else {
  94.       for (i = 0; i < n; i++) {
  95.          STORE_RGB_PIXEL(pixel, rgb[i][RCOMP], rgb[i][GCOMP],
  96.                          rgb[i][BCOMP]);
  97.          INC_PIXEL_PTR(pixel);
  98.       }
  99.    }
  100. }
  101.  
  102. static void
  103. NAME(write_monorgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  104.                            const GLchan color[4], const GLubyte mask[] )
  105. {
  106. #ifdef SPAN_VARS
  107.    SPAN_VARS
  108. #endif
  109.    GLuint i;
  110.    INIT_PIXEL_PTR(pixel, x, y);
  111.    if (mask) {
  112.       for (i = 0; i < n; i++) {
  113.          if (mask[i]) {
  114.             STORE_RGBA_PIXEL(pixel, color[RCOMP], color[GCOMP],
  115.                              color[BCOMP], color[ACOMP]);
  116.          }
  117.          INC_PIXEL_PTR(pixel);
  118.       }
  119.    }
  120.    else {
  121.       for (i = 0; i < n; i++) {
  122.          STORE_RGBA_PIXEL(pixel, color[RCOMP], color[GCOMP],
  123.                           color[BCOMP], color[ACOMP]);
  124.          INC_PIXEL_PTR(pixel);
  125.       }
  126.    }
  127. }
  128.  
  129. static void
  130. NAME(write_rgba_pixels)( const GLcontext *ctx, GLuint n,
  131.                          const GLint x[], const GLint y[],
  132.                          CONST GLchan rgba[][4], const GLubyte mask[] )
  133. {
  134. #ifdef SPAN_VARS
  135.    SPAN_VARS
  136. #endif
  137.    GLuint i;
  138.    ASSERT(mask);
  139.    for (i = 0; i < n; i++) {
  140.       if (mask[i]) {
  141.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  142.          STORE_RGBA_PIXEL(pixel, rgba[i][RCOMP], rgba[i][GCOMP],
  143.                           rgba[i][BCOMP], rgba[i][ACOMP]);
  144.       }
  145.    }
  146. }
  147.  
  148. static void
  149. NAME(write_monorgba_pixels)( const GLcontext *ctx,
  150.                              GLuint n, const GLint x[], const GLint y[],
  151.                              const GLchan color[4], const GLubyte mask[] )
  152. {
  153. #ifdef SPAN_VARS
  154.    SPAN_VARS
  155. #endif
  156.    GLuint i;
  157.    ASSERT(mask);
  158.    for (i = 0; i < n; i++) {
  159.       if (mask[i]) {
  160.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  161.          STORE_RGBA_PIXEL(pixel, color[RCOMP], color[GCOMP],
  162.                           color[BCOMP], color[ACOMP]);
  163.       }
  164.    }
  165. }
  166.  
  167. static void
  168. NAME(read_rgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  169.                       GLchan rgba[][4] )
  170. {
  171. #ifdef SPAN_VARS
  172.    SPAN_VARS
  173. #endif
  174.    GLuint i;
  175.    INIT_PIXEL_PTR(pixel, x, y);
  176.    for (i = 0; i < n; i++) {
  177.       FETCH_RGBA_PIXEL(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP],
  178.                        rgba[i][ACOMP], pixel);
  179.       INC_PIXEL_PTR(pixel);
  180.    }
  181. }
  182.  
  183. static void
  184. NAME(read_rgba_pixels)( const GLcontext *ctx,
  185.                         GLuint n, const GLint x[], const GLint y[],
  186.                         GLchan rgba[][4], const GLubyte mask[] )
  187. {
  188. #ifdef SPAN_VARS
  189.    SPAN_VARS
  190. #endif
  191.    GLuint i;
  192.    for (i = 0; i < n; i++) {
  193.       if (mask[i]) {
  194.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  195.          FETCH_RGBA_PIXEL(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP],
  196.                           rgba[i][ACOMP], pixel);
  197.       }
  198.    }
  199. }
  200.  
  201.  
  202. #endif /* STORE_RGBA_PIXEL */
  203.  
  204.  
  205.  
  206. #ifdef STORE_CI_PIXEL
  207.  
  208. static void
  209. NAME(write_index32_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  210.                           const GLuint index[], const GLubyte mask[] )
  211. {
  212. #ifdef SPAN_VARS
  213.    SPAN_VARS
  214. #endif
  215.    GLuint i;
  216.    INIT_PIXEL_PTR(pixel, x, y);
  217.    if (mask) {
  218.       for (i = 0; i < n; i++) {
  219.          if (mask[i]) {
  220.             STORE_CI_PIXEL(pixel, index[i]);
  221.          }
  222.          INC_PIXEL_PTR(pixel);
  223.       }
  224.    }
  225.    else if (sizeof(*pixel) == sizeof(GLuint)) {
  226.       _mesa_memcpy(pixel, index, n * sizeof(GLuint));
  227.    }
  228.    else {
  229.       for (i = 0; i < n; i++) {
  230.          STORE_CI_PIXEL(pixel, index[i]);
  231.          INC_PIXEL_PTR(pixel);
  232.       }
  233.    }
  234. }
  235.  
  236.  
  237. static void
  238. NAME(write_index8_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  239.                          const GLubyte index[], const GLubyte mask[] )
  240. {
  241. #ifdef SPAN_VARS
  242.    SPAN_VARS
  243. #endif
  244.    GLuint i;
  245.    INIT_PIXEL_PTR(pixel, x, y);
  246.    if (mask) {
  247.       for (i = 0; i < n; i++) {
  248.          if (mask[i]) {
  249.             STORE_CI_PIXEL(pixel, index[i]);
  250.          }
  251.          INC_PIXEL_PTR(pixel);
  252.       }
  253.    }
  254.    else if (sizeof(*pixel) == sizeof(GLubyte)) {
  255.       _mesa_memcpy(pixel, index, n * sizeof(GLubyte));
  256.    }
  257.    else {
  258.       for (i = 0; i < n; i++) {
  259.          STORE_CI_PIXEL(pixel, index[i]);
  260.          INC_PIXEL_PTR(pixel);
  261.       }
  262.    }
  263. }
  264.  
  265.  
  266. static void
  267. NAME(write_monoindex_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
  268.                             GLuint colorIndex, const GLubyte mask[] )
  269. {
  270. #ifdef SPAN_VARS
  271.    SPAN_VARS
  272. #endif
  273.    GLuint i;
  274.    INIT_PIXEL_PTR(pixel, x, y);
  275.    for (i = 0; i < n; i++) {
  276.       if (mask[i]) {
  277.          STORE_CI_PIXEL(pixel, colorIndex);
  278.       }
  279.       INC_PIXEL_PTR(pixel);
  280.    }
  281. }
  282.  
  283.  
  284. static void
  285. NAME(write_index_pixels)( const GLcontext *ctx,
  286.                           GLuint n, const GLint x[], const GLint y[],
  287.                           const GLuint index[], const GLubyte mask[] )
  288. {
  289. #ifdef SPAN_VARS
  290.    SPAN_VARS
  291. #endif
  292.    GLuint i;
  293.    for (i = 0; i < n; i++) {
  294.       if (mask[i]) {
  295.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  296.          STORE_CI_PIXEL(pixel, index[i]);
  297.       }
  298.    }
  299. }
  300.  
  301.  
  302. static void
  303. NAME(write_monoindex_pixels)( const GLcontext *ctx,
  304.                               GLuint n, const GLint x[], const GLint y[],
  305.                               GLuint colorIndex, const GLubyte mask[] )
  306. {
  307. #ifdef SPAN_VARS
  308.    SPAN_VARS
  309. #endif
  310.    GLuint i;
  311.    for (i = 0; i < n; i++) {
  312.       if (mask[i]) {
  313.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  314.          STORE_CI_PIXEL(pixel, colorIndex);
  315.       }
  316.    }
  317. }
  318.  
  319.  
  320. static void
  321. NAME(read_index_span)( const GLcontext *ctx,
  322.                        GLuint n, GLint x, GLint y, GLuint index[] )
  323. {
  324. #ifdef SPAN_VARS
  325.    SPAN_VARS
  326. #endif
  327.    GLuint i;
  328.    INIT_PIXEL_PTR(pixel, x, y);
  329.    for (i = 0; i < n; i++) {
  330.       FETCH_CI_PIXEL(index[i], pixel);
  331.       INC_PIXEL_PTR(pixel);
  332.    }
  333. }
  334.  
  335.  
  336. static void
  337. NAME(read_index_pixels)( const GLcontext *ctx,
  338.                          GLuint n, const GLint x[], const GLint y[],
  339.                          GLuint index[], const GLubyte mask[] )
  340. {
  341. #ifdef SPAN_VARS
  342.    SPAN_VARS
  343. #endif
  344.    GLuint i;
  345.    for (i = 0; i < n; i++) {
  346.       if (mask[i] ) {
  347.          INIT_PIXEL_PTR(pixel, x[i], y[i]);
  348.          FETCH_CI_PIXEL(index[i], pixel);
  349.       }
  350.    }
  351. }
  352.  
  353. #endif /* STORE_CI_PIXEL */
  354.  
  355.  
  356.  
  357. #undef NAME
  358. #undef INIT_PIXEL_PTR
  359. #undef INC_PIXEL_PTR
  360. #undef STORE_RGB_PIXEL
  361. #undef STORE_RGBA_PIXEL
  362. #undef FETCH_RGBA_PIXEL
  363. #undef STORE_CI_PIXEL
  364. #undef FETCH_CI_PIXEL
  365.