| 1 |
/* $Id: pb.h,v 1.2 2000/10/27 15:21:40 mholst Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Mesa 3-D graphics library |
| 5 |
* Version: 2.2 |
| 6 |
* Copyright (C) 1995-1997 Brian Paul |
| 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 |
#ifndef PB_H |
| 24 |
#define PB_H |
| 25 |
|
| 26 |
|
| 27 |
#include "types.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
/* |
| 32 |
* Pixel buffer size, must be larger than MAX_WIDTH. |
| 33 |
*/ |
| 34 |
#define PB_SIZE (3*MAX_WIDTH) |
| 35 |
|
| 36 |
|
| 37 |
struct pixel_buffer { |
| 38 |
GLint x[PB_SIZE]; /* X window coord in [0,MAX_WIDTH) */ |
| 39 |
GLint y[PB_SIZE]; /* Y window coord in [0,MAX_HEIGHT) */ |
| 40 |
GLdepth z[PB_SIZE]; /* Z window coord in [0,MAX_DEPTH] */ |
| 41 |
GLubyte r[PB_SIZE]; /* Red */ |
| 42 |
GLubyte g[PB_SIZE]; /* Green */ |
| 43 |
GLubyte b[PB_SIZE]; /* Blue */ |
| 44 |
GLubyte a[PB_SIZE]; /* Alpha */ |
| 45 |
GLuint i[PB_SIZE]; /* Index */ |
| 46 |
GLfloat s[PB_SIZE]; /* Texture S coordinate */ |
| 47 |
GLfloat t[PB_SIZE]; /* Texture T coordinate */ |
| 48 |
GLfloat u[PB_SIZE]; /* Texture R coordinate */ |
| 49 |
GLint color[4]; /* Mono color, integers! */ |
| 50 |
GLuint index; /* Mono index */ |
| 51 |
GLuint count; /* Number of pixels in buffer */ |
| 52 |
GLboolean mono; /* Same color or index for all pixels? */ |
| 53 |
GLenum primitive; /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/ |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
/* |
| 58 |
* Initialize the Pixel Buffer, specifying the type of primitive being drawn. |
| 59 |
*/ |
| 60 |
#define PB_INIT( PB, PRIM ) \ |
| 61 |
(PB)->count = 0; \ |
| 62 |
(PB)->mono = GL_FALSE; \ |
| 63 |
(PB)->primitive = (PRIM); |
| 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[0]!=(R) || (PB)->color[1]!=(G) \ |
| 72 |
|| (PB)->color[2]!=(B) || (PB)->color[3]!=(A) \ |
| 73 |
|| !(PB)->mono) { \ |
| 74 |
gl_flush_pb( ctx ); \ |
| 75 |
} \ |
| 76 |
(PB)->color[0] = R; \ |
| 77 |
(PB)->color[1] = G; \ |
| 78 |
(PB)->color[2] = B; \ |
| 79 |
(PB)->color[3] = 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)->r[(PB)->count] = R; \ |
| 112 |
(PB)->g[(PB)->count] = G; \ |
| 113 |
(PB)->b[(PB)->count] = B; \ |
| 114 |
(PB)->a[(PB)->count] = 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)->r[(PB)->count] = R; \ |
| 136 |
(PB)->g[(PB)->count] = G; \ |
| 137 |
(PB)->b[(PB)->count] = B; \ |
| 138 |
(PB)->a[(PB)->count] = A; \ |
| 139 |
(PB)->s[(PB)->count] = S; \ |
| 140 |
(PB)->t[(PB)->count] = T; \ |
| 141 |
(PB)->u[(PB)->count] = U; \ |
| 142 |
(PB)->count++; |
| 143 |
|
| 144 |
|
| 145 |
/* |
| 146 |
* Call this function at least every MAX_WIDTH pixels: |
| 147 |
*/ |
| 148 |
#define PB_CHECK_FLUSH( CTX, PB ) \ |
| 149 |
if ((PB)->count>=PB_SIZE-MAX_WIDTH) { \ |
| 150 |
gl_flush_pb( CTX ); \ |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
extern void gl_flush_pb( GLcontext *ctx ); |
| 155 |
|
| 156 |
#endif |