Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / swrast / s_spantemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /*
27 * Templates for the span/pixel-array write/read functions called via
28 * the gl_renderbuffer's GetRow, GetValues, PutRow, PutMonoRow, PutValues
29 * and PutMonoValues functions.
30 *
31 * Define the following macros before including this file:
32 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
33 * RB_TYPE the renderbuffer DataType
34 * CI_MODE if set, color index mode, else RGBA
35 * SPAN_VARS to declare any local variables
36 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
37 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
38 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
39 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
40 *
41 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
42 * for the pixels to be stored. This is useful when dithering and probably
43 * ignored otherwise.
44 */
45
46 #include "macros.h"
47
48
49 #ifdef CI_MODE
50 #define RB_COMPONENTS 1
51 #elif !defined(RB_COMPONENTS)
52 #define RB_COMPONENTS 4
53 #endif
54
55
56 static void
57 NAME(get_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
58 GLuint count, GLint x, GLint y, void *values )
59 {
60 #ifdef SPAN_VARS
61 SPAN_VARS
62 #endif
63 #ifdef CI_MODE
64 RB_TYPE *dest = (RB_TYPE *) values;
65 #else
66 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
67 #endif
68 GLuint i;
69 INIT_PIXEL_PTR(pixel, x, y);
70 for (i = 0; i < count; i++) {
71 FETCH_PIXEL(dest[i], pixel);
72 INC_PIXEL_PTR(pixel);
73 }
74 (void) rb;
75 }
76
77
78 static void
79 NAME(get_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
80 GLuint count, const GLint x[], const GLint y[], void *values )
81 {
82 #ifdef SPAN_VARS
83 SPAN_VARS
84 #endif
85 #ifdef CI_MODE
86 RB_TYPE *dest = (RB_TYPE *) values;
87 #else
88 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
89 #endif
90 GLuint i;
91 for (i = 0; i < count; i++) {
92 INIT_PIXEL_PTR(pixel, x[i], y[i]);
93 FETCH_PIXEL(dest[i], pixel);
94 }
95 (void) rb;
96 }
97
98
99 static void
100 NAME(put_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
101 GLuint count, GLint x, GLint y,
102 const void *values, const GLubyte mask[] )
103 {
104 #ifdef SPAN_VARS
105 SPAN_VARS
106 #endif
107 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
108 GLuint i;
109 INIT_PIXEL_PTR(pixel, x, y);
110 if (mask) {
111 for (i = 0; i < count; i++) {
112 if (mask[i]) {
113 STORE_PIXEL(pixel, x + i, y, src[i]);
114 }
115 INC_PIXEL_PTR(pixel);
116 }
117 }
118 else {
119 for (i = 0; i < count; i++) {
120 STORE_PIXEL(pixel, x + i, y, src[i]);
121 INC_PIXEL_PTR(pixel);
122 }
123 }
124 (void) rb;
125 }
126
127
128 #if !defined(CI_MODE)
129 static void
130 NAME(put_row_rgb)( GLcontext *ctx, struct gl_renderbuffer *rb,
131 GLuint count, GLint x, GLint y,
132 const void *values, const GLubyte mask[] )
133 {
134 #ifdef SPAN_VARS
135 SPAN_VARS
136 #endif
137 const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
138 GLuint i;
139 INIT_PIXEL_PTR(pixel, x, y);
140 for (i = 0; i < count; i++) {
141 if (!mask || mask[i]) {
142 #ifdef STORE_PIXEL_RGB
143 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
144 #else
145 STORE_PIXEL(pixel, x + i, y, src[i]);
146 #endif
147 }
148 INC_PIXEL_PTR(pixel);
149 }
150 (void) rb;
151 }
152 #endif
153
154
155 static void
156 NAME(put_mono_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
157 GLuint count, GLint x, GLint y,
158 const void *value, const GLubyte mask[] )
159 {
160 #ifdef SPAN_VARS
161 SPAN_VARS
162 #endif
163 const RB_TYPE *src = (const RB_TYPE *) value;
164 GLuint i;
165 INIT_PIXEL_PTR(pixel, x, y);
166 if (mask) {
167 for (i = 0; i < count; i++) {
168 if (mask[i]) {
169 STORE_PIXEL(pixel, x + i, y, src);
170 }
171 INC_PIXEL_PTR(pixel);
172 }
173 }
174 else {
175 for (i = 0; i < count; i++) {
176 STORE_PIXEL(pixel, x + i, y, src);
177 INC_PIXEL_PTR(pixel);
178 }
179 }
180 (void) rb;
181 }
182
183
184 static void
185 NAME(put_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
186 GLuint count, const GLint x[], const GLint y[],
187 const void *values, const GLubyte mask[] )
188 {
189 #ifdef SPAN_VARS
190 SPAN_VARS
191 #endif
192 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
193 GLuint i;
194 ASSERT(mask);
195 for (i = 0; i < count; i++) {
196 if (mask[i]) {
197 INIT_PIXEL_PTR(pixel, x[i], y[i]);
198 STORE_PIXEL(pixel, x[i], y[i], src[i]);
199 }
200 }
201 (void) rb;
202 }
203
204
205 static void
206 NAME(put_mono_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
207 GLuint count, const GLint x[], const GLint y[],
208 const void *value, const GLubyte mask[] )
209 {
210 #ifdef SPAN_VARS
211 SPAN_VARS
212 #endif
213 const RB_TYPE *src = (const RB_TYPE *) value;
214 GLuint i;
215 ASSERT(mask);
216 for (i = 0; i < count; i++) {
217 if (mask[i]) {
218 INIT_PIXEL_PTR(pixel, x[i], y[i]);
219 STORE_PIXEL(pixel, x[i], y[i], src);
220 }
221 }
222 (void) rb;
223 }
224
225
226 #undef NAME
227 #undef RB_TYPE
228 #undef RB_COMPONENTS
229 #undef CI_MODE
230 #undef SPAN_VARS
231 #undef INIT_PIXEL_PTR
232 #undef INC_PIXEL_PTR
233 #undef STORE_PIXEL
234 #undef STORE_PIXEL_RGB
235 #undef FETCH_PIXEL