1 /* $Id: texutil_tmp.h,v 1.5 2001/03/21 16:44:08 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Gareth Hughes <gareth@valinux.com>
31 * NOTE: All 3D code is untested and most definitely broken...
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)
45 /* ================================================================
46 * PRE: No pixelstore attribs, width == dstImageWidth.
49 TAG(texsubimage2d
)( struct gl_texture_convert
*convert
)
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
);
56 (void) dwords
; (void) i
;
59 fprintf( stderr
, __FUNCTION__
"\n" );
62 MEMCPY( dst
, src
, convert
->height
* DST_ROW_WIDTH
);
64 dwords
= (convert
->width
* convert
->height
+
65 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
67 for ( i
= 0 ; i
< dwords
; i
++ ) {
68 *dst
++ = CONVERT_TEXEL_DWORD( src
);
69 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
76 /* PRE: As above, height == dstImageHeight also.
79 TAG(texsubimage3d
)( struct gl_texture_convert
*convert
)
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
);
87 (void) dwords
; (void) i
;
90 fprintf( stderr
, __FUNCTION__
"\n" );
93 MEMCPY( dst
, src
, convert
->depth
* convert
->height
* DST_ROW_WIDTH
);
95 dwords
= (convert
->width
* convert
->height
* convert
->depth
+
96 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
98 for ( i
= 0 ; i
< dwords
; i
++ ) {
99 *dst
++ = CONVERT_TEXEL_DWORD( src
);
100 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
109 /* ================================================================
110 * PRE: No pixelstore attribs, width != dstImageWidth.
113 TAG(texsubimage2d_stride
)( struct gl_texture_convert
*convert
)
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
);
122 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
132 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
133 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
134 *dst
++ = CONVERT_TEXEL( src
);
135 src
+= SRC_TEXEL_BYTES
;
143 /* PRE: As above, or height != dstImageHeight also.
146 TAG(texsubimage3d_stride
)( struct gl_texture_convert
*convert
)
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
);
156 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
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 *dst
++ = CONVERT_TEXEL( src
);
170 src
+= SRC_TEXEL_BYTES
;
182 /* ================================================================
183 * PRE: Require pixelstore attribs, width == dstImageWidth.
186 TAG(texsubimage2d_pack
)( struct gl_texture_convert
*convert
)
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
);
203 fprintf( stderr
, __FUNCTION__
"\n" );
205 width
= ((convert
->width
+ DST_TEXELS_PER_DWORD
- 1)
206 & ~(DST_TEXELS_PER_DWORD
- 1));
208 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
209 #ifdef CONVERT_DIRECT
210 MEMCPY( dst
, src
, DST_ROW_STRIDE
);
212 dst
= (GLuint
*)((GLubyte
*)dst
+ DST_ROW_STRIDE
);
214 const GLubyte
*srcRow
= src
;
215 for ( col
= width
/ DST_TEXELS_PER_DWORD
; col
; col
-- ) {
216 *dst
++ = CONVERT_TEXEL_DWORD( src
);
217 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
219 src
= srcRow
+ srcRowStride
;
226 /* PRE: as above, height == dstImageHeight also.
229 TAG(texsubimage3d_pack
)( struct gl_texture_convert
*convert
)
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
);
247 fprintf( stderr
, __FUNCTION__
"\n" );
249 width
= ((convert
->width
+ DST_TEXELS_PER_DWORD
- 1)
250 & ~(DST_TEXELS_PER_DWORD
- 1));
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
);
257 dst
= (GLuint
*)((GLubyte
*)dst
+ DST_ROW_STRIDE
);
259 const GLubyte
*srcRow
= src
;
260 for ( col
= width
/ DST_TEXELS_PER_DWORD
; col
; col
-- ) {
261 *dst
++ = CONVERT_TEXEL_DWORD( src
);
262 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
264 src
= srcRow
+ srcRowStride
;
274 /* ================================================================
275 * PRE: Require pixelstore attribs, width != dstImageWidth.
278 TAG(texsubimage2d_stride_pack
)( struct gl_texture_convert
*convert
)
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
);
294 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
304 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
305 #ifdef CONVERT_DIRECT
306 MEMCPY( dst
, src
, DST_ROW_WIDTH
);
308 dst
+= convert
->dstImageWidth
;
310 const GLubyte
*srcRow
= src
;
311 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
312 *dst
++ = CONVERT_TEXEL( src
);
313 src
+= SRC_TEXEL_BYTES
;
315 src
= srcRow
+ srcRowStride
;
323 /* PRE: As above, or height != dstImageHeight also.
326 TAG(texsubimage3d_stride_pack
)( struct gl_texture_convert
*convert
)
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
);
343 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
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
);
358 dst
+= convert
->dstImageWidth
;
360 const GLubyte
*srcRow
= src
;
361 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
362 *dst
++ = CONVERT_TEXEL( src
);
363 src
+= SRC_TEXEL_BYTES
;
365 src
= srcRow
+ srcRowStride
;
377 static convert_func
TAG(texsubimage2d_tab
)[] = {
379 TAG(texsubimage2d_stride
),
380 TAG(texsubimage2d_pack
),
381 TAG(texsubimage2d_stride_pack
),
384 static convert_func
TAG(texsubimage3d_tab
)[] = {
386 TAG(texsubimage3d_stride
),
387 TAG(texsubimage3d_pack
),
388 TAG(texsubimage3d_stride_pack
),
392 #ifndef PRESERVE_DST_TYPE
394 #undef DST_TEXELS_PER_DWORD
397 #undef SRC_TEXEL_BYTES
398 #undef DST_TEXEL_BYTES
400 #undef DST_ROW_STRIDE
403 #undef CONVERT_TEXEL_DWORD
404 #undef CONVERT_DIRECT
408 #undef PRESERVE_DST_TYPE