xref: /reactos/dll/opengl/mesa/pb.h (revision 7eead935)
1 /* $Id: pb.h,v 1.4 1997/11/13 02:16:48 brianp Exp $ */
2 
3 /*
4  * Mesa 3-D graphics library
5  * Version:  2.5
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 
24 /*
25  * $Log: pb.h,v $
26  * Revision 1.4  1997/11/13 02:16:48  brianp
27  * added lambda array, initialized to zeros
28  *
29  * Revision 1.3  1997/05/09 22:40:19  brianp
30  * added gl_alloc_pb()
31  *
32  * Revision 1.2  1997/02/09 18:43:14  brianp
33  * added GL_EXT_texture3D support
34  *
35  * Revision 1.1  1996/09/13 01:38:16  brianp
36  * Initial revision
37  *
38  */
39 
40 
41 #ifndef PB_H
42 #define PB_H
43 
44 
45 #include "types.h"
46 
47 
48 
49 /*
50  * Pixel buffer size, must be larger than MAX_WIDTH.
51  */
52 #define PB_SIZE (3*MAX_WIDTH)
53 
54 
55 struct pixel_buffer {
56 	GLint x[PB_SIZE];	/* X window coord in [0,MAX_WIDTH) */
57 	GLint y[PB_SIZE];	/* Y window coord in [0,MAX_HEIGHT) */
58 	GLdepth z[PB_SIZE];	/* Z window coord in [0,MAX_DEPTH] */
59 	GLubyte r[PB_SIZE];	/* Red */
60 	GLubyte g[PB_SIZE];	/* Green */
61 	GLubyte b[PB_SIZE];	/* Blue */
62 	GLubyte a[PB_SIZE];	/* Alpha */
63 	GLuint i[PB_SIZE];	/* Index */
64 	GLfloat s[PB_SIZE];	/* Texture S coordinate */
65 	GLfloat t[PB_SIZE];	/* Texture T coordinate */
66 	GLfloat u[PB_SIZE];	/* Texture R coordinate */
67 	GLfloat lambda[PB_SIZE];/* Texture lambda value */
68 	GLint color[4];		/* Mono color, integers! */
69 	GLuint index;		/* Mono index */
70 	GLuint count;		/* Number of pixels in buffer */
71 	GLboolean mono;		/* Same color or index for all pixels? */
72 	GLenum primitive;	/* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
73 };
74 
75 
76 /*
77  * Initialize the Pixel Buffer, specifying the type of primitive being drawn.
78  */
79 #define PB_INIT( PB, PRIM )		\
80 	(PB)->count = 0;		\
81 	(PB)->mono = GL_FALSE;		\
82 	(PB)->primitive = (PRIM);
83 
84 
85 
86 /*
87  * Set the color used for all subsequent pixels in the buffer.
88  */
89 #define PB_SET_COLOR( CTX, PB, R, G, B, A )		\
90 	if ((PB)->color[0]!=(R) || (PB)->color[1]!=(G)	\
91 	 || (PB)->color[2]!=(B) || (PB)->color[3]!=(A)	\
92 	 || !(PB)->mono) {				\
93 		gl_flush_pb( ctx );			\
94 	}						\
95 	(PB)->color[0] = R;				\
96 	(PB)->color[1] = G;				\
97 	(PB)->color[2] = B;				\
98 	(PB)->color[3] = A;				\
99 	(PB)->mono = GL_TRUE;
100 
101 
102 /*
103  * Set the color index used for all subsequent pixels in the buffer.
104  */
105 #define PB_SET_INDEX( CTX, PB, I )		\
106 	if ((PB)->index!=(I) || !(PB)->mono) {	\
107 		gl_flush_pb( CTX );		\
108 	}					\
109 	(PB)->index = I;			\
110 	(PB)->mono = GL_TRUE;
111 
112 
113 /*
114  * "write" a pixel using current color or index
115  */
116 #define PB_WRITE_PIXEL( PB, X, Y, Z )		\
117 	(PB)->x[(PB)->count] = X;		\
118 	(PB)->y[(PB)->count] = Y;		\
119 	(PB)->z[(PB)->count] = Z;		\
120 	(PB)->count++;
121 
122 
123 /*
124  * "write" an RGBA pixel
125  */
126 #define PB_WRITE_RGBA_PIXEL( PB, X, Y, Z, R, G, B, A )	\
127 	(PB)->x[(PB)->count] = X;			\
128 	(PB)->y[(PB)->count] = Y;			\
129 	(PB)->z[(PB)->count] = Z;			\
130 	(PB)->r[(PB)->count] = R;			\
131 	(PB)->g[(PB)->count] = G;			\
132 	(PB)->b[(PB)->count] = B;			\
133 	(PB)->a[(PB)->count] = A;			\
134 	(PB)->count++;
135 
136 /*
137  * "write" a color-index pixel
138  */
139 #define PB_WRITE_CI_PIXEL( PB, X, Y, Z, I )	\
140 	(PB)->x[(PB)->count] = X;		\
141 	(PB)->y[(PB)->count] = Y;		\
142 	(PB)->z[(PB)->count] = Z;		\
143 	(PB)->i[(PB)->count] = I;		\
144 	(PB)->count++;
145 
146 
147 /*
148  * "write" an RGBA pixel with texture coordinates
149  */
150 #define PB_WRITE_TEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U )	\
151 	(PB)->x[(PB)->count] = X;				\
152 	(PB)->y[(PB)->count] = Y;				\
153 	(PB)->z[(PB)->count] = Z;				\
154 	(PB)->r[(PB)->count] = R;				\
155 	(PB)->g[(PB)->count] = G;				\
156 	(PB)->b[(PB)->count] = B;				\
157 	(PB)->a[(PB)->count] = A;				\
158 	(PB)->s[(PB)->count] = S;				\
159 	(PB)->t[(PB)->count] = T;				\
160 	(PB)->u[(PB)->count] = U;				\
161 	(PB)->count++;
162 
163 
164 /*
165  * Call this function at least every MAX_WIDTH pixels:
166  */
167 #define PB_CHECK_FLUSH( CTX, PB )		\
168 	if ((PB)->count>=PB_SIZE-MAX_WIDTH) {	\
169 	   gl_flush_pb( CTX );			\
170 	}
171 
172 
173 extern struct pixel_buffer *gl_alloc_pb(void);
174 
175 extern void gl_flush_pb( GLcontext *ctx );
176 
177 #endif
178