mesa: implement new texture format A16
[mesa.git] / src / mesa / main / texstore.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /*
27 * Authors:
28 * Brian Paul
29 */
30
31 /**
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
35 * texture image data.
36 *
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
39 * code:
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
43 * etc...
44 *
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
47 * pixel unpacking
48 * pixel transfer (scale, bais, lookup, etc)
49 *
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
52 */
53
54
55 #include "glheader.h"
56 #include "bufferobj.h"
57 #include "colormac.h"
58 #include "image.h"
59 #include "macros.h"
60 #include "mipmap.h"
61 #include "pack.h"
62 #include "imports.h"
63 #include "pack.h"
64 #include "texcompress.h"
65 #include "texcompress_fxt1.h"
66 #include "texcompress_s3tc.h"
67 #include "teximage.h"
68 #include "texstore.h"
69 #include "enums.h"
70
71
72 enum {
73 ZERO = 4,
74 ONE = 5
75 };
76
77
78 /**
79 * Texture image storage function.
80 */
81 typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
82
83
84 /**
85 * Return GL_TRUE if the given image format is one that be converted
86 * to another format by swizzling.
87 */
88 static GLboolean
89 can_swizzle(GLenum logicalBaseFormat)
90 {
91 switch (logicalBaseFormat) {
92 case GL_RGBA:
93 case GL_RGB:
94 case GL_LUMINANCE_ALPHA:
95 case GL_INTENSITY:
96 case GL_ALPHA:
97 case GL_LUMINANCE:
98 case GL_RED:
99 case GL_GREEN:
100 case GL_BLUE:
101 case GL_BGR:
102 case GL_BGRA:
103 case GL_ABGR_EXT:
104 case GL_RG:
105 return GL_TRUE;
106 default:
107 return GL_FALSE;
108 }
109 }
110
111
112
113 enum {
114 IDX_LUMINANCE = 0,
115 IDX_ALPHA,
116 IDX_INTENSITY,
117 IDX_LUMINANCE_ALPHA,
118 IDX_RGB,
119 IDX_RGBA,
120 IDX_RED,
121 IDX_GREEN,
122 IDX_BLUE,
123 IDX_BGR,
124 IDX_BGRA,
125 IDX_ABGR,
126 IDX_RG,
127 MAX_IDX
128 };
129
130 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
131 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
132 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
133 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
134
135
136 static const struct {
137 GLubyte format_idx;
138 GLubyte to_rgba[6];
139 GLubyte from_rgba[6];
140 } mappings[MAX_IDX] =
141 {
142 {
143 IDX_LUMINANCE,
144 MAP4(0,0,0,ONE),
145 MAP1(0)
146 },
147
148 {
149 IDX_ALPHA,
150 MAP4(ZERO, ZERO, ZERO, 0),
151 MAP1(3)
152 },
153
154 {
155 IDX_INTENSITY,
156 MAP4(0, 0, 0, 0),
157 MAP1(0),
158 },
159
160 {
161 IDX_LUMINANCE_ALPHA,
162 MAP4(0,0,0,1),
163 MAP2(0,3)
164 },
165
166 {
167 IDX_RGB,
168 MAP4(0,1,2,ONE),
169 MAP3(0,1,2)
170 },
171
172 {
173 IDX_RGBA,
174 MAP4(0,1,2,3),
175 MAP4(0,1,2,3),
176 },
177
178 {
179 IDX_RED,
180 MAP4(0, ZERO, ZERO, ONE),
181 MAP1(0),
182 },
183
184 {
185 IDX_GREEN,
186 MAP4(ZERO, 0, ZERO, ONE),
187 MAP1(1),
188 },
189
190 {
191 IDX_BLUE,
192 MAP4(ZERO, ZERO, 0, ONE),
193 MAP1(2),
194 },
195
196 {
197 IDX_BGR,
198 MAP4(2,1,0,ONE),
199 MAP3(2,1,0)
200 },
201
202 {
203 IDX_BGRA,
204 MAP4(2,1,0,3),
205 MAP4(2,1,0,3)
206 },
207
208 {
209 IDX_ABGR,
210 MAP4(3,2,1,0),
211 MAP4(3,2,1,0)
212 },
213
214 {
215 IDX_RG,
216 MAP4(0, 1, ZERO, ONE),
217 MAP2(0, 1)
218 },
219 };
220
221
222
223 /**
224 * Convert a GL image format enum to an IDX_* value (see above).
225 */
226 static int
227 get_map_idx(GLenum value)
228 {
229 switch (value) {
230 case GL_LUMINANCE: return IDX_LUMINANCE;
231 case GL_ALPHA: return IDX_ALPHA;
232 case GL_INTENSITY: return IDX_INTENSITY;
233 case GL_LUMINANCE_ALPHA: return IDX_LUMINANCE_ALPHA;
234 case GL_RGB: return IDX_RGB;
235 case GL_RGBA: return IDX_RGBA;
236 case GL_RED: return IDX_RED;
237 case GL_GREEN: return IDX_GREEN;
238 case GL_BLUE: return IDX_BLUE;
239 case GL_BGR: return IDX_BGR;
240 case GL_BGRA: return IDX_BGRA;
241 case GL_ABGR_EXT: return IDX_ABGR;
242 case GL_RG: return IDX_RG;
243 default:
244 _mesa_problem(NULL, "Unexpected inFormat");
245 return 0;
246 }
247 }
248
249
250 /**
251 * When promoting texture formats (see below) we need to compute the
252 * mapping of dest components back to source components.
253 * This function does that.
254 * \param inFormat the incoming format of the texture
255 * \param outFormat the final texture format
256 * \return map[6] a full 6-component map
257 */
258 static void
259 compute_component_mapping(GLenum inFormat, GLenum outFormat,
260 GLubyte *map)
261 {
262 const int inFmt = get_map_idx(inFormat);
263 const int outFmt = get_map_idx(outFormat);
264 const GLubyte *in2rgba = mappings[inFmt].to_rgba;
265 const GLubyte *rgba2out = mappings[outFmt].from_rgba;
266 int i;
267
268 for (i = 0; i < 4; i++)
269 map[i] = in2rgba[rgba2out[i]];
270
271 map[ZERO] = ZERO;
272 map[ONE] = ONE;
273
274 #if 0
275 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
276 inFormat, _mesa_lookup_enum_by_nr(inFormat),
277 outFormat, _mesa_lookup_enum_by_nr(outFormat),
278 map[0],
279 map[1],
280 map[2],
281 map[3],
282 map[4],
283 map[5]);
284 #endif
285 }
286
287
288 /**
289 * Make a temporary (color) texture image with GLfloat components.
290 * Apply all needed pixel unpacking and pixel transfer operations.
291 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
292 * Suppose the user specifies GL_LUMINANCE as the internal texture format
293 * but the graphics hardware doesn't support luminance textures. So, we might
294 * use an RGB hardware format instead.
295 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
296 *
297 * \param ctx the rendering context
298 * \param dims image dimensions: 1, 2 or 3
299 * \param logicalBaseFormat basic texture derived from the user's
300 * internal texture format value
301 * \param textureBaseFormat the actual basic format of the texture
302 * \param srcWidth source image width
303 * \param srcHeight source image height
304 * \param srcDepth source image depth
305 * \param srcFormat source image format
306 * \param srcType source image type
307 * \param srcAddr source image address
308 * \param srcPacking source image pixel packing
309 * \return resulting image with format = textureBaseFormat and type = GLfloat.
310 */
311 static GLfloat *
312 make_temp_float_image(struct gl_context *ctx, GLuint dims,
313 GLenum logicalBaseFormat,
314 GLenum textureBaseFormat,
315 GLint srcWidth, GLint srcHeight, GLint srcDepth,
316 GLenum srcFormat, GLenum srcType,
317 const GLvoid *srcAddr,
318 const struct gl_pixelstore_attrib *srcPacking,
319 GLbitfield transferOps)
320 {
321 GLfloat *tempImage;
322 const GLint components = _mesa_components_in_format(logicalBaseFormat);
323 const GLint srcStride =
324 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
325 GLfloat *dst;
326 GLint img, row;
327
328 ASSERT(dims >= 1 && dims <= 3);
329
330 ASSERT(logicalBaseFormat == GL_RGBA ||
331 logicalBaseFormat == GL_RGB ||
332 logicalBaseFormat == GL_RG ||
333 logicalBaseFormat == GL_RED ||
334 logicalBaseFormat == GL_LUMINANCE_ALPHA ||
335 logicalBaseFormat == GL_LUMINANCE ||
336 logicalBaseFormat == GL_ALPHA ||
337 logicalBaseFormat == GL_INTENSITY ||
338 logicalBaseFormat == GL_COLOR_INDEX ||
339 logicalBaseFormat == GL_DEPTH_COMPONENT);
340
341 ASSERT(textureBaseFormat == GL_RGBA ||
342 textureBaseFormat == GL_RGB ||
343 textureBaseFormat == GL_RG ||
344 textureBaseFormat == GL_RED ||
345 textureBaseFormat == GL_LUMINANCE_ALPHA ||
346 textureBaseFormat == GL_LUMINANCE ||
347 textureBaseFormat == GL_ALPHA ||
348 textureBaseFormat == GL_INTENSITY ||
349 textureBaseFormat == GL_COLOR_INDEX ||
350 textureBaseFormat == GL_DEPTH_COMPONENT);
351
352 tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
353 * components * sizeof(GLfloat));
354 if (!tempImage)
355 return NULL;
356
357 dst = tempImage;
358 for (img = 0; img < srcDepth; img++) {
359 const GLubyte *src
360 = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
361 srcWidth, srcHeight,
362 srcFormat, srcType,
363 img, 0, 0);
364 for (row = 0; row < srcHeight; row++) {
365 _mesa_unpack_color_span_float(ctx, srcWidth, logicalBaseFormat,
366 dst, srcFormat, srcType, src,
367 srcPacking, transferOps);
368 dst += srcWidth * components;
369 src += srcStride;
370 }
371 }
372
373 if (logicalBaseFormat != textureBaseFormat) {
374 /* more work */
375 GLint texComponents = _mesa_components_in_format(textureBaseFormat);
376 GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
377 GLfloat *newImage;
378 GLint i, n;
379 GLubyte map[6];
380
381 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
382 ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
383 textureBaseFormat == GL_LUMINANCE_ALPHA);
384
385 /* The actual texture format should have at least as many components
386 * as the logical texture format.
387 */
388 ASSERT(texComponents >= logComponents);
389
390 newImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
391 * texComponents * sizeof(GLfloat));
392 if (!newImage) {
393 free(tempImage);
394 return NULL;
395 }
396
397 compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
398
399 n = srcWidth * srcHeight * srcDepth;
400 for (i = 0; i < n; i++) {
401 GLint k;
402 for (k = 0; k < texComponents; k++) {
403 GLint j = map[k];
404 if (j == ZERO)
405 newImage[i * texComponents + k] = 0.0F;
406 else if (j == ONE)
407 newImage[i * texComponents + k] = 1.0F;
408 else
409 newImage[i * texComponents + k] = tempImage[i * logComponents + j];
410 }
411 }
412
413 free(tempImage);
414 tempImage = newImage;
415 }
416
417 return tempImage;
418 }
419
420
421 /**
422 * Make temporary image with uint pixel values. Used for unsigned
423 * integer-valued textures.
424 */
425 static GLuint *
426 make_temp_uint_image(struct gl_context *ctx, GLuint dims,
427 GLenum logicalBaseFormat,
428 GLenum textureBaseFormat,
429 GLint srcWidth, GLint srcHeight, GLint srcDepth,
430 GLenum srcFormat, GLenum srcType,
431 const GLvoid *srcAddr,
432 const struct gl_pixelstore_attrib *srcPacking)
433 {
434 GLuint *tempImage;
435 const GLint components = _mesa_components_in_format(logicalBaseFormat);
436 const GLint srcStride =
437 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
438 GLuint *dst;
439 GLint img, row;
440
441 ASSERT(dims >= 1 && dims <= 3);
442
443 ASSERT(logicalBaseFormat == GL_RGBA ||
444 logicalBaseFormat == GL_RGB ||
445 logicalBaseFormat == GL_RG ||
446 logicalBaseFormat == GL_RED ||
447 logicalBaseFormat == GL_LUMINANCE_ALPHA ||
448 logicalBaseFormat == GL_LUMINANCE ||
449 logicalBaseFormat == GL_INTENSITY ||
450 logicalBaseFormat == GL_ALPHA);
451
452 ASSERT(textureBaseFormat == GL_RGBA ||
453 textureBaseFormat == GL_RGB ||
454 textureBaseFormat == GL_RG ||
455 textureBaseFormat == GL_RED ||
456 textureBaseFormat == GL_LUMINANCE_ALPHA ||
457 textureBaseFormat == GL_LUMINANCE ||
458 textureBaseFormat == GL_ALPHA);
459
460 tempImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
461 * components * sizeof(GLuint));
462 if (!tempImage)
463 return NULL;
464
465 dst = tempImage;
466 for (img = 0; img < srcDepth; img++) {
467 const GLubyte *src
468 = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
469 srcWidth, srcHeight,
470 srcFormat, srcType,
471 img, 0, 0);
472 for (row = 0; row < srcHeight; row++) {
473 _mesa_unpack_color_span_uint(ctx, srcWidth, logicalBaseFormat,
474 dst, srcFormat, srcType, src,
475 srcPacking);
476 dst += srcWidth * components;
477 src += srcStride;
478 }
479 }
480
481 if (logicalBaseFormat != textureBaseFormat) {
482 /* more work */
483 GLint texComponents = _mesa_components_in_format(textureBaseFormat);
484 GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
485 GLuint *newImage;
486 GLint i, n;
487 GLubyte map[6];
488
489 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
490 ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
491 textureBaseFormat == GL_LUMINANCE_ALPHA);
492
493 /* The actual texture format should have at least as many components
494 * as the logical texture format.
495 */
496 ASSERT(texComponents >= logComponents);
497
498 newImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
499 * texComponents * sizeof(GLuint));
500 if (!newImage) {
501 free(tempImage);
502 return NULL;
503 }
504
505 compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
506
507 n = srcWidth * srcHeight * srcDepth;
508 for (i = 0; i < n; i++) {
509 GLint k;
510 for (k = 0; k < texComponents; k++) {
511 GLint j = map[k];
512 if (j == ZERO)
513 newImage[i * texComponents + k] = 0.0F;
514 else if (j == ONE)
515 newImage[i * texComponents + k] = 1.0F;
516 else
517 newImage[i * texComponents + k] = tempImage[i * logComponents + j];
518 }
519 }
520
521 free(tempImage);
522 tempImage = newImage;
523 }
524
525 return tempImage;
526 }
527
528
529
530 /**
531 * Make a temporary (color) texture image with GLchan components.
532 * Apply all needed pixel unpacking and pixel transfer operations.
533 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
534 * Suppose the user specifies GL_LUMINANCE as the internal texture format
535 * but the graphics hardware doesn't support luminance textures. So, we might
536 * use an RGB hardware format instead.
537 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
538 *
539 * \param ctx the rendering context
540 * \param dims image dimensions: 1, 2 or 3
541 * \param logicalBaseFormat basic texture derived from the user's
542 * internal texture format value
543 * \param textureBaseFormat the actual basic format of the texture
544 * \param srcWidth source image width
545 * \param srcHeight source image height
546 * \param srcDepth source image depth
547 * \param srcFormat source image format
548 * \param srcType source image type
549 * \param srcAddr source image address
550 * \param srcPacking source image pixel packing
551 * \return resulting image with format = textureBaseFormat and type = GLchan.
552 */
553 GLchan *
554 _mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
555 GLenum logicalBaseFormat,
556 GLenum textureBaseFormat,
557 GLint srcWidth, GLint srcHeight, GLint srcDepth,
558 GLenum srcFormat, GLenum srcType,
559 const GLvoid *srcAddr,
560 const struct gl_pixelstore_attrib *srcPacking)
561 {
562 GLuint transferOps = ctx->_ImageTransferState;
563 const GLint components = _mesa_components_in_format(logicalBaseFormat);
564 GLint img, row;
565 GLchan *tempImage, *dst;
566
567 ASSERT(dims >= 1 && dims <= 3);
568
569 ASSERT(logicalBaseFormat == GL_RGBA ||
570 logicalBaseFormat == GL_RGB ||
571 logicalBaseFormat == GL_RG ||
572 logicalBaseFormat == GL_RED ||
573 logicalBaseFormat == GL_LUMINANCE_ALPHA ||
574 logicalBaseFormat == GL_LUMINANCE ||
575 logicalBaseFormat == GL_ALPHA ||
576 logicalBaseFormat == GL_INTENSITY);
577
578 ASSERT(textureBaseFormat == GL_RGBA ||
579 textureBaseFormat == GL_RGB ||
580 textureBaseFormat == GL_RG ||
581 textureBaseFormat == GL_RED ||
582 textureBaseFormat == GL_LUMINANCE_ALPHA ||
583 textureBaseFormat == GL_LUMINANCE ||
584 textureBaseFormat == GL_ALPHA ||
585 textureBaseFormat == GL_INTENSITY);
586
587 /* unpack and transfer the source image */
588 tempImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
589 * components * sizeof(GLchan));
590 if (!tempImage) {
591 return NULL;
592 }
593
594 dst = tempImage;
595 for (img = 0; img < srcDepth; img++) {
596 const GLint srcStride =
597 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
598 const GLubyte *src =
599 (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
600 srcWidth, srcHeight,
601 srcFormat, srcType,
602 img, 0, 0);
603 for (row = 0; row < srcHeight; row++) {
604 _mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,
605 srcFormat, srcType, src, srcPacking,
606 transferOps);
607 dst += srcWidth * components;
608 src += srcStride;
609 }
610 }
611
612 if (logicalBaseFormat != textureBaseFormat) {
613 /* one more conversion step */
614 GLint texComponents = _mesa_components_in_format(textureBaseFormat);
615 GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
616 GLchan *newImage;
617 GLint i, n;
618 GLubyte map[6];
619
620 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
621 ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
622 textureBaseFormat == GL_LUMINANCE_ALPHA);
623
624 /* The actual texture format should have at least as many components
625 * as the logical texture format.
626 */
627 ASSERT(texComponents >= logComponents);
628
629 newImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
630 * texComponents * sizeof(GLchan));
631 if (!newImage) {
632 free(tempImage);
633 return NULL;
634 }
635
636 compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
637
638 n = srcWidth * srcHeight * srcDepth;
639 for (i = 0; i < n; i++) {
640 GLint k;
641 for (k = 0; k < texComponents; k++) {
642 GLint j = map[k];
643 if (j == ZERO)
644 newImage[i * texComponents + k] = 0;
645 else if (j == ONE)
646 newImage[i * texComponents + k] = CHAN_MAX;
647 else
648 newImage[i * texComponents + k] = tempImage[i * logComponents + j];
649 }
650 }
651
652 free(tempImage);
653 tempImage = newImage;
654 }
655
656 return tempImage;
657 }
658
659
660 /**
661 * Copy GLubyte pixels from <src> to <dst> with swizzling.
662 * \param dst destination pixels
663 * \param dstComponents number of color components in destination pixels
664 * \param src source pixels
665 * \param srcComponents number of color components in source pixels
666 * \param map the swizzle mapping. map[X] says where to find the X component
667 * in the source image's pixels. For example, if the source image
668 * is GL_BGRA and X = red, map[0] yields 2.
669 * \param count number of pixels to copy/swizzle.
670 */
671 static void
672 swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,
673 GLuint srcComponents, const GLubyte *map, GLuint count)
674 {
675 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
676 do { \
677 GLuint i; \
678 for (i = 0; i < count; i++) { \
679 GLuint j; \
680 if (srcComps == 4) { \
681 COPY_4UBV(tmp, src); \
682 } \
683 else { \
684 for (j = 0; j < srcComps; j++) { \
685 tmp[j] = src[j]; \
686 } \
687 } \
688 src += srcComps; \
689 for (j = 0; j < dstComps; j++) { \
690 dst[j] = tmp[map[j]]; \
691 } \
692 dst += dstComps; \
693 } \
694 } while (0)
695
696 GLubyte tmp[6];
697
698 tmp[ZERO] = 0x0;
699 tmp[ONE] = 0xff;
700
701 ASSERT(srcComponents <= 4);
702 ASSERT(dstComponents <= 4);
703
704 switch (dstComponents) {
705 case 4:
706 switch (srcComponents) {
707 case 4:
708 SWZ_CPY(dst, src, count, 4, 4);
709 break;
710 case 3:
711 SWZ_CPY(dst, src, count, 4, 3);
712 break;
713 case 2:
714 SWZ_CPY(dst, src, count, 4, 2);
715 break;
716 case 1:
717 SWZ_CPY(dst, src, count, 4, 1);
718 break;
719 default:
720 ;
721 }
722 break;
723 case 3:
724 switch (srcComponents) {
725 case 4:
726 SWZ_CPY(dst, src, count, 3, 4);
727 break;
728 case 3:
729 SWZ_CPY(dst, src, count, 3, 3);
730 break;
731 case 2:
732 SWZ_CPY(dst, src, count, 3, 2);
733 break;
734 case 1:
735 SWZ_CPY(dst, src, count, 3, 1);
736 break;
737 default:
738 ;
739 }
740 break;
741 case 2:
742 switch (srcComponents) {
743 case 4:
744 SWZ_CPY(dst, src, count, 2, 4);
745 break;
746 case 3:
747 SWZ_CPY(dst, src, count, 2, 3);
748 break;
749 case 2:
750 SWZ_CPY(dst, src, count, 2, 2);
751 break;
752 case 1:
753 SWZ_CPY(dst, src, count, 2, 1);
754 break;
755 default:
756 ;
757 }
758 break;
759 case 1:
760 switch (srcComponents) {
761 case 4:
762 SWZ_CPY(dst, src, count, 1, 4);
763 break;
764 case 3:
765 SWZ_CPY(dst, src, count, 1, 3);
766 break;
767 case 2:
768 SWZ_CPY(dst, src, count, 1, 2);
769 break;
770 case 1:
771 SWZ_CPY(dst, src, count, 1, 1);
772 break;
773 default:
774 ;
775 }
776 break;
777 default:
778 ;
779 }
780 #undef SWZ_CPY
781 }
782
783
784
785 static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };
786 static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };
787
788
789 /**
790 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
791 * mapping array depending on endianness.
792 */
793 static const GLubyte *
794 type_mapping( GLenum srcType )
795 {
796 switch (srcType) {
797 case GL_BYTE:
798 case GL_UNSIGNED_BYTE:
799 return map_identity;
800 case GL_UNSIGNED_INT_8_8_8_8:
801 return _mesa_little_endian() ? map_3210 : map_identity;
802 case GL_UNSIGNED_INT_8_8_8_8_REV:
803 return _mesa_little_endian() ? map_identity : map_3210;
804 default:
805 return NULL;
806 }
807 }
808
809
810 /**
811 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
812 * mapping array depending on pixelstore byte swapping state.
813 */
814 static const GLubyte *
815 byteswap_mapping( GLboolean swapBytes,
816 GLenum srcType )
817 {
818 if (!swapBytes)
819 return map_identity;
820
821 switch (srcType) {
822 case GL_BYTE:
823 case GL_UNSIGNED_BYTE:
824 return map_identity;
825 case GL_UNSIGNED_INT_8_8_8_8:
826 case GL_UNSIGNED_INT_8_8_8_8_REV:
827 return map_3210;
828 default:
829 return NULL;
830 }
831 }
832
833
834
835 /**
836 * Transfer a GLubyte texture image with component swizzling.
837 */
838 static void
839 _mesa_swizzle_ubyte_image(struct gl_context *ctx,
840 GLuint dimensions,
841 GLenum srcFormat,
842 GLenum srcType,
843
844 GLenum baseInternalFormat,
845
846 const GLubyte *rgba2dst,
847 GLuint dstComponents,
848
849 GLvoid *dstAddr,
850 GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
851 GLint dstRowStride,
852 const GLuint *dstImageOffsets,
853
854 GLint srcWidth, GLint srcHeight, GLint srcDepth,
855 const GLvoid *srcAddr,
856 const struct gl_pixelstore_attrib *srcPacking )
857 {
858 GLint srcComponents = _mesa_components_in_format(srcFormat);
859 const GLubyte *srctype2ubyte, *swap;
860 GLubyte map[4], src2base[6], base2rgba[6];
861 GLint i;
862 const GLint srcRowStride =
863 _mesa_image_row_stride(srcPacking, srcWidth,
864 srcFormat, GL_UNSIGNED_BYTE);
865 const GLint srcImageStride
866 = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat,
867 GL_UNSIGNED_BYTE);
868 const GLubyte *srcImage
869 = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr,
870 srcWidth, srcHeight, srcFormat,
871 GL_UNSIGNED_BYTE, 0, 0, 0);
872
873 (void) ctx;
874
875 /* Translate from src->baseInternal->GL_RGBA->dst. This will
876 * correctly deal with RGBA->RGB->RGBA conversions where the final
877 * A value must be 0xff regardless of the incoming alpha values.
878 */
879 compute_component_mapping(srcFormat, baseInternalFormat, src2base);
880 compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba);
881 swap = byteswap_mapping(srcPacking->SwapBytes, srcType);
882 srctype2ubyte = type_mapping(srcType);
883
884
885 for (i = 0; i < 4; i++)
886 map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];
887
888 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
889
890 if (srcComponents == dstComponents &&
891 srcRowStride == dstRowStride &&
892 srcRowStride == srcWidth * srcComponents &&
893 dimensions < 3) {
894 /* 1 and 2D images only */
895 GLubyte *dstImage = (GLubyte *) dstAddr
896 + dstYoffset * dstRowStride
897 + dstXoffset * dstComponents;
898 swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map,
899 srcWidth * srcHeight);
900 }
901 else {
902 GLint img, row;
903 for (img = 0; img < srcDepth; img++) {
904 const GLubyte *srcRow = srcImage;
905 GLubyte *dstRow = (GLubyte *) dstAddr
906 + dstImageOffsets[dstZoffset + img] * dstComponents
907 + dstYoffset * dstRowStride
908 + dstXoffset * dstComponents;
909 for (row = 0; row < srcHeight; row++) {
910 swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);
911 dstRow += dstRowStride;
912 srcRow += srcRowStride;
913 }
914 srcImage += srcImageStride;
915 }
916 }
917 }
918
919
920 /**
921 * Teximage storage routine for when a simple memcpy will do.
922 * No pixel transfer operations or special texel encodings allowed.
923 * 1D, 2D and 3D images supported.
924 */
925 static void
926 memcpy_texture(struct gl_context *ctx,
927 GLuint dimensions,
928 gl_format dstFormat,
929 GLvoid *dstAddr,
930 GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
931 GLint dstRowStride,
932 const GLuint *dstImageOffsets,
933 GLint srcWidth, GLint srcHeight, GLint srcDepth,
934 GLenum srcFormat, GLenum srcType,
935 const GLvoid *srcAddr,
936 const struct gl_pixelstore_attrib *srcPacking)
937 {
938 const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
939 srcFormat, srcType);
940 const GLint srcImageStride = _mesa_image_image_stride(srcPacking,
941 srcWidth, srcHeight, srcFormat, srcType);
942 const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
943 srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
944 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
945 const GLint bytesPerRow = srcWidth * texelBytes;
946
947 #if 0
948 /* XXX update/re-enable for dstImageOffsets array */
949 const GLint bytesPerImage = srcHeight * bytesPerRow;
950 const GLint bytesPerTexture = srcDepth * bytesPerImage;
951 GLubyte *dstImage = (GLubyte *) dstAddr
952 + dstZoffset * dstImageStride
953 + dstYoffset * dstRowStride
954 + dstXoffset * texelBytes;
955
956 if (dstRowStride == srcRowStride &&
957 dstRowStride == bytesPerRow &&
958 ((dstImageStride == srcImageStride &&
959 dstImageStride == bytesPerImage) ||
960 (srcDepth == 1))) {
961 /* one big memcpy */
962 ctx->Driver.TextureMemCpy(dstImage, srcImage, bytesPerTexture);
963 }
964 else
965 {
966 GLint img, row;
967 for (img = 0; img < srcDepth; img++) {
968 const GLubyte *srcRow = srcImage;
969 GLubyte *dstRow = dstImage;
970 for (row = 0; row < srcHeight; row++) {
971 ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
972 dstRow += dstRowStride;
973 srcRow += srcRowStride;
974 }
975 srcImage += srcImageStride;
976 dstImage += dstImageStride;
977 }
978 }
979 #endif
980
981 GLint img, row;
982 for (img = 0; img < srcDepth; img++) {
983 const GLubyte *srcRow = srcImage;
984 GLubyte *dstRow = (GLubyte *) dstAddr
985 + dstImageOffsets[dstZoffset + img] * texelBytes
986 + dstYoffset * dstRowStride
987 + dstXoffset * texelBytes;
988 for (row = 0; row < srcHeight; row++) {
989 ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
990 dstRow += dstRowStride;
991 srcRow += srcRowStride;
992 }
993 srcImage += srcImageStride;
994 }
995 }
996
997
998
999 /**
1000 * Store a 32-bit integer depth component texture image.
1001 */
1002 static GLboolean
1003 _mesa_texstore_z32(TEXSTORE_PARAMS)
1004 {
1005 const GLuint depthScale = 0xffffffff;
1006 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1007 (void) dims;
1008 ASSERT(dstFormat == MESA_FORMAT_Z32);
1009 ASSERT(texelBytes == sizeof(GLuint));
1010
1011 if (ctx->Pixel.DepthScale == 1.0f &&
1012 ctx->Pixel.DepthBias == 0.0f &&
1013 !srcPacking->SwapBytes &&
1014 baseInternalFormat == GL_DEPTH_COMPONENT &&
1015 srcFormat == GL_DEPTH_COMPONENT &&
1016 srcType == GL_UNSIGNED_INT) {
1017 /* simple memcpy path */
1018 memcpy_texture(ctx, dims,
1019 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1020 dstRowStride,
1021 dstImageOffsets,
1022 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1023 srcAddr, srcPacking);
1024 }
1025 else {
1026 /* general path */
1027 GLint img, row;
1028 for (img = 0; img < srcDepth; img++) {
1029 GLubyte *dstRow = (GLubyte *) dstAddr
1030 + dstImageOffsets[dstZoffset + img] * texelBytes
1031 + dstYoffset * dstRowStride
1032 + dstXoffset * texelBytes;
1033 for (row = 0; row < srcHeight; row++) {
1034 const GLvoid *src = _mesa_image_address(dims, srcPacking,
1035 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1036 _mesa_unpack_depth_span(ctx, srcWidth,
1037 GL_UNSIGNED_INT, (GLuint *) dstRow,
1038 depthScale, srcType, src, srcPacking);
1039 dstRow += dstRowStride;
1040 }
1041 }
1042 }
1043 return GL_TRUE;
1044 }
1045
1046
1047 /**
1048 * Store a 24-bit integer depth component texture image.
1049 */
1050 static GLboolean
1051 _mesa_texstore_x8_z24(TEXSTORE_PARAMS)
1052 {
1053 const GLuint depthScale = 0xffffff;
1054 const GLuint texelBytes = 4;
1055
1056 (void) dims;
1057 ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
1058
1059 {
1060 /* general path */
1061 GLint img, row;
1062 for (img = 0; img < srcDepth; img++) {
1063 GLubyte *dstRow = (GLubyte *) dstAddr
1064 + dstImageOffsets[dstZoffset + img] * texelBytes
1065 + dstYoffset * dstRowStride
1066 + dstXoffset * texelBytes;
1067 for (row = 0; row < srcHeight; row++) {
1068 const GLvoid *src = _mesa_image_address(dims, srcPacking,
1069 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1070 _mesa_unpack_depth_span(ctx, srcWidth,
1071 GL_UNSIGNED_INT, (GLuint *) dstRow,
1072 depthScale, srcType, src, srcPacking);
1073 dstRow += dstRowStride;
1074 }
1075 }
1076 }
1077 return GL_TRUE;
1078 }
1079
1080
1081 /**
1082 * Store a 24-bit integer depth component texture image.
1083 */
1084 static GLboolean
1085 _mesa_texstore_z24_x8(TEXSTORE_PARAMS)
1086 {
1087 const GLuint depthScale = 0xffffff;
1088 const GLuint texelBytes = 4;
1089
1090 (void) dims;
1091 ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
1092
1093 {
1094 /* general path */
1095 GLint img, row;
1096 for (img = 0; img < srcDepth; img++) {
1097 GLubyte *dstRow = (GLubyte *) dstAddr
1098 + dstImageOffsets[dstZoffset + img] * texelBytes
1099 + dstYoffset * dstRowStride
1100 + dstXoffset * texelBytes;
1101 for (row = 0; row < srcHeight; row++) {
1102 const GLvoid *src = _mesa_image_address(dims, srcPacking,
1103 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1104 GLuint *dst = (GLuint *) dstRow;
1105 GLint i;
1106 _mesa_unpack_depth_span(ctx, srcWidth,
1107 GL_UNSIGNED_INT, dst,
1108 depthScale, srcType, src, srcPacking);
1109 for (i = 0; i < srcWidth; i++)
1110 dst[i] <<= 8;
1111 dstRow += dstRowStride;
1112 }
1113 }
1114 }
1115 return GL_TRUE;
1116 }
1117
1118
1119 /**
1120 * Store a 16-bit integer depth component texture image.
1121 */
1122 static GLboolean
1123 _mesa_texstore_z16(TEXSTORE_PARAMS)
1124 {
1125 const GLuint depthScale = 0xffff;
1126 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1127 (void) dims;
1128 ASSERT(dstFormat == MESA_FORMAT_Z16);
1129 ASSERT(texelBytes == sizeof(GLushort));
1130
1131 if (ctx->Pixel.DepthScale == 1.0f &&
1132 ctx->Pixel.DepthBias == 0.0f &&
1133 !srcPacking->SwapBytes &&
1134 baseInternalFormat == GL_DEPTH_COMPONENT &&
1135 srcFormat == GL_DEPTH_COMPONENT &&
1136 srcType == GL_UNSIGNED_SHORT) {
1137 /* simple memcpy path */
1138 memcpy_texture(ctx, dims,
1139 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1140 dstRowStride,
1141 dstImageOffsets,
1142 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1143 srcAddr, srcPacking);
1144 }
1145 else {
1146 /* general path */
1147 GLint img, row;
1148 for (img = 0; img < srcDepth; img++) {
1149 GLubyte *dstRow = (GLubyte *) dstAddr
1150 + dstImageOffsets[dstZoffset + img] * texelBytes
1151 + dstYoffset * dstRowStride
1152 + dstXoffset * texelBytes;
1153 for (row = 0; row < srcHeight; row++) {
1154 const GLvoid *src = _mesa_image_address(dims, srcPacking,
1155 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1156 GLushort *dst16 = (GLushort *) dstRow;
1157 _mesa_unpack_depth_span(ctx, srcWidth,
1158 GL_UNSIGNED_SHORT, dst16, depthScale,
1159 srcType, src, srcPacking);
1160 dstRow += dstRowStride;
1161 }
1162 }
1163 }
1164 return GL_TRUE;
1165 }
1166
1167
1168 /**
1169 * Store an rgb565 or rgb565_rev texture image.
1170 */
1171 static GLboolean
1172 _mesa_texstore_rgb565(TEXSTORE_PARAMS)
1173 {
1174 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1175 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1176
1177 ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
1178 dstFormat == MESA_FORMAT_RGB565_REV);
1179 ASSERT(texelBytes == 2);
1180
1181 if (!ctx->_ImageTransferState &&
1182 !srcPacking->SwapBytes &&
1183 dstFormat == MESA_FORMAT_RGB565 &&
1184 baseInternalFormat == GL_RGB &&
1185 srcFormat == GL_RGB &&
1186 srcType == GL_UNSIGNED_SHORT_5_6_5) {
1187 /* simple memcpy path */
1188 memcpy_texture(ctx, dims,
1189 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1190 dstRowStride,
1191 dstImageOffsets,
1192 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1193 srcAddr, srcPacking);
1194 }
1195 else if (!ctx->_ImageTransferState &&
1196 !srcPacking->SwapBytes &&
1197 baseInternalFormat == GL_RGB &&
1198 srcFormat == GL_RGB &&
1199 srcType == GL_UNSIGNED_BYTE &&
1200 dims == 2) {
1201 /* do optimized tex store */
1202 const GLint srcRowStride =
1203 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1204 const GLubyte *src = (const GLubyte *)
1205 _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
1206 srcFormat, srcType, 0, 0, 0);
1207 GLubyte *dst = (GLubyte *) dstAddr
1208 + dstYoffset * dstRowStride
1209 + dstXoffset * texelBytes;
1210 GLint row, col;
1211 for (row = 0; row < srcHeight; row++) {
1212 const GLubyte *srcUB = (const GLubyte *) src;
1213 GLushort *dstUS = (GLushort *) dst;
1214 /* check for byteswapped format */
1215 if (dstFormat == MESA_FORMAT_RGB565) {
1216 for (col = 0; col < srcWidth; col++) {
1217 dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );
1218 srcUB += 3;
1219 }
1220 }
1221 else {
1222 for (col = 0; col < srcWidth; col++) {
1223 dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );
1224 srcUB += 3;
1225 }
1226 }
1227 dst += dstRowStride;
1228 src += srcRowStride;
1229 }
1230 }
1231 else {
1232 /* general path */
1233 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1234 baseInternalFormat,
1235 baseFormat,
1236 srcWidth, srcHeight, srcDepth,
1237 srcFormat, srcType, srcAddr,
1238 srcPacking);
1239 const GLchan *src = tempImage;
1240 GLint img, row, col;
1241 if (!tempImage)
1242 return GL_FALSE;
1243 for (img = 0; img < srcDepth; img++) {
1244 GLubyte *dstRow = (GLubyte *) dstAddr
1245 + dstImageOffsets[dstZoffset + img] * texelBytes
1246 + dstYoffset * dstRowStride
1247 + dstXoffset * texelBytes;
1248 for (row = 0; row < srcHeight; row++) {
1249 GLushort *dstUS = (GLushort *) dstRow;
1250 /* check for byteswapped format */
1251 if (dstFormat == MESA_FORMAT_RGB565) {
1252 for (col = 0; col < srcWidth; col++) {
1253 dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),
1254 CHAN_TO_UBYTE(src[GCOMP]),
1255 CHAN_TO_UBYTE(src[BCOMP]) );
1256 src += 3;
1257 }
1258 }
1259 else {
1260 for (col = 0; col < srcWidth; col++) {
1261 dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]),
1262 CHAN_TO_UBYTE(src[GCOMP]),
1263 CHAN_TO_UBYTE(src[BCOMP]) );
1264 src += 3;
1265 }
1266 }
1267 dstRow += dstRowStride;
1268 }
1269 }
1270 free((void *) tempImage);
1271 }
1272 return GL_TRUE;
1273 }
1274
1275
1276 /**
1277 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1278 */
1279 static GLboolean
1280 _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
1281 {
1282 const GLboolean littleEndian = _mesa_little_endian();
1283 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1284 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1285
1286 ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
1287 dstFormat == MESA_FORMAT_RGBA8888_REV);
1288 ASSERT(texelBytes == 4);
1289
1290 if (!ctx->_ImageTransferState &&
1291 !srcPacking->SwapBytes &&
1292 dstFormat == MESA_FORMAT_RGBA8888 &&
1293 baseInternalFormat == GL_RGBA &&
1294 ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
1295 (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
1296 (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
1297 (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
1298 /* simple memcpy path */
1299 memcpy_texture(ctx, dims,
1300 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1301 dstRowStride,
1302 dstImageOffsets,
1303 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1304 srcAddr, srcPacking);
1305 }
1306 else if (!ctx->_ImageTransferState &&
1307 !srcPacking->SwapBytes &&
1308 dstFormat == MESA_FORMAT_RGBA8888_REV &&
1309 baseInternalFormat == GL_RGBA &&
1310 ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
1311 (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
1312 (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
1313 (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
1314 /* simple memcpy path */
1315 memcpy_texture(ctx, dims,
1316 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1317 dstRowStride,
1318 dstImageOffsets,
1319 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1320 srcAddr, srcPacking);
1321 }
1322 else if (!ctx->_ImageTransferState &&
1323 (srcType == GL_UNSIGNED_BYTE ||
1324 srcType == GL_UNSIGNED_INT_8_8_8_8 ||
1325 srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
1326 can_swizzle(baseInternalFormat) &&
1327 can_swizzle(srcFormat)) {
1328
1329 GLubyte dstmap[4];
1330
1331 /* dstmap - how to swizzle from RGBA to dst format:
1332 */
1333 if ((littleEndian && dstFormat == MESA_FORMAT_RGBA8888) ||
1334 (!littleEndian && dstFormat == MESA_FORMAT_RGBA8888_REV)) {
1335 dstmap[3] = 0;
1336 dstmap[2] = 1;
1337 dstmap[1] = 2;
1338 dstmap[0] = 3;
1339 }
1340 else {
1341 dstmap[3] = 3;
1342 dstmap[2] = 2;
1343 dstmap[1] = 1;
1344 dstmap[0] = 0;
1345 }
1346
1347 _mesa_swizzle_ubyte_image(ctx, dims,
1348 srcFormat,
1349 srcType,
1350 baseInternalFormat,
1351 dstmap, 4,
1352 dstAddr, dstXoffset, dstYoffset, dstZoffset,
1353 dstRowStride, dstImageOffsets,
1354 srcWidth, srcHeight, srcDepth, srcAddr,
1355 srcPacking);
1356 }
1357 else {
1358 /* general path */
1359 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1360 baseInternalFormat,
1361 baseFormat,
1362 srcWidth, srcHeight, srcDepth,
1363 srcFormat, srcType, srcAddr,
1364 srcPacking);
1365 const GLchan *src = tempImage;
1366 GLint img, row, col;
1367 if (!tempImage)
1368 return GL_FALSE;
1369 for (img = 0; img < srcDepth; img++) {
1370 GLubyte *dstRow = (GLubyte *) dstAddr
1371 + dstImageOffsets[dstZoffset + img] * texelBytes
1372 + dstYoffset * dstRowStride
1373 + dstXoffset * texelBytes;
1374 for (row = 0; row < srcHeight; row++) {
1375 GLuint *dstUI = (GLuint *) dstRow;
1376 if (dstFormat == MESA_FORMAT_RGBA8888) {
1377 for (col = 0; col < srcWidth; col++) {
1378 dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),
1379 CHAN_TO_UBYTE(src[GCOMP]),
1380 CHAN_TO_UBYTE(src[BCOMP]),
1381 CHAN_TO_UBYTE(src[ACOMP]) );
1382 src += 4;
1383 }
1384 }
1385 else {
1386 for (col = 0; col < srcWidth; col++) {
1387 dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]),
1388 CHAN_TO_UBYTE(src[GCOMP]),
1389 CHAN_TO_UBYTE(src[BCOMP]),
1390 CHAN_TO_UBYTE(src[ACOMP]) );
1391 src += 4;
1392 }
1393 }
1394 dstRow += dstRowStride;
1395 }
1396 }
1397 free((void *) tempImage);
1398 }
1399 return GL_TRUE;
1400 }
1401
1402
1403 static GLboolean
1404 _mesa_texstore_argb8888(TEXSTORE_PARAMS)
1405 {
1406 const GLboolean littleEndian = _mesa_little_endian();
1407 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1408 const GLenum baseFormat = GL_RGBA;
1409
1410 ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
1411 dstFormat == MESA_FORMAT_ARGB8888_REV ||
1412 dstFormat == MESA_FORMAT_XRGB8888 ||
1413 dstFormat == MESA_FORMAT_XRGB8888_REV );
1414 ASSERT(texelBytes == 4);
1415
1416 if (!ctx->_ImageTransferState &&
1417 !srcPacking->SwapBytes &&
1418 (dstFormat == MESA_FORMAT_ARGB8888 ||
1419 dstFormat == MESA_FORMAT_XRGB8888) &&
1420 baseInternalFormat == GL_RGBA &&
1421 srcFormat == GL_BGRA &&
1422 ((srcType == GL_UNSIGNED_BYTE && littleEndian) ||
1423 srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {
1424 /* simple memcpy path (little endian) */
1425 memcpy_texture(ctx, dims,
1426 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1427 dstRowStride,
1428 dstImageOffsets,
1429 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1430 srcAddr, srcPacking);
1431 }
1432 else if (!ctx->_ImageTransferState &&
1433 !srcPacking->SwapBytes &&
1434 (dstFormat == MESA_FORMAT_ARGB8888_REV ||
1435 dstFormat == MESA_FORMAT_XRGB8888_REV) &&
1436 baseInternalFormat == GL_RGBA &&
1437 srcFormat == GL_BGRA &&
1438 ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
1439 srcType == GL_UNSIGNED_INT_8_8_8_8)) {
1440 /* simple memcpy path (big endian) */
1441 memcpy_texture(ctx, dims,
1442 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1443 dstRowStride,
1444 dstImageOffsets,
1445 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1446 srcAddr, srcPacking);
1447 }
1448 else if (!ctx->_ImageTransferState &&
1449 !srcPacking->SwapBytes &&
1450 (dstFormat == MESA_FORMAT_ARGB8888 ||
1451 dstFormat == MESA_FORMAT_XRGB8888) &&
1452 srcFormat == GL_RGB &&
1453 (baseInternalFormat == GL_RGBA ||
1454 baseInternalFormat == GL_RGB) &&
1455 srcType == GL_UNSIGNED_BYTE) {
1456 int img, row, col;
1457 for (img = 0; img < srcDepth; img++) {
1458 const GLint srcRowStride =
1459 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1460 GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1461 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1462 GLubyte *dstRow = (GLubyte *) dstAddr
1463 + dstImageOffsets[dstZoffset + img] * texelBytes
1464 + dstYoffset * dstRowStride
1465 + dstXoffset * texelBytes;
1466 for (row = 0; row < srcHeight; row++) {
1467 GLuint *d4 = (GLuint *) dstRow;
1468 for (col = 0; col < srcWidth; col++) {
1469 d4[col] = PACK_COLOR_8888(0xff,
1470 srcRow[col * 3 + RCOMP],
1471 srcRow[col * 3 + GCOMP],
1472 srcRow[col * 3 + BCOMP]);
1473 }
1474 dstRow += dstRowStride;
1475 srcRow += srcRowStride;
1476 }
1477 }
1478 }
1479 else if (!ctx->_ImageTransferState &&
1480 !srcPacking->SwapBytes &&
1481 dstFormat == MESA_FORMAT_ARGB8888 &&
1482 srcFormat == GL_RGBA &&
1483 baseInternalFormat == GL_RGBA &&
1484 srcType == GL_UNSIGNED_BYTE) {
1485 /* same as above case, but src data has alpha too */
1486 GLint img, row, col;
1487 /* For some reason, streaming copies to write-combined regions
1488 * are extremely sensitive to the characteristics of how the
1489 * source data is retrieved. By reordering the source reads to
1490 * be in-order, the speed of this operation increases by half.
1491 * Strangely the same isn't required for the RGB path, above.
1492 */
1493 for (img = 0; img < srcDepth; img++) {
1494 const GLint srcRowStride =
1495 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1496 GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1497 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1498 GLubyte *dstRow = (GLubyte *) dstAddr
1499 + dstImageOffsets[dstZoffset + img] * texelBytes
1500 + dstYoffset * dstRowStride
1501 + dstXoffset * texelBytes;
1502 for (row = 0; row < srcHeight; row++) {
1503 GLuint *d4 = (GLuint *) dstRow;
1504 for (col = 0; col < srcWidth; col++) {
1505 d4[col] = PACK_COLOR_8888(srcRow[col * 4 + ACOMP],
1506 srcRow[col * 4 + RCOMP],
1507 srcRow[col * 4 + GCOMP],
1508 srcRow[col * 4 + BCOMP]);
1509 }
1510 dstRow += dstRowStride;
1511 srcRow += srcRowStride;
1512 }
1513 }
1514 }
1515 else if (!ctx->_ImageTransferState &&
1516 (srcType == GL_UNSIGNED_BYTE ||
1517 srcType == GL_UNSIGNED_INT_8_8_8_8 ||
1518 srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
1519 can_swizzle(baseInternalFormat) &&
1520 can_swizzle(srcFormat)) {
1521
1522 GLubyte dstmap[4];
1523
1524 /* dstmap - how to swizzle from RGBA to dst format:
1525 */
1526 if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
1527 (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
1528 (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
1529 (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV)) {
1530 dstmap[3] = 3; /* alpha */
1531 dstmap[2] = 0; /* red */
1532 dstmap[1] = 1; /* green */
1533 dstmap[0] = 2; /* blue */
1534 }
1535 else {
1536 assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
1537 (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
1538 (littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV) ||
1539 (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
1540 dstmap[3] = 2;
1541 dstmap[2] = 1;
1542 dstmap[1] = 0;
1543 dstmap[0] = 3;
1544 }
1545
1546 _mesa_swizzle_ubyte_image(ctx, dims,
1547 srcFormat,
1548 srcType,
1549 baseInternalFormat,
1550 dstmap, 4,
1551 dstAddr, dstXoffset, dstYoffset, dstZoffset,
1552 dstRowStride,
1553 dstImageOffsets,
1554 srcWidth, srcHeight, srcDepth, srcAddr,
1555 srcPacking);
1556 }
1557 else {
1558 /* general path */
1559 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1560 baseInternalFormat,
1561 baseFormat,
1562 srcWidth, srcHeight, srcDepth,
1563 srcFormat, srcType, srcAddr,
1564 srcPacking);
1565 const GLchan *src = tempImage;
1566 GLint img, row, col;
1567 if (!tempImage)
1568 return GL_FALSE;
1569 for (img = 0; img < srcDepth; img++) {
1570 GLubyte *dstRow = (GLubyte *) dstAddr
1571 + dstImageOffsets[dstZoffset + img] * texelBytes
1572 + dstYoffset * dstRowStride
1573 + dstXoffset * texelBytes;
1574 for (row = 0; row < srcHeight; row++) {
1575 GLuint *dstUI = (GLuint *) dstRow;
1576 if (dstFormat == MESA_FORMAT_ARGB8888) {
1577 for (col = 0; col < srcWidth; col++) {
1578 dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]),
1579 CHAN_TO_UBYTE(src[RCOMP]),
1580 CHAN_TO_UBYTE(src[GCOMP]),
1581 CHAN_TO_UBYTE(src[BCOMP]) );
1582 src += 4;
1583 }
1584 }
1585 else if (dstFormat == MESA_FORMAT_XRGB8888) {
1586 for (col = 0; col < srcWidth; col++) {
1587 dstUI[col] = PACK_COLOR_8888( 0xff,
1588 CHAN_TO_UBYTE(src[RCOMP]),
1589 CHAN_TO_UBYTE(src[GCOMP]),
1590 CHAN_TO_UBYTE(src[BCOMP]) );
1591 src += 4;
1592 }
1593 }
1594 else {
1595 for (col = 0; col < srcWidth; col++) {
1596 dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]),
1597 CHAN_TO_UBYTE(src[RCOMP]),
1598 CHAN_TO_UBYTE(src[GCOMP]),
1599 CHAN_TO_UBYTE(src[BCOMP]) );
1600 src += 4;
1601 }
1602 }
1603 dstRow += dstRowStride;
1604 }
1605 }
1606 free((void *) tempImage);
1607 }
1608 return GL_TRUE;
1609 }
1610
1611
1612 static GLboolean
1613 _mesa_texstore_rgb888(TEXSTORE_PARAMS)
1614 {
1615 const GLboolean littleEndian = _mesa_little_endian();
1616 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1617 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1618
1619 ASSERT(dstFormat == MESA_FORMAT_RGB888);
1620 ASSERT(texelBytes == 3);
1621
1622 if (!ctx->_ImageTransferState &&
1623 !srcPacking->SwapBytes &&
1624 baseInternalFormat == GL_RGB &&
1625 srcFormat == GL_BGR &&
1626 srcType == GL_UNSIGNED_BYTE &&
1627 littleEndian) {
1628 /* simple memcpy path */
1629 memcpy_texture(ctx, dims,
1630 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1631 dstRowStride,
1632 dstImageOffsets,
1633 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1634 srcAddr, srcPacking);
1635 }
1636 else if (!ctx->_ImageTransferState &&
1637 !srcPacking->SwapBytes &&
1638 srcFormat == GL_RGBA &&
1639 srcType == GL_UNSIGNED_BYTE) {
1640 /* extract RGB from RGBA */
1641 GLint img, row, col;
1642 for (img = 0; img < srcDepth; img++) {
1643 const GLint srcRowStride =
1644 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1645 GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1646 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1647 GLubyte *dstRow = (GLubyte *) dstAddr
1648 + dstImageOffsets[dstZoffset + img] * texelBytes
1649 + dstYoffset * dstRowStride
1650 + dstXoffset * texelBytes;
1651 for (row = 0; row < srcHeight; row++) {
1652 for (col = 0; col < srcWidth; col++) {
1653 dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
1654 dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
1655 dstRow[col * 3 + 2] = srcRow[col * 4 + RCOMP];
1656 }
1657 dstRow += dstRowStride;
1658 srcRow += srcRowStride;
1659 }
1660 }
1661 }
1662 else if (!ctx->_ImageTransferState &&
1663 srcType == GL_UNSIGNED_BYTE &&
1664 can_swizzle(baseInternalFormat) &&
1665 can_swizzle(srcFormat)) {
1666
1667 GLubyte dstmap[4];
1668
1669 /* dstmap - how to swizzle from RGBA to dst format:
1670 */
1671 dstmap[0] = 2;
1672 dstmap[1] = 1;
1673 dstmap[2] = 0;
1674 dstmap[3] = ONE; /* ? */
1675
1676 _mesa_swizzle_ubyte_image(ctx, dims,
1677 srcFormat,
1678 srcType,
1679 baseInternalFormat,
1680 dstmap, 3,
1681 dstAddr, dstXoffset, dstYoffset, dstZoffset,
1682 dstRowStride, dstImageOffsets,
1683 srcWidth, srcHeight, srcDepth, srcAddr,
1684 srcPacking);
1685 }
1686 else {
1687 /* general path */
1688 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1689 baseInternalFormat,
1690 baseFormat,
1691 srcWidth, srcHeight, srcDepth,
1692 srcFormat, srcType, srcAddr,
1693 srcPacking);
1694 const GLchan *src = (const GLchan *) tempImage;
1695 GLint img, row, col;
1696 if (!tempImage)
1697 return GL_FALSE;
1698 for (img = 0; img < srcDepth; img++) {
1699 GLubyte *dstRow = (GLubyte *) dstAddr
1700 + dstImageOffsets[dstZoffset + img] * texelBytes
1701 + dstYoffset * dstRowStride
1702 + dstXoffset * texelBytes;
1703 for (row = 0; row < srcHeight; row++) {
1704 #if 0
1705 if (littleEndian) {
1706 for (col = 0; col < srcWidth; col++) {
1707 dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
1708 dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1709 dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
1710 srcUB += 3;
1711 }
1712 }
1713 else {
1714 for (col = 0; col < srcWidth; col++) {
1715 dstRow[col * 3 + 0] = srcUB[BCOMP];
1716 dstRow[col * 3 + 1] = srcUB[GCOMP];
1717 dstRow[col * 3 + 2] = srcUB[RCOMP];
1718 srcUB += 3;
1719 }
1720 }
1721 #else
1722 for (col = 0; col < srcWidth; col++) {
1723 dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[BCOMP]);
1724 dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1725 dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[RCOMP]);
1726 src += 3;
1727 }
1728 #endif
1729 dstRow += dstRowStride;
1730 }
1731 }
1732 free((void *) tempImage);
1733 }
1734 return GL_TRUE;
1735 }
1736
1737
1738 static GLboolean
1739 _mesa_texstore_bgr888(TEXSTORE_PARAMS)
1740 {
1741 const GLboolean littleEndian = _mesa_little_endian();
1742 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1743 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1744
1745 ASSERT(dstFormat == MESA_FORMAT_BGR888);
1746 ASSERT(texelBytes == 3);
1747
1748 if (!ctx->_ImageTransferState &&
1749 !srcPacking->SwapBytes &&
1750 baseInternalFormat == GL_RGB &&
1751 srcFormat == GL_RGB &&
1752 srcType == GL_UNSIGNED_BYTE &&
1753 littleEndian) {
1754 /* simple memcpy path */
1755 memcpy_texture(ctx, dims,
1756 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1757 dstRowStride,
1758 dstImageOffsets,
1759 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1760 srcAddr, srcPacking);
1761 }
1762 else if (!ctx->_ImageTransferState &&
1763 !srcPacking->SwapBytes &&
1764 srcFormat == GL_RGBA &&
1765 srcType == GL_UNSIGNED_BYTE) {
1766 /* extract BGR from RGBA */
1767 int img, row, col;
1768 for (img = 0; img < srcDepth; img++) {
1769 const GLint srcRowStride =
1770 _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1771 GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1772 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1773 GLubyte *dstRow = (GLubyte *) dstAddr
1774 + dstImageOffsets[dstZoffset + img] * texelBytes
1775 + dstYoffset * dstRowStride
1776 + dstXoffset * texelBytes;
1777 for (row = 0; row < srcHeight; row++) {
1778 for (col = 0; col < srcWidth; col++) {
1779 dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
1780 dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
1781 dstRow[col * 3 + 2] = srcRow[col * 4 + BCOMP];
1782 }
1783 dstRow += dstRowStride;
1784 srcRow += srcRowStride;
1785 }
1786 }
1787 }
1788 else if (!ctx->_ImageTransferState &&
1789 srcType == GL_UNSIGNED_BYTE &&
1790 can_swizzle(baseInternalFormat) &&
1791 can_swizzle(srcFormat)) {
1792
1793 GLubyte dstmap[4];
1794
1795 /* dstmap - how to swizzle from RGBA to dst format:
1796 */
1797 dstmap[0] = 0;
1798 dstmap[1] = 1;
1799 dstmap[2] = 2;
1800 dstmap[3] = ONE; /* ? */
1801
1802 _mesa_swizzle_ubyte_image(ctx, dims,
1803 srcFormat,
1804 srcType,
1805 baseInternalFormat,
1806 dstmap, 3,
1807 dstAddr, dstXoffset, dstYoffset, dstZoffset,
1808 dstRowStride, dstImageOffsets,
1809 srcWidth, srcHeight, srcDepth, srcAddr,
1810 srcPacking);
1811 }
1812 else {
1813 /* general path */
1814 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1815 baseInternalFormat,
1816 baseFormat,
1817 srcWidth, srcHeight, srcDepth,
1818 srcFormat, srcType, srcAddr,
1819 srcPacking);
1820 const GLchan *src = (const GLchan *) tempImage;
1821 GLint img, row, col;
1822 if (!tempImage)
1823 return GL_FALSE;
1824 for (img = 0; img < srcDepth; img++) {
1825 GLubyte *dstRow = (GLubyte *) dstAddr
1826 + dstImageOffsets[dstZoffset + img] * texelBytes
1827 + dstYoffset * dstRowStride
1828 + dstXoffset * texelBytes;
1829 for (row = 0; row < srcHeight; row++) {
1830 for (col = 0; col < srcWidth; col++) {
1831 dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
1832 dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1833 dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
1834 src += 3;
1835 }
1836 dstRow += dstRowStride;
1837 }
1838 }
1839 free((void *) tempImage);
1840 }
1841 return GL_TRUE;
1842 }
1843
1844
1845 static GLboolean
1846 _mesa_texstore_argb4444(TEXSTORE_PARAMS)
1847 {
1848 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1849 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1850
1851 ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
1852 dstFormat == MESA_FORMAT_ARGB4444_REV);
1853 ASSERT(texelBytes == 2);
1854
1855 if (!ctx->_ImageTransferState &&
1856 !srcPacking->SwapBytes &&
1857 dstFormat == MESA_FORMAT_ARGB4444 &&
1858 baseInternalFormat == GL_RGBA &&
1859 srcFormat == GL_BGRA &&
1860 srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
1861 /* simple memcpy path */
1862 memcpy_texture(ctx, dims,
1863 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1864 dstRowStride,
1865 dstImageOffsets,
1866 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1867 srcAddr, srcPacking);
1868 }
1869 else {
1870 /* general path */
1871 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1872 baseInternalFormat,
1873 baseFormat,
1874 srcWidth, srcHeight, srcDepth,
1875 srcFormat, srcType, srcAddr,
1876 srcPacking);
1877 const GLchan *src = tempImage;
1878 GLint img, row, col;
1879 if (!tempImage)
1880 return GL_FALSE;
1881 for (img = 0; img < srcDepth; img++) {
1882 GLubyte *dstRow = (GLubyte *) dstAddr
1883 + dstImageOffsets[dstZoffset + img] * texelBytes
1884 + dstYoffset * dstRowStride
1885 + dstXoffset * texelBytes;
1886 for (row = 0; row < srcHeight; row++) {
1887 GLushort *dstUS = (GLushort *) dstRow;
1888 if (dstFormat == MESA_FORMAT_ARGB4444) {
1889 for (col = 0; col < srcWidth; col++) {
1890 dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]),
1891 CHAN_TO_UBYTE(src[RCOMP]),
1892 CHAN_TO_UBYTE(src[GCOMP]),
1893 CHAN_TO_UBYTE(src[BCOMP]) );
1894 src += 4;
1895 }
1896 }
1897 else {
1898 for (col = 0; col < srcWidth; col++) {
1899 dstUS[col] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src[ACOMP]),
1900 CHAN_TO_UBYTE(src[RCOMP]),
1901 CHAN_TO_UBYTE(src[GCOMP]),
1902 CHAN_TO_UBYTE(src[BCOMP]) );
1903 src += 4;
1904 }
1905 }
1906 dstRow += dstRowStride;
1907 }
1908 }
1909 free((void *) tempImage);
1910 }
1911 return GL_TRUE;
1912 }
1913
1914 static GLboolean
1915 _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
1916 {
1917 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1918 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1919
1920 ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
1921 ASSERT(texelBytes == 2);
1922
1923 if (!ctx->_ImageTransferState &&
1924 !srcPacking->SwapBytes &&
1925 dstFormat == MESA_FORMAT_RGBA5551 &&
1926 baseInternalFormat == GL_RGBA &&
1927 srcFormat == GL_RGBA &&
1928 srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
1929 /* simple memcpy path */
1930 memcpy_texture(ctx, dims,
1931 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1932 dstRowStride,
1933 dstImageOffsets,
1934 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1935 srcAddr, srcPacking);
1936 }
1937 else {
1938 /* general path */
1939 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1940 baseInternalFormat,
1941 baseFormat,
1942 srcWidth, srcHeight, srcDepth,
1943 srcFormat, srcType, srcAddr,
1944 srcPacking);
1945 const GLchan *src =tempImage;
1946 GLint img, row, col;
1947 if (!tempImage)
1948 return GL_FALSE;
1949 for (img = 0; img < srcDepth; img++) {
1950 GLubyte *dstRow = (GLubyte *) dstAddr
1951 + dstImageOffsets[dstZoffset + img] * texelBytes
1952 + dstYoffset * dstRowStride
1953 + dstXoffset * texelBytes;
1954 for (row = 0; row < srcHeight; row++) {
1955 GLushort *dstUS = (GLushort *) dstRow;
1956 for (col = 0; col < srcWidth; col++) {
1957 dstUS[col] = PACK_COLOR_5551( CHAN_TO_UBYTE(src[RCOMP]),
1958 CHAN_TO_UBYTE(src[GCOMP]),
1959 CHAN_TO_UBYTE(src[BCOMP]),
1960 CHAN_TO_UBYTE(src[ACOMP]) );
1961 src += 4;
1962 }
1963 dstRow += dstRowStride;
1964 }
1965 }
1966 free((void *) tempImage);
1967 }
1968 return GL_TRUE;
1969 }
1970
1971 static GLboolean
1972 _mesa_texstore_argb1555(TEXSTORE_PARAMS)
1973 {
1974 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1975 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1976
1977 ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
1978 dstFormat == MESA_FORMAT_ARGB1555_REV);
1979 ASSERT(texelBytes == 2);
1980
1981 if (!ctx->_ImageTransferState &&
1982 !srcPacking->SwapBytes &&
1983 dstFormat == MESA_FORMAT_ARGB1555 &&
1984 baseInternalFormat == GL_RGBA &&
1985 srcFormat == GL_BGRA &&
1986 srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
1987 /* simple memcpy path */
1988 memcpy_texture(ctx, dims,
1989 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1990 dstRowStride,
1991 dstImageOffsets,
1992 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1993 srcAddr, srcPacking);
1994 }
1995 else {
1996 /* general path */
1997 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
1998 baseInternalFormat,
1999 baseFormat,
2000 srcWidth, srcHeight, srcDepth,
2001 srcFormat, srcType, srcAddr,
2002 srcPacking);
2003 const GLchan *src =tempImage;
2004 GLint img, row, col;
2005 if (!tempImage)
2006 return GL_FALSE;
2007 for (img = 0; img < srcDepth; img++) {
2008 GLubyte *dstRow = (GLubyte *) dstAddr
2009 + dstImageOffsets[dstZoffset + img] * texelBytes
2010 + dstYoffset * dstRowStride
2011 + dstXoffset * texelBytes;
2012 for (row = 0; row < srcHeight; row++) {
2013 GLushort *dstUS = (GLushort *) dstRow;
2014 if (dstFormat == MESA_FORMAT_ARGB1555) {
2015 for (col = 0; col < srcWidth; col++) {
2016 dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]),
2017 CHAN_TO_UBYTE(src[RCOMP]),
2018 CHAN_TO_UBYTE(src[GCOMP]),
2019 CHAN_TO_UBYTE(src[BCOMP]) );
2020 src += 4;
2021 }
2022 }
2023 else {
2024 for (col = 0; col < srcWidth; col++) {
2025 dstUS[col] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src[ACOMP]),
2026 CHAN_TO_UBYTE(src[RCOMP]),
2027 CHAN_TO_UBYTE(src[GCOMP]),
2028 CHAN_TO_UBYTE(src[BCOMP]) );
2029 src += 4;
2030 }
2031 }
2032 dstRow += dstRowStride;
2033 }
2034 }
2035 free((void *) tempImage);
2036 }
2037 return GL_TRUE;
2038 }
2039
2040
2041 static GLboolean
2042 _mesa_texstore_argb2101010(TEXSTORE_PARAMS)
2043 {
2044 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2045 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2046
2047 ASSERT(dstFormat == MESA_FORMAT_ARGB2101010);
2048 ASSERT(texelBytes == 4);
2049
2050 if (!ctx->_ImageTransferState &&
2051 !srcPacking->SwapBytes &&
2052 dstFormat == MESA_FORMAT_ARGB2101010 &&
2053 srcFormat == GL_BGRA &&
2054 srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
2055 baseInternalFormat == GL_RGBA) {
2056 /* simple memcpy path */
2057 memcpy_texture(ctx, dims,
2058 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2059 dstRowStride,
2060 dstImageOffsets,
2061 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2062 srcAddr, srcPacking);
2063 }
2064 else {
2065 /* general path */
2066 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
2067 baseInternalFormat,
2068 baseFormat,
2069 srcWidth, srcHeight, srcDepth,
2070 srcFormat, srcType, srcAddr,
2071 srcPacking);
2072 const GLchan *src = tempImage;
2073 GLint img, row, col;
2074 if (!tempImage)
2075 return GL_FALSE;
2076 for (img = 0; img < srcDepth; img++) {
2077 GLubyte *dstRow = (GLubyte *) dstAddr
2078 + dstImageOffsets[dstZoffset + img] * texelBytes
2079 + dstYoffset * dstRowStride
2080 + dstXoffset * texelBytes;
2081 if (baseInternalFormat == GL_RGBA) {
2082 for (row = 0; row < srcHeight; row++) {
2083 GLuint *dstUS = (GLuint *) dstRow;
2084 for (col = 0; col < srcWidth; col++) {
2085 dstUS[col] = PACK_COLOR_2101010( CHAN_TO_UBYTE(src[ACOMP]),
2086 CHAN_TO_UBYTE(src[RCOMP]),
2087 CHAN_TO_UBYTE(src[GCOMP]),
2088 CHAN_TO_UBYTE(src[BCOMP]) );
2089 src += 4;
2090 }
2091 dstRow += dstRowStride;
2092 }
2093 } else if (baseInternalFormat == GL_RGB) {
2094 for (row = 0; row < srcHeight; row++) {
2095 GLuint *dstUS = (GLuint *) dstRow;
2096 for (col = 0; col < srcWidth; col++) {
2097 dstUS[col] = PACK_COLOR_2101010( 0xff,
2098 CHAN_TO_UBYTE(src[RCOMP]),
2099 CHAN_TO_UBYTE(src[GCOMP]),
2100 CHAN_TO_UBYTE(src[BCOMP]) );
2101 src += 4;
2102 }
2103 dstRow += dstRowStride;
2104 }
2105 } else {
2106 ASSERT(0);
2107 }
2108 }
2109 free((void *) tempImage);
2110 }
2111 return GL_TRUE;
2112 }
2113
2114
2115 /**
2116 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2117 */
2118 static GLboolean
2119 _mesa_texstore_unorm44(TEXSTORE_PARAMS)
2120 {
2121 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2122 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2123
2124 ASSERT(dstFormat == MESA_FORMAT_AL44);
2125 ASSERT(texelBytes == 1);
2126
2127 {
2128 /* general path */
2129 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
2130 baseInternalFormat,
2131 baseFormat,
2132 srcWidth, srcHeight, srcDepth,
2133 srcFormat, srcType, srcAddr,
2134 srcPacking);
2135 const GLchan *src = tempImage;
2136 GLint img, row, col;
2137 if (!tempImage)
2138 return GL_FALSE;
2139 for (img = 0; img < srcDepth; img++) {
2140 GLubyte *dstRow = (GLubyte *) dstAddr
2141 + dstImageOffsets[dstZoffset + img] * texelBytes
2142 + dstYoffset * dstRowStride
2143 + dstXoffset * texelBytes;
2144 for (row = 0; row < srcHeight; row++) {
2145 GLubyte *dstUS = (GLubyte *) dstRow;
2146 for (col = 0; col < srcWidth; col++) {
2147 /* src[0] is luminance, src[1] is alpha */
2148 dstUS[col] = PACK_COLOR_44( CHAN_TO_UBYTE(src[1]),
2149 CHAN_TO_UBYTE(src[0]) );
2150 src += 2;
2151 }
2152 dstRow += dstRowStride;
2153 }
2154 }
2155 free((void *) tempImage);
2156 }
2157 return GL_TRUE;
2158 }
2159
2160
2161 /**
2162 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2163 */
2164 static GLboolean
2165 _mesa_texstore_unorm88(TEXSTORE_PARAMS)
2166 {
2167 const GLboolean littleEndian = _mesa_little_endian();
2168 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2169 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2170
2171 ASSERT(dstFormat == MESA_FORMAT_AL88 ||
2172 dstFormat == MESA_FORMAT_AL88_REV ||
2173 dstFormat == MESA_FORMAT_RG88 ||
2174 dstFormat == MESA_FORMAT_RG88_REV);
2175 ASSERT(texelBytes == 2);
2176
2177 if (!ctx->_ImageTransferState &&
2178 !srcPacking->SwapBytes &&
2179 (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_RG88) &&
2180 baseInternalFormat == srcFormat &&
2181 srcType == GL_UNSIGNED_BYTE &&
2182 littleEndian) {
2183 /* simple memcpy path */
2184 memcpy_texture(ctx, dims,
2185 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2186 dstRowStride,
2187 dstImageOffsets,
2188 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2189 srcAddr, srcPacking);
2190 }
2191 else if (!ctx->_ImageTransferState &&
2192 littleEndian &&
2193 srcType == GL_UNSIGNED_BYTE &&
2194 can_swizzle(baseInternalFormat) &&
2195 can_swizzle(srcFormat)) {
2196 GLubyte dstmap[4];
2197
2198 /* dstmap - how to swizzle from RGBA to dst format:
2199 */
2200 if (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_AL88_REV) {
2201 if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
2202 (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
2203 dstmap[0] = 0;
2204 dstmap[1] = 3;
2205 }
2206 else {
2207 dstmap[0] = 3;
2208 dstmap[1] = 0;
2209 }
2210 }
2211 else {
2212 if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
2213 (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
2214 dstmap[0] = 0;
2215 dstmap[1] = 1;
2216 }
2217 else {
2218 dstmap[0] = 1;
2219 dstmap[1] = 0;
2220 }
2221 }
2222 dstmap[2] = ZERO; /* ? */
2223 dstmap[3] = ONE; /* ? */
2224
2225 _mesa_swizzle_ubyte_image(ctx, dims,
2226 srcFormat,
2227 srcType,
2228 baseInternalFormat,
2229 dstmap, 2,
2230 dstAddr, dstXoffset, dstYoffset, dstZoffset,
2231 dstRowStride, dstImageOffsets,
2232 srcWidth, srcHeight, srcDepth, srcAddr,
2233 srcPacking);
2234 }
2235 else {
2236 /* general path */
2237 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
2238 baseInternalFormat,
2239 baseFormat,
2240 srcWidth, srcHeight, srcDepth,
2241 srcFormat, srcType, srcAddr,
2242 srcPacking);
2243 const GLchan *src = tempImage;
2244 GLint img, row, col;
2245 if (!tempImage)
2246 return GL_FALSE;
2247 for (img = 0; img < srcDepth; img++) {
2248 GLubyte *dstRow = (GLubyte *) dstAddr
2249 + dstImageOffsets[dstZoffset + img] * texelBytes
2250 + dstYoffset * dstRowStride
2251 + dstXoffset * texelBytes;
2252 for (row = 0; row < srcHeight; row++) {
2253 GLushort *dstUS = (GLushort *) dstRow;
2254 if (dstFormat == MESA_FORMAT_AL88 ||
2255 dstFormat == MESA_FORMAT_RG88) {
2256 for (col = 0; col < srcWidth; col++) {
2257 /* src[0] is luminance, src[1] is alpha */
2258 dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
2259 CHAN_TO_UBYTE(src[0]) );
2260 src += 2;
2261 }
2262 }
2263 else {
2264 for (col = 0; col < srcWidth; col++) {
2265 /* src[0] is luminance, src[1] is alpha */
2266 dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]),
2267 CHAN_TO_UBYTE(src[0]) );
2268 src += 2;
2269 }
2270 }
2271 dstRow += dstRowStride;
2272 }
2273 }
2274 free((void *) tempImage);
2275 }
2276 return GL_TRUE;
2277 }
2278
2279
2280 /**
2281 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2282 */
2283 static GLboolean
2284 _mesa_texstore_unorm1616(TEXSTORE_PARAMS)
2285 {
2286 const GLboolean littleEndian = _mesa_little_endian();
2287 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2288 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2289
2290 ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
2291 dstFormat == MESA_FORMAT_AL1616_REV ||
2292 dstFormat == MESA_FORMAT_RG1616 ||
2293 dstFormat == MESA_FORMAT_RG1616_REV);
2294 ASSERT(texelBytes == 4);
2295
2296 if (!ctx->_ImageTransferState &&
2297 !srcPacking->SwapBytes &&
2298 (dstFormat == MESA_FORMAT_AL1616 || dstFormat == MESA_FORMAT_RG1616) &&
2299 baseInternalFormat == srcFormat &&
2300 srcType == GL_UNSIGNED_SHORT &&
2301 littleEndian) {
2302 /* simple memcpy path */
2303 memcpy_texture(ctx, dims,
2304 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2305 dstRowStride,
2306 dstImageOffsets,
2307 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2308 srcAddr, srcPacking);
2309 }
2310 else {
2311 /* general path */
2312 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2313 baseInternalFormat,
2314 baseFormat,
2315 srcWidth, srcHeight, srcDepth,
2316 srcFormat, srcType, srcAddr,
2317 srcPacking,
2318 ctx->_ImageTransferState);
2319 const GLfloat *src = tempImage;
2320 GLint img, row, col;
2321 if (!tempImage)
2322 return GL_FALSE;
2323 for (img = 0; img < srcDepth; img++) {
2324 GLubyte *dstRow = (GLubyte *) dstAddr
2325 + dstImageOffsets[dstZoffset + img] * texelBytes
2326 + dstYoffset * dstRowStride
2327 + dstXoffset * texelBytes;
2328 for (row = 0; row < srcHeight; row++) {
2329 GLuint *dstUI = (GLuint *) dstRow;
2330 if (dstFormat == MESA_FORMAT_AL1616 ||
2331 dstFormat == MESA_FORMAT_RG1616) {
2332 for (col = 0; col < srcWidth; col++) {
2333 GLushort l, a;
2334
2335 UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
2336 UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
2337 dstUI[col] = PACK_COLOR_1616(a, l);
2338 src += 2;
2339 }
2340 }
2341 else {
2342 for (col = 0; col < srcWidth; col++) {
2343 GLushort l, a;
2344
2345 UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
2346 UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
2347 dstUI[col] = PACK_COLOR_1616_REV(a, l);
2348 src += 2;
2349 }
2350 }
2351 dstRow += dstRowStride;
2352 }
2353 }
2354 free((void *) tempImage);
2355 }
2356 return GL_TRUE;
2357 }
2358
2359
2360 /* Texstore for R16, A16. */
2361 static GLboolean
2362 _mesa_texstore_unorm16(TEXSTORE_PARAMS)
2363 {
2364 const GLboolean littleEndian = _mesa_little_endian();
2365 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2366 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2367
2368 ASSERT(dstFormat == MESA_FORMAT_R16 ||
2369 dstFormat == MESA_FORMAT_A16);
2370 ASSERT(texelBytes == 2);
2371
2372 if (!ctx->_ImageTransferState &&
2373 !srcPacking->SwapBytes &&
2374 baseInternalFormat == srcFormat &&
2375 srcType == GL_UNSIGNED_SHORT &&
2376 littleEndian) {
2377 /* simple memcpy path */
2378 memcpy_texture(ctx, dims,
2379 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2380 dstRowStride,
2381 dstImageOffsets,
2382 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2383 srcAddr, srcPacking);
2384 }
2385 else {
2386 /* general path */
2387 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2388 baseInternalFormat,
2389 baseFormat,
2390 srcWidth, srcHeight, srcDepth,
2391 srcFormat, srcType, srcAddr,
2392 srcPacking,
2393 ctx->_ImageTransferState);
2394 const GLfloat *src = tempImage;
2395 GLint img, row, col;
2396 if (!tempImage)
2397 return GL_FALSE;
2398 for (img = 0; img < srcDepth; img++) {
2399 GLubyte *dstRow = (GLubyte *) dstAddr
2400 + dstImageOffsets[dstZoffset + img] * texelBytes
2401 + dstYoffset * dstRowStride
2402 + dstXoffset * texelBytes;
2403 for (row = 0; row < srcHeight; row++) {
2404 GLushort *dstUS = (GLushort *) dstRow;
2405 for (col = 0; col < srcWidth; col++) {
2406 GLushort r;
2407
2408 UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
2409 dstUS[col] = r;
2410 src += 1;
2411 }
2412 dstRow += dstRowStride;
2413 }
2414 }
2415 free((void *) tempImage);
2416 }
2417 return GL_TRUE;
2418 }
2419
2420
2421 static GLboolean
2422 _mesa_texstore_rgba_16(TEXSTORE_PARAMS)
2423 {
2424 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2425 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2426
2427 ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
2428 ASSERT(texelBytes == 8);
2429
2430 if (!ctx->_ImageTransferState &&
2431 !srcPacking->SwapBytes &&
2432 baseInternalFormat == GL_RGBA &&
2433 srcFormat == GL_RGBA &&
2434 srcType == GL_UNSIGNED_SHORT) {
2435 /* simple memcpy path */
2436 memcpy_texture(ctx, dims,
2437 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2438 dstRowStride,
2439 dstImageOffsets,
2440 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2441 srcAddr, srcPacking);
2442 }
2443 else {
2444 /* general path */
2445 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2446 baseInternalFormat,
2447 baseFormat,
2448 srcWidth, srcHeight, srcDepth,
2449 srcFormat, srcType, srcAddr,
2450 srcPacking,
2451 ctx->_ImageTransferState);
2452 const GLfloat *src = tempImage;
2453 GLint img, row, col;
2454 if (!tempImage)
2455 return GL_FALSE;
2456 for (img = 0; img < srcDepth; img++) {
2457 GLubyte *dstRow = (GLubyte *) dstAddr
2458 + dstImageOffsets[dstZoffset + img] * texelBytes
2459 + dstYoffset * dstRowStride
2460 + dstXoffset * texelBytes;
2461 for (row = 0; row < srcHeight; row++) {
2462 GLushort *dstUS = (GLushort *) dstRow;
2463 for (col = 0; col < srcWidth; col++) {
2464 GLushort r, g, b, a;
2465
2466 UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
2467 UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
2468 UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
2469 UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
2470 dstUS[col*4+0] = r;
2471 dstUS[col*4+1] = g;
2472 dstUS[col*4+2] = b;
2473 dstUS[col*4+3] = a;
2474 src += 4;
2475 }
2476 dstRow += dstRowStride;
2477 }
2478 }
2479 free((void *) tempImage);
2480 }
2481 return GL_TRUE;
2482 }
2483
2484
2485 static GLboolean
2486 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
2487 {
2488 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2489 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2490
2491 ASSERT(dstFormat == MESA_FORMAT_SIGNED_R_16 ||
2492 dstFormat == MESA_FORMAT_SIGNED_RG_16 ||
2493 dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
2494 dstFormat == MESA_FORMAT_SIGNED_RGBA_16);
2495
2496 if (!ctx->_ImageTransferState &&
2497 !srcPacking->SwapBytes &&
2498 baseInternalFormat == GL_RGBA &&
2499 dstFormat == MESA_FORMAT_SIGNED_RGBA_16 &&
2500 srcFormat == GL_RGBA &&
2501 srcType == GL_SHORT) {
2502 /* simple memcpy path */
2503 memcpy_texture(ctx, dims,
2504 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2505 dstRowStride,
2506 dstImageOffsets,
2507 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2508 srcAddr, srcPacking);
2509 }
2510 else {
2511 /* general path */
2512 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2513 baseInternalFormat,
2514 baseFormat,
2515 srcWidth, srcHeight, srcDepth,
2516 srcFormat, srcType, srcAddr,
2517 srcPacking,
2518 ctx->_ImageTransferState);
2519 const GLfloat *src = tempImage;
2520 const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2;
2521 GLint img, row, col;
2522
2523 if (!tempImage)
2524 return GL_FALSE;
2525
2526 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2527 * 3 or 4 components/pixel here.
2528 */
2529 for (img = 0; img < srcDepth; img++) {
2530 GLubyte *dstRow = (GLubyte *) dstAddr
2531 + dstImageOffsets[dstZoffset + img] * texelBytes
2532 + dstYoffset * dstRowStride
2533 + dstXoffset * texelBytes;
2534 for (row = 0; row < srcHeight; row++) {
2535 GLshort *dstRowS = (GLshort *) dstRow;
2536 for (col = 0; col < srcWidth; col++) {
2537 GLuint c;
2538 for (c = 0; c < comps; c++) {
2539 GLshort p;
2540 UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]);
2541 dstRowS[col * comps + c] = p;
2542 }
2543 }
2544 dstRow += dstRowStride;
2545 src += 4 * srcWidth;
2546 }
2547 }
2548 free((void *) tempImage);
2549 }
2550 return GL_TRUE;
2551 }
2552
2553
2554 static GLboolean
2555 _mesa_texstore_rgb332(TEXSTORE_PARAMS)
2556 {
2557 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2558 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2559
2560 ASSERT(dstFormat == MESA_FORMAT_RGB332);
2561 ASSERT(texelBytes == 1);
2562
2563 if (!ctx->_ImageTransferState &&
2564 !srcPacking->SwapBytes &&
2565 baseInternalFormat == GL_RGB &&
2566 srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE_3_3_2) {
2567 /* simple memcpy path */
2568 memcpy_texture(ctx, dims,
2569 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2570 dstRowStride,
2571 dstImageOffsets,
2572 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2573 srcAddr, srcPacking);
2574 }
2575 else {
2576 /* general path */
2577 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
2578 baseInternalFormat,
2579 baseFormat,
2580 srcWidth, srcHeight, srcDepth,
2581 srcFormat, srcType, srcAddr,
2582 srcPacking);
2583 const GLchan *src = tempImage;
2584 GLint img, row, col;
2585 if (!tempImage)
2586 return GL_FALSE;
2587 for (img = 0; img < srcDepth; img++) {
2588 GLubyte *dstRow = (GLubyte *) dstAddr
2589 + dstImageOffsets[dstZoffset + img] * texelBytes
2590 + dstYoffset * dstRowStride
2591 + dstXoffset * texelBytes;
2592 for (row = 0; row < srcHeight; row++) {
2593 for (col = 0; col < srcWidth; col++) {
2594 dstRow[col] = PACK_COLOR_332( CHAN_TO_UBYTE(src[RCOMP]),
2595 CHAN_TO_UBYTE(src[GCOMP]),
2596 CHAN_TO_UBYTE(src[BCOMP]) );
2597 src += 3;
2598 }
2599 dstRow += dstRowStride;
2600 }
2601 }
2602 free((void *) tempImage);
2603 }
2604 return GL_TRUE;
2605 }
2606
2607
2608 /**
2609 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2610 */
2611 static GLboolean
2612 _mesa_texstore_a8(TEXSTORE_PARAMS)
2613 {
2614 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2615 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2616
2617 ASSERT(dstFormat == MESA_FORMAT_A8 ||
2618 dstFormat == MESA_FORMAT_L8 ||
2619 dstFormat == MESA_FORMAT_I8 ||
2620 dstFormat == MESA_FORMAT_R8);
2621 ASSERT(texelBytes == 1);
2622
2623 if (!ctx->_ImageTransferState &&
2624 !srcPacking->SwapBytes &&
2625 baseInternalFormat == srcFormat &&
2626 srcType == GL_UNSIGNED_BYTE) {
2627 /* simple memcpy path */
2628 memcpy_texture(ctx, dims,
2629 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2630 dstRowStride,
2631 dstImageOffsets,
2632 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2633 srcAddr, srcPacking);
2634 }
2635 else if (!ctx->_ImageTransferState &&
2636 srcType == GL_UNSIGNED_BYTE &&
2637 can_swizzle(baseInternalFormat) &&
2638 can_swizzle(srcFormat)) {
2639 GLubyte dstmap[4];
2640
2641 /* dstmap - how to swizzle from RGBA to dst format:
2642 */
2643 if (dstFormat == MESA_FORMAT_A8) {
2644 dstmap[0] = 3;
2645 }
2646 else {
2647 dstmap[0] = 0;
2648 }
2649 dstmap[1] = ZERO; /* ? */
2650 dstmap[2] = ZERO; /* ? */
2651 dstmap[3] = ONE; /* ? */
2652
2653 _mesa_swizzle_ubyte_image(ctx, dims,
2654 srcFormat,
2655 srcType,
2656 baseInternalFormat,
2657 dstmap, 1,
2658 dstAddr, dstXoffset, dstYoffset, dstZoffset,
2659 dstRowStride, dstImageOffsets,
2660 srcWidth, srcHeight, srcDepth, srcAddr,
2661 srcPacking);
2662 }
2663 else {
2664 /* general path */
2665 const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
2666 baseInternalFormat,
2667 baseFormat,
2668 srcWidth, srcHeight, srcDepth,
2669 srcFormat, srcType, srcAddr,
2670 srcPacking);
2671 const GLchan *src = tempImage;
2672 GLint img, row, col;
2673 if (!tempImage)
2674 return GL_FALSE;
2675 for (img = 0; img < srcDepth; img++) {
2676 GLubyte *dstRow = (GLubyte *) dstAddr
2677 + dstImageOffsets[dstZoffset + img] * texelBytes
2678 + dstYoffset * dstRowStride
2679 + dstXoffset * texelBytes;
2680 for (row = 0; row < srcHeight; row++) {
2681 for (col = 0; col < srcWidth; col++) {
2682 dstRow[col] = CHAN_TO_UBYTE(src[col]);
2683 }
2684 dstRow += dstRowStride;
2685 src += srcWidth;
2686 }
2687 }
2688 free((void *) tempImage);
2689 }
2690 return GL_TRUE;
2691 }
2692
2693
2694
2695 static GLboolean
2696 _mesa_texstore_ci8(TEXSTORE_PARAMS)
2697 {
2698 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2699
2700 (void) dims; (void) baseInternalFormat;
2701 ASSERT(dstFormat == MESA_FORMAT_CI8);
2702 ASSERT(texelBytes == 1);
2703 ASSERT(baseInternalFormat == GL_COLOR_INDEX);
2704
2705 if (!ctx->_ImageTransferState &&
2706 !srcPacking->SwapBytes &&
2707 srcFormat == GL_COLOR_INDEX &&
2708 srcType == GL_UNSIGNED_BYTE) {
2709 /* simple memcpy path */
2710 memcpy_texture(ctx, dims,
2711 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2712 dstRowStride,
2713 dstImageOffsets,
2714 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2715 srcAddr, srcPacking);
2716 }
2717 else {
2718 /* general path */
2719 GLint img, row;
2720 for (img = 0; img < srcDepth; img++) {
2721 GLubyte *dstRow = (GLubyte *) dstAddr
2722 + dstImageOffsets[dstZoffset + img] * texelBytes
2723 + dstYoffset * dstRowStride
2724 + dstXoffset * texelBytes;
2725 for (row = 0; row < srcHeight; row++) {
2726 const GLvoid *src = _mesa_image_address(dims, srcPacking,
2727 srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
2728 _mesa_unpack_index_span(ctx, srcWidth, GL_UNSIGNED_BYTE, dstRow,
2729 srcType, src, srcPacking,
2730 ctx->_ImageTransferState);
2731 dstRow += dstRowStride;
2732 }
2733 }
2734 }
2735 return GL_TRUE;
2736 }
2737
2738
2739 /**
2740 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2741 */
2742 static GLboolean
2743 _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
2744 {
2745 const GLboolean littleEndian = _mesa_little_endian();
2746 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2747
2748 (void) ctx; (void) dims; (void) baseInternalFormat;
2749
2750 ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
2751 (dstFormat == MESA_FORMAT_YCBCR_REV));
2752 ASSERT(texelBytes == 2);
2753 ASSERT(ctx->Extensions.MESA_ycbcr_texture);
2754 ASSERT(srcFormat == GL_YCBCR_MESA);
2755 ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
2756 (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA));
2757 ASSERT(baseInternalFormat == GL_YCBCR_MESA);
2758
2759 /* always just memcpy since no pixel transfer ops apply */
2760 memcpy_texture(ctx, dims,
2761 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2762 dstRowStride,
2763 dstImageOffsets,
2764 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2765 srcAddr, srcPacking);
2766
2767 /* Check if we need byte swapping */
2768 /* XXX the logic here _might_ be wrong */
2769 if (srcPacking->SwapBytes ^
2770 (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
2771 (dstFormat == MESA_FORMAT_YCBCR_REV) ^
2772 !littleEndian) {
2773 GLint img, row;
2774 for (img = 0; img < srcDepth; img++) {
2775 GLubyte *dstRow = (GLubyte *) dstAddr
2776 + dstImageOffsets[dstZoffset + img] * texelBytes
2777 + dstYoffset * dstRowStride
2778 + dstXoffset * texelBytes;
2779 for (row = 0; row < srcHeight; row++) {
2780 _mesa_swap2((GLushort *) dstRow, srcWidth);
2781 dstRow += dstRowStride;
2782 }
2783 }
2784 }
2785 return GL_TRUE;
2786 }
2787
2788 static GLboolean
2789 _mesa_texstore_dudv8(TEXSTORE_PARAMS)
2790 {
2791 const GLboolean littleEndian = _mesa_little_endian();
2792 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2793
2794 ASSERT(dstFormat == MESA_FORMAT_DUDV8);
2795 ASSERT(texelBytes == 2);
2796 ASSERT(ctx->Extensions.ATI_envmap_bumpmap);
2797 ASSERT((srcFormat == GL_DU8DV8_ATI) ||
2798 (srcFormat == GL_DUDV_ATI));
2799 ASSERT(baseInternalFormat == GL_DUDV_ATI);
2800
2801 if (!srcPacking->SwapBytes && srcType == GL_BYTE &&
2802 littleEndian) {
2803 /* simple memcpy path */
2804 memcpy_texture(ctx, dims,
2805 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2806 dstRowStride,
2807 dstImageOffsets,
2808 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2809 srcAddr, srcPacking);
2810 }
2811 else if (srcType == GL_BYTE) {
2812 GLubyte dstmap[4];
2813
2814 /* dstmap - how to swizzle from RGBA to dst format:
2815 */
2816 if (littleEndian) {
2817 dstmap[0] = 0;
2818 dstmap[1] = 3;
2819 }
2820 else {
2821 dstmap[0] = 3;
2822 dstmap[1] = 0;
2823 }
2824 dstmap[2] = ZERO; /* ? */
2825 dstmap[3] = ONE; /* ? */
2826
2827 _mesa_swizzle_ubyte_image(ctx, dims,
2828 GL_LUMINANCE_ALPHA, /* hack */
2829 GL_UNSIGNED_BYTE, /* hack */
2830 GL_LUMINANCE_ALPHA, /* hack */
2831 dstmap, 2,
2832 dstAddr, dstXoffset, dstYoffset, dstZoffset,
2833 dstRowStride, dstImageOffsets,
2834 srcWidth, srcHeight, srcDepth, srcAddr,
2835 srcPacking);
2836 }
2837 else {
2838 /* general path - note this is defined for 2d textures only */
2839 const GLint components = _mesa_components_in_format(baseInternalFormat);
2840 const GLint srcStride = _mesa_image_row_stride(srcPacking, srcWidth,
2841 srcFormat, srcType);
2842 GLbyte *tempImage, *dst, *src;
2843 GLint row;
2844
2845 tempImage = (GLbyte *) malloc(srcWidth * srcHeight * srcDepth
2846 * components * sizeof(GLbyte));
2847 if (!tempImage)
2848 return GL_FALSE;
2849
2850 src = (GLbyte *) _mesa_image_address(dims, srcPacking, srcAddr,
2851 srcWidth, srcHeight,
2852 srcFormat, srcType,
2853 0, 0, 0);
2854
2855 dst = tempImage;
2856 for (row = 0; row < srcHeight; row++) {
2857 _mesa_unpack_dudv_span_byte(ctx, srcWidth, baseInternalFormat,
2858 dst, srcFormat, srcType, src,
2859 srcPacking, 0);
2860 dst += srcWidth * components;
2861 src += srcStride;
2862 }
2863
2864 src = tempImage;
2865 dst = (GLbyte *) dstAddr
2866 + dstYoffset * dstRowStride
2867 + dstXoffset * texelBytes;
2868 for (row = 0; row < srcHeight; row++) {
2869 memcpy(dst, src, srcWidth * texelBytes);
2870 dst += dstRowStride;
2871 src += srcWidth * texelBytes;
2872 }
2873 free((void *) tempImage);
2874 }
2875 return GL_TRUE;
2876 }
2877
2878
2879 /**
2880 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2881 */
2882 static GLboolean
2883 _mesa_texstore_signed_r8(TEXSTORE_PARAMS)
2884 {
2885 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2886 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2887
2888 ASSERT(dstFormat == MESA_FORMAT_SIGNED_R8);
2889 ASSERT(texelBytes == 1);
2890
2891 /* XXX look at adding optimized paths */
2892 {
2893 /* general path */
2894 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2895 baseInternalFormat,
2896 baseFormat,
2897 srcWidth, srcHeight, srcDepth,
2898 srcFormat, srcType, srcAddr,
2899 srcPacking,
2900 ctx->_ImageTransferState);
2901 const GLfloat *srcRow = tempImage;
2902 GLint img, row, col;
2903 if (!tempImage)
2904 return GL_FALSE;
2905 for (img = 0; img < srcDepth; img++) {
2906 GLubyte *dstRow = (GLubyte *) dstAddr
2907 + dstImageOffsets[dstZoffset + img] * texelBytes
2908 + dstYoffset * dstRowStride
2909 + dstXoffset * texelBytes;
2910 for (row = 0; row < srcHeight; row++) {
2911 GLubyte *dstB = (GLubyte *) dstRow;
2912 for (col = 0; col < srcWidth; col++) {
2913 dstB[col] = FLOAT_TO_BYTE_TEX(srcRow[RCOMP]);
2914 }
2915 dstRow += dstRowStride;
2916 }
2917 }
2918 free((void *) tempImage);
2919 }
2920 return GL_TRUE;
2921 }
2922
2923
2924 /**
2925 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2926 */
2927 static GLboolean
2928 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS)
2929 {
2930 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2931 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2932
2933 ASSERT(dstFormat == MESA_FORMAT_SIGNED_RG88);
2934 ASSERT(texelBytes == 1);
2935
2936 /* XXX look at adding optimized paths */
2937 {
2938 /* general path */
2939 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2940 baseInternalFormat,
2941 baseFormat,
2942 srcWidth, srcHeight, srcDepth,
2943 srcFormat, srcType, srcAddr,
2944 srcPacking,
2945 ctx->_ImageTransferState);
2946 const GLfloat *srcRow = tempImage;
2947 GLint img, row, col;
2948 if (!tempImage)
2949 return GL_FALSE;
2950 for (img = 0; img < srcDepth; img++) {
2951 GLubyte *dstRow = (GLubyte *) dstAddr
2952 + dstImageOffsets[dstZoffset + img] * texelBytes
2953 + dstYoffset * dstRowStride
2954 + dstXoffset * texelBytes;
2955 for (row = 0; row < srcHeight; row++) {
2956 GLushort *dstUS = (GLushort *) dstRow;
2957 for (col = 0; col < srcWidth; col++) {
2958 dstUS[col] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
2959 FLOAT_TO_BYTE_TEX(srcRow[GCOMP]));
2960 }
2961 dstRow += dstRowStride;
2962 }
2963 }
2964 free((void *) tempImage);
2965 }
2966 return GL_TRUE;
2967 }
2968
2969
2970 /**
2971 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2972 */
2973 static GLboolean
2974 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS)
2975 {
2976 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2977 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2978
2979 ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888);
2980 ASSERT(texelBytes == 4);
2981
2982 {
2983 /* general path */
2984 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
2985 baseInternalFormat,
2986 baseFormat,
2987 srcWidth, srcHeight, srcDepth,
2988 srcFormat, srcType, srcAddr,
2989 srcPacking,
2990 ctx->_ImageTransferState);
2991 const GLfloat *srcRow = tempImage;
2992 GLint img, row, col;
2993 if (!tempImage)
2994 return GL_FALSE;
2995 for (img = 0; img < srcDepth; img++) {
2996 GLubyte *dstRow = (GLubyte *) dstAddr
2997 + dstImageOffsets[dstZoffset + img] * texelBytes
2998 + dstYoffset * dstRowStride
2999 + dstXoffset * texelBytes;
3000 for (row = 0; row < srcHeight; row++) {
3001 GLuint *dstUI = (GLuint *) dstRow;
3002 for (col = 0; col < srcWidth; col++) {
3003 dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
3004 FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
3005 FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
3006 0xff );
3007 srcRow += 4;
3008 }
3009 dstRow += dstRowStride;
3010 }
3011 }
3012 free((void *) tempImage);
3013 }
3014 return GL_TRUE;
3015 }
3016
3017
3018
3019 /**
3020 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3021 * MESA_FORMAT_SIGNED_RGBA8888_REV
3022 */
3023 static GLboolean
3024 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
3025 {
3026 const GLboolean littleEndian = _mesa_little_endian();
3027 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3028 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3029
3030 ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBA8888 ||
3031 dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV);
3032 ASSERT(texelBytes == 4);
3033
3034 if (!ctx->_ImageTransferState &&
3035 !srcPacking->SwapBytes &&
3036 dstFormat == MESA_FORMAT_SIGNED_RGBA8888 &&
3037 baseInternalFormat == GL_RGBA &&
3038 ((srcFormat == GL_RGBA && srcType == GL_BYTE && !littleEndian) ||
3039 (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && littleEndian))) {
3040 /* simple memcpy path */
3041 memcpy_texture(ctx, dims,
3042 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3043 dstRowStride,
3044 dstImageOffsets,
3045 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3046 srcAddr, srcPacking);
3047 }
3048 else if (!ctx->_ImageTransferState &&
3049 !srcPacking->SwapBytes &&
3050 dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV &&
3051 baseInternalFormat == GL_RGBA &&
3052 ((srcFormat == GL_RGBA && srcType == GL_BYTE && littleEndian) ||
3053 (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) {
3054 /* simple memcpy path */
3055 memcpy_texture(ctx, dims,
3056 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3057 dstRowStride,
3058 dstImageOffsets,
3059 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3060 srcAddr, srcPacking);
3061 }
3062 else if (!ctx->_ImageTransferState &&
3063 (srcType == GL_BYTE) &&
3064 can_swizzle(baseInternalFormat) &&
3065 can_swizzle(srcFormat)) {
3066
3067 GLubyte dstmap[4];
3068
3069 /* dstmap - how to swizzle from RGBA to dst format:
3070 */
3071 if ((littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888) ||
3072 (!littleEndian && dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV)) {
3073 dstmap[3] = 0;
3074 dstmap[2] = 1;
3075 dstmap[1] = 2;
3076 dstmap[0] = 3;
3077 }
3078 else {
3079 dstmap[3] = 3;
3080 dstmap[2] = 2;
3081 dstmap[1] = 1;
3082 dstmap[0] = 0;
3083 }
3084
3085 _mesa_swizzle_ubyte_image(ctx, dims,
3086 srcFormat,
3087 srcType,
3088 baseInternalFormat,
3089 dstmap, 4,
3090 dstAddr, dstXoffset, dstYoffset, dstZoffset,
3091 dstRowStride, dstImageOffsets,
3092 srcWidth, srcHeight, srcDepth, srcAddr,
3093 srcPacking);
3094 }
3095 else {
3096 /* general path */
3097 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3098 baseInternalFormat,
3099 baseFormat,
3100 srcWidth, srcHeight, srcDepth,
3101 srcFormat, srcType, srcAddr,
3102 srcPacking,
3103 ctx->_ImageTransferState);
3104 const GLfloat *srcRow = tempImage;
3105 GLint img, row, col;
3106 if (!tempImage)
3107 return GL_FALSE;
3108 for (img = 0; img < srcDepth; img++) {
3109 GLubyte *dstRow = (GLubyte *) dstAddr
3110 + dstImageOffsets[dstZoffset + img] * texelBytes
3111 + dstYoffset * dstRowStride
3112 + dstXoffset * texelBytes;
3113 for (row = 0; row < srcHeight; row++) {
3114 GLuint *dstUI = (GLuint *) dstRow;
3115 if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
3116 for (col = 0; col < srcWidth; col++) {
3117 dstUI[col] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
3118 FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
3119 FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
3120 FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
3121 srcRow += 4;
3122 }
3123 }
3124 else {
3125 for (col = 0; col < srcWidth; col++) {
3126 dstUI[col] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow[RCOMP]),
3127 FLOAT_TO_BYTE_TEX(srcRow[GCOMP]),
3128 FLOAT_TO_BYTE_TEX(srcRow[BCOMP]),
3129 FLOAT_TO_BYTE_TEX(srcRow[ACOMP]) );
3130 srcRow += 4;
3131 }
3132 }
3133 dstRow += dstRowStride;
3134 }
3135 }
3136 free((void *) tempImage);
3137 }
3138 return GL_TRUE;
3139 }
3140
3141
3142 /**
3143 * Store a combined depth/stencil texture image.
3144 */
3145 static GLboolean
3146 _mesa_texstore_z24_s8(TEXSTORE_PARAMS)
3147 {
3148 const GLuint depthScale = 0xffffff;
3149 const GLint srcRowStride
3150 = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3151 / sizeof(GLuint);
3152 GLint img, row;
3153
3154 ASSERT(dstFormat == MESA_FORMAT_Z24_S8);
3155 ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT || srcFormat == GL_DEPTH_COMPONENT);
3156 ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT || srcType == GL_UNSIGNED_INT_24_8_EXT);
3157
3158 if (srcFormat != GL_DEPTH_COMPONENT && ctx->Pixel.DepthScale == 1.0f &&
3159 ctx->Pixel.DepthBias == 0.0f &&
3160 !srcPacking->SwapBytes) {
3161 /* simple path */
3162 memcpy_texture(ctx, dims,
3163 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3164 dstRowStride,
3165 dstImageOffsets,
3166 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3167 srcAddr, srcPacking);
3168 }
3169 else if (srcFormat == GL_DEPTH_COMPONENT) {
3170 /* In case we only upload depth we need to preserve the stencil */
3171 for (img = 0; img < srcDepth; img++) {
3172 GLuint *dstRow = (GLuint *) dstAddr
3173 + dstImageOffsets[dstZoffset + img]
3174 + dstYoffset * dstRowStride / sizeof(GLuint)
3175 + dstXoffset;
3176 const GLuint *src
3177 = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
3178 srcWidth, srcHeight,
3179 srcFormat, srcType,
3180 img, 0, 0);
3181 for (row = 0; row < srcHeight; row++) {
3182 GLuint depth[MAX_WIDTH];
3183 GLubyte stencil[MAX_WIDTH];
3184 GLint i;
3185 GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
3186
3187 if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
3188 keepstencil = GL_TRUE;
3189 }
3190 else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
3191 keepdepth = GL_TRUE;
3192 }
3193
3194 if (keepdepth == GL_FALSE)
3195 /* the 24 depth bits will be in the low position: */
3196 _mesa_unpack_depth_span(ctx, srcWidth,
3197 GL_UNSIGNED_INT, /* dst type */
3198 keepstencil ? depth : dstRow, /* dst addr */
3199 depthScale,
3200 srcType, src, srcPacking);
3201
3202 if (keepstencil == GL_FALSE)
3203 /* get the 8-bit stencil values */
3204 _mesa_unpack_stencil_span(ctx, srcWidth,
3205 GL_UNSIGNED_BYTE, /* dst type */
3206 stencil, /* dst addr */
3207 srcType, src, srcPacking,
3208 ctx->_ImageTransferState);
3209
3210 for (i = 0; i < srcWidth; i++) {
3211 if (keepstencil)
3212 dstRow[i] = depth[i] << 8 | (dstRow[i] & 0x000000FF);
3213 else
3214 dstRow[i] = (dstRow[i] & 0xFFFFFF00) | (stencil[i] & 0xFF);
3215 }
3216
3217 src += srcRowStride;
3218 dstRow += dstRowStride / sizeof(GLuint);
3219 }
3220 }
3221 }
3222 return GL_TRUE;
3223 }
3224
3225
3226 /**
3227 * Store a combined depth/stencil texture image.
3228 */
3229 static GLboolean
3230 _mesa_texstore_s8_z24(TEXSTORE_PARAMS)
3231 {
3232 const GLuint depthScale = 0xffffff;
3233 const GLint srcRowStride
3234 = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3235 / sizeof(GLuint);
3236 GLint img, row;
3237
3238 ASSERT(dstFormat == MESA_FORMAT_S8_Z24);
3239 ASSERT(srcFormat == GL_DEPTH_STENCIL_EXT ||
3240 srcFormat == GL_DEPTH_COMPONENT ||
3241 srcFormat == GL_STENCIL_INDEX);
3242 ASSERT(srcFormat != GL_DEPTH_STENCIL_EXT ||
3243 srcType == GL_UNSIGNED_INT_24_8_EXT);
3244
3245 for (img = 0; img < srcDepth; img++) {
3246 GLuint *dstRow = (GLuint *) dstAddr
3247 + dstImageOffsets[dstZoffset + img]
3248 + dstYoffset * dstRowStride / sizeof(GLuint)
3249 + dstXoffset;
3250 const GLuint *src
3251 = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
3252 srcWidth, srcHeight,
3253 srcFormat, srcType,
3254 img, 0, 0);
3255 for (row = 0; row < srcHeight; row++) {
3256 GLuint depth[MAX_WIDTH];
3257 GLubyte stencil[MAX_WIDTH];
3258 GLint i;
3259 GLboolean keepdepth = GL_FALSE, keepstencil = GL_FALSE;
3260
3261 if (srcFormat == GL_DEPTH_COMPONENT) { /* preserve stencil */
3262 keepstencil = GL_TRUE;
3263 }
3264 else if (srcFormat == GL_STENCIL_INDEX) { /* preserve depth */
3265 keepdepth = GL_TRUE;
3266 }
3267
3268 if (keepdepth == GL_FALSE)
3269 /* the 24 depth bits will be in the low position: */
3270 _mesa_unpack_depth_span(ctx, srcWidth,
3271 GL_UNSIGNED_INT, /* dst type */
3272 keepstencil ? depth : dstRow, /* dst addr */
3273 depthScale,
3274 srcType, src, srcPacking);
3275
3276 if (keepstencil == GL_FALSE)
3277 /* get the 8-bit stencil values */
3278 _mesa_unpack_stencil_span(ctx, srcWidth,
3279 GL_UNSIGNED_BYTE, /* dst type */
3280 stencil, /* dst addr */
3281 srcType, src, srcPacking,
3282 ctx->_ImageTransferState);
3283
3284 /* merge stencil values into depth values */
3285 for (i = 0; i < srcWidth; i++) {
3286 if (keepstencil)
3287 dstRow[i] = depth[i] | (dstRow[i] & 0xFF000000);
3288 else
3289 dstRow[i] = (dstRow[i] & 0xFFFFFF) | (stencil[i] << 24);
3290
3291 }
3292 src += srcRowStride;
3293 dstRow += dstRowStride / sizeof(GLuint);
3294 }
3295 }
3296 return GL_TRUE;
3297 }
3298
3299
3300 /**
3301 * Store simple 8-bit/value stencil texture data.
3302 */
3303 static GLboolean
3304 _mesa_texstore_s8(TEXSTORE_PARAMS)
3305 {
3306 ASSERT(dstFormat == MESA_FORMAT_S8);
3307 ASSERT(srcFormat == GL_STENCIL_INDEX);
3308
3309 if (!ctx->_ImageTransferState &&
3310 !srcPacking->SwapBytes &&
3311 baseInternalFormat == srcFormat &&
3312 srcType == GL_UNSIGNED_BYTE) {
3313 /* simple memcpy path */
3314 memcpy_texture(ctx, dims,
3315 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3316 dstRowStride,
3317 dstImageOffsets,
3318 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3319 srcAddr, srcPacking);
3320 }
3321 else {
3322 const GLint srcRowStride
3323 = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3324 / sizeof(GLuint);
3325 GLint img, row;
3326
3327 for (img = 0; img < srcDepth; img++) {
3328 GLubyte *dstRow = (GLubyte *) dstAddr
3329 + dstImageOffsets[dstZoffset + img]
3330 + dstYoffset * dstRowStride / sizeof(GLuint)
3331 + dstXoffset;
3332 const GLuint *src
3333 = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
3334 srcWidth, srcHeight,
3335 srcFormat, srcType,
3336 img, 0, 0);
3337 for (row = 0; row < srcHeight; row++) {
3338 GLubyte stencil[MAX_WIDTH];
3339 GLint i;
3340
3341 /* get the 8-bit stencil values */
3342 _mesa_unpack_stencil_span(ctx, srcWidth,
3343 GL_UNSIGNED_BYTE, /* dst type */
3344 stencil, /* dst addr */
3345 srcType, src, srcPacking,
3346 ctx->_ImageTransferState);
3347 /* merge stencil values into depth values */
3348 for (i = 0; i < srcWidth; i++)
3349 dstRow[i] = stencil[i];
3350
3351 src += srcRowStride;
3352 dstRow += dstRowStride / sizeof(GLubyte);
3353 }
3354 }
3355
3356 }
3357
3358 return GL_TRUE;
3359 }
3360
3361
3362 /**
3363 * Store an image in any of the formats:
3364 * _mesa_texformat_rgba_float32
3365 * _mesa_texformat_rgb_float32
3366 * _mesa_texformat_alpha_float32
3367 * _mesa_texformat_luminance_float32
3368 * _mesa_texformat_luminance_alpha_float32
3369 * _mesa_texformat_intensity_float32
3370 */
3371 static GLboolean
3372 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
3373 {
3374 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3375 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3376 const GLint components = _mesa_components_in_format(baseFormat);
3377
3378 ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT32 ||
3379 dstFormat == MESA_FORMAT_RGB_FLOAT32 ||
3380 dstFormat == MESA_FORMAT_ALPHA_FLOAT32 ||
3381 dstFormat == MESA_FORMAT_LUMINANCE_FLOAT32 ||
3382 dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32 ||
3383 dstFormat == MESA_FORMAT_INTENSITY_FLOAT32);
3384 ASSERT(baseInternalFormat == GL_RGBA ||
3385 baseInternalFormat == GL_RGB ||
3386 baseInternalFormat == GL_ALPHA ||
3387 baseInternalFormat == GL_LUMINANCE ||
3388 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3389 baseInternalFormat == GL_INTENSITY);
3390 ASSERT(texelBytes == components * sizeof(GLfloat));
3391
3392 if (!ctx->_ImageTransferState &&
3393 !srcPacking->SwapBytes &&
3394 baseInternalFormat == srcFormat &&
3395 srcType == GL_FLOAT) {
3396 /* simple memcpy path */
3397 memcpy_texture(ctx, dims,
3398 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3399 dstRowStride,
3400 dstImageOffsets,
3401 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3402 srcAddr, srcPacking);
3403 }
3404 else {
3405 /* general path */
3406 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3407 baseInternalFormat,
3408 baseFormat,
3409 srcWidth, srcHeight, srcDepth,
3410 srcFormat, srcType, srcAddr,
3411 srcPacking,
3412 ctx->_ImageTransferState);
3413 const GLfloat *srcRow = tempImage;
3414 GLint bytesPerRow;
3415 GLint img, row;
3416 if (!tempImage)
3417 return GL_FALSE;
3418 bytesPerRow = srcWidth * components * sizeof(GLfloat);
3419 for (img = 0; img < srcDepth; img++) {
3420 GLubyte *dstRow = (GLubyte *) dstAddr
3421 + dstImageOffsets[dstZoffset + img] * texelBytes
3422 + dstYoffset * dstRowStride
3423 + dstXoffset * texelBytes;
3424 for (row = 0; row < srcHeight; row++) {
3425 memcpy(dstRow, srcRow, bytesPerRow);
3426 dstRow += dstRowStride;
3427 srcRow += srcWidth * components;
3428 }
3429 }
3430
3431 free((void *) tempImage);
3432 }
3433 return GL_TRUE;
3434 }
3435
3436
3437
3438 /**
3439 * As above, but store 16-bit floats.
3440 */
3441 static GLboolean
3442 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
3443 {
3444 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3445 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3446 const GLint components = _mesa_components_in_format(baseFormat);
3447
3448 ASSERT(dstFormat == MESA_FORMAT_RGBA_FLOAT16 ||
3449 dstFormat == MESA_FORMAT_RGB_FLOAT16 ||
3450 dstFormat == MESA_FORMAT_ALPHA_FLOAT16 ||
3451 dstFormat == MESA_FORMAT_LUMINANCE_FLOAT16 ||
3452 dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16 ||
3453 dstFormat == MESA_FORMAT_INTENSITY_FLOAT16);
3454 ASSERT(baseInternalFormat == GL_RGBA ||
3455 baseInternalFormat == GL_RGB ||
3456 baseInternalFormat == GL_ALPHA ||
3457 baseInternalFormat == GL_LUMINANCE ||
3458 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3459 baseInternalFormat == GL_INTENSITY);
3460 ASSERT(texelBytes == components * sizeof(GLhalfARB));
3461
3462 if (!ctx->_ImageTransferState &&
3463 !srcPacking->SwapBytes &&
3464 baseInternalFormat == srcFormat &&
3465 srcType == GL_HALF_FLOAT_ARB) {
3466 /* simple memcpy path */
3467 memcpy_texture(ctx, dims,
3468 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3469 dstRowStride,
3470 dstImageOffsets,
3471 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3472 srcAddr, srcPacking);
3473 }
3474 else {
3475 /* general path */
3476 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3477 baseInternalFormat,
3478 baseFormat,
3479 srcWidth, srcHeight, srcDepth,
3480 srcFormat, srcType, srcAddr,
3481 srcPacking,
3482 ctx->_ImageTransferState);
3483 const GLfloat *src = tempImage;
3484 GLint img, row;
3485 if (!tempImage)
3486 return GL_FALSE;
3487 for (img = 0; img < srcDepth; img++) {
3488 GLubyte *dstRow = (GLubyte *) dstAddr
3489 + dstImageOffsets[dstZoffset + img] * texelBytes
3490 + dstYoffset * dstRowStride
3491 + dstXoffset * texelBytes;
3492 for (row = 0; row < srcHeight; row++) {
3493 GLhalfARB *dstTexel = (GLhalfARB *) dstRow;
3494 GLint i;
3495 for (i = 0; i < srcWidth * components; i++) {
3496 dstTexel[i] = _mesa_float_to_half(src[i]);
3497 }
3498 dstRow += dstRowStride;
3499 src += srcWidth * components;
3500 }
3501 }
3502
3503 free((void *) tempImage);
3504 }
3505 return GL_TRUE;
3506 }
3507
3508
3509 /* non-normalized, signed int8 */
3510 static GLboolean
3511 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
3512 {
3513 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3514 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3515 const GLint components = _mesa_components_in_format(baseFormat);
3516
3517 ASSERT(dstFormat == MESA_FORMAT_RGBA_INT8);
3518 ASSERT(baseInternalFormat == GL_RGBA ||
3519 baseInternalFormat == GL_RGB ||
3520 baseInternalFormat == GL_ALPHA ||
3521 baseInternalFormat == GL_LUMINANCE ||
3522 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3523 baseInternalFormat == GL_INTENSITY);
3524 ASSERT(texelBytes == components * sizeof(GLbyte));
3525
3526 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3527 * to integer formats.
3528 */
3529 if (!srcPacking->SwapBytes &&
3530 baseInternalFormat == srcFormat &&
3531 srcType == GL_BYTE) {
3532 /* simple memcpy path */
3533 memcpy_texture(ctx, dims,
3534 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3535 dstRowStride,
3536 dstImageOffsets,
3537 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3538 srcAddr, srcPacking);
3539 }
3540 else {
3541 /* general path */
3542 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3543 baseInternalFormat,
3544 baseFormat,
3545 srcWidth, srcHeight, srcDepth,
3546 srcFormat, srcType, srcAddr,
3547 srcPacking, 0x0);
3548 const GLfloat *src = tempImage;
3549 GLint img, row;
3550 if (!tempImage)
3551 return GL_FALSE;
3552 for (img = 0; img < srcDepth; img++) {
3553 GLubyte *dstRow = (GLubyte *) dstAddr
3554 + dstImageOffsets[dstZoffset + img] * texelBytes
3555 + dstYoffset * dstRowStride
3556 + dstXoffset * texelBytes;
3557 for (row = 0; row < srcHeight; row++) {
3558 GLbyte *dstTexel = (GLbyte *) dstRow;
3559 GLint i;
3560 for (i = 0; i < srcWidth * components; i++) {
3561 dstTexel[i] = (GLbyte) src[i];
3562 }
3563 dstRow += dstRowStride;
3564 src += srcWidth * components;
3565 }
3566 }
3567
3568 free((void *) tempImage);
3569 }
3570 return GL_TRUE;
3571 }
3572
3573
3574 /* non-normalized, signed int16 */
3575 static GLboolean
3576 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
3577 {
3578 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3579 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3580 const GLint components = _mesa_components_in_format(baseFormat);
3581
3582 ASSERT(dstFormat == MESA_FORMAT_RGBA_INT16);
3583 ASSERT(baseInternalFormat == GL_RGBA ||
3584 baseInternalFormat == GL_RGB ||
3585 baseInternalFormat == GL_ALPHA ||
3586 baseInternalFormat == GL_LUMINANCE ||
3587 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3588 baseInternalFormat == GL_INTENSITY);
3589 ASSERT(texelBytes == components * sizeof(GLshort));
3590
3591 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3592 * to integer formats.
3593 */
3594 if (!srcPacking->SwapBytes &&
3595 baseInternalFormat == srcFormat &&
3596 srcType == GL_SHORT) {
3597 /* simple memcpy path */
3598 memcpy_texture(ctx, dims,
3599 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3600 dstRowStride,
3601 dstImageOffsets,
3602 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3603 srcAddr, srcPacking);
3604 }
3605 else {
3606 /* general path */
3607 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3608 baseInternalFormat,
3609 baseFormat,
3610 srcWidth, srcHeight, srcDepth,
3611 srcFormat, srcType, srcAddr,
3612 srcPacking, 0x0);
3613 const GLfloat *src = tempImage;
3614 GLint img, row;
3615 if (!tempImage)
3616 return GL_FALSE;
3617 for (img = 0; img < srcDepth; img++) {
3618 GLubyte *dstRow = (GLubyte *) dstAddr
3619 + dstImageOffsets[dstZoffset + img] * texelBytes
3620 + dstYoffset * dstRowStride
3621 + dstXoffset * texelBytes;
3622 for (row = 0; row < srcHeight; row++) {
3623 GLshort *dstTexel = (GLshort *) dstRow;
3624 GLint i;
3625 for (i = 0; i < srcWidth * components; i++) {
3626 dstTexel[i] = (GLint) src[i];
3627 }
3628 dstRow += dstRowStride;
3629 src += srcWidth * components;
3630 }
3631 }
3632
3633 free((void *) tempImage);
3634 }
3635 return GL_TRUE;
3636 }
3637
3638
3639 /* non-normalized, signed int32 */
3640 static GLboolean
3641 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
3642 {
3643 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3644 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3645 const GLint components = _mesa_components_in_format(baseFormat);
3646
3647 ASSERT(dstFormat == MESA_FORMAT_RGBA_INT32);
3648 ASSERT(baseInternalFormat == GL_RGBA ||
3649 baseInternalFormat == GL_RGB ||
3650 baseInternalFormat == GL_ALPHA ||
3651 baseInternalFormat == GL_LUMINANCE ||
3652 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3653 baseInternalFormat == GL_INTENSITY);
3654 ASSERT(texelBytes == components * sizeof(GLint));
3655
3656 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3657 * to integer formats.
3658 */
3659 if (!srcPacking->SwapBytes &&
3660 baseInternalFormat == srcFormat &&
3661 srcType == GL_INT) {
3662 /* simple memcpy path */
3663 memcpy_texture(ctx, dims,
3664 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3665 dstRowStride,
3666 dstImageOffsets,
3667 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3668 srcAddr, srcPacking);
3669 }
3670 else {
3671 /* general path */
3672 const GLfloat *tempImage = make_temp_float_image(ctx, dims,
3673 baseInternalFormat,
3674 baseFormat,
3675 srcWidth, srcHeight, srcDepth,
3676 srcFormat, srcType, srcAddr,
3677 srcPacking, 0x0);
3678 const GLfloat *src = tempImage;
3679 GLint img, row;
3680 if (!tempImage)
3681 return GL_FALSE;
3682 for (img = 0; img < srcDepth; img++) {
3683 GLubyte *dstRow = (GLubyte *) dstAddr
3684 + dstImageOffsets[dstZoffset + img] * texelBytes
3685 + dstYoffset * dstRowStride
3686 + dstXoffset * texelBytes;
3687 for (row = 0; row < srcHeight; row++) {
3688 GLint *dstTexel = (GLint *) dstRow;
3689 GLint i;
3690 for (i = 0; i < srcWidth * components; i++) {
3691 dstTexel[i] = (GLint) src[i];
3692 }
3693 dstRow += dstRowStride;
3694 src += srcWidth * components;
3695 }
3696 }
3697
3698 free((void *) tempImage);
3699 }
3700 return GL_TRUE;
3701 }
3702
3703
3704 /* non-normalized, unsigned int8 */
3705 static GLboolean
3706 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
3707 {
3708 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3709 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3710 const GLint components = _mesa_components_in_format(baseFormat);
3711
3712 ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT8);
3713 ASSERT(baseInternalFormat == GL_RGBA ||
3714 baseInternalFormat == GL_RGB ||
3715 baseInternalFormat == GL_ALPHA ||
3716 baseInternalFormat == GL_LUMINANCE ||
3717 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3718 baseInternalFormat == GL_INTENSITY);
3719 ASSERT(texelBytes == components * sizeof(GLubyte));
3720
3721 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3722 * to integer formats.
3723 */
3724 if (!srcPacking->SwapBytes &&
3725 baseInternalFormat == srcFormat &&
3726 srcType == GL_UNSIGNED_BYTE) {
3727 /* simple memcpy path */
3728 memcpy_texture(ctx, dims,
3729 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3730 dstRowStride,
3731 dstImageOffsets,
3732 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3733 srcAddr, srcPacking);
3734 }
3735 else {
3736 /* general path */
3737 const GLuint *tempImage =
3738 make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
3739 srcWidth, srcHeight, srcDepth,
3740 srcFormat, srcType, srcAddr, srcPacking);
3741 const GLuint *src = tempImage;
3742 GLint img, row;
3743 if (!tempImage)
3744 return GL_FALSE;
3745 for (img = 0; img < srcDepth; img++) {
3746 GLubyte *dstRow = (GLubyte *) dstAddr
3747 + dstImageOffsets[dstZoffset + img] * texelBytes
3748 + dstYoffset * dstRowStride
3749 + dstXoffset * texelBytes;
3750 for (row = 0; row < srcHeight; row++) {
3751 GLubyte *dstTexel = (GLubyte *) dstRow;
3752 GLint i;
3753 for (i = 0; i < srcWidth * components; i++) {
3754 dstTexel[i] = (GLubyte) CLAMP(src[i], 0, 0xff);
3755 }
3756 dstRow += dstRowStride;
3757 src += srcWidth * components;
3758 }
3759 }
3760
3761 free((void *) tempImage);
3762 }
3763 return GL_TRUE;
3764 }
3765
3766
3767 /* non-normalized, unsigned int16 */
3768 static GLboolean
3769 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
3770 {
3771 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3772 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3773 const GLint components = _mesa_components_in_format(baseFormat);
3774
3775 ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT16);
3776 ASSERT(baseInternalFormat == GL_RGBA ||
3777 baseInternalFormat == GL_RGB ||
3778 baseInternalFormat == GL_ALPHA ||
3779 baseInternalFormat == GL_LUMINANCE ||
3780 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3781 baseInternalFormat == GL_INTENSITY);
3782 ASSERT(texelBytes == components * sizeof(GLushort));
3783
3784 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3785 * to integer formats.
3786 */
3787 if (!srcPacking->SwapBytes &&
3788 baseInternalFormat == srcFormat &&
3789 srcType == GL_UNSIGNED_SHORT) {
3790 /* simple memcpy path */
3791 memcpy_texture(ctx, dims,
3792 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3793 dstRowStride,
3794 dstImageOffsets,
3795 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3796 srcAddr, srcPacking);
3797 }
3798 else {
3799 /* general path */
3800 const GLuint *tempImage =
3801 make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
3802 srcWidth, srcHeight, srcDepth,
3803 srcFormat, srcType, srcAddr, srcPacking);
3804 const GLuint *src = tempImage;
3805 GLint img, row;
3806 if (!tempImage)
3807 return GL_FALSE;
3808 for (img = 0; img < srcDepth; img++) {
3809 GLubyte *dstRow = (GLubyte *) dstAddr
3810 + dstImageOffsets[dstZoffset + img] * texelBytes
3811 + dstYoffset * dstRowStride
3812 + dstXoffset * texelBytes;
3813 for (row = 0; row < srcHeight; row++) {
3814 GLushort *dstTexel = (GLushort *) dstRow;
3815 GLint i;
3816 for (i = 0; i < srcWidth * components; i++) {
3817 dstTexel[i] = (GLushort) CLAMP(src[i], 0, 0xffff);
3818 }
3819 dstRow += dstRowStride;
3820 src += srcWidth * components;
3821 }
3822 }
3823
3824 free((void *) tempImage);
3825 }
3826 return GL_TRUE;
3827 }
3828
3829
3830 /* non-normalized, unsigned int32 */
3831 static GLboolean
3832 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
3833 {
3834 const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3835 const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3836 const GLint components = _mesa_components_in_format(baseFormat);
3837
3838 ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT32);
3839 ASSERT(baseInternalFormat == GL_RGBA ||
3840 baseInternalFormat == GL_RGB ||
3841 baseInternalFormat == GL_ALPHA ||
3842 baseInternalFormat == GL_LUMINANCE ||
3843 baseInternalFormat == GL_LUMINANCE_ALPHA ||
3844 baseInternalFormat == GL_INTENSITY);
3845 ASSERT(texelBytes == components * sizeof(GLuint));
3846
3847 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3848 * to integer formats.
3849 */
3850 if (!srcPacking->SwapBytes &&
3851 baseInternalFormat == srcFormat &&
3852 srcType == GL_UNSIGNED_INT) {
3853 /* simple memcpy path */
3854 memcpy_texture(ctx, dims,
3855 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3856 dstRowStride,
3857 dstImageOffsets,
3858 srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3859 srcAddr, srcPacking);
3860 }
3861 else {
3862 /* general path */
3863 const GLuint *tempImage =
3864 make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
3865 srcWidth, srcHeight, srcDepth,
3866 srcFormat, srcType, srcAddr, srcPacking);
3867 const GLuint *src = tempImage;
3868 GLint img, row;
3869 if (!tempImage)
3870 return GL_FALSE;
3871 for (img = 0; img < srcDepth; img++) {
3872 GLubyte *dstRow = (GLubyte *) dstAddr
3873 + dstImageOffsets[dstZoffset + img] * texelBytes
3874 + dstYoffset * dstRowStride
3875 + dstXoffset * texelBytes;
3876 for (row = 0; row < srcHeight; row++) {
3877 GLuint *dstTexel = (GLuint *) dstRow;
3878 GLint i;
3879 for (i = 0; i < srcWidth * components; i++) {
3880 dstTexel[i] = src[i];
3881 }
3882 dstRow += dstRowStride;
3883 src += srcWidth * components;
3884 }
3885 }
3886
3887 free((void *) tempImage);
3888 }
3889 return GL_TRUE;
3890 }
3891
3892
3893
3894
3895 #if FEATURE_EXT_texture_sRGB
3896 static GLboolean
3897 _mesa_texstore_srgb8(TEXSTORE_PARAMS)
3898 {
3899 gl_format newDstFormat;
3900 GLboolean k;
3901
3902 ASSERT(dstFormat == MESA_FORMAT_SRGB8);
3903
3904 /* reuse normal rgb texstore code */
3905 newDstFormat = MESA_FORMAT_RGB888;
3906
3907 k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat,
3908 newDstFormat, dstAddr,
3909 dstXoffset, dstYoffset, dstZoffset,
3910 dstRowStride, dstImageOffsets,
3911 srcWidth, srcHeight, srcDepth,
3912 srcFormat, srcType,
3913 srcAddr, srcPacking);
3914 return k;
3915 }
3916
3917
3918 static GLboolean
3919 _mesa_texstore_srgba8(TEXSTORE_PARAMS)
3920 {
3921 gl_format newDstFormat;
3922 GLboolean k;
3923
3924 ASSERT(dstFormat == MESA_FORMAT_SRGBA8);
3925
3926 /* reuse normal rgba texstore code */
3927 newDstFormat = MESA_FORMAT_RGBA8888;
3928 k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat,
3929 newDstFormat, dstAddr,
3930 dstXoffset, dstYoffset, dstZoffset,
3931 dstRowStride, dstImageOffsets,
3932 srcWidth, srcHeight, srcDepth,
3933 srcFormat, srcType,
3934 srcAddr, srcPacking);
3935 return k;
3936 }
3937
3938
3939 static GLboolean
3940 _mesa_texstore_sargb8(TEXSTORE_PARAMS)
3941 {
3942 gl_format newDstFormat;
3943 GLboolean k;
3944
3945 ASSERT(dstFormat == MESA_FORMAT_SARGB8);
3946
3947 /* reuse normal rgba texstore code */
3948 newDstFormat = MESA_FORMAT_ARGB8888;
3949
3950 k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat,
3951 newDstFormat, dstAddr,
3952 dstXoffset, dstYoffset, dstZoffset,
3953 dstRowStride, dstImageOffsets,
3954 srcWidth, srcHeight, srcDepth,
3955 srcFormat, srcType,
3956 srcAddr, srcPacking);
3957 return k;
3958 }
3959
3960
3961 static GLboolean
3962 _mesa_texstore_sl8(TEXSTORE_PARAMS)
3963 {
3964 gl_format newDstFormat;
3965 GLboolean k;
3966
3967 ASSERT(dstFormat == MESA_FORMAT_SL8);
3968
3969 newDstFormat = MESA_FORMAT_L8;
3970
3971 /* _mesa_textore_a8 handles luminance8 too */
3972 k = _mesa_texstore_a8(ctx, dims, baseInternalFormat,
3973 newDstFormat, dstAddr,
3974 dstXoffset, dstYoffset, dstZoffset,
3975 dstRowStride, dstImageOffsets,
3976 srcWidth, srcHeight, srcDepth,
3977 srcFormat, srcType,
3978 srcAddr, srcPacking);
3979 return k;
3980 }
3981
3982
3983 static GLboolean
3984 _mesa_texstore_sla8(TEXSTORE_PARAMS)
3985 {
3986 gl_format newDstFormat;
3987 GLboolean k;
3988
3989 ASSERT(dstFormat == MESA_FORMAT_SLA8);
3990
3991 /* reuse normal luminance/alpha texstore code */
3992 newDstFormat = MESA_FORMAT_AL88;
3993
3994 k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
3995 newDstFormat, dstAddr,
3996 dstXoffset, dstYoffset, dstZoffset,
3997 dstRowStride, dstImageOffsets,
3998 srcWidth, srcHeight, srcDepth,
3999 srcFormat, srcType,
4000 srcAddr, srcPacking);
4001 return k;
4002 }
4003
4004 #else
4005
4006 /* these are used only in texstore_funcs[] below */
4007 #define _mesa_texstore_srgb8 NULL
4008 #define _mesa_texstore_srgba8 NULL
4009 #define _mesa_texstore_sargb8 NULL
4010 #define _mesa_texstore_sl8 NULL
4011 #define _mesa_texstore_sla8 NULL
4012
4013 #endif /* FEATURE_EXT_texture_sRGB */
4014
4015
4016
4017
4018 /**
4019 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4020 * XXX this is somewhat temporary.
4021 */
4022 static const struct {
4023 gl_format Name;
4024 StoreTexImageFunc Store;
4025 }
4026 texstore_funcs[MESA_FORMAT_COUNT] =
4027 {
4028 { MESA_FORMAT_NONE, NULL },
4029 { MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
4030 { MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
4031 { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
4032 { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
4033 { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
4034 { MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
4035 { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
4036 { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
4037 { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
4038 { MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
4039 { MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
4040 { MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
4041 { MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
4042 { MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
4043 { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
4044 { MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
4045 { MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
4046 { MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
4047 { MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },
4048 { MESA_FORMAT_AL1616_REV, _mesa_texstore_unorm1616 },
4049 { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
4050 { MESA_FORMAT_A8, _mesa_texstore_a8 },
4051 { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
4052 { MESA_FORMAT_L8, _mesa_texstore_a8 },
4053 { MESA_FORMAT_I8, _mesa_texstore_a8 },
4054 { MESA_FORMAT_CI8, _mesa_texstore_ci8 },
4055 { MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
4056 { MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
4057 { MESA_FORMAT_R8, _mesa_texstore_a8 },
4058 { MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
4059 { MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
4060 { MESA_FORMAT_R16, _mesa_texstore_unorm16 },
4061 { MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
4062 { MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
4063 { MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
4064 { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
4065 { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
4066 { MESA_FORMAT_Z16, _mesa_texstore_z16 },
4067 { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
4068 { MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
4069 { MESA_FORMAT_Z32, _mesa_texstore_z32 },
4070 { MESA_FORMAT_S8, _mesa_texstore_s8 },
4071 { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
4072 { MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
4073 { MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
4074 { MESA_FORMAT_SL8, _mesa_texstore_sl8 },
4075 { MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
4076 { MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
4077 { MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4078 { MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4079 { MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4080 { MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
4081 { MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
4082 { MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
4083 { MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4084 { MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4085 { MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4086 { MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
4087 { MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
4088 { MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
4089 { MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
4090 { MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4091 { MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4092 { MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
4093 { MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
4094 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4095 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4096 { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
4097 { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
4098
4099 { MESA_FORMAT_RGBA_INT8, _mesa_texstore_rgba_int8 },
4100 { MESA_FORMAT_RGBA_INT16, _mesa_texstore_rgba_int16 },
4101 { MESA_FORMAT_RGBA_INT32, _mesa_texstore_rgba_int32 },
4102 { MESA_FORMAT_RGBA_UINT8, _mesa_texstore_rgba_uint8 },
4103 { MESA_FORMAT_RGBA_UINT16, _mesa_texstore_rgba_uint16 },
4104 { MESA_FORMAT_RGBA_UINT32, _mesa_texstore_rgba_uint32 },
4105
4106 { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
4107
4108 { MESA_FORMAT_SIGNED_R8, _mesa_texstore_signed_r8 },
4109 { MESA_FORMAT_SIGNED_RG88, _mesa_texstore_signed_rg88 },
4110 { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
4111
4112 { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
4113 { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
4114
4115 { MESA_FORMAT_SIGNED_R_16, _mesa_texstore_signed_rgba_16 },
4116 { MESA_FORMAT_SIGNED_RG_16, _mesa_texstore_signed_rgba_16 },
4117 { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
4118 { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
4119 { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 }
4120 };
4121
4122
4123 static GLboolean
4124 _mesa_texstore_null(TEXSTORE_PARAMS)
4125 {
4126 (void) ctx; (void) dims;
4127 (void) baseInternalFormat;
4128 (void) dstFormat;
4129 (void) dstAddr;
4130 (void) dstXoffset; (void) dstYoffset; (void) dstZoffset;
4131 (void) dstRowStride; (void) dstImageOffsets;
4132 (void) srcWidth; (void) srcHeight; (void) srcDepth;
4133 (void) srcFormat; (void) srcType;
4134 (void) srcAddr;
4135 (void) srcPacking;
4136
4137 /* should never happen */
4138 _mesa_problem(NULL, "_mesa_texstore_null() is called");
4139 return GL_FALSE;
4140 }
4141
4142
4143 /**
4144 * Return the StoreTexImageFunc pointer to store an image in the given format.
4145 */
4146 static StoreTexImageFunc
4147 _mesa_get_texstore_func(gl_format format)
4148 {
4149 #ifdef DEBUG
4150 GLuint i;
4151 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
4152 ASSERT(texstore_funcs[i].Name == i);
4153 }
4154 #endif
4155 ASSERT(texstore_funcs[format].Name == format);
4156
4157 if (texstore_funcs[format].Store)
4158 return texstore_funcs[format].Store;
4159 else
4160 return _mesa_texstore_null;
4161 }
4162
4163
4164 /**
4165 * Store user data into texture memory.
4166 * Called via glTex[Sub]Image1/2/3D()
4167 */
4168 GLboolean
4169 _mesa_texstore(TEXSTORE_PARAMS)
4170 {
4171 StoreTexImageFunc storeImage;
4172 GLboolean success;
4173
4174 storeImage = _mesa_get_texstore_func(dstFormat);
4175
4176 success = storeImage(ctx, dims, baseInternalFormat,
4177 dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4178 dstRowStride, dstImageOffsets,
4179 srcWidth, srcHeight, srcDepth,
4180 srcFormat, srcType, srcAddr, srcPacking);
4181 return success;
4182 }
4183
4184
4185 /**
4186 * Check if an unpack PBO is active prior to fetching a texture image.
4187 * If so, do bounds checking and map the buffer into main memory.
4188 * Any errors detected will be recorded.
4189 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4190 */
4191 const GLvoid *
4192 _mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions,
4193 GLsizei width, GLsizei height, GLsizei depth,
4194 GLenum format, GLenum type, const GLvoid *pixels,
4195 const struct gl_pixelstore_attrib *unpack,
4196 const char *funcName)
4197 {
4198 GLubyte *buf;
4199
4200 if (!_mesa_is_bufferobj(unpack->BufferObj)) {
4201 /* no PBO */
4202 return pixels;
4203 }
4204 if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth,
4205 format, type, pixels)) {
4206 _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)");
4207 return NULL;
4208 }
4209
4210 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
4211 GL_READ_ONLY_ARB, unpack->BufferObj);
4212 if (!buf) {
4213 _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped)");
4214 return NULL;
4215 }
4216
4217 return ADD_POINTERS(buf, pixels);
4218 }
4219
4220
4221 /**
4222 * Check if an unpack PBO is active prior to fetching a compressed texture
4223 * image.
4224 * If so, do bounds checking and map the buffer into main memory.
4225 * Any errors detected will be recorded.
4226 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
4227 */
4228 const GLvoid *
4229 _mesa_validate_pbo_compressed_teximage(struct gl_context *ctx,
4230 GLsizei imageSize, const GLvoid *pixels,
4231 const struct gl_pixelstore_attrib *packing,
4232 const char *funcName)
4233 {
4234 GLubyte *buf;
4235
4236 if (!_mesa_is_bufferobj(packing->BufferObj)) {
4237 /* not using a PBO - return pointer unchanged */
4238 return pixels;
4239 }
4240 if ((const GLubyte *) pixels + imageSize >
4241 ((const GLubyte *) 0) + packing->BufferObj->Size) {
4242 /* out of bounds read! */
4243 _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)");
4244 return NULL;
4245 }
4246
4247 buf = (GLubyte*) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
4248 GL_READ_ONLY_ARB, packing->BufferObj);
4249 if (!buf) {
4250 _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped");
4251 return NULL;
4252 }
4253
4254 return ADD_POINTERS(buf, pixels);
4255 }
4256
4257
4258 /**
4259 * This function must be called after either of the validate_pbo_*_teximage()
4260 * functions. It unmaps the PBO buffer if it was mapped earlier.
4261 */
4262 void
4263 _mesa_unmap_teximage_pbo(struct gl_context *ctx,
4264 const struct gl_pixelstore_attrib *unpack)
4265 {
4266 if (_mesa_is_bufferobj(unpack->BufferObj)) {
4267 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
4268 unpack->BufferObj);
4269 }
4270 }
4271
4272
4273 /** Return texture size in bytes */
4274 static GLuint
4275 texture_size(const struct gl_texture_image *texImage)
4276 {
4277 GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
4278 texImage->Height, texImage->Depth);
4279 return sz;
4280 }
4281
4282
4283 /** Return row stride in bytes */
4284 static GLuint
4285 texture_row_stride(const struct gl_texture_image *texImage)
4286 {
4287 GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
4288 texImage->Width);
4289 return stride;
4290 }
4291
4292
4293
4294 /**
4295 * This is the software fallback for Driver.TexImage1D()
4296 * and Driver.CopyTexImage1D().
4297 * \sa _mesa_store_teximage2d()
4298 */
4299 void
4300 _mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
4301 GLint internalFormat,
4302 GLint width, GLint border,
4303 GLenum format, GLenum type, const GLvoid *pixels,
4304 const struct gl_pixelstore_attrib *packing,
4305 struct gl_texture_object *texObj,
4306 struct gl_texture_image *texImage)
4307 {
4308 GLuint sizeInBytes;
4309 (void) border;
4310
4311 /* allocate memory */
4312 sizeInBytes = texture_size(texImage);
4313 texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4314 if (!texImage->Data) {
4315 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4316 return;
4317 }
4318
4319 pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4320 pixels, packing, "glTexImage1D");
4321 if (!pixels) {
4322 /* Note: we check for a NULL image pointer here, _after_ we allocated
4323 * memory for the texture. That's what the GL spec calls for.
4324 */
4325 return;
4326 }
4327 else {
4328 const GLint dstRowStride = 0;
4329 GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4330 texImage->TexFormat,
4331 texImage->Data,
4332 0, 0, 0, /* dstX/Y/Zoffset */
4333 dstRowStride,
4334 texImage->ImageOffsets,
4335 width, 1, 1,
4336 format, type, pixels, packing);
4337 if (!success) {
4338 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4339 }
4340 }
4341
4342 _mesa_unmap_teximage_pbo(ctx, packing);
4343 }
4344
4345
4346 /**
4347 * This is the software fallback for Driver.TexImage2D()
4348 * and Driver.CopyTexImage2D().
4349 *
4350 * This function is oriented toward storing images in main memory, rather
4351 * than VRAM. Device driver's can easily plug in their own replacement.
4352 */
4353 void
4354 _mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
4355 GLint internalFormat,
4356 GLint width, GLint height, GLint border,
4357 GLenum format, GLenum type, const void *pixels,
4358 const struct gl_pixelstore_attrib *packing,
4359 struct gl_texture_object *texObj,
4360 struct gl_texture_image *texImage)
4361 {
4362 GLuint sizeInBytes;
4363 (void) border;
4364
4365 /* allocate memory */
4366 sizeInBytes = texture_size(texImage);
4367 texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4368 if (!texImage->Data) {
4369 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4370 return;
4371 }
4372
4373 pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4374 pixels, packing, "glTexImage2D");
4375 if (!pixels) {
4376 /* Note: we check for a NULL image pointer here, _after_ we allocated
4377 * memory for the texture. That's what the GL spec calls for.
4378 */
4379 return;
4380 }
4381 else {
4382 GLint dstRowStride = texture_row_stride(texImage);
4383 GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4384 texImage->TexFormat,
4385 texImage->Data,
4386 0, 0, 0, /* dstX/Y/Zoffset */
4387 dstRowStride,
4388 texImage->ImageOffsets,
4389 width, height, 1,
4390 format, type, pixels, packing);
4391 if (!success) {
4392 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4393 }
4394 }
4395
4396 _mesa_unmap_teximage_pbo(ctx, packing);
4397 }
4398
4399
4400
4401 /**
4402 * This is the software fallback for Driver.TexImage3D()
4403 * and Driver.CopyTexImage3D().
4404 * \sa _mesa_store_teximage2d()
4405 */
4406 void
4407 _mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
4408 GLint internalFormat,
4409 GLint width, GLint height, GLint depth, GLint border,
4410 GLenum format, GLenum type, const void *pixels,
4411 const struct gl_pixelstore_attrib *packing,
4412 struct gl_texture_object *texObj,
4413 struct gl_texture_image *texImage)
4414 {
4415 GLuint sizeInBytes;
4416 (void) border;
4417
4418 /* allocate memory */
4419 sizeInBytes = texture_size(texImage);
4420 texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4421 if (!texImage->Data) {
4422 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4423 return;
4424 }
4425
4426 pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4427 type, pixels, packing, "glTexImage3D");
4428 if (!pixels) {
4429 /* Note: we check for a NULL image pointer here, _after_ we allocated
4430 * memory for the texture. That's what the GL spec calls for.
4431 */
4432 return;
4433 }
4434 else {
4435 GLint dstRowStride = texture_row_stride(texImage);
4436 GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4437 texImage->TexFormat,
4438 texImage->Data,
4439 0, 0, 0, /* dstX/Y/Zoffset */
4440 dstRowStride,
4441 texImage->ImageOffsets,
4442 width, height, depth,
4443 format, type, pixels, packing);
4444 if (!success) {
4445 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4446 }
4447 }
4448
4449 _mesa_unmap_teximage_pbo(ctx, packing);
4450 }
4451
4452
4453
4454
4455 /*
4456 * This is the software fallback for Driver.TexSubImage1D()
4457 * and Driver.CopyTexSubImage1D().
4458 */
4459 void
4460 _mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
4461 GLint xoffset, GLint width,
4462 GLenum format, GLenum type, const void *pixels,
4463 const struct gl_pixelstore_attrib *packing,
4464 struct gl_texture_object *texObj,
4465 struct gl_texture_image *texImage)
4466 {
4467 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4468 pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4469 pixels, packing, "glTexSubImage1D");
4470 if (!pixels)
4471 return;
4472
4473 {
4474 const GLint dstRowStride = 0;
4475 GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4476 texImage->TexFormat,
4477 texImage->Data,
4478 xoffset, 0, 0, /* offsets */
4479 dstRowStride,
4480 texImage->ImageOffsets,
4481 width, 1, 1,
4482 format, type, pixels, packing);
4483 if (!success) {
4484 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
4485 }
4486 }
4487
4488 _mesa_unmap_teximage_pbo(ctx, packing);
4489 }
4490
4491
4492
4493 /**
4494 * This is the software fallback for Driver.TexSubImage2D()
4495 * and Driver.CopyTexSubImage2D().
4496 */
4497 void
4498 _mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
4499 GLint xoffset, GLint yoffset,
4500 GLint width, GLint height,
4501 GLenum format, GLenum type, const void *pixels,
4502 const struct gl_pixelstore_attrib *packing,
4503 struct gl_texture_object *texObj,
4504 struct gl_texture_image *texImage)
4505 {
4506 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4507 pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4508 pixels, packing, "glTexSubImage2D");
4509 if (!pixels)
4510 return;
4511
4512 {
4513 GLint dstRowStride = texture_row_stride(texImage);
4514 GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4515 texImage->TexFormat,
4516 texImage->Data,
4517 xoffset, yoffset, 0,
4518 dstRowStride,
4519 texImage->ImageOffsets,
4520 width, height, 1,
4521 format, type, pixels, packing);
4522 if (!success) {
4523 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
4524 }
4525 }
4526
4527 _mesa_unmap_teximage_pbo(ctx, packing);
4528 }
4529
4530
4531 /*
4532 * This is the software fallback for Driver.TexSubImage3D().
4533 * and Driver.CopyTexSubImage3D().
4534 */
4535 void
4536 _mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
4537 GLint xoffset, GLint yoffset, GLint zoffset,
4538 GLint width, GLint height, GLint depth,
4539 GLenum format, GLenum type, const void *pixels,
4540 const struct gl_pixelstore_attrib *packing,
4541 struct gl_texture_object *texObj,
4542 struct gl_texture_image *texImage)
4543 {
4544 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4545 pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4546 type, pixels, packing,
4547 "glTexSubImage3D");
4548 if (!pixels)
4549 return;
4550
4551 {
4552 GLint dstRowStride = texture_row_stride(texImage);
4553 GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4554 texImage->TexFormat,
4555 texImage->Data,
4556 xoffset, yoffset, zoffset,
4557 dstRowStride,
4558 texImage->ImageOffsets,
4559 width, height, depth,
4560 format, type, pixels, packing);
4561 if (!success) {
4562 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
4563 }
4564 }
4565
4566 _mesa_unmap_teximage_pbo(ctx, packing);
4567 }
4568
4569
4570 /*
4571 * Fallback for Driver.CompressedTexImage1D()
4572 */
4573 void
4574 _mesa_store_compressed_teximage1d(struct gl_context *ctx,
4575 GLenum target, GLint level,
4576 GLint internalFormat,
4577 GLint width, GLint border,
4578 GLsizei imageSize, const GLvoid *data,
4579 struct gl_texture_object *texObj,
4580 struct gl_texture_image *texImage)
4581 {
4582 /* this space intentionally left blank */
4583 (void) ctx;
4584 (void) target; (void) level;
4585 (void) internalFormat;
4586 (void) width; (void) border;
4587 (void) imageSize; (void) data;
4588 (void) texObj;
4589 (void) texImage;
4590 }
4591
4592
4593
4594 /**
4595 * Fallback for Driver.CompressedTexImage2D()
4596 */
4597 void
4598 _mesa_store_compressed_teximage2d(struct gl_context *ctx,
4599 GLenum target, GLint level,
4600 GLint internalFormat,
4601 GLint width, GLint height, GLint border,
4602 GLsizei imageSize, const GLvoid *data,
4603 struct gl_texture_object *texObj,
4604 struct gl_texture_image *texImage)
4605 {
4606 (void) width; (void) height; (void) border;
4607
4608 /* This is pretty simple, basically just do a memcpy without worrying
4609 * about the usual image unpacking or image transfer operations.
4610 */
4611 ASSERT(texObj);
4612 ASSERT(texImage);
4613 ASSERT(texImage->Width > 0);
4614 ASSERT(texImage->Height > 0);
4615 ASSERT(texImage->Depth == 1);
4616 ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
4617
4618 /* allocate storage */
4619 texImage->Data = _mesa_alloc_texmemory(imageSize);
4620 if (!texImage->Data) {
4621 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
4622 return;
4623 }
4624
4625 data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
4626 &ctx->Unpack,
4627 "glCompressedTexImage2D");
4628 if (!data)
4629 return;
4630
4631 /* copy the data */
4632 memcpy(texImage->Data, data, imageSize);
4633
4634 _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
4635 }
4636
4637
4638
4639 /*
4640 * Fallback for Driver.CompressedTexImage3D()
4641 */
4642 void
4643 _mesa_store_compressed_teximage3d(struct gl_context *ctx,
4644 GLenum target, GLint level,
4645 GLint internalFormat,
4646 GLint width, GLint height, GLint depth,
4647 GLint border,
4648 GLsizei imageSize, const GLvoid *data,
4649 struct gl_texture_object *texObj,
4650 struct gl_texture_image *texImage)
4651 {
4652 /* this space intentionally left blank */
4653 (void) ctx;
4654 (void) target; (void) level;
4655 (void) internalFormat;
4656 (void) width; (void) height; (void) depth;
4657 (void) border;
4658 (void) imageSize; (void) data;
4659 (void) texObj;
4660 (void) texImage;
4661 }
4662
4663
4664
4665 /**
4666 * Fallback for Driver.CompressedTexSubImage1D()
4667 */
4668 void
4669 _mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
4670 GLint level,
4671 GLint xoffset, GLsizei width,
4672 GLenum format,
4673 GLsizei imageSize, const GLvoid *data,
4674 struct gl_texture_object *texObj,
4675 struct gl_texture_image *texImage)
4676 {
4677 /* there are no compressed 1D texture formats yet */
4678 (void) ctx;
4679 (void) target; (void) level;
4680 (void) xoffset; (void) width;
4681 (void) format;
4682 (void) imageSize; (void) data;
4683 (void) texObj;
4684 (void) texImage;
4685 }
4686
4687
4688 /**
4689 * Fallback for Driver.CompressedTexSubImage2D()
4690 */
4691 void
4692 _mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
4693 GLint level,
4694 GLint xoffset, GLint yoffset,
4695 GLsizei width, GLsizei height,
4696 GLenum format,
4697 GLsizei imageSize, const GLvoid *data,
4698 struct gl_texture_object *texObj,
4699 struct gl_texture_image *texImage)
4700 {
4701 GLint bytesPerRow, destRowStride, srcRowStride;
4702 GLint i, rows;
4703 GLubyte *dest;
4704 const GLubyte *src;
4705 const gl_format texFormat = texImage->TexFormat;
4706 const GLint destWidth = texImage->Width;
4707 GLuint bw, bh;
4708
4709 _mesa_get_format_block_size(texFormat, &bw, &bh);
4710
4711 (void) level;
4712 (void) format;
4713
4714 /* these should have been caught sooner */
4715 ASSERT((width % bw) == 0 || width == 2 || width == 1);
4716 ASSERT((height % bh) == 0 || height == 2 || height == 1);
4717 ASSERT((xoffset % bw) == 0);
4718 ASSERT((yoffset % bh) == 0);
4719
4720 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4721 data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
4722 &ctx->Unpack,
4723 "glCompressedTexSubImage2D");
4724 if (!data)
4725 return;
4726
4727 srcRowStride = _mesa_format_row_stride(texFormat, width);
4728 src = (const GLubyte *) data;
4729
4730 destRowStride = _mesa_format_row_stride(texFormat, destWidth);
4731 dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
4732 texFormat, destWidth,
4733 (GLubyte *) texImage->Data);
4734
4735 bytesPerRow = srcRowStride; /* bytes per row of blocks */
4736 rows = height / bh; /* rows in blocks */
4737
4738 /* copy rows of blocks */
4739 for (i = 0; i < rows; i++) {
4740 memcpy(dest, src, bytesPerRow);
4741 dest += destRowStride;
4742 src += srcRowStride;
4743 }
4744
4745 _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
4746 }
4747
4748
4749 /**
4750 * Fallback for Driver.CompressedTexSubImage3D()
4751 */
4752 void
4753 _mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
4754 GLint level,
4755 GLint xoffset, GLint yoffset, GLint zoffset,
4756 GLsizei width, GLsizei height, GLsizei depth,
4757 GLenum format,
4758 GLsizei imageSize, const GLvoid *data,
4759 struct gl_texture_object *texObj,
4760 struct gl_texture_image *texImage)
4761 {
4762 /* there are no compressed 3D texture formats yet */
4763 (void) ctx;
4764 (void) target; (void) level;
4765 (void) xoffset; (void) yoffset; (void) zoffset;
4766 (void) width; (void) height; (void) depth;
4767 (void) format;
4768 (void) imageSize; (void) data;
4769 (void) texObj;
4770 (void) texImage;
4771 }