Remove all traces of CULL_MASK_ACTIVE.
[mesa.git] / src / mesa / main / texutil_tmp.h
1 /* $Id: texutil_tmp.h,v 1.7 2001/03/30 14:44:43 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 *
26 * Author:
27 * Gareth Hughes <gareth@valinux.com>
28 */
29
30 /*
31 * NOTE: All 3D code is untested and most definitely broken...
32 */
33
34 #ifdef VMS
35 #define __FUNCTION__
36 #endif
37
38 #define DST_TEXEL_BYTES (4 / DST_TEXELS_PER_DWORD)
39 #define DST_ROW_WIDTH (convert->width * DST_TEXEL_BYTES)
40 #define DST_ROW_STRIDE (convert->dstImageWidth * DST_TEXEL_BYTES)
41 #define DST_IMG_STRIDE (convert->dstImageWidth * \
42 convert->dstImageHeight * DST_TEXEL_BYTES)
43
44
45 /* =============================================================
46 * PRE: No pixelstore attribs, width == dstImageWidth.
47 */
48 static GLboolean
49 TAG(texsubimage2d)( struct gl_texture_convert *convert )
50 {
51 const GLubyte *src = (const GLubyte *)convert->srcImage;
52 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
53 (convert->yoffset * convert->dstImageWidth +
54 convert->xoffset) * DST_TEXEL_BYTES);
55 GLint dwords, i;
56 (void) dwords; (void) i;
57
58 if ( DBG )
59 fprintf( stderr, __FUNCTION__ "\n" );
60
61 #ifdef CONVERT_DIRECT
62 MEMCPY( dst, src, convert->height * DST_ROW_WIDTH );
63 #else
64 dwords = (convert->width * convert->height +
65 DST_TEXELS_PER_DWORD - 1) / DST_TEXELS_PER_DWORD;
66
67 for ( i = 0 ; i < dwords ; i++ ) {
68 CONVERT_TEXEL_DWORD( *dst++, src );
69 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
70 }
71 #endif
72
73 return GL_TRUE;
74 }
75
76 /* PRE: As above, height == dstImageHeight also.
77 */
78 static GLboolean
79 TAG(texsubimage3d)( struct gl_texture_convert *convert )
80 {
81 const GLubyte *src = (const GLubyte *)convert->srcImage;
82 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
83 ((convert->zoffset * convert->height +
84 convert->yoffset) * convert->width +
85 convert->xoffset) * DST_TEXEL_BYTES);
86 GLint dwords, i;
87 (void) dwords; (void) i;
88
89 if ( DBG )
90 fprintf( stderr, __FUNCTION__ "\n" );
91
92 #ifdef CONVERT_DIRECT
93 MEMCPY( dst, src, convert->depth * convert->height * DST_ROW_WIDTH );
94 #else
95 dwords = (convert->width * convert->height * convert->depth +
96 DST_TEXELS_PER_DWORD - 1) / DST_TEXELS_PER_DWORD;
97
98 for ( i = 0 ; i < dwords ; i++ ) {
99 CONVERT_TEXEL_DWORD( *dst++, src );
100 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
101 }
102 #endif
103
104 return GL_TRUE;
105 }
106
107
108
109 /* =============================================================
110 * PRE: No pixelstore attribs, width != dstImageWidth.
111 */
112 static GLboolean
113 TAG(texsubimage2d_stride)( struct gl_texture_convert *convert )
114 {
115 const GLubyte *src = (const GLubyte *)convert->srcImage;
116 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
117 (convert->yoffset * convert->dstImageWidth +
118 convert->xoffset) * DST_TEXEL_BYTES);
119 GLint adjust;
120 GLint row, col;
121
122 adjust = convert->dstImageWidth - convert->width;
123
124 if ( DBG ) {
125 fprintf( stderr, __FUNCTION__ ":\n" );
126 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
127 convert->xoffset, convert->yoffset, convert->width,
128 convert->height, convert->dstImageWidth );
129 fprintf( stderr, " adjust=%d\n", adjust );
130 }
131
132 for ( row = 0 ; row < convert->height ; row++ ) {
133 for ( col = 0 ; col < convert->width ; col++ ) {
134 CONVERT_TEXEL( *dst++, src );
135 src += SRC_TEXEL_BYTES;
136 }
137 dst += adjust;
138 }
139
140 return GL_TRUE;
141 }
142
143 /* PRE: As above, or height != dstImageHeight also.
144 */
145 static GLboolean
146 TAG(texsubimage3d_stride)( struct gl_texture_convert *convert )
147 {
148 const GLubyte *src = (const GLubyte *)convert->srcImage;
149 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
150 ((convert->zoffset * convert->dstImageHeight +
151 convert->yoffset) * convert->dstImageWidth +
152 convert->xoffset) * DST_TEXEL_BYTES);
153 GLint adjust;
154 GLint row, col, img;
155
156 adjust = convert->dstImageWidth - convert->width;
157
158 if ( DBG ) {
159 fprintf( stderr, __FUNCTION__ ":\n" );
160 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
161 convert->xoffset, convert->yoffset, convert->width,
162 convert->height, convert->dstImageWidth );
163 fprintf( stderr, " adjust=%d\n", adjust );
164 }
165
166 for ( img = 0 ; img < convert->depth ; img++ ) {
167 for ( row = 0 ; row < convert->height ; row++ ) {
168 for ( col = 0 ; col < convert->width ; col++ ) {
169 CONVERT_TEXEL( *dst++, src );
170 src += SRC_TEXEL_BYTES;
171 }
172 dst += adjust;
173 }
174 /* FIXME: ... */
175 }
176
177 return GL_TRUE;
178 }
179
180
181
182 /* =============================================================
183 * PRE: Require pixelstore attribs, width == dstImageWidth.
184 */
185 static GLboolean
186 TAG(texsubimage2d_pack)( struct gl_texture_convert *convert )
187 {
188 const GLubyte *src = (const GLubyte *)
189 _mesa_image_address( convert->packing, convert->srcImage,
190 convert->width, convert->height,
191 convert->format, convert->type, 0, 0, 0 );
192 const GLint srcRowStride =
193 _mesa_image_row_stride( convert->packing, convert->width,
194 convert->format, convert->type );
195 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
196 (convert->yoffset * convert->width +
197 convert->xoffset) * DST_TEXEL_BYTES);
198 GLint width;
199 GLint row, col;
200 (void) col;
201
202 if ( DBG )
203 fprintf( stderr, __FUNCTION__ "\n" );
204
205 width = ((convert->width + DST_TEXELS_PER_DWORD - 1)
206 & ~(DST_TEXELS_PER_DWORD - 1));
207
208 for ( row = 0 ; row < convert->height ; row++ ) {
209 #ifdef CONVERT_DIRECT
210 MEMCPY( dst, src, DST_ROW_STRIDE );
211 src += srcRowStride;
212 dst = (GLuint *)((GLubyte *)dst + DST_ROW_STRIDE);
213 #else
214 const GLubyte *srcRow = src;
215 for ( col = width / DST_TEXELS_PER_DWORD ; col ; col-- ) {
216 CONVERT_TEXEL_DWORD( *dst++, src );
217 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
218 }
219 src = srcRow + srcRowStride;
220 #endif
221 }
222
223 return GL_TRUE;
224 }
225
226 /* PRE: as above, height == dstImageHeight also.
227 */
228 static GLboolean
229 TAG(texsubimage3d_pack)( struct gl_texture_convert *convert )
230 {
231 const GLubyte *src = (const GLubyte *)
232 _mesa_image_address( convert->packing, convert->srcImage,
233 convert->width, convert->height,
234 convert->format, convert->type, 0, 0, 0 );
235 const GLint srcRowStride =
236 _mesa_image_row_stride( convert->packing, convert->width,
237 convert->format, convert->type );
238 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
239 ((convert->zoffset * convert->height +
240 convert->yoffset) * convert->width +
241 convert->xoffset) * DST_TEXEL_BYTES);
242 GLint width;
243 GLint row, col, img;
244 (void) col;
245
246 if ( DBG )
247 fprintf( stderr, __FUNCTION__ "\n" );
248
249 width = ((convert->width + DST_TEXELS_PER_DWORD - 1)
250 & ~(DST_TEXELS_PER_DWORD - 1));
251
252 for ( img = 0 ; img < convert->depth ; img++ ) {
253 for ( row = 0 ; row < convert->height ; row++ ) {
254 #ifdef CONVERT_DIRECT
255 MEMCPY( dst, src, DST_ROW_STRIDE );
256 src += srcRowStride;
257 dst = (GLuint *)((GLubyte *)dst + DST_ROW_STRIDE);
258 #else
259 const GLubyte *srcRow = src;
260 for ( col = width / DST_TEXELS_PER_DWORD ; col ; col-- ) {
261 CONVERT_TEXEL_DWORD( *dst++, src );
262 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
263 }
264 src = srcRow + srcRowStride;
265 #endif
266 }
267 }
268
269 return GL_TRUE;
270 }
271
272
273
274 /* =============================================================
275 * PRE: Require pixelstore attribs, width != dstImageWidth.
276 */
277 static GLboolean
278 TAG(texsubimage2d_stride_pack)( struct gl_texture_convert *convert )
279 {
280 const GLubyte *src = (const GLubyte *)
281 _mesa_image_address( convert->packing, convert->srcImage,
282 convert->width, convert->height,
283 convert->format, convert->type, 0, 0, 0 );
284 const GLint srcRowStride =
285 _mesa_image_row_stride( convert->packing, convert->width,
286 convert->format, convert->type );
287 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
288 (convert->yoffset * convert->dstImageWidth +
289 convert->xoffset) * DST_TEXEL_BYTES);
290 GLint adjust;
291 GLint row, col;
292 (void) col;
293
294 adjust = convert->dstImageWidth - convert->width;
295
296 if ( DBG ) {
297 fprintf( stderr, __FUNCTION__ ":\n" );
298 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
299 convert->xoffset, convert->yoffset, convert->width,
300 convert->height, convert->dstImageWidth );
301 fprintf( stderr, " adjust=%d\n", adjust );
302 }
303
304 for ( row = 0 ; row < convert->height ; row++ ) {
305 #ifdef CONVERT_DIRECT
306 MEMCPY( dst, src, DST_ROW_WIDTH );
307 src += srcRowStride;
308 dst += convert->dstImageWidth;
309 #else
310 const GLubyte *srcRow = src;
311 for ( col = 0 ; col < convert->width ; col++ ) {
312 CONVERT_TEXEL( *dst++, src );
313 src += SRC_TEXEL_BYTES;
314 }
315 src = srcRow + srcRowStride;
316 dst += adjust;
317 #endif
318 }
319
320 return GL_TRUE;
321 }
322
323 /* PRE: As above, or height != dstImageHeight also.
324 */
325 static GLboolean
326 TAG(texsubimage3d_stride_pack)( struct gl_texture_convert *convert )
327 {
328 const GLubyte *src = (const GLubyte *)
329 _mesa_image_address( convert->packing, convert->srcImage,
330 convert->width, convert->height,
331 convert->format, convert->type, 0, 0, 0 );
332 const GLint srcRowStride =
333 _mesa_image_row_stride( convert->packing, convert->width,
334 convert->format, convert->type );
335 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
336 ((convert->zoffset * convert->dstImageHeight +
337 convert->yoffset) * convert->dstImageWidth +
338 convert->xoffset) * DST_TEXEL_BYTES);
339 GLint adjust;
340 GLint row, col, img;
341 (void) col;
342
343 adjust = convert->dstImageWidth - convert->width;
344
345 if ( DBG ) {
346 fprintf( stderr, __FUNCTION__ ":\n" );
347 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
348 convert->xoffset, convert->yoffset, convert->width,
349 convert->height, convert->dstImageWidth );
350 fprintf( stderr, " adjust=%d\n", adjust );
351 }
352
353 for ( img = 0 ; img < convert->depth ; img++ ) {
354 for ( row = 0 ; row < convert->height ; row++ ) {
355 #ifdef CONVERT_DIRECT
356 MEMCPY( dst, src, DST_ROW_WIDTH );
357 src += srcRowStride;
358 dst += convert->dstImageWidth;
359 #else
360 const GLubyte *srcRow = src;
361 for ( col = 0 ; col < convert->width ; col++ ) {
362 CONVERT_TEXEL( *dst++, src );
363 src += SRC_TEXEL_BYTES;
364 }
365 src = srcRow + srcRowStride;
366 dst += adjust;
367 #endif
368 }
369 /* FIXME: ... */
370 }
371
372 return GL_TRUE;
373 }
374
375
376
377 static convert_func TAG(texsubimage2d_tab)[] = {
378 TAG(texsubimage2d),
379 TAG(texsubimage2d_stride),
380 TAG(texsubimage2d_pack),
381 TAG(texsubimage2d_stride_pack),
382 };
383
384 static convert_func TAG(texsubimage3d_tab)[] = {
385 TAG(texsubimage3d),
386 TAG(texsubimage3d_stride),
387 TAG(texsubimage3d_pack),
388 TAG(texsubimage3d_stride_pack),
389 };
390
391
392 #ifndef PRESERVE_DST_TYPE
393 #undef DST_TYPE
394 #undef DST_TEXELS_PER_DWORD
395 #endif
396
397 #undef SRC_TEXEL_BYTES
398 #undef DST_TEXEL_BYTES
399 #undef DST_ROW_WIDTH
400 #undef DST_ROW_STRIDE
401
402 #undef CONVERT_TEXEL
403 #undef CONVERT_TEXEL_DWORD
404 #undef CONVERT_DIRECT
405
406 #undef TAG
407
408 #undef PRESERVE_DST_TYPE