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