2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
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
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
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
75 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
76 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
78 #include "u_format_rgb9e5.h"
79 #include "u_format_r11g11b10f.h"
90 * Texture image storage function.
92 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
96 * Return GL_TRUE if the given image format is one that be converted
97 * to another format by swizzling.
100 can_swizzle(GLenum logicalBaseFormat
)
102 switch (logicalBaseFormat
) {
105 case GL_LUMINANCE_ALPHA
:
141 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
142 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
143 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
144 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
147 static const struct {
150 GLubyte from_rgba
[6];
151 } mappings
[MAX_IDX
] =
161 MAP4(ZERO
, ZERO
, ZERO
, 0),
191 MAP4(0, ZERO
, ZERO
, ONE
),
197 MAP4(ZERO
, 0, ZERO
, ONE
),
203 MAP4(ZERO
, ZERO
, 0, ONE
),
227 MAP4(0, 1, ZERO
, ONE
),
235 * Convert a GL image format enum to an IDX_* value (see above).
238 get_map_idx(GLenum value
)
241 case GL_LUMINANCE
: return IDX_LUMINANCE
;
242 case GL_ALPHA
: return IDX_ALPHA
;
243 case GL_INTENSITY
: return IDX_INTENSITY
;
244 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
245 case GL_RGB
: return IDX_RGB
;
246 case GL_RGBA
: return IDX_RGBA
;
247 case GL_RED
: return IDX_RED
;
248 case GL_GREEN
: return IDX_GREEN
;
249 case GL_BLUE
: return IDX_BLUE
;
250 case GL_BGR
: return IDX_BGR
;
251 case GL_BGRA
: return IDX_BGRA
;
252 case GL_ABGR_EXT
: return IDX_ABGR
;
253 case GL_RG
: return IDX_RG
;
255 _mesa_problem(NULL
, "Unexpected inFormat");
262 * When promoting texture formats (see below) we need to compute the
263 * mapping of dest components back to source components.
264 * This function does that.
265 * \param inFormat the incoming format of the texture
266 * \param outFormat the final texture format
267 * \return map[6] a full 6-component map
270 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
273 const int inFmt
= get_map_idx(inFormat
);
274 const int outFmt
= get_map_idx(outFormat
);
275 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
276 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
279 for (i
= 0; i
< 4; i
++)
280 map
[i
] = in2rgba
[rgba2out
[i
]];
286 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
287 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
288 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
300 * Make a temporary (color) texture image with GLfloat components.
301 * Apply all needed pixel unpacking and pixel transfer operations.
302 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
303 * Suppose the user specifies GL_LUMINANCE as the internal texture format
304 * but the graphics hardware doesn't support luminance textures. So, we might
305 * use an RGB hardware format instead.
306 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
308 * \param ctx the rendering context
309 * \param dims image dimensions: 1, 2 or 3
310 * \param logicalBaseFormat basic texture derived from the user's
311 * internal texture format value
312 * \param textureBaseFormat the actual basic format of the texture
313 * \param srcWidth source image width
314 * \param srcHeight source image height
315 * \param srcDepth source image depth
316 * \param srcFormat source image format
317 * \param srcType source image type
318 * \param srcAddr source image address
319 * \param srcPacking source image pixel packing
320 * \return resulting image with format = textureBaseFormat and type = GLfloat.
323 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
324 GLenum logicalBaseFormat
,
325 GLenum textureBaseFormat
,
326 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
327 GLenum srcFormat
, GLenum srcType
,
328 const GLvoid
*srcAddr
,
329 const struct gl_pixelstore_attrib
*srcPacking
,
330 GLbitfield transferOps
)
333 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
334 const GLint srcStride
=
335 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
339 ASSERT(dims
>= 1 && dims
<= 3);
341 ASSERT(logicalBaseFormat
== GL_RGBA
||
342 logicalBaseFormat
== GL_RGB
||
343 logicalBaseFormat
== GL_RG
||
344 logicalBaseFormat
== GL_RED
||
345 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
346 logicalBaseFormat
== GL_LUMINANCE
||
347 logicalBaseFormat
== GL_ALPHA
||
348 logicalBaseFormat
== GL_INTENSITY
||
349 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
351 ASSERT(textureBaseFormat
== GL_RGBA
||
352 textureBaseFormat
== GL_RGB
||
353 textureBaseFormat
== GL_RG
||
354 textureBaseFormat
== GL_RED
||
355 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
356 textureBaseFormat
== GL_LUMINANCE
||
357 textureBaseFormat
== GL_ALPHA
||
358 textureBaseFormat
== GL_INTENSITY
||
359 textureBaseFormat
== GL_DEPTH_COMPONENT
);
361 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
362 * components
* sizeof(GLfloat
));
367 for (img
= 0; img
< srcDepth
; img
++) {
369 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
373 for (row
= 0; row
< srcHeight
; row
++) {
374 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
375 dst
, srcFormat
, srcType
, src
,
376 srcPacking
, transferOps
);
377 dst
+= srcWidth
* components
;
382 if (logicalBaseFormat
!= textureBaseFormat
) {
384 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
385 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
390 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
391 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
392 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
394 /* The actual texture format should have at least as many components
395 * as the logical texture format.
397 ASSERT(texComponents
>= logComponents
);
399 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
400 * texComponents
* sizeof(GLfloat
));
406 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
408 n
= srcWidth
* srcHeight
* srcDepth
;
409 for (i
= 0; i
< n
; i
++) {
411 for (k
= 0; k
< texComponents
; k
++) {
414 newImage
[i
* texComponents
+ k
] = 0.0F
;
416 newImage
[i
* texComponents
+ k
] = 1.0F
;
418 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
423 tempImage
= newImage
;
431 * Make temporary image with uint pixel values. Used for unsigned
432 * integer-valued textures.
435 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
436 GLenum logicalBaseFormat
,
437 GLenum textureBaseFormat
,
438 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
439 GLenum srcFormat
, GLenum srcType
,
440 const GLvoid
*srcAddr
,
441 const struct gl_pixelstore_attrib
*srcPacking
)
444 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
445 const GLint srcStride
=
446 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
450 ASSERT(dims
>= 1 && dims
<= 3);
452 ASSERT(logicalBaseFormat
== GL_RGBA
||
453 logicalBaseFormat
== GL_RGB
||
454 logicalBaseFormat
== GL_RG
||
455 logicalBaseFormat
== GL_RED
||
456 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
457 logicalBaseFormat
== GL_LUMINANCE
||
458 logicalBaseFormat
== GL_INTENSITY
||
459 logicalBaseFormat
== GL_ALPHA
);
461 ASSERT(textureBaseFormat
== GL_RGBA
||
462 textureBaseFormat
== GL_RGB
||
463 textureBaseFormat
== GL_RG
||
464 textureBaseFormat
== GL_RED
||
465 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
466 textureBaseFormat
== GL_LUMINANCE
||
467 textureBaseFormat
== GL_INTENSITY
||
468 textureBaseFormat
== GL_ALPHA
);
470 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
471 * components
* sizeof(GLuint
));
476 for (img
= 0; img
< srcDepth
; img
++) {
478 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
482 for (row
= 0; row
< srcHeight
; row
++) {
483 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
484 dst
, srcFormat
, srcType
, src
,
486 dst
+= srcWidth
* components
;
491 if (logicalBaseFormat
!= textureBaseFormat
) {
493 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
494 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
499 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
500 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
501 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
503 /* The actual texture format should have at least as many components
504 * as the logical texture format.
506 ASSERT(texComponents
>= logComponents
);
508 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
509 * texComponents
* sizeof(GLuint
));
515 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
517 n
= srcWidth
* srcHeight
* srcDepth
;
518 for (i
= 0; i
< n
; i
++) {
520 for (k
= 0; k
< texComponents
; k
++) {
523 newImage
[i
* texComponents
+ k
] = 0;
525 newImage
[i
* texComponents
+ k
] = 1;
527 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
532 tempImage
= newImage
;
541 * Make a temporary (color) texture image with GLubyte components.
542 * Apply all needed pixel unpacking and pixel transfer operations.
543 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
544 * Suppose the user specifies GL_LUMINANCE as the internal texture format
545 * but the graphics hardware doesn't support luminance textures. So, we might
546 * use an RGB hardware format instead.
547 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
549 * \param ctx the rendering context
550 * \param dims image dimensions: 1, 2 or 3
551 * \param logicalBaseFormat basic texture derived from the user's
552 * internal texture format value
553 * \param textureBaseFormat the actual basic format of the texture
554 * \param srcWidth source image width
555 * \param srcHeight source image height
556 * \param srcDepth source image depth
557 * \param srcFormat source image format
558 * \param srcType source image type
559 * \param srcAddr source image address
560 * \param srcPacking source image pixel packing
561 * \return resulting image with format = textureBaseFormat and type = GLubyte.
564 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
565 GLenum logicalBaseFormat
,
566 GLenum textureBaseFormat
,
567 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
568 GLenum srcFormat
, GLenum srcType
,
569 const GLvoid
*srcAddr
,
570 const struct gl_pixelstore_attrib
*srcPacking
)
572 GLuint transferOps
= ctx
->_ImageTransferState
;
573 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
575 GLubyte
*tempImage
, *dst
;
577 ASSERT(dims
>= 1 && dims
<= 3);
579 ASSERT(logicalBaseFormat
== GL_RGBA
||
580 logicalBaseFormat
== GL_RGB
||
581 logicalBaseFormat
== GL_RG
||
582 logicalBaseFormat
== GL_RED
||
583 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
584 logicalBaseFormat
== GL_LUMINANCE
||
585 logicalBaseFormat
== GL_ALPHA
||
586 logicalBaseFormat
== GL_INTENSITY
);
588 ASSERT(textureBaseFormat
== GL_RGBA
||
589 textureBaseFormat
== GL_RGB
||
590 textureBaseFormat
== GL_RG
||
591 textureBaseFormat
== GL_RED
||
592 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
593 textureBaseFormat
== GL_LUMINANCE
||
594 textureBaseFormat
== GL_ALPHA
||
595 textureBaseFormat
== GL_INTENSITY
);
597 /* unpack and transfer the source image */
598 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
599 * components
* sizeof(GLubyte
));
605 for (img
= 0; img
< srcDepth
; img
++) {
606 const GLint srcStride
=
607 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
609 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
613 for (row
= 0; row
< srcHeight
; row
++) {
614 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
615 srcFormat
, srcType
, src
, srcPacking
,
617 dst
+= srcWidth
* components
;
622 if (logicalBaseFormat
!= textureBaseFormat
) {
623 /* one more conversion step */
624 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
625 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
630 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
631 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
632 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
634 /* The actual texture format should have at least as many components
635 * as the logical texture format.
637 ASSERT(texComponents
>= logComponents
);
639 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
640 * texComponents
* sizeof(GLubyte
));
646 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
648 n
= srcWidth
* srcHeight
* srcDepth
;
649 for (i
= 0; i
< n
; i
++) {
651 for (k
= 0; k
< texComponents
; k
++) {
654 newImage
[i
* texComponents
+ k
] = 0;
656 newImage
[i
* texComponents
+ k
] = 255;
658 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
663 tempImage
= newImage
;
671 * Copy GLubyte pixels from <src> to <dst> with swizzling.
672 * \param dst destination pixels
673 * \param dstComponents number of color components in destination pixels
674 * \param src source pixels
675 * \param srcComponents number of color components in source pixels
676 * \param map the swizzle mapping. map[X] says where to find the X component
677 * in the source image's pixels. For example, if the source image
678 * is GL_BGRA and X = red, map[0] yields 2.
679 * \param count number of pixels to copy/swizzle.
682 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
683 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
685 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
688 for (i = 0; i < count; i++) { \
690 if (srcComps == 4) { \
691 COPY_4UBV(tmp, src); \
694 for (j = 0; j < srcComps; j++) { \
699 for (j = 0; j < dstComps; j++) { \
700 dst[j] = tmp[map[j]]; \
711 ASSERT(srcComponents
<= 4);
712 ASSERT(dstComponents
<= 4);
714 switch (dstComponents
) {
716 switch (srcComponents
) {
718 SWZ_CPY(dst
, src
, count
, 4, 4);
721 SWZ_CPY(dst
, src
, count
, 4, 3);
724 SWZ_CPY(dst
, src
, count
, 4, 2);
727 SWZ_CPY(dst
, src
, count
, 4, 1);
734 switch (srcComponents
) {
736 SWZ_CPY(dst
, src
, count
, 3, 4);
739 SWZ_CPY(dst
, src
, count
, 3, 3);
742 SWZ_CPY(dst
, src
, count
, 3, 2);
745 SWZ_CPY(dst
, src
, count
, 3, 1);
752 switch (srcComponents
) {
754 SWZ_CPY(dst
, src
, count
, 2, 4);
757 SWZ_CPY(dst
, src
, count
, 2, 3);
760 SWZ_CPY(dst
, src
, count
, 2, 2);
763 SWZ_CPY(dst
, src
, count
, 2, 1);
770 switch (srcComponents
) {
772 SWZ_CPY(dst
, src
, count
, 1, 4);
775 SWZ_CPY(dst
, src
, count
, 1, 3);
778 SWZ_CPY(dst
, src
, count
, 1, 2);
781 SWZ_CPY(dst
, src
, count
, 1, 1);
795 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
796 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
800 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
801 * mapping array depending on endianness.
803 static const GLubyte
*
804 type_mapping( GLenum srcType
)
808 case GL_UNSIGNED_BYTE
:
810 case GL_UNSIGNED_INT_8_8_8_8
:
811 return _mesa_little_endian() ? map_3210
: map_identity
;
812 case GL_UNSIGNED_INT_8_8_8_8_REV
:
813 return _mesa_little_endian() ? map_identity
: map_3210
;
821 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
822 * mapping array depending on pixelstore byte swapping state.
824 static const GLubyte
*
825 byteswap_mapping( GLboolean swapBytes
,
833 case GL_UNSIGNED_BYTE
:
835 case GL_UNSIGNED_INT_8_8_8_8
:
836 case GL_UNSIGNED_INT_8_8_8_8_REV
:
846 * Transfer a GLubyte texture image with component swizzling.
849 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
854 GLenum baseInternalFormat
,
856 const GLubyte
*rgba2dst
,
857 GLuint dstComponents
,
862 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
863 const GLvoid
*srcAddr
,
864 const struct gl_pixelstore_attrib
*srcPacking
)
866 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
867 const GLubyte
*srctype2ubyte
, *swap
;
868 GLubyte map
[4], src2base
[6], base2rgba
[6];
870 const GLint srcRowStride
=
871 _mesa_image_row_stride(srcPacking
, srcWidth
,
872 srcFormat
, GL_UNSIGNED_BYTE
);
873 const GLint srcImageStride
874 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
876 const GLubyte
*srcImage
877 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
878 srcWidth
, srcHeight
, srcFormat
,
879 GL_UNSIGNED_BYTE
, 0, 0, 0);
883 /* Translate from src->baseInternal->GL_RGBA->dst. This will
884 * correctly deal with RGBA->RGB->RGBA conversions where the final
885 * A value must be 0xff regardless of the incoming alpha values.
887 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
888 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
889 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
890 srctype2ubyte
= type_mapping(srcType
);
893 for (i
= 0; i
< 4; i
++)
894 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
896 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
898 if (srcComponents
== dstComponents
&&
899 srcRowStride
== dstRowStride
&&
900 srcRowStride
== srcWidth
* srcComponents
&&
902 /* 1 and 2D images only */
903 GLubyte
*dstImage
= dstSlices
[0];
904 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
905 srcWidth
* srcHeight
);
909 for (img
= 0; img
< srcDepth
; img
++) {
910 const GLubyte
*srcRow
= srcImage
;
911 GLubyte
*dstRow
= dstSlices
[img
];
912 for (row
= 0; row
< srcHeight
; row
++) {
913 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
914 dstRow
+= dstRowStride
;
915 srcRow
+= srcRowStride
;
917 srcImage
+= srcImageStride
;
924 * Teximage storage routine for when a simple memcpy will do.
925 * No pixel transfer operations or special texel encodings allowed.
926 * 1D, 2D and 3D images supported.
929 memcpy_texture(struct gl_context
*ctx
,
934 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
935 GLenum srcFormat
, GLenum srcType
,
936 const GLvoid
*srcAddr
,
937 const struct gl_pixelstore_attrib
*srcPacking
)
939 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
941 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
942 srcWidth
, srcHeight
, srcFormat
, srcType
);
943 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
944 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
945 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
946 const GLint bytesPerRow
= srcWidth
* texelBytes
;
948 if (dstRowStride
== srcRowStride
&&
949 dstRowStride
== bytesPerRow
) {
950 /* memcpy image by image */
952 for (img
= 0; img
< srcDepth
; img
++) {
953 GLubyte
*dstImage
= dstSlices
[img
];
954 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
955 srcImage
+= srcImageStride
;
959 /* memcpy row by row */
961 for (img
= 0; img
< srcDepth
; img
++) {
962 const GLubyte
*srcRow
= srcImage
;
963 GLubyte
*dstRow
= dstSlices
[img
];
964 for (row
= 0; row
< srcHeight
; row
++) {
965 memcpy(dstRow
, srcRow
, bytesPerRow
);
966 dstRow
+= dstRowStride
;
967 srcRow
+= srcRowStride
;
969 srcImage
+= srcImageStride
;
977 * Store a 32-bit integer or float depth component texture image.
980 _mesa_texstore_z32(TEXSTORE_PARAMS
)
982 const GLuint depthScale
= 0xffffffff;
985 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
986 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
987 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
989 if (dstFormat
== MESA_FORMAT_Z32
)
990 dstType
= GL_UNSIGNED_INT
;
994 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
995 ctx
->Pixel
.DepthBias
== 0.0f
&&
996 !srcPacking
->SwapBytes
&&
997 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
998 srcFormat
== GL_DEPTH_COMPONENT
&&
999 srcType
== dstType
) {
1000 /* simple memcpy path */
1001 memcpy_texture(ctx
, dims
,
1003 dstRowStride
, dstSlices
,
1004 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1005 srcAddr
, srcPacking
);
1010 for (img
= 0; img
< srcDepth
; img
++) {
1011 GLubyte
*dstRow
= dstSlices
[img
];
1012 for (row
= 0; row
< srcHeight
; row
++) {
1013 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1014 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1015 _mesa_unpack_depth_span(ctx
, srcWidth
,
1017 depthScale
, srcType
, src
, srcPacking
);
1018 dstRow
+= dstRowStride
;
1027 * Store a 24-bit integer depth component texture image.
1030 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1032 const GLuint depthScale
= 0xffffff;
1035 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1040 for (img
= 0; img
< srcDepth
; img
++) {
1041 GLubyte
*dstRow
= dstSlices
[img
];
1042 for (row
= 0; row
< srcHeight
; row
++) {
1043 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1044 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1045 _mesa_unpack_depth_span(ctx
, srcWidth
,
1046 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1047 depthScale
, srcType
, src
, srcPacking
);
1048 dstRow
+= dstRowStride
;
1057 * Store a 24-bit integer depth component texture image.
1060 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1062 const GLuint depthScale
= 0xffffff;
1065 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1070 for (img
= 0; img
< srcDepth
; img
++) {
1071 GLubyte
*dstRow
= dstSlices
[img
];
1072 for (row
= 0; row
< srcHeight
; row
++) {
1073 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1074 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1075 GLuint
*dst
= (GLuint
*) dstRow
;
1077 _mesa_unpack_depth_span(ctx
, srcWidth
,
1078 GL_UNSIGNED_INT
, dst
,
1079 depthScale
, srcType
, src
, srcPacking
);
1080 for (i
= 0; i
< srcWidth
; i
++)
1082 dstRow
+= dstRowStride
;
1091 * Store a 16-bit integer depth component texture image.
1094 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1096 const GLuint depthScale
= 0xffff;
1098 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1099 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1101 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1102 ctx
->Pixel
.DepthBias
== 0.0f
&&
1103 !srcPacking
->SwapBytes
&&
1104 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1105 srcFormat
== GL_DEPTH_COMPONENT
&&
1106 srcType
== GL_UNSIGNED_SHORT
) {
1107 /* simple memcpy path */
1108 memcpy_texture(ctx
, dims
,
1110 dstRowStride
, dstSlices
,
1111 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1112 srcAddr
, srcPacking
);
1117 for (img
= 0; img
< srcDepth
; img
++) {
1118 GLubyte
*dstRow
= dstSlices
[img
];
1119 for (row
= 0; row
< srcHeight
; row
++) {
1120 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1121 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1122 GLushort
*dst16
= (GLushort
*) dstRow
;
1123 _mesa_unpack_depth_span(ctx
, srcWidth
,
1124 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1125 srcType
, src
, srcPacking
);
1126 dstRow
+= dstRowStride
;
1135 * Store an rgb565 or rgb565_rev texture image.
1138 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1140 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1142 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1143 dstFormat
== MESA_FORMAT_RGB565_REV
);
1144 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1146 if (!ctx
->_ImageTransferState
&&
1147 !srcPacking
->SwapBytes
&&
1148 dstFormat
== MESA_FORMAT_RGB565
&&
1149 baseInternalFormat
== GL_RGB
&&
1150 srcFormat
== GL_RGB
&&
1151 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1152 /* simple memcpy path */
1153 memcpy_texture(ctx
, dims
,
1155 dstRowStride
, dstSlices
,
1156 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1157 srcAddr
, srcPacking
);
1159 else if (!ctx
->_ImageTransferState
&&
1160 !srcPacking
->SwapBytes
&&
1161 baseInternalFormat
== GL_RGB
&&
1162 srcFormat
== GL_RGB
&&
1163 srcType
== GL_UNSIGNED_BYTE
&&
1165 /* do optimized tex store */
1166 const GLint srcRowStride
=
1167 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1168 const GLubyte
*src
= (const GLubyte
*)
1169 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1170 srcFormat
, srcType
, 0, 0, 0);
1171 GLubyte
*dst
= dstSlices
[0];
1173 for (row
= 0; row
< srcHeight
; row
++) {
1174 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1175 GLushort
*dstUS
= (GLushort
*) dst
;
1176 /* check for byteswapped format */
1177 if (dstFormat
== MESA_FORMAT_RGB565
) {
1178 for (col
= 0; col
< srcWidth
; col
++) {
1179 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1184 for (col
= 0; col
< srcWidth
; col
++) {
1185 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1189 dst
+= dstRowStride
;
1190 src
+= srcRowStride
;
1195 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1198 srcWidth
, srcHeight
, srcDepth
,
1199 srcFormat
, srcType
, srcAddr
,
1201 const GLubyte
*src
= tempImage
;
1202 GLint img
, row
, col
;
1205 for (img
= 0; img
< srcDepth
; img
++) {
1206 GLubyte
*dstRow
= dstSlices
[img
];
1207 for (row
= 0; row
< srcHeight
; row
++) {
1208 GLushort
*dstUS
= (GLushort
*) dstRow
;
1209 /* check for byteswapped format */
1210 if (dstFormat
== MESA_FORMAT_RGB565
) {
1211 for (col
= 0; col
< srcWidth
; col
++) {
1212 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1219 for (col
= 0; col
< srcWidth
; col
++) {
1220 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1226 dstRow
+= dstRowStride
;
1229 free((void *) tempImage
);
1236 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1239 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1241 const GLboolean littleEndian
= _mesa_little_endian();
1242 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1244 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1245 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1246 dstFormat
== MESA_FORMAT_RGBX8888
||
1247 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1248 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1250 if (!ctx
->_ImageTransferState
&&
1251 !srcPacking
->SwapBytes
&&
1252 (dstFormat
== MESA_FORMAT_RGBA8888
||
1253 dstFormat
== MESA_FORMAT_RGBX8888
) &&
1254 baseInternalFormat
== GL_RGBA
&&
1255 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1256 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1257 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1258 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1259 /* simple memcpy path */
1260 memcpy_texture(ctx
, dims
,
1262 dstRowStride
, dstSlices
,
1263 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1264 srcAddr
, srcPacking
);
1266 else if (!ctx
->_ImageTransferState
&&
1267 !srcPacking
->SwapBytes
&&
1268 (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1269 dstFormat
== MESA_FORMAT_RGBX8888_REV
) &&
1270 baseInternalFormat
== GL_RGBA
&&
1271 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1272 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1273 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1274 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1275 /* simple memcpy path */
1276 memcpy_texture(ctx
, dims
,
1278 dstRowStride
, dstSlices
,
1279 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1280 srcAddr
, srcPacking
);
1282 else if (!ctx
->_ImageTransferState
&&
1283 (srcType
== GL_UNSIGNED_BYTE
||
1284 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1285 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1286 can_swizzle(baseInternalFormat
) &&
1287 can_swizzle(srcFormat
)) {
1291 /* dstmap - how to swizzle from RGBA to dst format:
1293 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1294 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1295 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1296 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1309 _mesa_swizzle_ubyte_image(ctx
, dims
,
1314 dstRowStride
, dstSlices
,
1315 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1320 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1323 srcWidth
, srcHeight
, srcDepth
,
1324 srcFormat
, srcType
, srcAddr
,
1326 const GLubyte
*src
= tempImage
;
1327 GLint img
, row
, col
;
1330 for (img
= 0; img
< srcDepth
; img
++) {
1331 GLubyte
*dstRow
= dstSlices
[img
];
1332 for (row
= 0; row
< srcHeight
; row
++) {
1333 GLuint
*dstUI
= (GLuint
*) dstRow
;
1334 if (dstFormat
== MESA_FORMAT_RGBA8888
||
1335 dstFormat
== MESA_FORMAT_RGBX8888
) {
1336 for (col
= 0; col
< srcWidth
; col
++) {
1337 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1345 for (col
= 0; col
< srcWidth
; col
++) {
1346 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1353 dstRow
+= dstRowStride
;
1356 free((void *) tempImage
);
1363 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1365 const GLboolean littleEndian
= _mesa_little_endian();
1366 const GLenum baseFormat
= GL_RGBA
;
1368 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1369 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1370 dstFormat
== MESA_FORMAT_XRGB8888
||
1371 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1372 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1374 if (!ctx
->_ImageTransferState
&&
1375 !srcPacking
->SwapBytes
&&
1376 (dstFormat
== MESA_FORMAT_ARGB8888
||
1377 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1378 baseInternalFormat
== GL_RGBA
&&
1379 srcFormat
== GL_BGRA
&&
1380 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1381 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1382 /* simple memcpy path (little endian) */
1383 memcpy_texture(ctx
, dims
,
1385 dstRowStride
, dstSlices
,
1386 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1387 srcAddr
, srcPacking
);
1389 else if (!ctx
->_ImageTransferState
&&
1390 !srcPacking
->SwapBytes
&&
1391 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1392 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1393 baseInternalFormat
== GL_RGBA
&&
1394 srcFormat
== GL_BGRA
&&
1395 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1396 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1397 /* simple memcpy path (big endian) */
1398 memcpy_texture(ctx
, dims
,
1400 dstRowStride
, dstSlices
,
1401 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1402 srcAddr
, srcPacking
);
1404 else if (!ctx
->_ImageTransferState
&&
1405 !srcPacking
->SwapBytes
&&
1406 (dstFormat
== MESA_FORMAT_ARGB8888
||
1407 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1408 srcFormat
== GL_RGB
&&
1409 (baseInternalFormat
== GL_RGBA
||
1410 baseInternalFormat
== GL_RGB
) &&
1411 srcType
== GL_UNSIGNED_BYTE
) {
1413 for (img
= 0; img
< srcDepth
; img
++) {
1414 const GLint srcRowStride
=
1415 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1416 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1417 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1418 GLubyte
*dstRow
= dstSlices
[img
];
1419 for (row
= 0; row
< srcHeight
; row
++) {
1420 GLuint
*d4
= (GLuint
*) dstRow
;
1421 for (col
= 0; col
< srcWidth
; col
++) {
1422 d4
[col
] = PACK_COLOR_8888(0xff,
1423 srcRow
[col
* 3 + RCOMP
],
1424 srcRow
[col
* 3 + GCOMP
],
1425 srcRow
[col
* 3 + BCOMP
]);
1427 dstRow
+= dstRowStride
;
1428 srcRow
+= srcRowStride
;
1432 else if (!ctx
->_ImageTransferState
&&
1433 !srcPacking
->SwapBytes
&&
1434 dstFormat
== MESA_FORMAT_ARGB8888
&&
1435 srcFormat
== GL_RGBA
&&
1436 baseInternalFormat
== GL_RGBA
&&
1437 srcType
== GL_UNSIGNED_BYTE
) {
1438 /* same as above case, but src data has alpha too */
1439 GLint img
, row
, col
;
1440 /* For some reason, streaming copies to write-combined regions
1441 * are extremely sensitive to the characteristics of how the
1442 * source data is retrieved. By reordering the source reads to
1443 * be in-order, the speed of this operation increases by half.
1444 * Strangely the same isn't required for the RGB path, above.
1446 for (img
= 0; img
< srcDepth
; img
++) {
1447 const GLint srcRowStride
=
1448 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1449 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1450 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1451 GLubyte
*dstRow
= dstSlices
[img
];
1452 for (row
= 0; row
< srcHeight
; row
++) {
1453 GLuint
*d4
= (GLuint
*) dstRow
;
1454 for (col
= 0; col
< srcWidth
; col
++) {
1455 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1456 srcRow
[col
* 4 + RCOMP
],
1457 srcRow
[col
* 4 + GCOMP
],
1458 srcRow
[col
* 4 + BCOMP
]);
1460 dstRow
+= dstRowStride
;
1461 srcRow
+= srcRowStride
;
1465 else if (!ctx
->_ImageTransferState
&&
1466 (srcType
== GL_UNSIGNED_BYTE
||
1467 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1468 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1469 can_swizzle(baseInternalFormat
) &&
1470 can_swizzle(srcFormat
)) {
1474 /* dstmap - how to swizzle from RGBA to dst format:
1476 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1477 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1478 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1479 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1480 dstmap
[3] = 3; /* alpha */
1481 dstmap
[2] = 0; /* red */
1482 dstmap
[1] = 1; /* green */
1483 dstmap
[0] = 2; /* blue */
1486 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1487 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1488 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1489 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1496 _mesa_swizzle_ubyte_image(ctx
, dims
,
1503 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1508 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1511 srcWidth
, srcHeight
, srcDepth
,
1512 srcFormat
, srcType
, srcAddr
,
1514 const GLubyte
*src
= tempImage
;
1515 GLint img
, row
, col
;
1518 for (img
= 0; img
< srcDepth
; img
++) {
1519 GLubyte
*dstRow
= dstSlices
[img
];
1520 for (row
= 0; row
< srcHeight
; row
++) {
1521 GLuint
*dstUI
= (GLuint
*) dstRow
;
1522 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1523 for (col
= 0; col
< srcWidth
; col
++) {
1524 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1531 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1532 for (col
= 0; col
< srcWidth
; col
++) {
1533 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1541 for (col
= 0; col
< srcWidth
; col
++) {
1542 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1549 dstRow
+= dstRowStride
;
1552 free((void *) tempImage
);
1559 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1561 const GLboolean littleEndian
= _mesa_little_endian();
1562 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1564 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1565 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1567 if (!ctx
->_ImageTransferState
&&
1568 !srcPacking
->SwapBytes
&&
1569 baseInternalFormat
== GL_RGB
&&
1570 srcFormat
== GL_BGR
&&
1571 srcType
== GL_UNSIGNED_BYTE
&&
1573 /* simple memcpy path */
1574 memcpy_texture(ctx
, dims
,
1576 dstRowStride
, dstSlices
,
1577 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1578 srcAddr
, srcPacking
);
1580 else if (!ctx
->_ImageTransferState
&&
1581 !srcPacking
->SwapBytes
&&
1582 srcFormat
== GL_RGBA
&&
1583 srcType
== GL_UNSIGNED_BYTE
) {
1584 /* extract RGB from RGBA */
1585 GLint img
, row
, col
;
1586 for (img
= 0; img
< srcDepth
; img
++) {
1587 const GLint srcRowStride
=
1588 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1589 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1590 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1591 GLubyte
*dstRow
= dstSlices
[img
];
1592 for (row
= 0; row
< srcHeight
; row
++) {
1593 for (col
= 0; col
< srcWidth
; col
++) {
1594 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1595 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1596 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1598 dstRow
+= dstRowStride
;
1599 srcRow
+= srcRowStride
;
1603 else if (!ctx
->_ImageTransferState
&&
1604 srcType
== GL_UNSIGNED_BYTE
&&
1605 can_swizzle(baseInternalFormat
) &&
1606 can_swizzle(srcFormat
)) {
1610 /* dstmap - how to swizzle from RGBA to dst format:
1615 dstmap
[3] = ONE
; /* ? */
1617 _mesa_swizzle_ubyte_image(ctx
, dims
,
1622 dstRowStride
, dstSlices
,
1623 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1628 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1631 srcWidth
, srcHeight
, srcDepth
,
1632 srcFormat
, srcType
, srcAddr
,
1634 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1635 GLint img
, row
, col
;
1638 for (img
= 0; img
< srcDepth
; img
++) {
1639 GLubyte
*dstRow
= dstSlices
[img
];
1640 for (row
= 0; row
< srcHeight
; row
++) {
1643 for (col
= 0; col
< srcWidth
; col
++) {
1644 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1645 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1646 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1651 for (col
= 0; col
< srcWidth
; col
++) {
1652 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1653 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1654 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1659 for (col
= 0; col
< srcWidth
; col
++) {
1660 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1661 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1662 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1666 dstRow
+= dstRowStride
;
1669 free((void *) tempImage
);
1676 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1678 const GLboolean littleEndian
= _mesa_little_endian();
1679 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1681 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1682 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1684 if (!ctx
->_ImageTransferState
&&
1685 !srcPacking
->SwapBytes
&&
1686 baseInternalFormat
== GL_RGB
&&
1687 srcFormat
== GL_RGB
&&
1688 srcType
== GL_UNSIGNED_BYTE
&&
1690 /* simple memcpy path */
1691 memcpy_texture(ctx
, dims
,
1693 dstRowStride
, dstSlices
,
1694 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1695 srcAddr
, srcPacking
);
1697 else if (!ctx
->_ImageTransferState
&&
1698 !srcPacking
->SwapBytes
&&
1699 srcFormat
== GL_RGBA
&&
1700 srcType
== GL_UNSIGNED_BYTE
) {
1701 /* extract BGR from RGBA */
1703 for (img
= 0; img
< srcDepth
; img
++) {
1704 const GLint srcRowStride
=
1705 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1706 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1707 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1708 GLubyte
*dstRow
= dstSlices
[img
];
1709 for (row
= 0; row
< srcHeight
; row
++) {
1710 for (col
= 0; col
< srcWidth
; col
++) {
1711 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1712 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1713 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1715 dstRow
+= dstRowStride
;
1716 srcRow
+= srcRowStride
;
1720 else if (!ctx
->_ImageTransferState
&&
1721 srcType
== GL_UNSIGNED_BYTE
&&
1722 can_swizzle(baseInternalFormat
) &&
1723 can_swizzle(srcFormat
)) {
1727 /* dstmap - how to swizzle from RGBA to dst format:
1732 dstmap
[3] = ONE
; /* ? */
1734 _mesa_swizzle_ubyte_image(ctx
, dims
,
1739 dstRowStride
, dstSlices
,
1740 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1745 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1748 srcWidth
, srcHeight
, srcDepth
,
1749 srcFormat
, srcType
, srcAddr
,
1751 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1752 GLint img
, row
, col
;
1755 for (img
= 0; img
< srcDepth
; img
++) {
1756 GLubyte
*dstRow
= dstSlices
[img
];
1757 for (row
= 0; row
< srcHeight
; row
++) {
1758 for (col
= 0; col
< srcWidth
; col
++) {
1759 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1760 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1761 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1764 dstRow
+= dstRowStride
;
1767 free((void *) tempImage
);
1774 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1776 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1778 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1779 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1780 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1782 if (!ctx
->_ImageTransferState
&&
1783 !srcPacking
->SwapBytes
&&
1784 dstFormat
== MESA_FORMAT_ARGB4444
&&
1785 baseInternalFormat
== GL_RGBA
&&
1786 srcFormat
== GL_BGRA
&&
1787 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1788 /* simple memcpy path */
1789 memcpy_texture(ctx
, dims
,
1791 dstRowStride
, dstSlices
,
1792 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1793 srcAddr
, srcPacking
);
1797 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1800 srcWidth
, srcHeight
, srcDepth
,
1801 srcFormat
, srcType
, srcAddr
,
1803 const GLubyte
*src
= tempImage
;
1804 GLint img
, row
, col
;
1807 for (img
= 0; img
< srcDepth
; img
++) {
1808 GLubyte
*dstRow
= dstSlices
[img
];
1809 for (row
= 0; row
< srcHeight
; row
++) {
1810 GLushort
*dstUS
= (GLushort
*) dstRow
;
1811 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1812 for (col
= 0; col
< srcWidth
; col
++) {
1813 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1821 for (col
= 0; col
< srcWidth
; col
++) {
1822 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1829 dstRow
+= dstRowStride
;
1832 free((void *) tempImage
);
1838 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1840 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1842 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1843 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1845 if (!ctx
->_ImageTransferState
&&
1846 !srcPacking
->SwapBytes
&&
1847 dstFormat
== MESA_FORMAT_RGBA5551
&&
1848 baseInternalFormat
== GL_RGBA
&&
1849 srcFormat
== GL_RGBA
&&
1850 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1851 /* simple memcpy path */
1852 memcpy_texture(ctx
, dims
,
1854 dstRowStride
, dstSlices
,
1855 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1856 srcAddr
, srcPacking
);
1860 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1863 srcWidth
, srcHeight
, srcDepth
,
1864 srcFormat
, srcType
, srcAddr
,
1866 const GLubyte
*src
=tempImage
;
1867 GLint img
, row
, col
;
1870 for (img
= 0; img
< srcDepth
; img
++) {
1871 GLubyte
*dstRow
= dstSlices
[img
];
1872 for (row
= 0; row
< srcHeight
; row
++) {
1873 GLushort
*dstUS
= (GLushort
*) dstRow
;
1874 for (col
= 0; col
< srcWidth
; col
++) {
1875 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1881 dstRow
+= dstRowStride
;
1884 free((void *) tempImage
);
1890 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1892 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1894 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1895 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1896 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1898 if (!ctx
->_ImageTransferState
&&
1899 !srcPacking
->SwapBytes
&&
1900 dstFormat
== MESA_FORMAT_ARGB1555
&&
1901 baseInternalFormat
== GL_RGBA
&&
1902 srcFormat
== GL_BGRA
&&
1903 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1904 /* simple memcpy path */
1905 memcpy_texture(ctx
, dims
,
1907 dstRowStride
, dstSlices
,
1908 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1909 srcAddr
, srcPacking
);
1913 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1916 srcWidth
, srcHeight
, srcDepth
,
1917 srcFormat
, srcType
, srcAddr
,
1919 const GLubyte
*src
=tempImage
;
1920 GLint img
, row
, col
;
1923 for (img
= 0; img
< srcDepth
; img
++) {
1924 GLubyte
*dstRow
= dstSlices
[img
];
1925 for (row
= 0; row
< srcHeight
; row
++) {
1926 GLushort
*dstUS
= (GLushort
*) dstRow
;
1927 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1928 for (col
= 0; col
< srcWidth
; col
++) {
1929 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1937 for (col
= 0; col
< srcWidth
; col
++) {
1938 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
1945 dstRow
+= dstRowStride
;
1948 free((void *) tempImage
);
1955 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1957 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1959 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
1960 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1962 if (!ctx
->_ImageTransferState
&&
1963 !srcPacking
->SwapBytes
&&
1964 dstFormat
== MESA_FORMAT_ARGB2101010
&&
1965 srcFormat
== GL_BGRA
&&
1966 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
1967 baseInternalFormat
== GL_RGBA
) {
1968 /* simple memcpy path */
1969 memcpy_texture(ctx
, dims
,
1971 dstRowStride
, dstSlices
,
1972 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1973 srcAddr
, srcPacking
);
1977 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1980 srcWidth
, srcHeight
, srcDepth
,
1981 srcFormat
, srcType
, srcAddr
,
1983 ctx
->_ImageTransferState
);
1984 const GLfloat
*src
= tempImage
;
1985 GLint img
, row
, col
;
1988 for (img
= 0; img
< srcDepth
; img
++) {
1989 GLubyte
*dstRow
= dstSlices
[img
];
1990 if (baseInternalFormat
== GL_RGBA
) {
1991 for (row
= 0; row
< srcHeight
; row
++) {
1992 GLuint
*dstUI
= (GLuint
*) dstRow
;
1993 for (col
= 0; col
< srcWidth
; col
++) {
1996 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1997 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1998 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1999 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2000 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2003 dstRow
+= dstRowStride
;
2005 } else if (baseInternalFormat
== GL_RGB
) {
2006 for (row
= 0; row
< srcHeight
; row
++) {
2007 GLuint
*dstUI
= (GLuint
*) dstRow
;
2008 for (col
= 0; col
< srcWidth
; col
++) {
2011 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2012 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2013 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2014 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2017 dstRow
+= dstRowStride
;
2023 free((void *) tempImage
);
2030 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2033 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2035 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2037 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2038 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2042 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2045 srcWidth
, srcHeight
, srcDepth
,
2046 srcFormat
, srcType
, srcAddr
,
2048 const GLubyte
*src
= tempImage
;
2049 GLint img
, row
, col
;
2052 for (img
= 0; img
< srcDepth
; img
++) {
2053 GLubyte
*dstRow
= dstSlices
[img
];
2054 for (row
= 0; row
< srcHeight
; row
++) {
2055 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2056 for (col
= 0; col
< srcWidth
; col
++) {
2057 /* src[0] is luminance, src[1] is alpha */
2058 dstUS
[col
] = PACK_COLOR_44( src
[1],
2062 dstRow
+= dstRowStride
;
2065 free((void *) tempImage
);
2072 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2075 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2077 const GLboolean littleEndian
= _mesa_little_endian();
2078 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2080 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2081 dstFormat
== MESA_FORMAT_AL88_REV
||
2082 dstFormat
== MESA_FORMAT_GR88
||
2083 dstFormat
== MESA_FORMAT_RG88
);
2084 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2086 if (!ctx
->_ImageTransferState
&&
2087 !srcPacking
->SwapBytes
&&
2088 ((dstFormat
== MESA_FORMAT_AL88
&&
2089 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2090 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2091 (dstFormat
== MESA_FORMAT_GR88
&&
2092 baseInternalFormat
== srcFormat
)) &&
2093 srcType
== GL_UNSIGNED_BYTE
&&
2095 /* simple memcpy path */
2096 memcpy_texture(ctx
, dims
,
2098 dstRowStride
, dstSlices
,
2099 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2100 srcAddr
, srcPacking
);
2102 else if (!ctx
->_ImageTransferState
&&
2104 srcType
== GL_UNSIGNED_BYTE
&&
2105 can_swizzle(baseInternalFormat
) &&
2106 can_swizzle(srcFormat
)) {
2109 /* dstmap - how to swizzle from RGBA to dst format:
2111 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2112 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2113 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2123 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
2124 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
2133 dstmap
[2] = ZERO
; /* ? */
2134 dstmap
[3] = ONE
; /* ? */
2136 _mesa_swizzle_ubyte_image(ctx
, dims
,
2141 dstRowStride
, dstSlices
,
2142 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2147 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2150 srcWidth
, srcHeight
, srcDepth
,
2151 srcFormat
, srcType
, srcAddr
,
2153 const GLubyte
*src
= tempImage
;
2154 GLint img
, row
, col
;
2157 for (img
= 0; img
< srcDepth
; img
++) {
2158 GLubyte
*dstRow
= dstSlices
[img
];
2159 for (row
= 0; row
< srcHeight
; row
++) {
2160 GLushort
*dstUS
= (GLushort
*) dstRow
;
2161 if (dstFormat
== MESA_FORMAT_AL88
||
2162 dstFormat
== MESA_FORMAT_GR88
) {
2163 for (col
= 0; col
< srcWidth
; col
++) {
2164 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2165 dstUS
[col
] = PACK_COLOR_88( src
[1],
2171 for (col
= 0; col
< srcWidth
; col
++) {
2172 /* src[0] is luminance (or R), src[1] is alpha (or G) */
2173 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2178 dstRow
+= dstRowStride
;
2181 free((void *) tempImage
);
2188 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2191 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2193 const GLboolean littleEndian
= _mesa_little_endian();
2194 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2196 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2197 dstFormat
== MESA_FORMAT_AL1616_REV
||
2198 dstFormat
== MESA_FORMAT_RG1616
||
2199 dstFormat
== MESA_FORMAT_RG1616_REV
);
2200 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2202 if (!ctx
->_ImageTransferState
&&
2203 !srcPacking
->SwapBytes
&&
2204 ((dstFormat
== MESA_FORMAT_AL1616
&&
2205 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2206 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2207 (dstFormat
== MESA_FORMAT_RG1616
&&
2208 baseInternalFormat
== srcFormat
)) &&
2209 srcType
== GL_UNSIGNED_SHORT
&&
2211 /* simple memcpy path */
2212 memcpy_texture(ctx
, dims
,
2214 dstRowStride
, dstSlices
,
2215 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2216 srcAddr
, srcPacking
);
2220 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2223 srcWidth
, srcHeight
, srcDepth
,
2224 srcFormat
, srcType
, srcAddr
,
2226 ctx
->_ImageTransferState
);
2227 const GLfloat
*src
= tempImage
;
2228 GLint img
, row
, col
;
2231 for (img
= 0; img
< srcDepth
; img
++) {
2232 GLubyte
*dstRow
= dstSlices
[img
];
2233 for (row
= 0; row
< srcHeight
; row
++) {
2234 GLuint
*dstUI
= (GLuint
*) dstRow
;
2235 if (dstFormat
== MESA_FORMAT_AL1616
||
2236 dstFormat
== MESA_FORMAT_RG1616
) {
2237 for (col
= 0; col
< srcWidth
; col
++) {
2240 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2241 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2242 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2247 for (col
= 0; col
< srcWidth
; col
++) {
2250 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2251 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2252 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2256 dstRow
+= dstRowStride
;
2259 free((void *) tempImage
);
2265 /* Texstore for R16, A16, L16, I16. */
2267 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2269 const GLboolean littleEndian
= _mesa_little_endian();
2270 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2272 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2273 dstFormat
== MESA_FORMAT_A16
||
2274 dstFormat
== MESA_FORMAT_L16
||
2275 dstFormat
== MESA_FORMAT_I16
);
2276 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2278 if (!ctx
->_ImageTransferState
&&
2279 !srcPacking
->SwapBytes
&&
2280 baseInternalFormat
== srcFormat
&&
2281 srcType
== GL_UNSIGNED_SHORT
&&
2283 /* simple memcpy path */
2284 memcpy_texture(ctx
, dims
,
2286 dstRowStride
, dstSlices
,
2287 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2288 srcAddr
, srcPacking
);
2292 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2295 srcWidth
, srcHeight
, srcDepth
,
2296 srcFormat
, srcType
, srcAddr
,
2298 ctx
->_ImageTransferState
);
2299 const GLfloat
*src
= tempImage
;
2300 GLint img
, row
, col
;
2303 for (img
= 0; img
< srcDepth
; img
++) {
2304 GLubyte
*dstRow
= dstSlices
[img
];
2305 for (row
= 0; row
< srcHeight
; row
++) {
2306 GLushort
*dstUS
= (GLushort
*) dstRow
;
2307 for (col
= 0; col
< srcWidth
; col
++) {
2310 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2314 dstRow
+= dstRowStride
;
2317 free((void *) tempImage
);
2324 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2326 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2328 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2329 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2331 if (!ctx
->_ImageTransferState
&&
2332 !srcPacking
->SwapBytes
&&
2333 baseInternalFormat
== GL_RGBA
&&
2334 srcFormat
== GL_RGBA
&&
2335 srcType
== GL_UNSIGNED_SHORT
) {
2336 /* simple memcpy path */
2337 memcpy_texture(ctx
, dims
,
2339 dstRowStride
, dstSlices
,
2340 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2341 srcAddr
, srcPacking
);
2345 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2348 srcWidth
, srcHeight
, srcDepth
,
2349 srcFormat
, srcType
, srcAddr
,
2351 ctx
->_ImageTransferState
);
2352 const GLfloat
*src
= tempImage
;
2353 GLint img
, row
, col
;
2356 for (img
= 0; img
< srcDepth
; img
++) {
2357 GLubyte
*dstRow
= dstSlices
[img
];
2358 for (row
= 0; row
< srcHeight
; row
++) {
2359 GLushort
*dstUS
= (GLushort
*) dstRow
;
2360 for (col
= 0; col
< srcWidth
; col
++) {
2361 GLushort r
, g
, b
, a
;
2363 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2364 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2365 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2366 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2373 dstRow
+= dstRowStride
;
2376 free((void *) tempImage
);
2383 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2385 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2387 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2388 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2390 if (!ctx
->_ImageTransferState
&&
2391 !srcPacking
->SwapBytes
&&
2392 baseInternalFormat
== GL_RGBA
&&
2393 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2394 srcFormat
== GL_RGBA
&&
2395 srcType
== GL_SHORT
) {
2396 /* simple memcpy path */
2397 memcpy_texture(ctx
, dims
,
2399 dstRowStride
, dstSlices
,
2400 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2401 srcAddr
, srcPacking
);
2405 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2408 srcWidth
, srcHeight
, srcDepth
,
2409 srcFormat
, srcType
, srcAddr
,
2411 ctx
->_ImageTransferState
);
2412 const GLfloat
*src
= tempImage
;
2413 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2414 GLint img
, row
, col
;
2419 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2420 * 3 or 4 components/pixel here.
2422 for (img
= 0; img
< srcDepth
; img
++) {
2423 GLubyte
*dstRow
= dstSlices
[img
];
2424 for (row
= 0; row
< srcHeight
; row
++) {
2425 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2426 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2427 for (col
= 0; col
< srcWidth
; col
++) {
2429 for (c
= 0; c
< comps
; c
++) {
2431 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2432 dstRowS
[col
* comps
+ c
] = p
;
2435 dstRow
+= dstRowStride
;
2436 src
+= 4 * srcWidth
;
2438 for (col
= 0; col
< srcWidth
; col
++) {
2440 for (c
= 0; c
< comps
; c
++) {
2442 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2443 dstRowS
[col
* comps
+ c
] = p
;
2446 dstRow
+= dstRowStride
;
2447 src
+= 3 * srcWidth
;
2451 free((void *) tempImage
);
2458 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2460 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2462 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2463 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2465 if (!ctx
->_ImageTransferState
&&
2466 !srcPacking
->SwapBytes
&&
2467 baseInternalFormat
== GL_RGB
&&
2468 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2469 /* simple memcpy path */
2470 memcpy_texture(ctx
, dims
,
2472 dstRowStride
, dstSlices
,
2473 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2474 srcAddr
, srcPacking
);
2478 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2481 srcWidth
, srcHeight
, srcDepth
,
2482 srcFormat
, srcType
, srcAddr
,
2484 const GLubyte
*src
= tempImage
;
2485 GLint img
, row
, col
;
2488 for (img
= 0; img
< srcDepth
; img
++) {
2489 GLubyte
*dstRow
= dstSlices
[img
];
2490 for (row
= 0; row
< srcHeight
; row
++) {
2491 for (col
= 0; col
< srcWidth
; col
++) {
2492 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2497 dstRow
+= dstRowStride
;
2500 free((void *) tempImage
);
2507 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2510 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2512 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2514 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2515 dstFormat
== MESA_FORMAT_L8
||
2516 dstFormat
== MESA_FORMAT_I8
||
2517 dstFormat
== MESA_FORMAT_R8
);
2518 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2520 if (!ctx
->_ImageTransferState
&&
2521 !srcPacking
->SwapBytes
&&
2522 baseInternalFormat
== srcFormat
&&
2523 srcType
== GL_UNSIGNED_BYTE
) {
2524 /* simple memcpy path */
2525 memcpy_texture(ctx
, dims
,
2527 dstRowStride
, dstSlices
,
2528 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2529 srcAddr
, srcPacking
);
2531 else if (!ctx
->_ImageTransferState
&&
2532 srcType
== GL_UNSIGNED_BYTE
&&
2533 can_swizzle(baseInternalFormat
) &&
2534 can_swizzle(srcFormat
)) {
2537 /* dstmap - how to swizzle from RGBA to dst format:
2539 if (dstFormat
== MESA_FORMAT_A8
) {
2545 dstmap
[1] = ZERO
; /* ? */
2546 dstmap
[2] = ZERO
; /* ? */
2547 dstmap
[3] = ONE
; /* ? */
2549 _mesa_swizzle_ubyte_image(ctx
, dims
,
2554 dstRowStride
, dstSlices
,
2555 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2560 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2563 srcWidth
, srcHeight
, srcDepth
,
2564 srcFormat
, srcType
, srcAddr
,
2566 const GLubyte
*src
= tempImage
;
2567 GLint img
, row
, col
;
2570 for (img
= 0; img
< srcDepth
; img
++) {
2571 GLubyte
*dstRow
= dstSlices
[img
];
2572 for (row
= 0; row
< srcHeight
; row
++) {
2573 for (col
= 0; col
< srcWidth
; col
++) {
2574 dstRow
[col
] = src
[col
];
2576 dstRow
+= dstRowStride
;
2580 free((void *) tempImage
);
2588 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2591 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2593 const GLboolean littleEndian
= _mesa_little_endian();
2595 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2597 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2598 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2599 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2600 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2601 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2602 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2603 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2604 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2606 /* always just memcpy since no pixel transfer ops apply */
2607 memcpy_texture(ctx
, dims
,
2609 dstRowStride
, dstSlices
,
2610 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2611 srcAddr
, srcPacking
);
2613 /* Check if we need byte swapping */
2614 /* XXX the logic here _might_ be wrong */
2615 if (srcPacking
->SwapBytes
^
2616 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2617 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2620 for (img
= 0; img
< srcDepth
; img
++) {
2621 GLubyte
*dstRow
= dstSlices
[img
];
2622 for (row
= 0; row
< srcHeight
; row
++) {
2623 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2624 dstRow
+= dstRowStride
;
2632 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2634 const GLboolean littleEndian
= _mesa_little_endian();
2635 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2637 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2638 ASSERT(texelBytes
== 2);
2639 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2640 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2641 (srcFormat
== GL_DUDV_ATI
));
2642 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2644 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2646 /* simple memcpy path */
2647 memcpy_texture(ctx
, dims
,
2649 dstRowStride
, dstSlices
,
2650 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2651 srcAddr
, srcPacking
);
2653 else if (srcType
== GL_BYTE
) {
2656 /* dstmap - how to swizzle from RGBA to dst format:
2666 dstmap
[2] = ZERO
; /* ? */
2667 dstmap
[3] = ONE
; /* ? */
2669 _mesa_swizzle_ubyte_image(ctx
, dims
,
2670 GL_LUMINANCE_ALPHA
, /* hack */
2671 GL_UNSIGNED_BYTE
, /* hack */
2672 GL_LUMINANCE_ALPHA
, /* hack */
2674 dstRowStride
, dstSlices
,
2675 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2679 /* general path - note this is defined for 2d textures only */
2680 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2681 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2682 srcFormat
, srcType
);
2683 GLbyte
*tempImage
, *dst
, *src
;
2686 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2687 * components
* sizeof(GLbyte
));
2691 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2692 srcWidth
, srcHeight
,
2697 for (row
= 0; row
< srcHeight
; row
++) {
2698 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2699 dst
, srcFormat
, srcType
, src
,
2701 dst
+= srcWidth
* components
;
2706 dst
= (GLbyte
*) dstSlices
[0];
2707 for (row
= 0; row
< srcHeight
; row
++) {
2708 memcpy(dst
, src
, srcWidth
* texelBytes
);
2709 dst
+= dstRowStride
;
2710 src
+= srcWidth
* texelBytes
;
2712 free((void *) tempImage
);
2719 * Store a texture in a signed normalized 8-bit format.
2722 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2724 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2726 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2727 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2728 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2729 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2730 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2732 if (!ctx
->_ImageTransferState
&&
2733 !srcPacking
->SwapBytes
&&
2734 baseInternalFormat
== srcFormat
&&
2735 srcType
== GL_BYTE
) {
2736 /* simple memcpy path */
2737 memcpy_texture(ctx
, dims
,
2739 dstRowStride
, dstSlices
,
2740 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2741 srcAddr
, srcPacking
);
2745 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2748 srcWidth
, srcHeight
, srcDepth
,
2749 srcFormat
, srcType
, srcAddr
,
2751 ctx
->_ImageTransferState
);
2752 const GLfloat
*src
= tempImage
;
2753 GLint img
, row
, col
;
2756 for (img
= 0; img
< srcDepth
; img
++) {
2757 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2758 for (row
= 0; row
< srcHeight
; row
++) {
2759 for (col
= 0; col
< srcWidth
; col
++) {
2760 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2762 dstRow
+= dstRowStride
;
2766 free((void *) tempImage
);
2773 * Store a texture in a signed normalized two-channel 16-bit format.
2776 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2778 const GLboolean littleEndian
= _mesa_little_endian();
2779 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2781 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2782 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2783 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2785 if (!ctx
->_ImageTransferState
&&
2786 !srcPacking
->SwapBytes
&&
2787 baseInternalFormat
== srcFormat
&&
2788 srcType
== GL_BYTE
&&
2790 /* simple memcpy path */
2791 memcpy_texture(ctx
, dims
,
2793 dstRowStride
, dstSlices
,
2794 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2795 srcAddr
, srcPacking
);
2799 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2802 srcWidth
, srcHeight
, srcDepth
,
2803 srcFormat
, srcType
, srcAddr
,
2805 ctx
->_ImageTransferState
);
2806 const GLfloat
*src
= tempImage
;
2807 GLint img
, row
, col
;
2810 for (img
= 0; img
< srcDepth
; img
++) {
2811 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2812 for (row
= 0; row
< srcHeight
; row
++) {
2813 GLbyte
*dst
= dstRow
;
2814 for (col
= 0; col
< srcWidth
; col
++) {
2815 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2816 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2820 dstRow
+= dstRowStride
;
2823 free((void *) tempImage
);
2828 /* Texstore for signed R16, A16, L16, I16. */
2830 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2832 const GLboolean littleEndian
= _mesa_little_endian();
2833 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2835 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2836 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2837 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2838 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2839 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2841 if (!ctx
->_ImageTransferState
&&
2842 !srcPacking
->SwapBytes
&&
2843 baseInternalFormat
== srcFormat
&&
2844 srcType
== GL_SHORT
&&
2846 /* simple memcpy path */
2847 memcpy_texture(ctx
, dims
,
2849 dstRowStride
, dstSlices
,
2850 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2851 srcAddr
, srcPacking
);
2855 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2858 srcWidth
, srcHeight
, srcDepth
,
2859 srcFormat
, srcType
, srcAddr
,
2861 ctx
->_ImageTransferState
);
2862 const GLfloat
*src
= tempImage
;
2863 GLint img
, row
, col
;
2866 for (img
= 0; img
< srcDepth
; img
++) {
2867 GLubyte
*dstRow
= dstSlices
[img
];
2868 for (row
= 0; row
< srcHeight
; row
++) {
2869 GLshort
*dstUS
= (GLshort
*) dstRow
;
2870 for (col
= 0; col
< srcWidth
; col
++) {
2873 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2877 dstRow
+= dstRowStride
;
2880 free((void *) tempImage
);
2886 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2889 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2891 const GLboolean littleEndian
= _mesa_little_endian();
2892 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2894 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2895 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2896 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2898 if (!ctx
->_ImageTransferState
&&
2899 !srcPacking
->SwapBytes
&&
2900 baseInternalFormat
== srcFormat
&&
2901 srcType
== GL_SHORT
&&
2903 /* simple memcpy path */
2904 memcpy_texture(ctx
, dims
,
2906 dstRowStride
, dstSlices
,
2907 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2908 srcAddr
, srcPacking
);
2912 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2915 srcWidth
, srcHeight
, srcDepth
,
2916 srcFormat
, srcType
, srcAddr
,
2918 ctx
->_ImageTransferState
);
2919 const GLfloat
*src
= tempImage
;
2920 GLint img
, row
, col
;
2923 for (img
= 0; img
< srcDepth
; img
++) {
2924 GLubyte
*dstRow
= dstSlices
[img
];
2925 for (row
= 0; row
< srcHeight
; row
++) {
2926 GLshort
*dst
= (GLshort
*) dstRow
;
2927 for (col
= 0; col
< srcWidth
; col
++) {
2930 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2931 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2937 dstRow
+= dstRowStride
;
2940 free((void *) tempImage
);
2946 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2949 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2951 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2953 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2954 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2958 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2961 srcWidth
, srcHeight
, srcDepth
,
2962 srcFormat
, srcType
, srcAddr
,
2964 ctx
->_ImageTransferState
);
2965 const GLfloat
*srcRow
= tempImage
;
2966 GLint img
, row
, col
;
2969 for (img
= 0; img
< srcDepth
; img
++) {
2970 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2971 for (row
= 0; row
< srcHeight
; row
++) {
2972 GLbyte
*dst
= dstRow
;
2973 for (col
= 0; col
< srcWidth
; col
++) {
2974 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2975 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2976 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2981 dstRow
+= dstRowStride
;
2984 free((void *) tempImage
);
2992 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2993 * MESA_FORMAT_SIGNED_RGBA8888_REV
2996 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2998 const GLboolean littleEndian
= _mesa_little_endian();
2999 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3001 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3002 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3003 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3005 if (!ctx
->_ImageTransferState
&&
3006 !srcPacking
->SwapBytes
&&
3007 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3008 baseInternalFormat
== GL_RGBA
&&
3009 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3010 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3011 /* simple memcpy path */
3012 memcpy_texture(ctx
, dims
,
3014 dstRowStride
, dstSlices
,
3015 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3016 srcAddr
, srcPacking
);
3018 else if (!ctx
->_ImageTransferState
&&
3019 !srcPacking
->SwapBytes
&&
3020 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3021 baseInternalFormat
== GL_RGBA
&&
3022 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3023 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3024 /* simple memcpy path */
3025 memcpy_texture(ctx
, dims
,
3027 dstRowStride
, dstSlices
,
3028 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3029 srcAddr
, srcPacking
);
3033 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3036 srcWidth
, srcHeight
, srcDepth
,
3037 srcFormat
, srcType
, srcAddr
,
3039 ctx
->_ImageTransferState
);
3040 const GLfloat
*srcRow
= tempImage
;
3041 GLint img
, row
, col
;
3044 for (img
= 0; img
< srcDepth
; img
++) {
3045 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
3046 for (row
= 0; row
< srcHeight
; row
++) {
3047 GLbyte
*dst
= dstRow
;
3048 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3049 for (col
= 0; col
< srcWidth
; col
++) {
3050 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3051 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3052 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3053 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3059 for (col
= 0; col
< srcWidth
; col
++) {
3060 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3061 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3062 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3063 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3068 dstRow
+= dstRowStride
;
3071 free((void *) tempImage
);
3078 * Store a combined depth/stencil texture image.
3081 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3083 const GLuint depthScale
= 0xffffff;
3084 const GLint srcRowStride
3085 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3088 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3089 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3090 srcFormat
== GL_DEPTH_COMPONENT
||
3091 srcFormat
== GL_STENCIL_INDEX
);
3092 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3094 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3095 ctx
->Pixel
.DepthBias
== 0.0f
&&
3096 !srcPacking
->SwapBytes
) {
3098 memcpy_texture(ctx
, dims
,
3100 dstRowStride
, dstSlices
,
3101 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3102 srcAddr
, srcPacking
);
3104 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3105 srcFormat
== GL_STENCIL_INDEX
) {
3106 /* In case we only upload depth we need to preserve the stencil */
3107 for (img
= 0; img
< srcDepth
; img
++) {
3108 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3110 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3111 srcWidth
, srcHeight
,
3114 for (row
= 0; row
< srcHeight
; row
++) {
3115 GLuint depth
[MAX_WIDTH
];
3116 GLubyte stencil
[MAX_WIDTH
];
3118 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3120 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3121 keepstencil
= GL_TRUE
;
3123 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3124 keepdepth
= GL_TRUE
;
3127 if (keepdepth
== GL_FALSE
)
3128 /* the 24 depth bits will be in the low position: */
3129 _mesa_unpack_depth_span(ctx
, srcWidth
,
3130 GL_UNSIGNED_INT
, /* dst type */
3131 keepstencil
? depth
: dstRow
, /* dst addr */
3133 srcType
, src
, srcPacking
);
3135 if (keepstencil
== GL_FALSE
)
3136 /* get the 8-bit stencil values */
3137 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3138 GL_UNSIGNED_BYTE
, /* dst type */
3139 stencil
, /* dst addr */
3140 srcType
, src
, srcPacking
,
3141 ctx
->_ImageTransferState
);
3143 for (i
= 0; i
< srcWidth
; i
++) {
3145 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3147 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3150 src
+= srcRowStride
;
3151 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3160 * Store a combined depth/stencil texture image.
3163 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3165 const GLuint depthScale
= 0xffffff;
3166 const GLint srcRowStride
3167 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3170 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3171 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3172 srcFormat
== GL_DEPTH_COMPONENT
||
3173 srcFormat
== GL_STENCIL_INDEX
);
3174 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3175 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3177 for (img
= 0; img
< srcDepth
; img
++) {
3178 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
3180 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3181 srcWidth
, srcHeight
,
3184 for (row
= 0; row
< srcHeight
; row
++) {
3185 GLuint depth
[MAX_WIDTH
];
3186 GLubyte stencil
[MAX_WIDTH
];
3188 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3190 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3191 keepstencil
= GL_TRUE
;
3193 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3194 keepdepth
= GL_TRUE
;
3197 if (keepdepth
== GL_FALSE
)
3198 /* the 24 depth bits will be in the low position: */
3199 _mesa_unpack_depth_span(ctx
, srcWidth
,
3200 GL_UNSIGNED_INT
, /* dst type */
3201 keepstencil
? depth
: dstRow
, /* dst addr */
3203 srcType
, src
, srcPacking
);
3205 if (keepstencil
== GL_FALSE
)
3206 /* get the 8-bit stencil values */
3207 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3208 GL_UNSIGNED_BYTE
, /* dst type */
3209 stencil
, /* dst addr */
3210 srcType
, src
, srcPacking
,
3211 ctx
->_ImageTransferState
);
3213 /* merge stencil values into depth values */
3214 for (i
= 0; i
< srcWidth
; i
++) {
3216 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3218 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3221 src
+= srcRowStride
;
3222 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3230 * Store simple 8-bit/value stencil texture data.
3233 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3235 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3236 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3238 if (!ctx
->_ImageTransferState
&&
3239 !srcPacking
->SwapBytes
&&
3240 baseInternalFormat
== srcFormat
&&
3241 srcType
== GL_UNSIGNED_BYTE
) {
3242 /* simple memcpy path */
3243 memcpy_texture(ctx
, dims
,
3245 dstRowStride
, dstSlices
,
3246 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3247 srcAddr
, srcPacking
);
3250 const GLint srcRowStride
3251 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3254 for (img
= 0; img
< srcDepth
; img
++) {
3255 GLubyte
*dstRow
= dstSlices
[img
];
3257 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3258 srcWidth
, srcHeight
,
3261 for (row
= 0; row
< srcHeight
; row
++) {
3262 GLubyte stencil
[MAX_WIDTH
];
3265 /* get the 8-bit stencil values */
3266 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3267 GL_UNSIGNED_BYTE
, /* dst type */
3268 stencil
, /* dst addr */
3269 srcType
, src
, srcPacking
,
3270 ctx
->_ImageTransferState
);
3271 /* merge stencil values into depth values */
3272 for (i
= 0; i
< srcWidth
; i
++)
3273 dstRow
[i
] = stencil
[i
];
3275 src
+= srcRowStride
;
3276 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3287 * Store an image in any of the formats:
3288 * _mesa_texformat_rgba_float32
3289 * _mesa_texformat_rgb_float32
3290 * _mesa_texformat_alpha_float32
3291 * _mesa_texformat_luminance_float32
3292 * _mesa_texformat_luminance_alpha_float32
3293 * _mesa_texformat_intensity_float32
3296 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3298 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3299 const GLint components
= _mesa_components_in_format(baseFormat
);
3301 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3302 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3303 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3304 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3305 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3306 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3307 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3308 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3309 ASSERT(baseInternalFormat
== GL_RGBA
||
3310 baseInternalFormat
== GL_RGB
||
3311 baseInternalFormat
== GL_ALPHA
||
3312 baseInternalFormat
== GL_LUMINANCE
||
3313 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3314 baseInternalFormat
== GL_INTENSITY
||
3315 baseInternalFormat
== GL_RED
||
3316 baseInternalFormat
== GL_RG
);
3317 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
3319 if (!ctx
->_ImageTransferState
&&
3320 !srcPacking
->SwapBytes
&&
3321 baseInternalFormat
== srcFormat
&&
3322 baseInternalFormat
== baseFormat
&&
3323 srcType
== GL_FLOAT
) {
3324 /* simple memcpy path */
3325 memcpy_texture(ctx
, dims
,
3327 dstRowStride
, dstSlices
,
3328 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3329 srcAddr
, srcPacking
);
3333 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3336 srcWidth
, srcHeight
, srcDepth
,
3337 srcFormat
, srcType
, srcAddr
,
3339 ctx
->_ImageTransferState
);
3340 const GLfloat
*srcRow
= tempImage
;
3345 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3346 for (img
= 0; img
< srcDepth
; img
++) {
3347 GLubyte
*dstRow
= dstSlices
[img
];
3348 for (row
= 0; row
< srcHeight
; row
++) {
3349 memcpy(dstRow
, srcRow
, bytesPerRow
);
3350 dstRow
+= dstRowStride
;
3351 srcRow
+= srcWidth
* components
;
3355 free((void *) tempImage
);
3363 * As above, but store 16-bit floats.
3366 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3368 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3369 const GLint components
= _mesa_components_in_format(baseFormat
);
3371 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3372 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3373 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3374 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3375 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3376 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3377 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3378 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3379 ASSERT(baseInternalFormat
== GL_RGBA
||
3380 baseInternalFormat
== GL_RGB
||
3381 baseInternalFormat
== GL_ALPHA
||
3382 baseInternalFormat
== GL_LUMINANCE
||
3383 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3384 baseInternalFormat
== GL_INTENSITY
||
3385 baseInternalFormat
== GL_RED
||
3386 baseInternalFormat
== GL_RG
);
3387 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
3389 if (!ctx
->_ImageTransferState
&&
3390 !srcPacking
->SwapBytes
&&
3391 baseInternalFormat
== srcFormat
&&
3392 baseInternalFormat
== baseFormat
&&
3393 srcType
== GL_HALF_FLOAT_ARB
) {
3394 /* simple memcpy path */
3395 memcpy_texture(ctx
, dims
,
3397 dstRowStride
, dstSlices
,
3398 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3399 srcAddr
, srcPacking
);
3403 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3406 srcWidth
, srcHeight
, srcDepth
,
3407 srcFormat
, srcType
, srcAddr
,
3409 ctx
->_ImageTransferState
);
3410 const GLfloat
*src
= tempImage
;
3414 for (img
= 0; img
< srcDepth
; img
++) {
3415 GLubyte
*dstRow
= dstSlices
[img
];
3416 for (row
= 0; row
< srcHeight
; row
++) {
3417 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3419 for (i
= 0; i
< srcWidth
* components
; i
++) {
3420 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3422 dstRow
+= dstRowStride
;
3423 src
+= srcWidth
* components
;
3427 free((void *) tempImage
);
3433 /* non-normalized, signed int8 */
3435 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3437 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3438 const GLint components
= _mesa_components_in_format(baseFormat
);
3440 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3441 dstFormat
== MESA_FORMAT_RG_INT8
||
3442 dstFormat
== MESA_FORMAT_RGB_INT8
||
3443 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3444 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3445 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3446 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3447 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3448 ASSERT(baseInternalFormat
== GL_RGBA
||
3449 baseInternalFormat
== GL_RGB
||
3450 baseInternalFormat
== GL_RG
||
3451 baseInternalFormat
== GL_RED
||
3452 baseInternalFormat
== GL_ALPHA
||
3453 baseInternalFormat
== GL_LUMINANCE
||
3454 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3455 baseInternalFormat
== GL_INTENSITY
);
3456 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
3458 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3459 * to integer formats.
3461 if (!srcPacking
->SwapBytes
&&
3462 baseInternalFormat
== srcFormat
&&
3463 srcType
== GL_BYTE
) {
3464 /* simple memcpy path */
3465 memcpy_texture(ctx
, dims
,
3467 dstRowStride
, dstSlices
,
3468 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3469 srcAddr
, srcPacking
);
3473 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3476 srcWidth
, srcHeight
, srcDepth
,
3480 const GLuint
*src
= tempImage
;
3484 for (img
= 0; img
< srcDepth
; img
++) {
3485 GLubyte
*dstRow
= dstSlices
[img
];
3486 for (row
= 0; row
< srcHeight
; row
++) {
3487 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3489 for (i
= 0; i
< srcWidth
* components
; i
++) {
3490 dstTexel
[i
] = (GLbyte
) src
[i
];
3492 dstRow
+= dstRowStride
;
3493 src
+= srcWidth
* components
;
3497 free((void *) tempImage
);
3503 /* non-normalized, signed int16 */
3505 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3507 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3508 const GLint components
= _mesa_components_in_format(baseFormat
);
3510 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3511 dstFormat
== MESA_FORMAT_RG_INT16
||
3512 dstFormat
== MESA_FORMAT_RGB_INT16
||
3513 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3514 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3515 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3516 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3517 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3518 ASSERT(baseInternalFormat
== GL_RGBA
||
3519 baseInternalFormat
== GL_RGB
||
3520 baseInternalFormat
== GL_RG
||
3521 baseInternalFormat
== GL_RED
||
3522 baseInternalFormat
== GL_ALPHA
||
3523 baseInternalFormat
== GL_LUMINANCE
||
3524 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3525 baseInternalFormat
== GL_INTENSITY
);
3526 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
3528 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3529 * to integer formats.
3531 if (!srcPacking
->SwapBytes
&&
3532 baseInternalFormat
== srcFormat
&&
3533 srcType
== GL_SHORT
) {
3534 /* simple memcpy path */
3535 memcpy_texture(ctx
, dims
,
3537 dstRowStride
, dstSlices
,
3538 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3539 srcAddr
, srcPacking
);
3543 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3546 srcWidth
, srcHeight
, srcDepth
,
3550 const GLuint
*src
= tempImage
;
3554 for (img
= 0; img
< srcDepth
; img
++) {
3555 GLubyte
*dstRow
= dstSlices
[img
];
3556 for (row
= 0; row
< srcHeight
; row
++) {
3557 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3559 for (i
= 0; i
< srcWidth
* components
; i
++) {
3560 dstTexel
[i
] = (GLint
) src
[i
];
3562 dstRow
+= dstRowStride
;
3563 src
+= srcWidth
* components
;
3567 free((void *) tempImage
);
3573 /* non-normalized, signed int32 */
3575 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3577 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3578 const GLint components
= _mesa_components_in_format(baseFormat
);
3580 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3581 dstFormat
== MESA_FORMAT_RG_INT32
||
3582 dstFormat
== MESA_FORMAT_RGB_INT32
||
3583 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3584 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3585 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3586 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3587 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3588 ASSERT(baseInternalFormat
== GL_RGBA
||
3589 baseInternalFormat
== GL_RGB
||
3590 baseInternalFormat
== GL_RG
||
3591 baseInternalFormat
== GL_RED
||
3592 baseInternalFormat
== GL_ALPHA
||
3593 baseInternalFormat
== GL_LUMINANCE
||
3594 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3595 baseInternalFormat
== GL_INTENSITY
);
3596 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
3598 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3599 * to integer formats.
3601 if (!srcPacking
->SwapBytes
&&
3602 baseInternalFormat
== srcFormat
&&
3603 srcType
== GL_INT
) {
3604 /* simple memcpy path */
3605 memcpy_texture(ctx
, dims
,
3607 dstRowStride
, dstSlices
,
3608 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3609 srcAddr
, srcPacking
);
3613 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3616 srcWidth
, srcHeight
, srcDepth
,
3620 const GLuint
*src
= tempImage
;
3624 for (img
= 0; img
< srcDepth
; img
++) {
3625 GLubyte
*dstRow
= dstSlices
[img
];
3626 for (row
= 0; row
< srcHeight
; row
++) {
3627 GLint
*dstTexel
= (GLint
*) dstRow
;
3629 for (i
= 0; i
< srcWidth
* components
; i
++) {
3630 dstTexel
[i
] = (GLint
) src
[i
];
3632 dstRow
+= dstRowStride
;
3633 src
+= srcWidth
* components
;
3637 free((void *) tempImage
);
3643 /* non-normalized, unsigned int8 */
3645 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3647 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3648 const GLint components
= _mesa_components_in_format(baseFormat
);
3650 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3651 dstFormat
== MESA_FORMAT_RG_UINT8
||
3652 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3653 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3654 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3655 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3656 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3657 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3658 ASSERT(baseInternalFormat
== GL_RGBA
||
3659 baseInternalFormat
== GL_RGB
||
3660 baseInternalFormat
== GL_RG
||
3661 baseInternalFormat
== GL_RED
||
3662 baseInternalFormat
== GL_ALPHA
||
3663 baseInternalFormat
== GL_LUMINANCE
||
3664 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3665 baseInternalFormat
== GL_INTENSITY
);
3666 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3668 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3669 * to integer formats.
3671 if (!srcPacking
->SwapBytes
&&
3672 baseInternalFormat
== srcFormat
&&
3673 srcType
== GL_UNSIGNED_BYTE
) {
3674 /* simple memcpy path */
3675 memcpy_texture(ctx
, dims
,
3677 dstRowStride
, dstSlices
,
3678 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3679 srcAddr
, srcPacking
);
3683 const GLuint
*tempImage
=
3684 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3685 srcWidth
, srcHeight
, srcDepth
,
3686 srcFormat
, srcType
, srcAddr
, srcPacking
);
3687 const GLuint
*src
= tempImage
;
3691 for (img
= 0; img
< srcDepth
; img
++) {
3692 GLubyte
*dstRow
= dstSlices
[img
];
3693 for (row
= 0; row
< srcHeight
; row
++) {
3694 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3696 for (i
= 0; i
< srcWidth
* components
; i
++) {
3697 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3699 dstRow
+= dstRowStride
;
3700 src
+= srcWidth
* components
;
3704 free((void *) tempImage
);
3710 /* non-normalized, unsigned int16 */
3712 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3714 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3715 const GLint components
= _mesa_components_in_format(baseFormat
);
3717 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3718 dstFormat
== MESA_FORMAT_RG_UINT16
||
3719 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3720 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3721 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3722 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3723 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3724 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3725 ASSERT(baseInternalFormat
== GL_RGBA
||
3726 baseInternalFormat
== GL_RGB
||
3727 baseInternalFormat
== GL_RG
||
3728 baseInternalFormat
== GL_RED
||
3729 baseInternalFormat
== GL_ALPHA
||
3730 baseInternalFormat
== GL_LUMINANCE
||
3731 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3732 baseInternalFormat
== GL_INTENSITY
);
3733 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3735 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3736 * to integer formats.
3738 if (!srcPacking
->SwapBytes
&&
3739 baseInternalFormat
== srcFormat
&&
3740 srcType
== GL_UNSIGNED_SHORT
) {
3741 /* simple memcpy path */
3742 memcpy_texture(ctx
, dims
,
3744 dstRowStride
, dstSlices
,
3745 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3746 srcAddr
, srcPacking
);
3750 const GLuint
*tempImage
=
3751 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3752 srcWidth
, srcHeight
, srcDepth
,
3753 srcFormat
, srcType
, srcAddr
, srcPacking
);
3754 const GLuint
*src
= tempImage
;
3758 for (img
= 0; img
< srcDepth
; img
++) {
3759 GLubyte
*dstRow
= dstSlices
[img
];
3760 for (row
= 0; row
< srcHeight
; row
++) {
3761 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3763 for (i
= 0; i
< srcWidth
* components
; i
++) {
3764 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3766 dstRow
+= dstRowStride
;
3767 src
+= srcWidth
* components
;
3771 free((void *) tempImage
);
3777 /* non-normalized, unsigned int32 */
3779 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3781 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3782 const GLint components
= _mesa_components_in_format(baseFormat
);
3784 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3785 dstFormat
== MESA_FORMAT_RG_UINT32
||
3786 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3787 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3788 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3789 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3790 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3791 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3792 ASSERT(baseInternalFormat
== GL_RGBA
||
3793 baseInternalFormat
== GL_RGB
||
3794 baseInternalFormat
== GL_RG
||
3795 baseInternalFormat
== GL_RED
||
3796 baseInternalFormat
== GL_ALPHA
||
3797 baseInternalFormat
== GL_LUMINANCE
||
3798 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3799 baseInternalFormat
== GL_INTENSITY
);
3800 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3802 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3803 * to integer formats.
3805 if (!srcPacking
->SwapBytes
&&
3806 baseInternalFormat
== srcFormat
&&
3807 srcType
== GL_UNSIGNED_INT
) {
3808 /* simple memcpy path */
3809 memcpy_texture(ctx
, dims
,
3811 dstRowStride
, dstSlices
,
3812 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3813 srcAddr
, srcPacking
);
3817 const GLuint
*tempImage
=
3818 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3819 srcWidth
, srcHeight
, srcDepth
,
3820 srcFormat
, srcType
, srcAddr
, srcPacking
);
3821 const GLuint
*src
= tempImage
;
3825 for (img
= 0; img
< srcDepth
; img
++) {
3826 GLubyte
*dstRow
= dstSlices
[img
];
3827 for (row
= 0; row
< srcHeight
; row
++) {
3828 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3830 for (i
= 0; i
< srcWidth
* components
; i
++) {
3831 dstTexel
[i
] = src
[i
];
3833 dstRow
+= dstRowStride
;
3834 src
+= srcWidth
* components
;
3838 free((void *) tempImage
);
3846 #if FEATURE_EXT_texture_sRGB
3848 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3850 gl_format newDstFormat
;
3853 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3855 /* reuse normal rgb texstore code */
3856 newDstFormat
= MESA_FORMAT_RGB888
;
3858 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3860 dstRowStride
, dstSlices
,
3861 srcWidth
, srcHeight
, srcDepth
,
3863 srcAddr
, srcPacking
);
3869 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3871 gl_format newDstFormat
;
3874 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3876 /* reuse normal rgba texstore code */
3877 newDstFormat
= MESA_FORMAT_RGBA8888
;
3878 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3880 dstRowStride
, dstSlices
,
3881 srcWidth
, srcHeight
, srcDepth
,
3883 srcAddr
, srcPacking
);
3889 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3891 gl_format newDstFormat
;
3894 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3896 /* reuse normal rgba texstore code */
3897 newDstFormat
= MESA_FORMAT_ARGB8888
;
3899 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3901 dstRowStride
, dstSlices
,
3902 srcWidth
, srcHeight
, srcDepth
,
3904 srcAddr
, srcPacking
);
3910 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3912 gl_format newDstFormat
;
3915 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3917 newDstFormat
= MESA_FORMAT_L8
;
3919 /* _mesa_textore_a8 handles luminance8 too */
3920 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3922 dstRowStride
, dstSlices
,
3923 srcWidth
, srcHeight
, srcDepth
,
3925 srcAddr
, srcPacking
);
3931 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3933 gl_format newDstFormat
;
3936 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3938 /* reuse normal luminance/alpha texstore code */
3939 newDstFormat
= MESA_FORMAT_AL88
;
3941 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3943 dstRowStride
, dstSlices
,
3944 srcWidth
, srcHeight
, srcDepth
,
3946 srcAddr
, srcPacking
);
3952 /* these are used only in texstore_funcs[] below */
3953 #define _mesa_texstore_srgb8 NULL
3954 #define _mesa_texstore_srgba8 NULL
3955 #define _mesa_texstore_sargb8 NULL
3956 #define _mesa_texstore_sl8 NULL
3957 #define _mesa_texstore_sla8 NULL
3959 #endif /* FEATURE_EXT_texture_sRGB */
3962 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3964 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3966 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3967 ASSERT(baseInternalFormat
== GL_RGB
);
3969 if (!ctx
->_ImageTransferState
&&
3970 !srcPacking
->SwapBytes
&&
3971 srcFormat
== GL_RGB
&&
3972 srcType
== GL_UNSIGNED_INT_5_9_9_9_REV
) {
3973 /* simple memcpy path */
3974 memcpy_texture(ctx
, dims
,
3976 dstRowStride
, dstSlices
,
3977 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3978 srcAddr
, srcPacking
);
3982 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3985 srcWidth
, srcHeight
, srcDepth
,
3986 srcFormat
, srcType
, srcAddr
,
3988 ctx
->_ImageTransferState
);
3989 const GLfloat
*srcRow
= tempImage
;
3990 GLint img
, row
, col
;
3993 for (img
= 0; img
< srcDepth
; img
++) {
3994 GLubyte
*dstRow
= dstSlices
[img
];
3995 for (row
= 0; row
< srcHeight
; row
++) {
3996 GLuint
*dstUI
= (GLuint
*)dstRow
;
3997 for (col
= 0; col
< srcWidth
; col
++) {
3998 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
4000 dstRow
+= dstRowStride
;
4001 srcRow
+= srcWidth
* 3;
4005 free((void *) tempImage
);
4011 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
4013 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4015 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
4016 ASSERT(baseInternalFormat
== GL_RGB
);
4018 if (!ctx
->_ImageTransferState
&&
4019 !srcPacking
->SwapBytes
&&
4020 srcFormat
== GL_RGB
&&
4021 srcType
== GL_UNSIGNED_INT_10F_11F_11F_REV
) {
4022 /* simple memcpy path */
4023 memcpy_texture(ctx
, dims
,
4025 dstRowStride
, dstSlices
,
4026 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4027 srcAddr
, srcPacking
);
4031 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4034 srcWidth
, srcHeight
, srcDepth
,
4035 srcFormat
, srcType
, srcAddr
,
4037 ctx
->_ImageTransferState
);
4038 const GLfloat
*srcRow
= tempImage
;
4039 GLint img
, row
, col
;
4042 for (img
= 0; img
< srcDepth
; img
++) {
4043 GLubyte
*dstRow
= dstSlices
[img
];
4044 for (row
= 0; row
< srcHeight
; row
++) {
4045 GLuint
*dstUI
= (GLuint
*)dstRow
;
4046 for (col
= 0; col
< srcWidth
; col
++) {
4047 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
4049 dstRow
+= dstRowStride
;
4050 srcRow
+= srcWidth
* 3;
4054 free((void *) tempImage
);
4061 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
4063 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
4064 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
4065 srcFormat
== GL_DEPTH_COMPONENT
||
4066 srcFormat
== GL_STENCIL_INDEX
);
4067 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
4068 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
4070 if (srcFormat
== GL_DEPTH_STENCIL
&&
4071 ctx
->Pixel
.DepthScale
== 1.0f
&&
4072 ctx
->Pixel
.DepthBias
== 0.0f
&&
4073 !srcPacking
->SwapBytes
) {
4075 memcpy_texture(ctx
, dims
,
4077 dstRowStride
, dstSlices
,
4078 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4079 srcAddr
, srcPacking
);
4081 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4082 srcFormat
== GL_STENCIL_INDEX
) {
4084 const GLint srcRowStride
4085 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4088 /* In case we only upload depth we need to preserve the stencil */
4089 for (img
= 0; img
< srcDepth
; img
++) {
4090 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
4092 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4093 srcWidth
, srcHeight
,
4096 for (row
= 0; row
< srcHeight
; row
++) {
4097 /* The unpack functions with:
4098 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4099 * only write their own dword, so the other dword (stencil
4100 * or depth) is preserved. */
4101 if (srcFormat
!= GL_STENCIL_INDEX
)
4102 _mesa_unpack_depth_span(ctx
, srcWidth
,
4103 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4104 dstRow
, /* dst addr */
4105 ~0U, srcType
, src
, srcPacking
);
4107 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4108 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4109 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4110 dstRow
, /* dst addr */
4111 srcType
, src
, srcPacking
,
4112 ctx
->_ImageTransferState
);
4114 src
+= srcRowStride
;
4115 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4123 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
4125 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4127 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
4128 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
4130 if (!srcPacking
->SwapBytes
&&
4131 dstFormat
== MESA_FORMAT_ARGB2101010_UINT
&&
4132 srcFormat
== GL_BGRA_INTEGER_EXT
&&
4133 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
4134 baseInternalFormat
== GL_RGBA
) {
4135 /* simple memcpy path */
4136 memcpy_texture(ctx
, dims
,
4138 dstRowStride
, dstSlices
,
4139 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4140 srcAddr
, srcPacking
);
4144 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
4147 srcWidth
, srcHeight
,
4148 srcDepth
, srcFormat
,
4151 const GLuint
*src
= tempImage
;
4152 GLint img
, row
, col
;
4155 for (img
= 0; img
< srcDepth
; img
++) {
4156 GLubyte
*dstRow
= dstSlices
[img
];
4158 for (row
= 0; row
< srcHeight
; row
++) {
4159 GLuint
*dstUI
= (GLuint
*) dstRow
;
4160 for (col
= 0; col
< srcWidth
; col
++) {
4166 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
4169 dstRow
+= dstRowStride
;
4172 free((void *) tempImage
);
4178 _mesa_texstore_null(TEXSTORE_PARAMS
)
4180 (void) ctx
; (void) dims
;
4181 (void) baseInternalFormat
;
4183 (void) dstRowStride
; (void) dstSlices
,
4184 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4185 (void) srcFormat
; (void) srcType
;
4189 /* should never happen */
4190 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4196 * Return the StoreTexImageFunc pointer to store an image in the given format.
4198 static StoreTexImageFunc
4199 _mesa_get_texstore_func(gl_format format
)
4201 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
4202 static GLboolean initialized
= GL_FALSE
;
4205 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
4207 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
4208 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
4209 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
4210 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
4211 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
4212 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
4213 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
4214 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
4215 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
4216 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
4217 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
4218 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
4219 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
4220 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
4221 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
4222 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
4223 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
4224 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
4225 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
4226 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
4227 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
4228 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
4229 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
4230 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
4231 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
4232 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
4233 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
4234 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
4235 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
4236 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
4237 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
4238 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
4239 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
4240 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
4241 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
4242 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
4243 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
4244 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
4245 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
4246 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
4247 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
4248 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
4249 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
4250 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
4251 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
4252 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
4253 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
4254 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
4255 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
4256 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
4257 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4258 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4259 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4260 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4261 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
4262 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
4263 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4264 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4265 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4266 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4267 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4268 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4269 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
4270 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
4271 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4272 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4273 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
4274 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
4275 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4276 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4277 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
4278 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
4279 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
4280 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
4281 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
4282 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
4283 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4284 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4285 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4286 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4287 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4288 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4289 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4290 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4291 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4292 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4293 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4294 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4295 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4296 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4297 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4298 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4299 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4300 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4301 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4302 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
4303 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4304 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4305 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4306 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4307 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4308 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4309 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4310 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4311 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4312 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4313 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4314 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4316 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4317 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4318 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4319 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4320 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4321 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4323 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4324 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4325 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4326 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4327 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4328 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4330 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4331 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4332 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4333 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4334 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4335 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4337 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4338 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4339 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4340 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4341 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4342 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4344 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4345 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4346 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4347 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4348 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4349 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4350 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4351 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4352 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4353 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4354 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4355 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4357 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4358 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4359 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4360 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4361 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4362 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4363 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4364 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4365 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4366 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4367 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4368 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4370 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4371 initialized
= GL_TRUE
;
4374 ASSERT(table
[format
]);
4375 return table
[format
];
4380 * Store user data into texture memory.
4381 * Called via glTex[Sub]Image1/2/3D()
4384 _mesa_texstore(TEXSTORE_PARAMS
)
4386 StoreTexImageFunc storeImage
;
4389 storeImage
= _mesa_get_texstore_func(dstFormat
);
4391 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4393 dstRowStride
, dstSlices
,
4394 srcWidth
, srcHeight
, srcDepth
,
4395 srcFormat
, srcType
, srcAddr
, srcPacking
);
4401 * Normally, we'll only _write_ texel data to a texture when we map it.
4402 * But if the user is providing depth or stencil values and the texture
4403 * image is a combined depth/stencil format, we'll actually read from
4404 * the texture buffer too (in order to insert the depth or stencil values.
4405 * \param userFormat the user-provided image format
4406 * \param texFormat the destination texture format
4409 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4411 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4412 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4413 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4415 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
4420 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4422 * The source of the image data may be user memory or a PBO. In the later
4423 * case, we'll map the PBO, copy from it, then unmap it.
4426 store_texsubimage(struct gl_context
*ctx
,
4427 struct gl_texture_image
*texImage
,
4428 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4429 GLint width
, GLint height
, GLint depth
,
4430 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4431 const struct gl_pixelstore_attrib
*packing
,
4435 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4436 const GLenum target
= texImage
->TexObject
->Target
;
4437 GLboolean success
= GL_FALSE
;
4438 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4439 GLint srcImageStride
= 0;
4442 assert(xoffset
+ width
<= texImage
->Width
);
4443 assert(yoffset
+ height
<= texImage
->Height
);
4444 assert(zoffset
+ depth
<= texImage
->Depth
);
4450 case GL_TEXTURE_2D_ARRAY
:
4458 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4459 src
= (const GLubyte
*)
4460 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4461 format
, type
, pixels
, packing
, caller
);
4465 /* compute slice info (and do some sanity checks) */
4468 case GL_TEXTURE_RECTANGLE
:
4469 case GL_TEXTURE_CUBE_MAP
:
4470 /* one image slice, nothing special needs to be done */
4473 assert(height
== 1);
4475 assert(yoffset
== 0);
4476 assert(zoffset
== 0);
4478 case GL_TEXTURE_1D_ARRAY
:
4480 assert(zoffset
== 0);
4482 sliceOffset
= yoffset
;
4485 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4487 case GL_TEXTURE_2D_ARRAY
:
4489 sliceOffset
= zoffset
;
4492 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4496 /* we'll store 3D images as a series of slices */
4498 sliceOffset
= zoffset
;
4499 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4503 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4507 assert(numSlices
== 1 || srcImageStride
!= 0);
4509 for (slice
= 0; slice
< numSlices
; slice
++) {
4513 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4514 slice
+ sliceOffset
,
4515 xoffset
, yoffset
, width
, height
,
4516 mapMode
, &dstMap
, &dstRowStride
);
4518 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4519 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4520 * used for 3D images.
4522 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4523 texImage
->TexFormat
,
4526 width
, height
, 1, /* w, h, d */
4527 format
, type
, src
, packing
);
4529 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4532 src
+= srcImageStride
;
4539 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4541 _mesa_unmap_teximage_pbo(ctx
, packing
);
4547 * This is the fallback for Driver.TexImage1D().
4550 _mesa_store_teximage1d(struct gl_context
*ctx
,
4551 struct gl_texture_image
*texImage
,
4552 GLint internalFormat
,
4553 GLint width
, GLint border
,
4554 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4555 const struct gl_pixelstore_attrib
*packing
)
4560 /* allocate storage for texture data */
4561 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4563 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4567 store_texsubimage(ctx
, texImage
,
4568 0, 0, 0, width
, 1, 1,
4569 format
, type
, pixels
, packing
, "glTexImage1D");
4574 * This is the fallback for Driver.TexImage2D().
4577 _mesa_store_teximage2d(struct gl_context
*ctx
,
4578 struct gl_texture_image
*texImage
,
4579 GLint internalFormat
,
4580 GLint width
, GLint height
, GLint border
,
4581 GLenum format
, GLenum type
, const void *pixels
,
4582 const struct gl_pixelstore_attrib
*packing
)
4584 if (width
== 0 || height
== 0)
4587 /* allocate storage for texture data */
4588 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4589 width
, height
, 1)) {
4590 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4594 store_texsubimage(ctx
, texImage
,
4595 0, 0, 0, width
, height
, 1,
4596 format
, type
, pixels
, packing
, "glTexImage2D");
4602 * This is the fallback for Driver.TexImage3D().
4605 _mesa_store_teximage3d(struct gl_context
*ctx
,
4606 struct gl_texture_image
*texImage
,
4607 GLint internalFormat
,
4608 GLint width
, GLint height
, GLint depth
, GLint border
,
4609 GLenum format
, GLenum type
, const void *pixels
,
4610 const struct gl_pixelstore_attrib
*packing
)
4612 if (width
== 0 || height
== 0 || depth
== 0)
4615 /* allocate storage for texture data */
4616 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4617 width
, height
, depth
)) {
4618 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4622 store_texsubimage(ctx
, texImage
,
4623 0, 0, 0, width
, height
, depth
,
4624 format
, type
, pixels
, packing
, "glTexImage3D");
4631 * This is the fallback for Driver.TexSubImage1D().
4634 _mesa_store_texsubimage1d(struct gl_context
*ctx
,
4635 struct gl_texture_image
*texImage
,
4636 GLint xoffset
, GLint width
,
4637 GLenum format
, GLenum type
, const void *pixels
,
4638 const struct gl_pixelstore_attrib
*packing
)
4640 store_texsubimage(ctx
, texImage
,
4641 xoffset
, 0, 0, width
, 1, 1,
4642 format
, type
, pixels
, packing
, "glTexSubImage1D");
4648 * This is the fallback for Driver.TexSubImage2D().
4651 _mesa_store_texsubimage2d(struct gl_context
*ctx
,
4652 struct gl_texture_image
*texImage
,
4653 GLint xoffset
, GLint yoffset
,
4654 GLint width
, GLint height
,
4655 GLenum format
, GLenum type
, const void *pixels
,
4656 const struct gl_pixelstore_attrib
*packing
)
4658 store_texsubimage(ctx
, texImage
,
4659 xoffset
, yoffset
, 0, width
, height
, 1,
4660 format
, type
, pixels
, packing
, "glTexSubImage2D");
4665 * This is the fallback for Driver.TexSubImage3D().
4668 _mesa_store_texsubimage3d(struct gl_context
*ctx
,
4669 struct gl_texture_image
*texImage
,
4670 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4671 GLint width
, GLint height
, GLint depth
,
4672 GLenum format
, GLenum type
, const void *pixels
,
4673 const struct gl_pixelstore_attrib
*packing
)
4675 store_texsubimage(ctx
, texImage
,
4676 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4677 format
, type
, pixels
, packing
, "glTexSubImage3D");
4682 * Fallback for Driver.CompressedTexImage1D()
4685 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4686 struct gl_texture_image
*texImage
,
4687 GLint internalFormat
,
4688 GLint width
, GLint border
,
4689 GLsizei imageSize
, const GLvoid
*data
)
4691 /* no compressed 1D image formats at this time */
4693 (void) internalFormat
;
4694 (void) width
; (void) border
;
4695 (void) imageSize
; (void) data
;
4702 * Fallback for Driver.CompressedTexImage2D()
4705 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4706 struct gl_texture_image
*texImage
,
4707 GLint internalFormat
,
4708 GLint width
, GLint height
, GLint border
,
4709 GLsizei imageSize
, const GLvoid
*data
)
4711 /* This is pretty simple, because unlike the general texstore path we don't
4712 * have to worry about the usual image unpacking or image transfer
4716 ASSERT(texImage
->Width
> 0);
4717 ASSERT(texImage
->Height
> 0);
4718 ASSERT(texImage
->Depth
== 1);
4720 /* allocate storage for texture data */
4721 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4722 width
, height
, 1)) {
4723 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4727 _mesa_store_compressed_texsubimage2d(ctx
, texImage
,
4730 texImage
->TexFormat
,
4737 * Fallback for Driver.CompressedTexImage3D()
4740 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4741 struct gl_texture_image
*texImage
,
4742 GLint internalFormat
,
4743 GLint width
, GLint height
, GLint depth
,
4745 GLsizei imageSize
, const GLvoid
*data
)
4747 /* this space intentionally left blank */
4749 (void) internalFormat
;
4750 (void) width
; (void) height
; (void) depth
;
4752 (void) imageSize
; (void) data
;
4759 * Fallback for Driver.CompressedTexSubImage1D()
4762 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
,
4763 struct gl_texture_image
*texImage
,
4764 GLint xoffset
, GLsizei width
,
4766 GLsizei imageSize
, const GLvoid
*data
)
4768 /* there are no compressed 1D texture formats yet */
4770 (void) xoffset
; (void) width
;
4772 (void) imageSize
; (void) data
;
4778 * Fallback for Driver.CompressedTexSubImage2D()
4781 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
,
4782 struct gl_texture_image
*texImage
,
4783 GLint xoffset
, GLint yoffset
,
4784 GLsizei width
, GLsizei height
,
4786 GLsizei imageSize
, const GLvoid
*data
)
4788 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4792 const gl_format texFormat
= texImage
->TexFormat
;
4795 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4797 /* these should have been caught sooner */
4798 ASSERT((width
% bw
) == 0 || width
< bw
);
4799 ASSERT((height
% bh
) == 0 || height
< bh
);
4800 ASSERT((xoffset
% bw
) == 0);
4801 ASSERT((yoffset
% bh
) == 0);
4803 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4804 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4806 "glCompressedTexSubImage2D");
4810 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4811 src
= (const GLubyte
*) data
;
4813 /* Map dest texture buffer */
4814 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4815 xoffset
, yoffset
, width
, height
,
4816 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4817 &dstMap
, &dstRowStride
);
4820 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4821 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4823 /* copy rows of blocks */
4824 for (i
= 0; i
< rows
; i
++) {
4825 memcpy(dstMap
, src
, bytesPerRow
);
4826 dstMap
+= dstRowStride
;
4827 src
+= srcRowStride
;
4830 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4833 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
4836 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4841 * Fallback for Driver.CompressedTexSubImage3D()
4844 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
,
4845 struct gl_texture_image
*texImage
,
4846 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4847 GLsizei width
, GLsizei height
, GLsizei depth
,
4849 GLsizei imageSize
, const GLvoid
*data
)
4851 /* there are no compressed 3D texture formats yet */
4853 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4854 (void) width
; (void) height
; (void) depth
;
4856 (void) imageSize
; (void) data
;