1 /* $Id: s_spantemp.h,v 1.2 2002/11/28 15:56:06 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Templates for the span/pixel-array write/read functions called via
30 * swrast. This is intended for memory-based framebuffers (like OSMesa).
32 * Define the following macros before including this file:
33 * NAME(PREFIX) to generate the function name
34 * SPAN_VARS to declare any local variables
35 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
36 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
37 * STORE_RGB_PIXEL(P, R, G, B) to store RGB values in pixel P
38 * STORE_RGBA_PIXEL(P, R, G, B, A) to store RGBA values in pixel P
39 * FETCH_RGBA_PIXEL(R, G, B, A, P) to fetch RGBA values from pixel P
40 * For color index mode:
41 * STORE_CI_PIXEL(P, CI) to store a color index in pixel P
42 * FETCH_CI_PIXEL(CI, P) to fetch a pixel index from pixel P
46 #ifdef STORE_RGBA_PIXEL
49 NAME(write_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
50 CONST GLchan rgba
[][4], const GLubyte mask
[] )
56 INIT_PIXEL_PTR(pixel
, x
, y
);
58 for (i
= 0; i
< n
; i
++) {
60 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
61 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
67 for (i
= 0; i
< n
; i
++) {
68 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
69 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
76 NAME(write_rgb_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
77 CONST GLchan rgb
[][3], const GLubyte mask
[] )
83 INIT_PIXEL_PTR(pixel
, x
, y
);
85 for (i
= 0; i
< n
; i
++) {
87 STORE_RGB_PIXEL(pixel
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
94 for (i
= 0; i
< n
; i
++) {
95 STORE_RGB_PIXEL(pixel
, rgb
[i
][RCOMP
], rgb
[i
][GCOMP
],
103 NAME(write_monorgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
104 const GLchan color
[4], const GLubyte mask
[] )
110 INIT_PIXEL_PTR(pixel
, x
, y
);
112 for (i
= 0; i
< n
; i
++) {
114 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
115 color
[BCOMP
], color
[ACOMP
]);
117 INC_PIXEL_PTR(pixel
);
121 for (i
= 0; i
< n
; i
++) {
122 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
123 color
[BCOMP
], color
[ACOMP
]);
124 INC_PIXEL_PTR(pixel
);
130 NAME(write_rgba_pixels
)( const GLcontext
*ctx
, GLuint n
,
131 const GLint x
[], const GLint y
[],
132 CONST GLchan rgba
[][4], const GLubyte mask
[] )
139 for (i
= 0; i
< n
; i
++) {
141 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
142 STORE_RGBA_PIXEL(pixel
, rgba
[i
][RCOMP
], rgba
[i
][GCOMP
],
143 rgba
[i
][BCOMP
], rgba
[i
][ACOMP
]);
149 NAME(write_monorgba_pixels
)( const GLcontext
*ctx
,
150 GLuint n
, const GLint x
[], const GLint y
[],
151 const GLchan color
[4], const GLubyte mask
[] )
158 for (i
= 0; i
< n
; i
++) {
160 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
161 STORE_RGBA_PIXEL(pixel
, color
[RCOMP
], color
[GCOMP
],
162 color
[BCOMP
], color
[ACOMP
]);
168 NAME(read_rgba_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
175 INIT_PIXEL_PTR(pixel
, x
, y
);
176 for (i
= 0; i
< n
; i
++) {
177 FETCH_RGBA_PIXEL(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
],
178 rgba
[i
][ACOMP
], pixel
);
179 INC_PIXEL_PTR(pixel
);
184 NAME(read_rgba_pixels
)( const GLcontext
*ctx
,
185 GLuint n
, const GLint x
[], const GLint y
[],
186 GLchan rgba
[][4], const GLubyte mask
[] )
192 for (i
= 0; i
< n
; i
++) {
194 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
195 FETCH_RGBA_PIXEL(rgba
[i
][RCOMP
], rgba
[i
][GCOMP
], rgba
[i
][BCOMP
],
196 rgba
[i
][ACOMP
], pixel
);
202 #endif /* STORE_RGBA_PIXEL */
206 #ifdef STORE_CI_PIXEL
209 NAME(write_index32_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
210 const GLuint index
[], const GLubyte mask
[] )
216 INIT_PIXEL_PTR(pixel
, x
, y
);
218 for (i
= 0; i
< n
; i
++) {
220 STORE_CI_PIXEL(pixel
, index
[i
]);
222 INC_PIXEL_PTR(pixel
);
225 else if (sizeof(*pixel
) == sizeof(GLuint
)) {
226 _mesa_memcpy(pixel
, index
, n
* sizeof(GLuint
));
229 for (i
= 0; i
< n
; i
++) {
230 STORE_CI_PIXEL(pixel
, index
[i
]);
231 INC_PIXEL_PTR(pixel
);
238 NAME(write_index8_span
)( const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
239 const GLubyte index
[], const GLubyte mask
[] )
245 INIT_PIXEL_PTR(pixel
, x
, y
);
247 for (i
= 0; i
< n
; i
++) {
249 STORE_CI_PIXEL(pixel
, index
[i
]);
251 INC_PIXEL_PTR(pixel
);
254 else if (sizeof(*pixel
) == sizeof(GLubyte
)) {
255 _mesa_memcpy(pixel
, index
, n
* sizeof(GLubyte
));
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
);
275 for (i
= 0; i
< n
; i
++) {
277 STORE_CI_PIXEL(pixel
, colorIndex
);
279 INC_PIXEL_PTR(pixel
);
285 NAME(write_index_pixels
)( const GLcontext
*ctx
,
286 GLuint n
, const GLint x
[], const GLint y
[],
287 const GLuint index
[], const GLubyte mask
[] )
293 for (i
= 0; i
< n
; i
++) {
295 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
296 STORE_CI_PIXEL(pixel
, index
[i
]);
303 NAME(write_monoindex_pixels
)( const GLcontext
*ctx
,
304 GLuint n
, const GLint x
[], const GLint y
[],
305 GLuint colorIndex
, const GLubyte mask
[] )
311 for (i
= 0; i
< n
; i
++) {
313 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
314 STORE_CI_PIXEL(pixel
, colorIndex
);
321 NAME(read_index_span
)( const GLcontext
*ctx
,
322 GLuint n
, GLint x
, GLint y
, GLuint index
[] )
328 INIT_PIXEL_PTR(pixel
, x
, y
);
329 for (i
= 0; i
< n
; i
++) {
330 FETCH_CI_PIXEL(index
[i
], pixel
);
331 INC_PIXEL_PTR(pixel
);
337 NAME(read_index_pixels
)( const GLcontext
*ctx
,
338 GLuint n
, const GLint x
[], const GLint y
[],
339 GLuint index
[], const GLubyte mask
[] )
345 for (i
= 0; i
< n
; i
++) {
347 INIT_PIXEL_PTR(pixel
, x
[i
], y
[i
]);
348 FETCH_CI_PIXEL(index
[i
], pixel
);
353 #endif /* STORE_CI_PIXEL */
358 #undef INIT_PIXEL_PTR
360 #undef STORE_RGB_PIXEL
361 #undef STORE_RGBA_PIXEL
362 #undef FETCH_RGBA_PIXEL
363 #undef STORE_CI_PIXEL
364 #undef FETCH_CI_PIXEL