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, R, G, B) to store RGB values in pixel P
37 * STORE_RGBA_PIXEL(P, 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 * For color index mode:
40 * STORE_CI_PIXEL(P, CI) to store a color index in pixel P
41 * FETCH_CI_PIXEL(CI, P) to fetch a pixel index from pixel P
45 #ifdef STORE_RGBA_PIXEL
48 NAME(write_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
49 CONST GLchan rgba
[][4], const GLubyte mask
[] )
55 INIT_PIXEL_PTR(pixel
, x
, y
);
57 for (i
= 0; i
< n
; i
++) {
59 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
60 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
66 for (i
= 0; i
< n
; i
++) {
67 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
68 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
75 NAME(write_rgb_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
76 CONST GLchan rgb
[][3], const GLubyte mask
[] )
82 INIT_PIXEL_PTR(pixel
, x
, y
);
84 for (i
= 0; i
< n
; i
++) {
86 STORE_RGB_PIXEL(pixel
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
93 for (i
= 0; i
< n
; i
++) {
94 STORE_RGB_PIXEL(pixel
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
102 NAME(write_monorgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
103 const GLchan color
[4], const GLubyte mask
[] )
109 INIT_PIXEL_PTR(pixel
, x
, y
);
111 for (i
= 0; i
< n
; i
++) {
113 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
114 color
[BCOMP
], color
[ACOMP
]);
116 INC_PIXEL_PTR(pixel
);
120 for (i
= 0; i
< n
; i
++) {
121 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
122 color
[BCOMP
], color
[ACOMP
]);
123 INC_PIXEL_PTR(pixel
);
129 NAME(write_rgba_pixels
)( const GLcontext
*ctx
, GLuint n
,
130 const GLint x
[], const GLint y
[],
131 CONST GLchan rgba
[][4], const GLubyte mask
[] )
138 for (i
= 0; i
< n
; i
++) {
140 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
141 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
142 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
148 NAME(write_monorgba_pixels
)( const GLcontext
*ctx
,
149 GLuint n
, const GLint x
[], const GLint y
[],
150 const GLchan color
[4], const GLubyte mask
[] )
157 for (i
= 0; i
< n
; i
++) {
159 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
160 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
161 color
[BCOMP
], color
[ACOMP
]);
167 NAME(read_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
174 INIT_PIXEL_PTR(pixel
, x
, y
);
175 for (i
= 0; i
< n
; i
++) {
176 FETCH_RGBA_PIXEL(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
],
177 rgba
[i
][ACOMP
], pixel
);
178 INC_PIXEL_PTR(pixel
);
183 NAME(read_rgba_pixels
)( const GLcontext
*ctx
,
184 GLuint n
, const GLint x
[], const GLint y
[],
185 GLchan rgba
[][4], const GLubyte mask
[] )
191 for (i
= 0; i
< n
; i
++) {
193 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
194 FETCH_RGBA_PIXEL(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
],
195 rgba
[i
][ACOMP
], pixel
);
201 #endif /* STORE_RGBA_PIXEL */
205 #ifdef STORE_CI_PIXEL
208 NAME(write_index32_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
209 const GLuint index
[], const GLubyte mask
[] )
215 INIT_PIXEL_PTR(pixel
, x
, y
);
217 for (i
= 0; i
< n
; i
++) {
219 STORE_CI_PIXEL(pixel
, index
[i
]);
221 INC_PIXEL_PTR(pixel
);
224 else if (sizeof(*pixel
) == sizeof(GLuint
)) {
225 _mesa_memcpy(pixel
, index
, n
* sizeof(GLuint
));
228 for (i
= 0; i
< n
; i
++) {
229 STORE_CI_PIXEL(pixel
, index
[i
]);
230 INC_PIXEL_PTR(pixel
);
237 NAME(write_index8_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
238 const GLubyte index
[], const GLubyte mask
[] )
244 INIT_PIXEL_PTR(pixel
, x
, y
);
246 for (i
= 0; i
< n
; i
++) {
248 STORE_CI_PIXEL(pixel
, index
[i
]);
250 INC_PIXEL_PTR(pixel
);
253 else if (sizeof(*pixel
) == sizeof(GLubyte
)) {
254 _mesa_memcpy(pixel
, index
, n
* sizeof(GLubyte
));
257 for (i
= 0; i
< n
; i
++) {
258 STORE_CI_PIXEL(pixel
, index
[i
]);
259 INC_PIXEL_PTR(pixel
);
266 NAME(write_monoindex_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
267 GLuint colorIndex
, const GLubyte mask
[] )
273 INIT_PIXEL_PTR(pixel
, x
, y
);
274 for (i
= 0; i
< n
; i
++) {
276 STORE_CI_PIXEL(pixel
, colorIndex
);
278 INC_PIXEL_PTR(pixel
);
284 NAME(write_index_pixels
)( const GLcontext
*ctx
,
285 GLuint n
, const GLint x
[], const GLint y
[],
286 const GLuint index
[], const GLubyte mask
[] )
292 for (i
= 0; i
< n
; i
++) {
294 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
295 STORE_CI_PIXEL(pixel
, index
[i
]);
302 NAME(write_monoindex_pixels
)( const GLcontext
*ctx
,
303 GLuint n
, const GLint x
[], const GLint y
[],
304 GLuint colorIndex
, const GLubyte mask
[] )
310 for (i
= 0; i
< n
; i
++) {
312 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
313 STORE_CI_PIXEL(pixel
, colorIndex
);
320 NAME(read_index_span
)( const GLcontext
*ctx
,
321 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
327 INIT_PIXEL_PTR(pixel
, x
, y
);
328 for (i
= 0; i
< n
; i
++) {
329 FETCH_CI_PIXEL(index
[i
], pixel
);
330 INC_PIXEL_PTR(pixel
);
336 NAME(read_index_pixels
)( const GLcontext
*ctx
,
337 GLuint n
, const GLint x
[], const GLint y
[],
338 GLuint index
[], const GLubyte mask
[] )
344 for (i
= 0; i
< n
; i
++) {
346 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
347 FETCH_CI_PIXEL(index
[i
], pixel
);
352 #endif /* STORE_CI_PIXEL */
357 #undef INIT_PIXEL_PTR
359 #undef STORE_RGB_PIXEL
360 #undef STORE_RGBA_PIXEL
361 #undef FETCH_RGBA_PIXEL
362 #undef STORE_CI_PIXEL
363 #undef FETCH_CI_PIXEL