1 /* $Id: texutil_tmp.h,v 1.8 2001/04/20 19:21:41 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 teximage code is untested and most definitely broken...
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)
42 /* =============================================================
43 * PRE: No pixelstore attribs, width == dstImageWidth.
46 TAG(texsubimage2d
)( struct gl_texture_convert
*convert
)
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
);
53 (void) dwords
; (void) i
;
56 fprintf( stderr
, __FUNCTION__
"\n" );
60 MEMCPY( dst
, src
, convert
->height
* DST_ROW_WIDTH
);
62 dwords
= (convert
->width
* convert
->height
+
63 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
65 for ( i
= 0 ; i
< dwords
; i
++ ) {
66 CONVERT_TEXEL_DWORD( *dst
++, src
);
67 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
74 /* PRE: As above, height == dstImageHeight also.
77 TAG(texsubimage3d
)( struct gl_texture_convert
*convert
)
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
);
85 (void) dwords
; (void) i
;
88 fprintf( stderr
, __FUNCTION__
"\n" );
92 MEMCPY( dst
, src
, convert
->depth
* convert
->height
* DST_ROW_WIDTH
);
94 dwords
= (convert
->width
* convert
->height
* convert
->depth
+
95 DST_TEXELS_PER_DWORD
- 1) / DST_TEXELS_PER_DWORD
;
97 for ( i
= 0 ; i
< dwords
; i
++ ) {
98 CONVERT_TEXEL_DWORD( *dst
++, src
);
99 src
+= SRC_TEXEL_BYTES
* DST_TEXELS_PER_DWORD
;
108 /* =============================================================
109 * PRE: No pixelstore attribs, width != dstImageWidth.
112 TAG(texsubimage2d_stride
)( struct gl_texture_convert
*convert
)
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
);
121 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
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
;
142 /* PRE: As above, or height != dstImageHeight also.
145 TAG(texsubimage3d_stride
)( struct gl_texture_convert
*convert
)
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
);
155 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
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
;
181 /* =============================================================
182 * PRE: Require pixelstore attribs, width == dstImageWidth.
185 TAG(texsubimage2d_pack
)( struct gl_texture_convert
*convert
)
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
);
202 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 CONVERT_TEXEL_DWORD( *dst
++, 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" );
250 width
= ((convert
->width
+ DST_TEXELS_PER_DWORD
- 1)
251 & ~(DST_TEXELS_PER_DWORD
- 1));
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
);
258 dst
= (GLuint
*)((GLubyte
*)dst
+ DST_ROW_STRIDE
);
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
;
265 src
= srcRow
+ srcRowStride
;
275 /* =============================================================
276 * PRE: Require pixelstore attribs, width != dstImageWidth.
279 TAG(texsubimage2d_stride_pack
)( struct gl_texture_convert
*convert
)
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
);
295 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
305 for ( row
= 0 ; row
< convert
->height
; row
++ ) {
306 #ifdef CONVERT_DIRECT
307 MEMCPY( dst
, src
, DST_ROW_WIDTH
);
309 dst
+= convert
->dstImageWidth
;
311 const GLubyte
*srcRow
= src
;
312 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
313 CONVERT_TEXEL( *dst
++, src
);
314 src
+= SRC_TEXEL_BYTES
;
316 src
= srcRow
+ srcRowStride
;
324 /* PRE: As above, or height != dstImageHeight also.
327 TAG(texsubimage3d_stride_pack
)( struct gl_texture_convert
*convert
)
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
);
344 adjust
= convert
->dstImageWidth
- convert
->width
;
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
);
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
);
359 dst
+= convert
->dstImageWidth
;
361 const GLubyte
*srcRow
= src
;
362 for ( col
= 0 ; col
< convert
->width
; col
++ ) {
363 CONVERT_TEXEL( *dst
++, src
);
364 src
+= SRC_TEXEL_BYTES
;
366 src
= srcRow
+ srcRowStride
;
378 static convert_func
TAG(texsubimage2d_tab
)[] = {
380 TAG(texsubimage2d_stride
),
381 TAG(texsubimage2d_pack
),
382 TAG(texsubimage2d_stride_pack
),
385 static convert_func
TAG(texsubimage3d_tab
)[] = {
387 TAG(texsubimage3d_stride
),
388 TAG(texsubimage3d_pack
),
389 TAG(texsubimage3d_stride_pack
),
393 #ifndef PRESERVE_DST_TYPE
395 #undef DST_TEXELS_PER_DWORD
398 #undef SRC_TEXEL_BYTES
399 #undef DST_TEXEL_BYTES
401 #undef DST_ROW_STRIDE
404 #undef CONVERT_TEXEL_DWORD
405 #undef CONVERT_DIRECT
409 #undef PRESERVE_DST_TYPE