Removed all RCS / CVS tags (Id, Header, Date, etc.) from everything.
[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, 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
42 */
43
44
45 #ifdef STORE_RGBA_PIXEL
46
47 static void
48 NAME(write_rgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
49 CONST GLchan rgba[][4], const GLubyte mask[] )
50 {
51 #ifdef SPAN_VARS
52 SPAN_VARS
53 #endif
54 GLuint i;
55 INIT_PIXEL_PTR(pixel, x, y);
56 if (mask) {
57 for (i = 0; i < n; i++) {
58 if (mask[i]) {
59 STORE_RGBA_PIXEL(pixel, rgba[i][RCOMP], rgba[i][GCOMP],
60 rgba[i][BCOMP], rgba[i][ACOMP]);
61 }
62 INC_PIXEL_PTR(pixel);
63 }
64 }
65 else {
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]);
69 INC_PIXEL_PTR(pixel);
70 }
71 }
72 }
73
74 static void
75 NAME(write_rgb_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
76 CONST GLchan rgb[][3], const GLubyte mask[] )
77 {
78 #ifdef SPAN_VARS
79 SPAN_VARS
80 #endif
81 GLuint i;
82 INIT_PIXEL_PTR(pixel, x, y);
83 if (mask) {
84 for (i = 0; i < n; i++) {
85 if (mask[i]) {
86 STORE_RGB_PIXEL(pixel, rgb[i][RCOMP], rgb[i][GCOMP],
87 rgb[i][BCOMP]);
88 }
89 INC_PIXEL_PTR(pixel);
90 }
91 }
92 else {
93 for (i = 0; i < n; i++) {
94 STORE_RGB_PIXEL(pixel, rgb[i][RCOMP], rgb[i][GCOMP],
95 rgb[i][BCOMP]);
96 INC_PIXEL_PTR(pixel);
97 }
98 }
99 }
100
101 static void
102 NAME(write_monorgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
103 const GLchan color[4], const GLubyte mask[] )
104 {
105 #ifdef SPAN_VARS
106 SPAN_VARS
107 #endif
108 GLuint i;
109 INIT_PIXEL_PTR(pixel, x, y);
110 if (mask) {
111 for (i = 0; i < n; i++) {
112 if (mask[i]) {
113 STORE_RGBA_PIXEL(pixel, color[RCOMP], color[GCOMP],
114 color[BCOMP], color[ACOMP]);
115 }
116 INC_PIXEL_PTR(pixel);
117 }
118 }
119 else {
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);
124 }
125 }
126 }
127
128 static void
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[] )
132 {
133 #ifdef SPAN_VARS
134 SPAN_VARS
135 #endif
136 GLuint i;
137 ASSERT(mask);
138 for (i = 0; i < n; i++) {
139 if (mask[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]);
143 }
144 }
145 }
146
147 static void
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[] )
151 {
152 #ifdef SPAN_VARS
153 SPAN_VARS
154 #endif
155 GLuint i;
156 ASSERT(mask);
157 for (i = 0; i < n; i++) {
158 if (mask[i]) {
159 INIT_PIXEL_PTR(pixel, x[i], y[i]);
160 STORE_RGBA_PIXEL(pixel, color[RCOMP], color[GCOMP],
161 color[BCOMP], color[ACOMP]);
162 }
163 }
164 }
165
166 static void
167 NAME(read_rgba_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
168 GLchan rgba[][4] )
169 {
170 #ifdef SPAN_VARS
171 SPAN_VARS
172 #endif
173 GLuint i;
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);
179 }
180 }
181
182 static void
183 NAME(read_rgba_pixels)( const GLcontext *ctx,
184 GLuint n, const GLint x[], const GLint y[],
185 GLchan rgba[][4], const GLubyte mask[] )
186 {
187 #ifdef SPAN_VARS
188 SPAN_VARS
189 #endif
190 GLuint i;
191 for (i = 0; i < n; i++) {
192 if (mask[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);
196 }
197 }
198 }
199
200
201 #endif /* STORE_RGBA_PIXEL */
202
203
204
205 #ifdef STORE_CI_PIXEL
206
207 static void
208 NAME(write_index32_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
209 const GLuint index[], const GLubyte mask[] )
210 {
211 #ifdef SPAN_VARS
212 SPAN_VARS
213 #endif
214 GLuint i;
215 INIT_PIXEL_PTR(pixel, x, y);
216 if (mask) {
217 for (i = 0; i < n; i++) {
218 if (mask[i]) {
219 STORE_CI_PIXEL(pixel, index[i]);
220 }
221 INC_PIXEL_PTR(pixel);
222 }
223 }
224 else if (sizeof(*pixel) == sizeof(GLuint)) {
225 _mesa_memcpy(pixel, index, n * sizeof(GLuint));
226 }
227 else {
228 for (i = 0; i < n; i++) {
229 STORE_CI_PIXEL(pixel, index[i]);
230 INC_PIXEL_PTR(pixel);
231 }
232 }
233 }
234
235
236 static void
237 NAME(write_index8_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
238 const GLubyte index[], const GLubyte mask[] )
239 {
240 #ifdef SPAN_VARS
241 SPAN_VARS
242 #endif
243 GLuint i;
244 INIT_PIXEL_PTR(pixel, x, y);
245 if (mask) {
246 for (i = 0; i < n; i++) {
247 if (mask[i]) {
248 STORE_CI_PIXEL(pixel, index[i]);
249 }
250 INC_PIXEL_PTR(pixel);
251 }
252 }
253 else if (sizeof(*pixel) == sizeof(GLubyte)) {
254 _mesa_memcpy(pixel, index, n * sizeof(GLubyte));
255 }
256 else {
257 for (i = 0; i < n; i++) {
258 STORE_CI_PIXEL(pixel, index[i]);
259 INC_PIXEL_PTR(pixel);
260 }
261 }
262 }
263
264
265 static void
266 NAME(write_monoindex_span)( const GLcontext *ctx, GLuint n, GLint x, GLint y,
267 GLuint colorIndex, const GLubyte mask[] )
268 {
269 #ifdef SPAN_VARS
270 SPAN_VARS
271 #endif
272 GLuint i;
273 INIT_PIXEL_PTR(pixel, x, y);
274 for (i = 0; i < n; i++) {
275 if (mask[i]) {
276 STORE_CI_PIXEL(pixel, colorIndex);
277 }
278 INC_PIXEL_PTR(pixel);
279 }
280 }
281
282
283 static void
284 NAME(write_index_pixels)( const GLcontext *ctx,
285 GLuint n, const GLint x[], const GLint y[],
286 const GLuint index[], const GLubyte mask[] )
287 {
288 #ifdef SPAN_VARS
289 SPAN_VARS
290 #endif
291 GLuint i;
292 for (i = 0; i < n; i++) {
293 if (mask[i]) {
294 INIT_PIXEL_PTR(pixel, x[i], y[i]);
295 STORE_CI_PIXEL(pixel, index[i]);
296 }
297 }
298 }
299
300
301 static void
302 NAME(write_monoindex_pixels)( const GLcontext *ctx,
303 GLuint n, const GLint x[], const GLint y[],
304 GLuint colorIndex, const GLubyte mask[] )
305 {
306 #ifdef SPAN_VARS
307 SPAN_VARS
308 #endif
309 GLuint i;
310 for (i = 0; i < n; i++) {
311 if (mask[i]) {
312 INIT_PIXEL_PTR(pixel, x[i], y[i]);
313 STORE_CI_PIXEL(pixel, colorIndex);
314 }
315 }
316 }
317
318
319 static void
320 NAME(read_index_span)( const GLcontext *ctx,
321 GLuint n, GLint x, GLint y, GLuint index[] )
322 {
323 #ifdef SPAN_VARS
324 SPAN_VARS
325 #endif
326 GLuint i;
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);
331 }
332 }
333
334
335 static void
336 NAME(read_index_pixels)( const GLcontext *ctx,
337 GLuint n, const GLint x[], const GLint y[],
338 GLuint index[], const GLubyte mask[] )
339 {
340 #ifdef SPAN_VARS
341 SPAN_VARS
342 #endif
343 GLuint i;
344 for (i = 0; i < n; i++) {
345 if (mask[i] ) {
346 INIT_PIXEL_PTR(pixel, x[i], y[i]);
347 FETCH_CI_PIXEL(index[i], pixel);
348 }
349 }
350 }
351
352 #endif /* STORE_CI_PIXEL */
353
354
355
356 #undef NAME
357 #undef INIT_PIXEL_PTR
358 #undef INC_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