3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
28 * Templates for the span/pixel-array write/read functions called via
29 * swrast. This is intended for memory-based framebuffers (like OSMesa).
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
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.
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
51 #ifdef STORE_RGBA_PIXEL
54 NAME(write_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
55 CONST GLchan rgba
[][4], const GLubyte mask
[] )
61 INIT_PIXEL_PTR(pixel
, x
, y
);
63 for (i
= 0; i
< n
; i
++) {
65 STORE_RGBA_PIXEL(pixel
, x
+i
, y
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
66 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
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
]);
81 NAME(write_rgb_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
82 CONST GLchan rgb
[][3], const GLubyte mask
[] )
88 INIT_PIXEL_PTR(pixel
, x
, y
);
90 for (i
= 0; i
< n
; i
++) {
92 STORE_RGB_PIXEL(pixel
, x
+i
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
99 for (i
= 0; i
< n
; i
++) {
100 STORE_RGB_PIXEL(pixel
, x
+i
, y
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
102 INC_PIXEL_PTR(pixel
);
108 NAME(write_monorgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
109 const GLchan color
[4], const GLubyte mask
[] )
115 INIT_PIXEL_PTR(pixel
, x
, y
);
117 for (i
= 0; i
< n
; i
++) {
119 STORE_RGBA_PIXEL(pixel
, x
+i
, y
, color
[RCOMP
], color
[GCOMP
],
120 color
[BCOMP
], color
[ACOMP
]);
122 INC_PIXEL_PTR(pixel
);
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
);
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
[] )
144 for (i
= 0; i
< n
; 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
]);
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
[] )
163 for (i
= 0; i
< n
; 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
]);
173 NAME(read_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
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
);
189 NAME(read_rgba_pixels
)( const GLcontext
*ctx
,
190 GLuint n
, const GLint x
[], const GLint y
[],
191 GLchan rgba
[][4], const GLubyte mask
[] )
198 for (i
= 0; i
< n
; 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
);
208 #endif /* STORE_RGBA_PIXEL */
212 #ifdef STORE_CI_PIXEL
215 NAME(write_index32_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
216 const GLuint index
[], const GLubyte mask
[] )
222 INIT_PIXEL_PTR(pixel
, x
, y
);
224 for (i
= 0; i
< n
; i
++) {
226 STORE_CI_PIXEL(pixel
, index
[i
]);
228 INC_PIXEL_PTR(pixel
);
232 for (i
= 0; i
< n
; i
++) {
233 STORE_CI_PIXEL(pixel
, index
[i
]);
234 INC_PIXEL_PTR(pixel
);
241 NAME(write_index8_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
242 const GLubyte index
[], const GLubyte mask
[] )
248 INIT_PIXEL_PTR(pixel
, x
, y
);
250 for (i
= 0; i
< n
; i
++) {
252 STORE_CI_PIXEL(pixel
, index
[i
]);
254 INC_PIXEL_PTR(pixel
);
258 for (i
= 0; i
< n
; i
++) {
259 STORE_CI_PIXEL(pixel
, index
[i
]);
260 INC_PIXEL_PTR(pixel
);
267 NAME(write_monoindex_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
268 GLuint colorIndex
, const GLubyte mask
[] )
274 INIT_PIXEL_PTR(pixel
, x
, y
);
276 for (i
= 0; i
< n
; i
++) {
278 STORE_CI_PIXEL(pixel
, colorIndex
);
280 INC_PIXEL_PTR(pixel
);
284 for (i
= 0; i
< n
; i
++) {
285 STORE_CI_PIXEL(pixel
, colorIndex
);
286 INC_PIXEL_PTR(pixel
);
293 NAME(write_index_pixels
)( const GLcontext
*ctx
,
294 GLuint n
, const GLint x
[], const GLint y
[],
295 const GLuint index
[], const GLubyte mask
[] )
302 for (i
= 0; i
< n
; i
++) {
304 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
305 STORE_CI_PIXEL(pixel
, index
[i
]);
312 NAME(write_monoindex_pixels
)( const GLcontext
*ctx
,
313 GLuint n
, const GLint x
[], const GLint y
[],
314 GLuint colorIndex
, const GLubyte mask
[] )
321 for (i
= 0; i
< n
; i
++) {
323 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
324 STORE_CI_PIXEL(pixel
, colorIndex
);
331 NAME(read_index_span
)( const GLcontext
*ctx
,
332 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
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
);
347 NAME(read_index_pixels
)( const GLcontext
*ctx
,
348 GLuint n
, const GLint x
[], const GLint y
[],
349 GLuint index
[], const GLubyte mask
[] )
356 for (i
= 0; i
< n
; i
++) {
358 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
359 FETCH_CI_PIXEL(index
[i
], pixel
);
364 #endif /* STORE_CI_PIXEL */
370 #undef INIT_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