home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src / pb.h < prev    next >
C/C++ Source or Header  |  1996-05-27  |  5KB  |  209 lines

  1. /* pb.h */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: pb.h,v 1.13 1996/03/07 15:28:54 brianp Exp $
  26.  
  27. $Log: pb.h,v $
  28.  * Revision 1.13  1996/03/07  15:28:54  brianp
  29.  * define PB_SIZE to be 3*MAX_WIDTH per Wolfram Gloger
  30.  *
  31.  * Revision 1.12  1996/01/22  15:31:30  brianp
  32.  * replaced gl_init_pb() with PB_INIT macro
  33.  *
  34.  * Revision 1.11  1995/12/30  00:57:46  brianp
  35.  * use integer colors instead of floating point
  36.  *
  37.  * Revision 1.10  1995/12/18  17:28:20  brianp
  38.  * use new GLdepth datatype
  39.  *
  40.  * Revision 1.9  1995/07/15  14:04:10  brianp
  41.  * added PB_WRITE_TEX_PIXEL
  42.  *
  43.  * Revision 1.8  1995/06/20  16:18:39  brianp
  44.  * removed clipflag
  45.  *
  46.  * Revision 1.7  1995/06/12  15:34:47  brianp
  47.  * changed color arrays to GLubyte
  48.  *
  49.  * Revision 1.6  1995/05/22  20:59:34  brianp
  50.  * Release 1.2
  51.  *
  52.  * Revision 1.5  1995/05/17  13:17:22  brianp
  53.  * changed default CC.Mode value to allow use of real OpenGL headers
  54.  * removed need for CC.MajorMode variable
  55.  *
  56.  * Revision 1.4  1995/05/12  16:26:33  brianp
  57.  * added pixel clipping
  58.  *
  59.  * Revision 1.3  1995/03/07  14:21:24  brianp
  60.  * updated for new XSetForeground/GC scheme
  61.  *
  62.  * Revision 1.2  1995/03/04  19:25:29  brianp
  63.  * 1.1 beta revision
  64.  *
  65.  * Revision 1.1  1995/02/24  17:51:57  brianp
  66.  * Initial revision
  67.  *
  68.  */
  69.  
  70.  
  71. #ifndef PB_H
  72. #define PB_H
  73.  
  74.  
  75. #include "GL/gl.h"
  76. #include "config.h"
  77.  
  78.  
  79.  
  80. /*
  81.  * Pixel buffer size, must be larger than MAX_WIDTH.
  82.  */
  83. #define PB_SIZE (3*MAX_WIDTH)
  84.  
  85.  
  86. struct pixel_buffer {
  87.     GLint x[PB_SIZE];    /* X window coord in [0,MAX_WIDTH) */
  88.     GLint y[PB_SIZE];    /* Y window coord in [0,MAX_HEIGHT) */
  89.     GLdepth z[PB_SIZE];    /* Z window coord in [0,MAX_DEPTH] */
  90.     GLubyte r[PB_SIZE];    /* Red */
  91.     GLubyte g[PB_SIZE];    /* Green */
  92.     GLubyte b[PB_SIZE];    /* Blue */
  93.     GLubyte a[PB_SIZE];    /* Alpha */
  94.     GLuint i[PB_SIZE];    /* Index */
  95.     GLfloat s[PB_SIZE];    /* Texture S coordinate */
  96.     GLfloat t[PB_SIZE];    /* Texture T coordinate */
  97.     GLint color[4];        /* Mono color, integers! */
  98.     GLuint index;        /* Mono index */
  99.     GLuint count;        /* Number of pixels in buffer */
  100.     GLboolean mono;        /* Same color or index for all pixels? */
  101.     GLenum primitive;    /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
  102. };
  103.  
  104.  
  105. extern struct pixel_buffer PB;
  106.  
  107.  
  108. /*
  109.  * Initialize the Pixel Buffer, specifying the type of primitive being drawn.
  110.  */
  111. #define PB_INIT( PRIM )        \
  112.     PB.count = 0;        \
  113.     PB.mono = GL_FALSE;    \
  114.     PB.primitive = (PRIM);
  115.  
  116.  
  117.  
  118. /*
  119.  * Set the color used for all subsequent pixels in the buffer.
  120.  */
  121. #define PB_SET_COLOR( R, G, B, A )            \
  122.     if (PB.color[0]!=(R) || PB.color[1]!=(G)    \
  123.      || PB.color[2]!=(B) || PB.color[3]!=(A)    \
  124.      || !PB.mono) {                    \
  125.         gl_flush_pb();                \
  126.     }                        \
  127.     PB.color[0] = R;                \
  128.     PB.color[1] = G;                \
  129.     PB.color[2] = B;                \
  130.     PB.color[3] = A;                \
  131.     PB.mono = GL_TRUE;
  132.  
  133.  
  134. /*
  135.  * Set the color index used for all subsequent pixels in the buffer.
  136.  */
  137. #define PB_SET_INDEX( I )            \
  138.     if (PB.index!=(I) || !PB.mono) {    \
  139.         gl_flush_pb();            \
  140.     }                    \
  141.     PB.index = I;                \
  142.     PB.mono = GL_TRUE;
  143.  
  144.  
  145. /*
  146.  * "write" a pixel using current color or index
  147.  */
  148. #define PB_WRITE_PIXEL( X, Y, Z )    \
  149.     PB.x[PB.count] = X;        \
  150.     PB.y[PB.count] = Y;        \
  151.     PB.z[PB.count] = Z;        \
  152.     PB.count++;
  153.  
  154.  
  155. /*
  156.  * "write" an RGBA pixel
  157.  */
  158. #define PB_WRITE_RGBA_PIXEL( X, Y, Z, R, G, B, A )    \
  159.     PB.x[PB.count] = X;                \
  160.     PB.y[PB.count] = Y;                \
  161.     PB.z[PB.count] = Z;                \
  162.     PB.r[PB.count] = R;                \
  163.     PB.g[PB.count] = G;                \
  164.     PB.b[PB.count] = B;                \
  165.     PB.a[PB.count] = A;                \
  166.     PB.count++;
  167.  
  168. /*
  169.  * "write" a color-index pixel
  170.  */
  171. #define PB_WRITE_CI_PIXEL( X, Y, Z, I )    \
  172.     PB.x[PB.count] = X;        \
  173.     PB.y[PB.count] = Y;        \
  174.     PB.z[PB.count] = Z;        \
  175.     PB.i[PB.count] = I;        \
  176.     PB.count++;
  177.  
  178.  
  179. /*
  180.  * "write" an RGBA pixel with texture coordinates
  181.  */
  182. #define PB_WRITE_TEX_PIXEL( X, Y, Z, R, G, B, A, S, T )    \
  183.     PB.x[PB.count] = X;                \
  184.     PB.y[PB.count] = Y;                \
  185.     PB.z[PB.count] = Z;                \
  186.     PB.r[PB.count] = R;                \
  187.     PB.g[PB.count] = G;                \
  188.     PB.b[PB.count] = B;                \
  189.     PB.a[PB.count] = A;                \
  190.     PB.s[PB.count] = S;                \
  191.     PB.t[PB.count] = T;                \
  192.     PB.count++;
  193.  
  194.  
  195. /*
  196.  * Call this function at least every MAX_WIDTH pixels:
  197.  */
  198. #define PB_CHECK_FLUSH                \
  199.     if (PB.count>=PB_SIZE-MAX_WIDTH) {    \
  200.        gl_flush_pb();            \
  201.     }
  202.  
  203.  
  204. extern void gl_flush_pb( void );
  205.  
  206.  
  207.  
  208. #endif
  209.