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