blob: b15bbb257766372e0416d9b3fe09a24c5f29c445 [file] [log] [blame]
Keith Whitwelldc45ee72004-10-13 23:16:02 +00001/*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * (C) Copyright IBM Corporation 2002, 2003
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keithw@tungstengraphics.com>
27 * Gareth Hughes <gareth@nvidia.com>
28 */
29
Keith Whitwell93a45882003-08-06 18:12:22 +000030#ifndef DBG
31#define DBG 0
32#endif
33
34#ifndef HW_WRITE_LOCK
35#define HW_WRITE_LOCK() HW_LOCK()
36#endif
37
38#ifndef HW_WRITE_UNLOCK
39#define HW_WRITE_UNLOCK() HW_UNLOCK()
40#endif
41
42#ifndef HW_READ_LOCK
43#define HW_READ_LOCK() HW_LOCK()
44#endif
45
46#ifndef HW_READ_UNLOCK
47#define HW_READ_UNLOCK() HW_UNLOCK()
48#endif
49
50#ifndef HW_READ_CLIPLOOP
51#define HW_READ_CLIPLOOP() HW_CLIPLOOP()
52#endif
53
54#ifndef HW_WRITE_CLIPLOOP
55#define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
56#endif
57
58
Brian Paule4b23562005-05-04 20:11:35 +000059static void TAG(WriteRGBASpan)( GLcontext *ctx,
60 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +000061 GLuint n, GLint x, GLint y,
Brian Paule4b23562005-05-04 20:11:35 +000062 const void *values, const GLubyte mask[] )
Keith Whitwell93a45882003-08-06 18:12:22 +000063{
64 HW_WRITE_LOCK()
65 {
Brian Paule4b23562005-05-04 20:11:35 +000066 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
Keith Whitwell93a45882003-08-06 18:12:22 +000067 GLint x1;
68 GLint n1;
69 LOCAL_VARS;
70
71 y = Y_FLIP(y);
72
73 HW_WRITE_CLIPLOOP()
74 {
75 GLint i = 0;
76 CLIPSPAN(x,y,n,x1,n1,i);
77
78 if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
79 (int)i, (int)n1, (int)x1);
80
81 if (mask)
82 {
83 for (;n1>0;i++,x1++,n1--)
84 if (mask[i])
85 WRITE_RGBA( x1, y,
86 rgba[i][0], rgba[i][1],
87 rgba[i][2], rgba[i][3] );
88 }
89 else
90 {
91 for (;n1>0;i++,x1++,n1--)
92 WRITE_RGBA( x1, y,
93 rgba[i][0], rgba[i][1],
94 rgba[i][2], rgba[i][3] );
95 }
96 }
97 HW_ENDCLIPLOOP();
98 }
99 HW_WRITE_UNLOCK();
100}
101
Brian Paule4b23562005-05-04 20:11:35 +0000102static void TAG(WriteRGBSpan)( GLcontext *ctx,
103 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +0000104 GLuint n, GLint x, GLint y,
Brian Paule4b23562005-05-04 20:11:35 +0000105 const void *values, const GLubyte mask[] )
Keith Whitwell93a45882003-08-06 18:12:22 +0000106{
107 HW_WRITE_LOCK()
108 {
Brian Paule4b23562005-05-04 20:11:35 +0000109 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
Keith Whitwell93a45882003-08-06 18:12:22 +0000110 GLint x1;
111 GLint n1;
112 LOCAL_VARS;
113
114 y = Y_FLIP(y);
115
116 HW_WRITE_CLIPLOOP()
117 {
118 GLint i = 0;
119 CLIPSPAN(x,y,n,x1,n1,i);
120
121 if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
122 (int)i, (int)n1, (int)x1);
123
124 if (mask)
125 {
126 for (;n1>0;i++,x1++,n1--)
127 if (mask[i])
128 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
129 }
130 else
131 {
132 for (;n1>0;i++,x1++,n1--)
133 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
134 }
135 }
136 HW_ENDCLIPLOOP();
137 }
138 HW_WRITE_UNLOCK();
139}
140
Brian Paule4b23562005-05-04 20:11:35 +0000141static void TAG(WriteRGBAPixels)( GLcontext *ctx,
142 struct gl_renderbuffer *rb,
143 GLuint n, const GLint x[], const GLint y[],
144 const void *values, const GLubyte mask[] )
Keith Whitwell93a45882003-08-06 18:12:22 +0000145{
146 HW_WRITE_LOCK()
147 {
Brian Paule4b23562005-05-04 20:11:35 +0000148 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
Dave Airlie8d12a6d2005-02-14 09:27:38 +0000149 GLuint i;
Keith Whitwell93a45882003-08-06 18:12:22 +0000150 LOCAL_VARS;
151
152 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
153
154 HW_WRITE_CLIPLOOP()
155 {
Brian Paul328a0392004-09-24 14:30:13 +0000156 if (mask)
Keith Whitwell93a45882003-08-06 18:12:22 +0000157 {
Brian Paul328a0392004-09-24 14:30:13 +0000158 for (i=0;i<n;i++)
159 {
160 if (mask[i]) {
161 const int fy = Y_FLIP(y[i]);
162 if (CLIPPIXEL(x[i],fy))
163 WRITE_RGBA( x[i], fy,
164 rgba[i][0], rgba[i][1],
165 rgba[i][2], rgba[i][3] );
166 }
167 }
168 }
169 else
170 {
171 for (i=0;i<n;i++)
172 {
Keith Whitwell93a45882003-08-06 18:12:22 +0000173 const int fy = Y_FLIP(y[i]);
174 if (CLIPPIXEL(x[i],fy))
175 WRITE_RGBA( x[i], fy,
176 rgba[i][0], rgba[i][1],
177 rgba[i][2], rgba[i][3] );
Brian Paul328a0392004-09-24 14:30:13 +0000178 }
Keith Whitwell93a45882003-08-06 18:12:22 +0000179 }
180 }
181 HW_ENDCLIPLOOP();
182 }
183 HW_WRITE_UNLOCK();
184}
185
186
Brian Paule4b23562005-05-04 20:11:35 +0000187static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,
188 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +0000189 GLuint n, GLint x, GLint y,
Brian Paule4b23562005-05-04 20:11:35 +0000190 const void *value,
Keith Whitwell93a45882003-08-06 18:12:22 +0000191 const GLubyte mask[] )
192{
193 HW_WRITE_LOCK()
194 {
Brian Paule4b23562005-05-04 20:11:35 +0000195 const GLubyte *color = (const GLubyte *) value;
Keith Whitwell93a45882003-08-06 18:12:22 +0000196 GLint x1;
197 GLint n1;
198 LOCAL_VARS;
199 INIT_MONO_PIXEL(p, color);
200
201 y = Y_FLIP( y );
202
203 if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
204
205 HW_WRITE_CLIPLOOP()
206 {
207 GLint i = 0;
208 CLIPSPAN(x,y,n,x1,n1,i);
Brian Paul328a0392004-09-24 14:30:13 +0000209 if (mask)
210 {
211 for (;n1>0;i++,x1++,n1--)
212 if (mask[i])
213 WRITE_PIXEL( x1, y, p );
214 }
215 else
216 {
217 for (;n1>0;i++,x1++,n1--)
Keith Whitwell93a45882003-08-06 18:12:22 +0000218 WRITE_PIXEL( x1, y, p );
Brian Paul328a0392004-09-24 14:30:13 +0000219 }
Keith Whitwell93a45882003-08-06 18:12:22 +0000220 }
221 HW_ENDCLIPLOOP();
222 }
223 HW_WRITE_UNLOCK();
224}
225
226
Brian Paule4b23562005-05-04 20:11:35 +0000227static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
228 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +0000229 GLuint n,
Brian Paule4b23562005-05-04 20:11:35 +0000230 const GLint x[], const GLint y[],
231 const void *value,
232 const GLubyte mask[] )
Keith Whitwell93a45882003-08-06 18:12:22 +0000233{
234 HW_WRITE_LOCK()
235 {
Brian Paule4b23562005-05-04 20:11:35 +0000236 const GLubyte *color = (const GLubyte *) value;
Dave Airlie8d12a6d2005-02-14 09:27:38 +0000237 GLuint i;
Keith Whitwell93a45882003-08-06 18:12:22 +0000238 LOCAL_VARS;
239 INIT_MONO_PIXEL(p, color);
240
241 if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
242
243 HW_WRITE_CLIPLOOP()
244 {
Brian Paul328a0392004-09-24 14:30:13 +0000245 if (mask)
246 {
247 for (i=0;i<n;i++)
248 if (mask[i]) {
249 int fy = Y_FLIP(y[i]);
250 if (CLIPPIXEL( x[i], fy ))
251 WRITE_PIXEL( x[i], fy, p );
252 }
253 }
254 else
255 {
256 for (i=0;i<n;i++) {
Keith Whitwell93a45882003-08-06 18:12:22 +0000257 int fy = Y_FLIP(y[i]);
258 if (CLIPPIXEL( x[i], fy ))
259 WRITE_PIXEL( x[i], fy, p );
260 }
Brian Paul328a0392004-09-24 14:30:13 +0000261 }
Keith Whitwell93a45882003-08-06 18:12:22 +0000262 }
263 HW_ENDCLIPLOOP();
264 }
265 HW_WRITE_UNLOCK();
266}
267
268
Brian Paule4b23562005-05-04 20:11:35 +0000269static void TAG(ReadRGBASpan)( GLcontext *ctx,
270 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +0000271 GLuint n, GLint x, GLint y,
Brian Paule4b23562005-05-04 20:11:35 +0000272 void *values)
Keith Whitwell93a45882003-08-06 18:12:22 +0000273{
274 HW_READ_LOCK()
275 {
Brian Paule4b23562005-05-04 20:11:35 +0000276 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
Keith Whitwell93a45882003-08-06 18:12:22 +0000277 GLint x1,n1;
278 LOCAL_VARS;
279
280 y = Y_FLIP(y);
281
282 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
283
284 HW_READ_CLIPLOOP()
285 {
286 GLint i = 0;
287 CLIPSPAN(x,y,n,x1,n1,i);
288 for (;n1>0;i++,x1++,n1--)
289 READ_RGBA( rgba[i], x1, y );
290 }
291 HW_ENDCLIPLOOP();
292 }
293 HW_READ_UNLOCK();
294}
295
296
Brian Paule4b23562005-05-04 20:11:35 +0000297static void TAG(ReadRGBAPixels)( GLcontext *ctx,
298 struct gl_renderbuffer *rb,
Keith Whitwell93a45882003-08-06 18:12:22 +0000299 GLuint n, const GLint x[], const GLint y[],
Brian Paule4b23562005-05-04 20:11:35 +0000300 void *values )
Keith Whitwell93a45882003-08-06 18:12:22 +0000301{
302 HW_READ_LOCK()
303 {
Brian Paule4b23562005-05-04 20:11:35 +0000304 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
305 const GLubyte *mask = NULL; /* remove someday */
Dave Airlie8d12a6d2005-02-14 09:27:38 +0000306 GLuint i;
Keith Whitwell93a45882003-08-06 18:12:22 +0000307 LOCAL_VARS;
308
309 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
310
311 HW_READ_CLIPLOOP()
312 {
Brian Paul328a0392004-09-24 14:30:13 +0000313 if (mask)
314 {
315 for (i=0;i<n;i++)
316 if (mask[i]) {
317 int fy = Y_FLIP( y[i] );
318 if (CLIPPIXEL( x[i], fy ))
319 READ_RGBA( rgba[i], x[i], fy );
320 }
321 }
322 else
323 {
324 for (i=0;i<n;i++) {
Keith Whitwell93a45882003-08-06 18:12:22 +0000325 int fy = Y_FLIP( y[i] );
326 if (CLIPPIXEL( x[i], fy ))
327 READ_RGBA( rgba[i], x[i], fy );
328 }
Brian Paul328a0392004-09-24 14:30:13 +0000329 }
Keith Whitwell93a45882003-08-06 18:12:22 +0000330 }
331 HW_ENDCLIPLOOP();
332 }
333 HW_READ_UNLOCK();
334}
335
336
337
338
339#undef WRITE_PIXEL
340#undef WRITE_RGBA
341#undef READ_RGBA
342#undef TAG