Minor fixes for Win32 (Karl Schultz).
[mesa.git] / src / mesa / main / texutil_tmp.h
1 /* $Id: texutil_tmp.h,v 1.8 2001/04/20 19:21:41 brianp 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 teximage code is untested and most definitely broken...
32 */
33
34
35 #define DST_TEXEL_BYTES (4 / DST_TEXELS_PER_DWORD)
36 #define DST_ROW_WIDTH (convert->width * DST_TEXEL_BYTES)
37 #define DST_ROW_STRIDE (convert->dstImageWidth * DST_TEXEL_BYTES)
38 #define DST_IMG_STRIDE (convert->dstImageWidth * \
39 convert->dstImageHeight * DST_TEXEL_BYTES)
40
41
42 /* =============================================================
43 * PRE: No pixelstore attribs, width == dstImageWidth.
44 */
45 static GLboolean
46 TAG(texsubimage2d)( struct gl_texture_convert *convert )
47 {
48 const GLubyte *src = (const GLubyte *)convert->srcImage;
49 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
50 (convert->yoffset * convert->dstImageWidth +
51 convert->xoffset) * DST_TEXEL_BYTES);
52 GLint dwords, i;
53 (void) dwords; (void) i;
54
55 #if DEBUG_TEXUTIL
56 fprintf( stderr, __FUNCTION__ "\n" );
57 #endif
58
59 #ifdef CONVERT_DIRECT
60 MEMCPY( dst, src, convert->height * DST_ROW_WIDTH );
61 #else
62 dwords = (convert->width * convert->height +
63 DST_TEXELS_PER_DWORD - 1) / DST_TEXELS_PER_DWORD;
64
65 for ( i = 0 ; i < dwords ; i++ ) {
66 CONVERT_TEXEL_DWORD( *dst++, src );
67 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
68 }
69 #endif
70
71 return GL_TRUE;
72 }
73
74 /* PRE: As above, height == dstImageHeight also.
75 */
76 static GLboolean
77 TAG(texsubimage3d)( struct gl_texture_convert *convert )
78 {
79 const GLubyte *src = (const GLubyte *)convert->srcImage;
80 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
81 ((convert->zoffset * convert->height +
82 convert->yoffset) * convert->width +
83 convert->xoffset) * DST_TEXEL_BYTES);
84 GLint dwords, i;
85 (void) dwords; (void) i;
86
87 #if DEBUG_TEXUTIL
88 fprintf( stderr, __FUNCTION__ "\n" );
89 #endif
90
91 #ifdef CONVERT_DIRECT
92 MEMCPY( dst, src, convert->depth * convert->height * DST_ROW_WIDTH );
93 #else
94 dwords = (convert->width * convert->height * convert->depth +
95 DST_TEXELS_PER_DWORD - 1) / DST_TEXELS_PER_DWORD;
96
97 for ( i = 0 ; i < dwords ; i++ ) {
98 CONVERT_TEXEL_DWORD( *dst++, src );
99 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
100 }
101 #endif
102
103 return GL_TRUE;
104 }
105
106
107
108 /* =============================================================
109 * PRE: No pixelstore attribs, width != dstImageWidth.
110 */
111 static GLboolean
112 TAG(texsubimage2d_stride)( struct gl_texture_convert *convert )
113 {
114 const GLubyte *src = (const GLubyte *)convert->srcImage;
115 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
116 (convert->yoffset * convert->dstImageWidth +
117 convert->xoffset) * DST_TEXEL_BYTES);
118 GLint adjust;
119 GLint row, col;
120
121 adjust = convert->dstImageWidth - convert->width;
122
123 #if DEBUG_TEXUTIL
124 fprintf( stderr, __FUNCTION__ ":\n" );
125 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
126 convert->xoffset, convert->yoffset, convert->width,
127 convert->height, convert->dstImageWidth );
128 fprintf( stderr, " adjust=%d\n", adjust );
129 #endif
130
131 for ( row = 0 ; row < convert->height ; row++ ) {
132 for ( col = 0 ; col < convert->width ; col++ ) {
133 CONVERT_TEXEL( *dst++, src );
134 src += SRC_TEXEL_BYTES;
135 }
136 dst += adjust;
137 }
138
139 return GL_TRUE;
140 }
141
142 /* PRE: As above, or height != dstImageHeight also.
143 */
144 static GLboolean
145 TAG(texsubimage3d_stride)( struct gl_texture_convert *convert )
146 {
147 const GLubyte *src = (const GLubyte *)convert->srcImage;
148 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
149 ((convert->zoffset * convert->dstImageHeight +
150 convert->yoffset) * convert->dstImageWidth +
151 convert->xoffset) * DST_TEXEL_BYTES);
152 GLint adjust;
153 GLint row, col, img;
154
155 adjust = convert->dstImageWidth - convert->width;
156
157 #if DEBUG_TEXUTIL
158 fprintf( stderr, __FUNCTION__ ":\n" );
159 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
160 convert->xoffset, convert->yoffset, convert->width,
161 convert->height, convert->dstImageWidth );
162 fprintf( stderr, " adjust=%d\n", adjust );
163 #endif
164
165 for ( img = 0 ; img < convert->depth ; img++ ) {
166 for ( row = 0 ; row < convert->height ; row++ ) {
167 for ( col = 0 ; col < convert->width ; col++ ) {
168 CONVERT_TEXEL( *dst++, src );
169 src += SRC_TEXEL_BYTES;
170 }
171 dst += adjust;
172 }
173 /* FIXME: ... */
174 }
175
176 return GL_TRUE;
177 }
178
179
180
181 /* =============================================================
182 * PRE: Require pixelstore attribs, width == dstImageWidth.
183 */
184 static GLboolean
185 TAG(texsubimage2d_pack)( struct gl_texture_convert *convert )
186 {
187 const GLubyte *src = (const GLubyte *)
188 _mesa_image_address( convert->packing, convert->srcImage,
189 convert->width, convert->height,
190 convert->format, convert->type, 0, 0, 0 );
191 const GLint srcRowStride =
192 _mesa_image_row_stride( convert->packing, convert->width,
193 convert->format, convert->type );
194 GLuint *dst = (GLuint *)((GLubyte *)convert->dstImage +
195 (convert->yoffset * convert->width +
196 convert->xoffset) * DST_TEXEL_BYTES);
197 GLint width;
198 GLint row, col;
199 (void) col;
200
201 #if DEBUG_TEXUTIL
202 fprintf( stderr, __FUNCTION__ "\n" );
203 #endif
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 DEBUG_TEXUTIL
247 fprintf( stderr, __FUNCTION__ "\n" );
248 #endif
249
250 width = ((convert->width + DST_TEXELS_PER_DWORD - 1)
251 & ~(DST_TEXELS_PER_DWORD - 1));
252
253 for ( img = 0 ; img < convert->depth ; img++ ) {
254 for ( row = 0 ; row < convert->height ; row++ ) {
255 #ifdef CONVERT_DIRECT
256 MEMCPY( dst, src, DST_ROW_STRIDE );
257 src += srcRowStride;
258 dst = (GLuint *)((GLubyte *)dst + DST_ROW_STRIDE);
259 #else
260 const GLubyte *srcRow = src;
261 for ( col = width / DST_TEXELS_PER_DWORD ; col ; col-- ) {
262 CONVERT_TEXEL_DWORD( *dst++, src );
263 src += SRC_TEXEL_BYTES * DST_TEXELS_PER_DWORD;
264 }
265 src = srcRow + srcRowStride;
266 #endif
267 }
268 }
269
270 return GL_TRUE;
271 }
272
273
274
275 /* =============================================================
276 * PRE: Require pixelstore attribs, width != dstImageWidth.
277 */
278 static GLboolean
279 TAG(texsubimage2d_stride_pack)( struct gl_texture_convert *convert )
280 {
281 const GLubyte *src = (const GLubyte *)
282 _mesa_image_address( convert->packing, convert->srcImage,
283 convert->width, convert->height,
284 convert->format, convert->type, 0, 0, 0 );
285 const GLint srcRowStride =
286 _mesa_image_row_stride( convert->packing, convert->width,
287 convert->format, convert->type );
288 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
289 (convert->yoffset * convert->dstImageWidth +
290 convert->xoffset) * DST_TEXEL_BYTES);
291 GLint adjust;
292 GLint row, col;
293 (void) col;
294
295 adjust = convert->dstImageWidth - convert->width;
296
297 #if DEBUG_TEXUTIL
298 fprintf( stderr, __FUNCTION__ ":\n" );
299 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
300 convert->xoffset, convert->yoffset, convert->width,
301 convert->height, convert->dstImageWidth );
302 fprintf( stderr, " adjust=%d\n", adjust );
303 #endif
304
305 for ( row = 0 ; row < convert->height ; row++ ) {
306 #ifdef CONVERT_DIRECT
307 MEMCPY( dst, src, DST_ROW_WIDTH );
308 src += srcRowStride;
309 dst += convert->dstImageWidth;
310 #else
311 const GLubyte *srcRow = src;
312 for ( col = 0 ; col < convert->width ; col++ ) {
313 CONVERT_TEXEL( *dst++, src );
314 src += SRC_TEXEL_BYTES;
315 }
316 src = srcRow + srcRowStride;
317 dst += adjust;
318 #endif
319 }
320
321 return GL_TRUE;
322 }
323
324 /* PRE: As above, or height != dstImageHeight also.
325 */
326 static GLboolean
327 TAG(texsubimage3d_stride_pack)( struct gl_texture_convert *convert )
328 {
329 const GLubyte *src = (const GLubyte *)
330 _mesa_image_address( convert->packing, convert->srcImage,
331 convert->width, convert->height,
332 convert->format, convert->type, 0, 0, 0 );
333 const GLint srcRowStride =
334 _mesa_image_row_stride( convert->packing, convert->width,
335 convert->format, convert->type );
336 DST_TYPE *dst = (DST_TYPE *)((GLubyte *)convert->dstImage +
337 ((convert->zoffset * convert->dstImageHeight +
338 convert->yoffset) * convert->dstImageWidth +
339 convert->xoffset) * DST_TEXEL_BYTES);
340 GLint adjust;
341 GLint row, col, img;
342 (void) col;
343
344 adjust = convert->dstImageWidth - convert->width;
345
346 #if DEBUG_TEXUTIL
347 fprintf( stderr, __FUNCTION__ ":\n" );
348 fprintf( stderr, " x=%d y=%d w=%d h=%d s=%d\n",
349 convert->xoffset, convert->yoffset, convert->width,
350 convert->height, convert->dstImageWidth );
351 fprintf( stderr, " adjust=%d\n", adjust );
352 #endif
353
354 for ( img = 0 ; img < convert->depth ; img++ ) {
355 for ( row = 0 ; row < convert->height ; row++ ) {
356 #ifdef CONVERT_DIRECT
357 MEMCPY( dst, src, DST_ROW_WIDTH );
358 src += srcRowStride;
359 dst += convert->dstImageWidth;
360 #else
361 const GLubyte *srcRow = src;
362 for ( col = 0 ; col < convert->width ; col++ ) {
363 CONVERT_TEXEL( *dst++, src );
364 src += SRC_TEXEL_BYTES;
365 }
366 src = srcRow + srcRowStride;
367 dst += adjust;
368 #endif
369 }
370 /* FIXME: ... */
371 }
372
373 return GL_TRUE;
374 }
375
376
377
378 static convert_func TAG(texsubimage2d_tab)[] = {
379 TAG(texsubimage2d),
380 TAG(texsubimage2d_stride),
381 TAG(texsubimage2d_pack),
382 TAG(texsubimage2d_stride_pack),
383 };
384
385 static convert_func TAG(texsubimage3d_tab)[] = {
386 TAG(texsubimage3d),
387 TAG(texsubimage3d_stride),
388 TAG(texsubimage3d_pack),
389 TAG(texsubimage3d_stride_pack),
390 };
391
392
393 #ifndef PRESERVE_DST_TYPE
394 #undef DST_TYPE
395 #undef DST_TEXELS_PER_DWORD
396 #endif
397
398 #undef SRC_TEXEL_BYTES
399 #undef DST_TEXEL_BYTES
400 #undef DST_ROW_WIDTH
401 #undef DST_ROW_STRIDE
402
403 #undef CONVERT_TEXEL
404 #undef CONVERT_TEXEL_DWORD
405 #undef CONVERT_DIRECT
406
407 #undef TAG
408
409 #undef PRESERVE_DST_TYPE