home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / pb.h < prev    next >
C/C++ Source or Header  |  2000-01-07  |  6KB  |  203 lines

  1. /* $Id: pb.h,v 1.2 1999/09/18 20:41:23 keithw Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  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.  
  30.  
  31. #ifndef PB_H
  32. #define PB_H
  33.  
  34.  
  35. #include "types.h"
  36.  
  37.  
  38.  
  39. /*
  40.  * Pixel buffer size, must be larger than MAX_WIDTH.
  41.  */
  42. #define PB_SIZE (3*MAX_WIDTH)
  43.  
  44.  
  45. struct pixel_buffer {
  46.     GLint x[PB_SIZE];         /* X window coord in [0,MAX_WIDTH) */
  47.     GLint y[PB_SIZE];         /* Y window coord in [0,MAX_HEIGHT) */
  48.     GLdepth z[PB_SIZE];       /* Z window coord in [0,MAX_DEPTH] */
  49.     GLubyte rgba[PB_SIZE][4]; /* Colors */
  50.     GLubyte spec[PB_SIZE][3]; /* Separate specular colors */
  51.     GLuint i[PB_SIZE];        /* Index */
  52.     GLfloat s[MAX_TEXTURE_UNITS][PB_SIZE];    /* Texture S coordinates */
  53.     GLfloat t[MAX_TEXTURE_UNITS][PB_SIZE];    /* Texture T coordinates */
  54.     GLfloat u[MAX_TEXTURE_UNITS][PB_SIZE];    /* Texture R coordinates */
  55.     GLfloat lambda[MAX_TEXTURE_UNITS][PB_SIZE];/* Texture lambda values */
  56.     GLint color[4];        /* Mono color, integers! */
  57.     GLuint index;        /* Mono index */
  58.     GLuint count;        /* Number of pixels in buffer */
  59.     GLboolean mono;        /* Same color or index for all pixels? */
  60.     GLenum primitive;    /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
  61. };
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /*
  68.  * Set the color used for all subsequent pixels in the buffer.
  69.  */
  70. #define PB_SET_COLOR( CTX, PB, R, G, B, A )            \
  71.     if ((PB)->color[RCOMP]!=(R) || (PB)->color[GCOMP]!=(G)    \
  72.      || (PB)->color[BCOMP]!=(B) || (PB)->color[ACOMP]!=(A)    \
  73.      || !(PB)->mono) {                    \
  74.         gl_flush_pb( ctx );                \
  75.     }                                \
  76.     (PB)->color[RCOMP] = R;                    \
  77.     (PB)->color[GCOMP] = G;                    \
  78.     (PB)->color[BCOMP] = B;                    \
  79.     (PB)->color[ACOMP] = A;                    \
  80.     (PB)->mono = GL_TRUE;
  81.  
  82.  
  83. /*
  84.  * Set the color index used for all subsequent pixels in the buffer.
  85.  */
  86. #define PB_SET_INDEX( CTX, PB, I )        \
  87.     if ((PB)->index!=(I) || !(PB)->mono) {    \
  88.         gl_flush_pb( CTX );        \
  89.     }                    \
  90.     (PB)->index = I;            \
  91.     (PB)->mono = GL_TRUE;
  92.  
  93.  
  94. /*
  95.  * "write" a pixel using current color or index
  96.  */
  97. #define PB_WRITE_PIXEL( PB, X, Y, Z )        \
  98.     (PB)->x[(PB)->count] = X;        \
  99.     (PB)->y[(PB)->count] = Y;        \
  100.     (PB)->z[(PB)->count] = Z;        \
  101.     (PB)->count++;
  102.  
  103.  
  104. /*
  105.  * "write" an RGBA pixel
  106.  */
  107. #define PB_WRITE_RGBA_PIXEL( PB, X, Y, Z, R, G, B, A )    \
  108.     (PB)->x[(PB)->count] = X;            \
  109.     (PB)->y[(PB)->count] = Y;            \
  110.     (PB)->z[(PB)->count] = Z;            \
  111.     (PB)->rgba[(PB)->count][RCOMP] = R;        \
  112.     (PB)->rgba[(PB)->count][GCOMP] = G;        \
  113.     (PB)->rgba[(PB)->count][BCOMP] = B;        \
  114.     (PB)->rgba[(PB)->count][ACOMP] = A;        \
  115.     (PB)->count++;
  116.  
  117. /*
  118.  * "write" a color-index pixel
  119.  */
  120. #define PB_WRITE_CI_PIXEL( PB, X, Y, Z, I )    \
  121.     (PB)->x[(PB)->count] = X;        \
  122.     (PB)->y[(PB)->count] = Y;        \
  123.     (PB)->z[(PB)->count] = Z;        \
  124.     (PB)->i[(PB)->count] = I;        \
  125.     (PB)->count++;
  126.  
  127.  
  128. /*
  129.  * "write" an RGBA pixel with texture coordinates
  130.  */
  131. #define PB_WRITE_TEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U )    \
  132.     (PB)->x[(PB)->count] = X;                \
  133.     (PB)->y[(PB)->count] = Y;                \
  134.     (PB)->z[(PB)->count] = Z;                \
  135.     (PB)->rgba[(PB)->count][RCOMP] = R;            \
  136.     (PB)->rgba[(PB)->count][GCOMP] = G;            \
  137.     (PB)->rgba[(PB)->count][BCOMP] = B;            \
  138.     (PB)->rgba[(PB)->count][ACOMP] = A;            \
  139.     (PB)->s[0][(PB)->count] = S;                \
  140.     (PB)->t[0][(PB)->count] = T;                \
  141.     (PB)->u[0][(PB)->count] = U;                \
  142.     (PB)->count++;
  143.  
  144. /*
  145.  * "write" an RGBA pixel with multiple texture coordinates
  146.  */
  147. #define PB_WRITE_MULTITEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U, S1, T1, U1 )    \
  148.     (PB)->x[(PB)->count] = X;                \
  149.     (PB)->y[(PB)->count] = Y;                \
  150.     (PB)->z[(PB)->count] = Z;                \
  151.     (PB)->rgba[(PB)->count][RCOMP] = R;            \
  152.     (PB)->rgba[(PB)->count][GCOMP] = G;            \
  153.     (PB)->rgba[(PB)->count][BCOMP] = B;            \
  154.     (PB)->rgba[(PB)->count][ACOMP] = A;            \
  155.     (PB)->s[0][(PB)->count] = S;                \
  156.     (PB)->t[0][(PB)->count] = T;                \
  157.     (PB)->u[0][(PB)->count] = U;                \
  158.     (PB)->s[1][(PB)->count] = S1;                \
  159.     (PB)->t[1][(PB)->count] = T1;                \
  160.     (PB)->u[1][(PB)->count] = U1;                \
  161.     (PB)->count++;
  162.  
  163. /*
  164.  * "write" an RGBA pixel with multiple texture coordinates and specular color
  165.  */
  166. #define PB_WRITE_MULTITEX_SPEC_PIXEL( PB, X, Y, Z, R, G, B, A,    \
  167.             SR, SG, SB, S, T, U, S1, T1, U1 )    \
  168.     (PB)->x[(PB)->count] = X;                \
  169.     (PB)->y[(PB)->count] = Y;                \
  170.     (PB)->z[(PB)->count] = Z;                \
  171.     (PB)->rgba[(PB)->count][RCOMP] = R;            \
  172.     (PB)->rgba[(PB)->count][GCOMP] = G;            \
  173.     (PB)->rgba[(PB)->count][BCOMP] = B;            \
  174.     (PB)->rgba[(PB)->count][ACOMP] = A;            \
  175.     (PB)->spec[(PB)->count][RCOMP] = SR;            \
  176.     (PB)->spec[(PB)->count][GCOMP] = SG;            \
  177.     (PB)->spec[(PB)->count][BCOMP] = SB;            \
  178.     (PB)->s[0][(PB)->count] = S;                \
  179.     (PB)->t[0][(PB)->count] = T;                \
  180.     (PB)->u[0][(PB)->count] = U;                \
  181.     (PB)->s[1][(PB)->count] = S1;                \
  182.     (PB)->t[1][(PB)->count] = T1;                \
  183.     (PB)->u[1][(PB)->count] = U1;                \
  184.     (PB)->count++;
  185.  
  186.  
  187.  
  188. /*
  189.  * Call this function at least every MAX_WIDTH pixels:
  190.  */
  191. #define PB_CHECK_FLUSH( CTX, PB )        \
  192. do {                        \
  193.     if ((PB)->count>=PB_SIZE-MAX_WIDTH) {    \
  194.        gl_flush_pb( CTX );            \
  195.     }                    \
  196. } while(0)
  197.  
  198. extern struct pixel_buffer *gl_alloc_pb(void);
  199.  
  200. extern void gl_flush_pb( GLcontext *ctx );
  201.  
  202. #endif
  203.