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"
73 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
74 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
84 * Texture image storage function.
86 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
90 * Return GL_TRUE if the given image format is one that be converted
91 * to another format by swizzling.
94 can_swizzle(GLenum logicalBaseFormat
)
96 switch (logicalBaseFormat
) {
99 case GL_LUMINANCE_ALPHA
:
135 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
136 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
137 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
138 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
141 static const struct {
144 GLubyte from_rgba
[6];
145 } mappings
[MAX_IDX
] =
155 MAP4(ZERO
, ZERO
, ZERO
, 0),
185 MAP4(0, ZERO
, ZERO
, ONE
),
191 MAP4(ZERO
, 0, ZERO
, ONE
),
197 MAP4(ZERO
, ZERO
, 0, ONE
),
221 MAP4(0, 1, ZERO
, ONE
),
229 * Convert a GL image format enum to an IDX_* value (see above).
232 get_map_idx(GLenum value
)
235 case GL_LUMINANCE
: return IDX_LUMINANCE
;
236 case GL_ALPHA
: return IDX_ALPHA
;
237 case GL_INTENSITY
: return IDX_INTENSITY
;
238 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
239 case GL_RGB
: return IDX_RGB
;
240 case GL_RGBA
: return IDX_RGBA
;
241 case GL_RED
: return IDX_RED
;
242 case GL_GREEN
: return IDX_GREEN
;
243 case GL_BLUE
: return IDX_BLUE
;
244 case GL_BGR
: return IDX_BGR
;
245 case GL_BGRA
: return IDX_BGRA
;
246 case GL_ABGR_EXT
: return IDX_ABGR
;
247 case GL_RG
: return IDX_RG
;
249 _mesa_problem(NULL
, "Unexpected inFormat");
256 * When promoting texture formats (see below) we need to compute the
257 * mapping of dest components back to source components.
258 * This function does that.
259 * \param inFormat the incoming format of the texture
260 * \param outFormat the final texture format
261 * \return map[6] a full 6-component map
264 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
267 const int inFmt
= get_map_idx(inFormat
);
268 const int outFmt
= get_map_idx(outFormat
);
269 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
270 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
273 for (i
= 0; i
< 4; i
++)
274 map
[i
] = in2rgba
[rgba2out
[i
]];
280 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
281 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
282 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
294 * Make a temporary (color) texture image with GLfloat components.
295 * Apply all needed pixel unpacking and pixel transfer operations.
296 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
297 * Suppose the user specifies GL_LUMINANCE as the internal texture format
298 * but the graphics hardware doesn't support luminance textures. So, we might
299 * use an RGB hardware format instead.
300 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
302 * \param ctx the rendering context
303 * \param dims image dimensions: 1, 2 or 3
304 * \param logicalBaseFormat basic texture derived from the user's
305 * internal texture format value
306 * \param textureBaseFormat the actual basic format of the texture
307 * \param srcWidth source image width
308 * \param srcHeight source image height
309 * \param srcDepth source image depth
310 * \param srcFormat source image format
311 * \param srcType source image type
312 * \param srcAddr source image address
313 * \param srcPacking source image pixel packing
314 * \return resulting image with format = textureBaseFormat and type = GLfloat.
317 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
318 GLenum logicalBaseFormat
,
319 GLenum textureBaseFormat
,
320 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
321 GLenum srcFormat
, GLenum srcType
,
322 const GLvoid
*srcAddr
,
323 const struct gl_pixelstore_attrib
*srcPacking
,
324 GLbitfield transferOps
)
327 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
328 const GLint srcStride
=
329 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
333 ASSERT(dims
>= 1 && dims
<= 3);
335 ASSERT(logicalBaseFormat
== GL_RGBA
||
336 logicalBaseFormat
== GL_RGB
||
337 logicalBaseFormat
== GL_RG
||
338 logicalBaseFormat
== GL_RED
||
339 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
340 logicalBaseFormat
== GL_LUMINANCE
||
341 logicalBaseFormat
== GL_ALPHA
||
342 logicalBaseFormat
== GL_INTENSITY
||
343 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
345 ASSERT(textureBaseFormat
== GL_RGBA
||
346 textureBaseFormat
== GL_RGB
||
347 textureBaseFormat
== GL_RG
||
348 textureBaseFormat
== GL_RED
||
349 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
350 textureBaseFormat
== GL_LUMINANCE
||
351 textureBaseFormat
== GL_ALPHA
||
352 textureBaseFormat
== GL_INTENSITY
||
353 textureBaseFormat
== GL_DEPTH_COMPONENT
);
355 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
356 * components
* sizeof(GLfloat
));
361 for (img
= 0; img
< srcDepth
; img
++) {
363 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
367 for (row
= 0; row
< srcHeight
; row
++) {
368 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
369 dst
, srcFormat
, srcType
, src
,
370 srcPacking
, transferOps
);
371 dst
+= srcWidth
* components
;
376 if (logicalBaseFormat
!= textureBaseFormat
) {
378 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
379 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
384 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
385 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
386 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
388 /* The actual texture format should have at least as many components
389 * as the logical texture format.
391 ASSERT(texComponents
>= logComponents
);
393 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
394 * texComponents
* sizeof(GLfloat
));
400 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
402 n
= srcWidth
* srcHeight
* srcDepth
;
403 for (i
= 0; i
< n
; i
++) {
405 for (k
= 0; k
< texComponents
; k
++) {
408 newImage
[i
* texComponents
+ k
] = 0.0F
;
410 newImage
[i
* texComponents
+ k
] = 1.0F
;
412 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
417 tempImage
= newImage
;
425 * Make temporary image with uint pixel values. Used for unsigned
426 * integer-valued textures.
429 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
430 GLenum logicalBaseFormat
,
431 GLenum textureBaseFormat
,
432 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
433 GLenum srcFormat
, GLenum srcType
,
434 const GLvoid
*srcAddr
,
435 const struct gl_pixelstore_attrib
*srcPacking
)
438 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
439 const GLint srcStride
=
440 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
444 ASSERT(dims
>= 1 && dims
<= 3);
446 ASSERT(logicalBaseFormat
== GL_RGBA
||
447 logicalBaseFormat
== GL_RGB
||
448 logicalBaseFormat
== GL_RG
||
449 logicalBaseFormat
== GL_RED
||
450 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
451 logicalBaseFormat
== GL_LUMINANCE
||
452 logicalBaseFormat
== GL_INTENSITY
||
453 logicalBaseFormat
== GL_ALPHA
);
455 ASSERT(textureBaseFormat
== GL_RGBA
||
456 textureBaseFormat
== GL_RGB
||
457 textureBaseFormat
== GL_RG
||
458 textureBaseFormat
== GL_RED
||
459 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
460 textureBaseFormat
== GL_LUMINANCE
||
461 textureBaseFormat
== GL_INTENSITY
||
462 textureBaseFormat
== GL_ALPHA
);
464 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
465 * components
* sizeof(GLuint
));
470 for (img
= 0; img
< srcDepth
; img
++) {
472 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
476 for (row
= 0; row
< srcHeight
; row
++) {
477 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
478 dst
, srcFormat
, srcType
, src
,
480 dst
+= srcWidth
* components
;
485 if (logicalBaseFormat
!= textureBaseFormat
) {
487 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
488 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
493 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
494 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
495 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
497 /* The actual texture format should have at least as many components
498 * as the logical texture format.
500 ASSERT(texComponents
>= logComponents
);
502 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
503 * texComponents
* sizeof(GLuint
));
509 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
511 n
= srcWidth
* srcHeight
* srcDepth
;
512 for (i
= 0; i
< n
; i
++) {
514 for (k
= 0; k
< texComponents
; k
++) {
517 newImage
[i
* texComponents
+ k
] = 0.0F
;
519 newImage
[i
* texComponents
+ k
] = 1.0F
;
521 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
526 tempImage
= newImage
;
535 * Make a temporary (color) texture image with GLubyte components.
536 * Apply all needed pixel unpacking and pixel transfer operations.
537 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
538 * Suppose the user specifies GL_LUMINANCE as the internal texture format
539 * but the graphics hardware doesn't support luminance textures. So, we might
540 * use an RGB hardware format instead.
541 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
543 * \param ctx the rendering context
544 * \param dims image dimensions: 1, 2 or 3
545 * \param logicalBaseFormat basic texture derived from the user's
546 * internal texture format value
547 * \param textureBaseFormat the actual basic format of the texture
548 * \param srcWidth source image width
549 * \param srcHeight source image height
550 * \param srcDepth source image depth
551 * \param srcFormat source image format
552 * \param srcType source image type
553 * \param srcAddr source image address
554 * \param srcPacking source image pixel packing
555 * \return resulting image with format = textureBaseFormat and type = GLubyte.
558 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
559 GLenum logicalBaseFormat
,
560 GLenum textureBaseFormat
,
561 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
562 GLenum srcFormat
, GLenum srcType
,
563 const GLvoid
*srcAddr
,
564 const struct gl_pixelstore_attrib
*srcPacking
)
566 GLuint transferOps
= ctx
->_ImageTransferState
;
567 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
569 GLubyte
*tempImage
, *dst
;
571 ASSERT(dims
>= 1 && dims
<= 3);
573 ASSERT(logicalBaseFormat
== GL_RGBA
||
574 logicalBaseFormat
== GL_RGB
||
575 logicalBaseFormat
== GL_RG
||
576 logicalBaseFormat
== GL_RED
||
577 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
578 logicalBaseFormat
== GL_LUMINANCE
||
579 logicalBaseFormat
== GL_ALPHA
||
580 logicalBaseFormat
== GL_INTENSITY
);
582 ASSERT(textureBaseFormat
== GL_RGBA
||
583 textureBaseFormat
== GL_RGB
||
584 textureBaseFormat
== GL_RG
||
585 textureBaseFormat
== GL_RED
||
586 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
587 textureBaseFormat
== GL_LUMINANCE
||
588 textureBaseFormat
== GL_ALPHA
||
589 textureBaseFormat
== GL_INTENSITY
);
591 /* unpack and transfer the source image */
592 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
593 * components
* sizeof(GLubyte
));
599 for (img
= 0; img
< srcDepth
; img
++) {
600 const GLint srcStride
=
601 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
603 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
607 for (row
= 0; row
< srcHeight
; row
++) {
608 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
609 srcFormat
, srcType
, src
, srcPacking
,
611 dst
+= srcWidth
* components
;
616 if (logicalBaseFormat
!= textureBaseFormat
) {
617 /* one more conversion step */
618 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
619 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
624 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
625 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
626 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
628 /* The actual texture format should have at least as many components
629 * as the logical texture format.
631 ASSERT(texComponents
>= logComponents
);
633 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
634 * texComponents
* sizeof(GLubyte
));
640 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
642 n
= srcWidth
* srcHeight
* srcDepth
;
643 for (i
= 0; i
< n
; i
++) {
645 for (k
= 0; k
< texComponents
; k
++) {
648 newImage
[i
* texComponents
+ k
] = 0;
650 newImage
[i
* texComponents
+ k
] = 255;
652 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
657 tempImage
= newImage
;
665 * Copy GLubyte pixels from <src> to <dst> with swizzling.
666 * \param dst destination pixels
667 * \param dstComponents number of color components in destination pixels
668 * \param src source pixels
669 * \param srcComponents number of color components in source pixels
670 * \param map the swizzle mapping. map[X] says where to find the X component
671 * in the source image's pixels. For example, if the source image
672 * is GL_BGRA and X = red, map[0] yields 2.
673 * \param count number of pixels to copy/swizzle.
676 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
677 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
679 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
682 for (i = 0; i < count; i++) { \
684 if (srcComps == 4) { \
685 COPY_4UBV(tmp, src); \
688 for (j = 0; j < srcComps; j++) { \
693 for (j = 0; j < dstComps; j++) { \
694 dst[j] = tmp[map[j]]; \
705 ASSERT(srcComponents
<= 4);
706 ASSERT(dstComponents
<= 4);
708 switch (dstComponents
) {
710 switch (srcComponents
) {
712 SWZ_CPY(dst
, src
, count
, 4, 4);
715 SWZ_CPY(dst
, src
, count
, 4, 3);
718 SWZ_CPY(dst
, src
, count
, 4, 2);
721 SWZ_CPY(dst
, src
, count
, 4, 1);
728 switch (srcComponents
) {
730 SWZ_CPY(dst
, src
, count
, 3, 4);
733 SWZ_CPY(dst
, src
, count
, 3, 3);
736 SWZ_CPY(dst
, src
, count
, 3, 2);
739 SWZ_CPY(dst
, src
, count
, 3, 1);
746 switch (srcComponents
) {
748 SWZ_CPY(dst
, src
, count
, 2, 4);
751 SWZ_CPY(dst
, src
, count
, 2, 3);
754 SWZ_CPY(dst
, src
, count
, 2, 2);
757 SWZ_CPY(dst
, src
, count
, 2, 1);
764 switch (srcComponents
) {
766 SWZ_CPY(dst
, src
, count
, 1, 4);
769 SWZ_CPY(dst
, src
, count
, 1, 3);
772 SWZ_CPY(dst
, src
, count
, 1, 2);
775 SWZ_CPY(dst
, src
, count
, 1, 1);
789 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
790 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
794 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
795 * mapping array depending on endianness.
797 static const GLubyte
*
798 type_mapping( GLenum srcType
)
802 case GL_UNSIGNED_BYTE
:
804 case GL_UNSIGNED_INT_8_8_8_8
:
805 return _mesa_little_endian() ? map_3210
: map_identity
;
806 case GL_UNSIGNED_INT_8_8_8_8_REV
:
807 return _mesa_little_endian() ? map_identity
: map_3210
;
815 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
816 * mapping array depending on pixelstore byte swapping state.
818 static const GLubyte
*
819 byteswap_mapping( GLboolean swapBytes
,
827 case GL_UNSIGNED_BYTE
:
829 case GL_UNSIGNED_INT_8_8_8_8
:
830 case GL_UNSIGNED_INT_8_8_8_8_REV
:
840 * Transfer a GLubyte texture image with component swizzling.
843 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
848 GLenum baseInternalFormat
,
850 const GLubyte
*rgba2dst
,
851 GLuint dstComponents
,
853 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= dstSlices
[0]
899 + dstYoffset
* dstRowStride
900 + dstXoffset
* dstComponents
;
901 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
902 srcWidth
* srcHeight
);
906 for (img
= 0; img
< srcDepth
; img
++) {
907 const GLubyte
*srcRow
= srcImage
;
908 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
909 + dstYoffset
* dstRowStride
910 + dstXoffset
* dstComponents
;
911 for (row
= 0; row
< srcHeight
; row
++) {
912 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
913 dstRow
+= dstRowStride
;
914 srcRow
+= srcRowStride
;
916 srcImage
+= srcImageStride
;
923 * Teximage storage routine for when a simple memcpy will do.
924 * No pixel transfer operations or special texel encodings allowed.
925 * 1D, 2D and 3D images supported.
928 memcpy_texture(struct gl_context
*ctx
,
931 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
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
[dstZoffset
+ img
]
954 + dstYoffset
* dstRowStride
955 + dstXoffset
* texelBytes
;
956 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
,
957 bytesPerRow
* srcHeight
);
958 srcImage
+= srcImageStride
;
962 /* memcpy row by row */
964 for (img
= 0; img
< srcDepth
; img
++) {
965 const GLubyte
*srcRow
= srcImage
;
966 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
967 + dstYoffset
* dstRowStride
968 + dstXoffset
* texelBytes
;
969 for (row
= 0; row
< srcHeight
; row
++) {
970 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
971 dstRow
+= dstRowStride
;
972 srcRow
+= srcRowStride
;
974 srcImage
+= srcImageStride
;
982 * Store a 32-bit integer or float depth component texture image.
985 _mesa_texstore_z32(TEXSTORE_PARAMS
)
987 const GLuint depthScale
= 0xffffffff;
988 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
989 const GLenum dstType
= _mesa_get_format_datatype(dstFormat
);
991 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
992 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
993 ASSERT(texelBytes
== sizeof(GLuint
));
995 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
996 ctx
->Pixel
.DepthBias
== 0.0f
&&
997 !srcPacking
->SwapBytes
&&
998 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
999 srcFormat
== GL_DEPTH_COMPONENT
&&
1000 srcType
== dstType
) {
1001 /* simple memcpy path */
1002 memcpy_texture(ctx
, dims
,
1003 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1004 dstRowStride
, dstSlices
,
1005 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1006 srcAddr
, srcPacking
);
1011 for (img
= 0; img
< srcDepth
; img
++) {
1012 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1013 + dstYoffset
* dstRowStride
1014 + dstXoffset
* texelBytes
;
1015 for (row
= 0; row
< srcHeight
; row
++) {
1016 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1017 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1018 _mesa_unpack_depth_span(ctx
, srcWidth
,
1020 depthScale
, srcType
, src
, srcPacking
);
1021 dstRow
+= dstRowStride
;
1030 * Store a 24-bit integer depth component texture image.
1033 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1035 const GLuint depthScale
= 0xffffff;
1036 const GLuint texelBytes
= 4;
1039 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1044 for (img
= 0; img
< srcDepth
; img
++) {
1045 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1046 + dstYoffset
* dstRowStride
1047 + dstXoffset
* texelBytes
;
1048 for (row
= 0; row
< srcHeight
; row
++) {
1049 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1050 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1051 _mesa_unpack_depth_span(ctx
, srcWidth
,
1052 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1053 depthScale
, srcType
, src
, srcPacking
);
1054 dstRow
+= dstRowStride
;
1063 * Store a 24-bit integer depth component texture image.
1066 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1068 const GLuint depthScale
= 0xffffff;
1069 const GLuint texelBytes
= 4;
1072 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1077 for (img
= 0; img
< srcDepth
; img
++) {
1078 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1079 + dstYoffset
* dstRowStride
1080 + dstXoffset
* texelBytes
;
1081 for (row
= 0; row
< srcHeight
; row
++) {
1082 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1083 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1084 GLuint
*dst
= (GLuint
*) dstRow
;
1086 _mesa_unpack_depth_span(ctx
, srcWidth
,
1087 GL_UNSIGNED_INT
, dst
,
1088 depthScale
, srcType
, src
, srcPacking
);
1089 for (i
= 0; i
< srcWidth
; i
++)
1091 dstRow
+= dstRowStride
;
1100 * Store a 16-bit integer depth component texture image.
1103 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1105 const GLuint depthScale
= 0xffff;
1106 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1108 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1109 ASSERT(texelBytes
== sizeof(GLushort
));
1111 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1112 ctx
->Pixel
.DepthBias
== 0.0f
&&
1113 !srcPacking
->SwapBytes
&&
1114 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1115 srcFormat
== GL_DEPTH_COMPONENT
&&
1116 srcType
== GL_UNSIGNED_SHORT
) {
1117 /* simple memcpy path */
1118 memcpy_texture(ctx
, dims
,
1119 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1120 dstRowStride
, dstSlices
,
1121 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1122 srcAddr
, srcPacking
);
1127 for (img
= 0; img
< srcDepth
; img
++) {
1128 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1129 + dstYoffset
* dstRowStride
1130 + dstXoffset
* texelBytes
;
1131 for (row
= 0; row
< srcHeight
; row
++) {
1132 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1133 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1134 GLushort
*dst16
= (GLushort
*) dstRow
;
1135 _mesa_unpack_depth_span(ctx
, srcWidth
,
1136 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1137 srcType
, src
, srcPacking
);
1138 dstRow
+= dstRowStride
;
1147 * Store an rgb565 or rgb565_rev texture image.
1150 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1152 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1153 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1155 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1156 dstFormat
== MESA_FORMAT_RGB565_REV
);
1157 ASSERT(texelBytes
== 2);
1159 if (!ctx
->_ImageTransferState
&&
1160 !srcPacking
->SwapBytes
&&
1161 dstFormat
== MESA_FORMAT_RGB565
&&
1162 baseInternalFormat
== GL_RGB
&&
1163 srcFormat
== GL_RGB
&&
1164 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1165 /* simple memcpy path */
1166 memcpy_texture(ctx
, dims
,
1167 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1168 dstRowStride
, dstSlices
,
1169 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1170 srcAddr
, srcPacking
);
1172 else if (!ctx
->_ImageTransferState
&&
1173 !srcPacking
->SwapBytes
&&
1174 baseInternalFormat
== GL_RGB
&&
1175 srcFormat
== GL_RGB
&&
1176 srcType
== GL_UNSIGNED_BYTE
&&
1178 /* do optimized tex store */
1179 const GLint srcRowStride
=
1180 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1181 const GLubyte
*src
= (const GLubyte
*)
1182 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1183 srcFormat
, srcType
, 0, 0, 0);
1184 GLubyte
*dst
= dstSlices
[0]
1185 + dstYoffset
* dstRowStride
1186 + dstXoffset
* texelBytes
;
1188 for (row
= 0; row
< srcHeight
; row
++) {
1189 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1190 GLushort
*dstUS
= (GLushort
*) dst
;
1191 /* check for byteswapped format */
1192 if (dstFormat
== MESA_FORMAT_RGB565
) {
1193 for (col
= 0; col
< srcWidth
; col
++) {
1194 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1199 for (col
= 0; col
< srcWidth
; col
++) {
1200 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1204 dst
+= dstRowStride
;
1205 src
+= srcRowStride
;
1210 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1213 srcWidth
, srcHeight
, srcDepth
,
1214 srcFormat
, srcType
, srcAddr
,
1216 const GLubyte
*src
= tempImage
;
1217 GLint img
, row
, col
;
1220 for (img
= 0; img
< srcDepth
; img
++) {
1221 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1222 + dstYoffset
* dstRowStride
1223 + dstXoffset
* texelBytes
;
1224 for (row
= 0; row
< srcHeight
; row
++) {
1225 GLushort
*dstUS
= (GLushort
*) dstRow
;
1226 /* check for byteswapped format */
1227 if (dstFormat
== MESA_FORMAT_RGB565
) {
1228 for (col
= 0; col
< srcWidth
; col
++) {
1229 dstUS
[col
] = PACK_COLOR_565( src
[RCOMP
],
1236 for (col
= 0; col
< srcWidth
; col
++) {
1237 dstUS
[col
] = PACK_COLOR_565_REV( src
[RCOMP
],
1243 dstRow
+= dstRowStride
;
1246 free((void *) tempImage
);
1253 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1256 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1258 const GLboolean littleEndian
= _mesa_little_endian();
1259 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1260 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1262 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1263 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1264 ASSERT(texelBytes
== 4);
1266 if (!ctx
->_ImageTransferState
&&
1267 !srcPacking
->SwapBytes
&&
1268 dstFormat
== MESA_FORMAT_RGBA8888
&&
1269 baseInternalFormat
== GL_RGBA
&&
1270 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1271 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1272 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1273 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1274 /* simple memcpy path */
1275 memcpy_texture(ctx
, dims
,
1276 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1277 dstRowStride
, dstSlices
,
1278 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1279 srcAddr
, srcPacking
);
1281 else if (!ctx
->_ImageTransferState
&&
1282 !srcPacking
->SwapBytes
&&
1283 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1284 baseInternalFormat
== GL_RGBA
&&
1285 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1286 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1287 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1288 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1289 /* simple memcpy path */
1290 memcpy_texture(ctx
, dims
,
1291 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1292 dstRowStride
, dstSlices
,
1293 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1294 srcAddr
, srcPacking
);
1296 else if (!ctx
->_ImageTransferState
&&
1297 (srcType
== GL_UNSIGNED_BYTE
||
1298 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1299 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1300 can_swizzle(baseInternalFormat
) &&
1301 can_swizzle(srcFormat
)) {
1305 /* dstmap - how to swizzle from RGBA to dst format:
1307 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1308 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1321 _mesa_swizzle_ubyte_image(ctx
, dims
,
1326 dstXoffset
, dstYoffset
, dstZoffset
,
1327 dstRowStride
, dstSlices
,
1328 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1333 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1336 srcWidth
, srcHeight
, srcDepth
,
1337 srcFormat
, srcType
, srcAddr
,
1339 const GLubyte
*src
= tempImage
;
1340 GLint img
, row
, col
;
1343 for (img
= 0; img
< srcDepth
; img
++) {
1344 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1345 + dstYoffset
* dstRowStride
1346 + dstXoffset
* texelBytes
;
1347 for (row
= 0; row
< srcHeight
; row
++) {
1348 GLuint
*dstUI
= (GLuint
*) dstRow
;
1349 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1350 for (col
= 0; col
< srcWidth
; col
++) {
1351 dstUI
[col
] = PACK_COLOR_8888( src
[RCOMP
],
1359 for (col
= 0; col
< srcWidth
; col
++) {
1360 dstUI
[col
] = PACK_COLOR_8888_REV( src
[RCOMP
],
1367 dstRow
+= dstRowStride
;
1370 free((void *) tempImage
);
1377 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1379 const GLboolean littleEndian
= _mesa_little_endian();
1380 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1381 const GLenum baseFormat
= GL_RGBA
;
1383 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1384 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1385 dstFormat
== MESA_FORMAT_XRGB8888
||
1386 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1387 ASSERT(texelBytes
== 4);
1389 if (!ctx
->_ImageTransferState
&&
1390 !srcPacking
->SwapBytes
&&
1391 (dstFormat
== MESA_FORMAT_ARGB8888
||
1392 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1393 baseInternalFormat
== GL_RGBA
&&
1394 srcFormat
== GL_BGRA
&&
1395 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1396 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1397 /* simple memcpy path (little endian) */
1398 memcpy_texture(ctx
, dims
,
1399 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
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_REV
||
1407 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1408 baseInternalFormat
== GL_RGBA
&&
1409 srcFormat
== GL_BGRA
&&
1410 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1411 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1412 /* simple memcpy path (big endian) */
1413 memcpy_texture(ctx
, dims
,
1414 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1415 dstRowStride
, dstSlices
,
1416 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1417 srcAddr
, srcPacking
);
1419 else if (!ctx
->_ImageTransferState
&&
1420 !srcPacking
->SwapBytes
&&
1421 (dstFormat
== MESA_FORMAT_ARGB8888
||
1422 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1423 srcFormat
== GL_RGB
&&
1424 (baseInternalFormat
== GL_RGBA
||
1425 baseInternalFormat
== GL_RGB
) &&
1426 srcType
== GL_UNSIGNED_BYTE
) {
1428 for (img
= 0; img
< srcDepth
; img
++) {
1429 const GLint srcRowStride
=
1430 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1431 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1432 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1433 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1434 + dstYoffset
* dstRowStride
1435 + dstXoffset
* texelBytes
;
1436 for (row
= 0; row
< srcHeight
; row
++) {
1437 GLuint
*d4
= (GLuint
*) dstRow
;
1438 for (col
= 0; col
< srcWidth
; col
++) {
1439 d4
[col
] = PACK_COLOR_8888(0xff,
1440 srcRow
[col
* 3 + RCOMP
],
1441 srcRow
[col
* 3 + GCOMP
],
1442 srcRow
[col
* 3 + BCOMP
]);
1444 dstRow
+= dstRowStride
;
1445 srcRow
+= srcRowStride
;
1449 else if (!ctx
->_ImageTransferState
&&
1450 !srcPacking
->SwapBytes
&&
1451 dstFormat
== MESA_FORMAT_ARGB8888
&&
1452 srcFormat
== GL_RGBA
&&
1453 baseInternalFormat
== GL_RGBA
&&
1454 srcType
== GL_UNSIGNED_BYTE
) {
1455 /* same as above case, but src data has alpha too */
1456 GLint img
, row
, col
;
1457 /* For some reason, streaming copies to write-combined regions
1458 * are extremely sensitive to the characteristics of how the
1459 * source data is retrieved. By reordering the source reads to
1460 * be in-order, the speed of this operation increases by half.
1461 * Strangely the same isn't required for the RGB path, above.
1463 for (img
= 0; img
< srcDepth
; img
++) {
1464 const GLint srcRowStride
=
1465 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1466 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1467 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1468 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1469 + dstYoffset
* dstRowStride
1470 + dstXoffset
* texelBytes
;
1471 for (row
= 0; row
< srcHeight
; row
++) {
1472 GLuint
*d4
= (GLuint
*) dstRow
;
1473 for (col
= 0; col
< srcWidth
; col
++) {
1474 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1475 srcRow
[col
* 4 + RCOMP
],
1476 srcRow
[col
* 4 + GCOMP
],
1477 srcRow
[col
* 4 + BCOMP
]);
1479 dstRow
+= dstRowStride
;
1480 srcRow
+= srcRowStride
;
1484 else if (!ctx
->_ImageTransferState
&&
1485 (srcType
== GL_UNSIGNED_BYTE
||
1486 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1487 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1488 can_swizzle(baseInternalFormat
) &&
1489 can_swizzle(srcFormat
)) {
1493 /* dstmap - how to swizzle from RGBA to dst format:
1495 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1496 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1497 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1498 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1499 dstmap
[3] = 3; /* alpha */
1500 dstmap
[2] = 0; /* red */
1501 dstmap
[1] = 1; /* green */
1502 dstmap
[0] = 2; /* blue */
1505 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1506 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1507 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1508 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1515 _mesa_swizzle_ubyte_image(ctx
, dims
,
1520 dstXoffset
, dstYoffset
, dstZoffset
,
1523 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1528 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1531 srcWidth
, srcHeight
, srcDepth
,
1532 srcFormat
, srcType
, srcAddr
,
1534 const GLubyte
*src
= tempImage
;
1535 GLint img
, row
, col
;
1538 for (img
= 0; img
< srcDepth
; img
++) {
1539 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1540 + dstYoffset
* dstRowStride
1541 + dstXoffset
* texelBytes
;
1542 for (row
= 0; row
< srcHeight
; row
++) {
1543 GLuint
*dstUI
= (GLuint
*) dstRow
;
1544 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1545 for (col
= 0; col
< srcWidth
; col
++) {
1546 dstUI
[col
] = PACK_COLOR_8888( src
[ACOMP
],
1553 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1554 for (col
= 0; col
< srcWidth
; col
++) {
1555 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1563 for (col
= 0; col
< srcWidth
; col
++) {
1564 dstUI
[col
] = PACK_COLOR_8888_REV( src
[ACOMP
],
1571 dstRow
+= dstRowStride
;
1574 free((void *) tempImage
);
1581 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1583 const GLboolean littleEndian
= _mesa_little_endian();
1584 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1585 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1587 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1588 ASSERT(texelBytes
== 3);
1590 if (!ctx
->_ImageTransferState
&&
1591 !srcPacking
->SwapBytes
&&
1592 baseInternalFormat
== GL_RGB
&&
1593 srcFormat
== GL_BGR
&&
1594 srcType
== GL_UNSIGNED_BYTE
&&
1596 /* simple memcpy path */
1597 memcpy_texture(ctx
, dims
,
1598 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1599 dstRowStride
, dstSlices
,
1600 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1601 srcAddr
, srcPacking
);
1603 else if (!ctx
->_ImageTransferState
&&
1604 !srcPacking
->SwapBytes
&&
1605 srcFormat
== GL_RGBA
&&
1606 srcType
== GL_UNSIGNED_BYTE
) {
1607 /* extract RGB from RGBA */
1608 GLint img
, row
, col
;
1609 for (img
= 0; img
< srcDepth
; img
++) {
1610 const GLint srcRowStride
=
1611 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1612 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1613 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1614 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1615 + dstYoffset
* dstRowStride
1616 + dstXoffset
* texelBytes
;
1617 for (row
= 0; row
< srcHeight
; row
++) {
1618 for (col
= 0; col
< srcWidth
; col
++) {
1619 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1620 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1621 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1623 dstRow
+= dstRowStride
;
1624 srcRow
+= srcRowStride
;
1628 else if (!ctx
->_ImageTransferState
&&
1629 srcType
== GL_UNSIGNED_BYTE
&&
1630 can_swizzle(baseInternalFormat
) &&
1631 can_swizzle(srcFormat
)) {
1635 /* dstmap - how to swizzle from RGBA to dst format:
1640 dstmap
[3] = ONE
; /* ? */
1642 _mesa_swizzle_ubyte_image(ctx
, dims
,
1647 dstXoffset
, dstYoffset
, dstZoffset
,
1648 dstRowStride
, dstSlices
,
1649 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1654 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1657 srcWidth
, srcHeight
, srcDepth
,
1658 srcFormat
, srcType
, srcAddr
,
1660 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1661 GLint img
, row
, col
;
1664 for (img
= 0; img
< srcDepth
; img
++) {
1665 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1666 + dstYoffset
* dstRowStride
1667 + dstXoffset
* texelBytes
;
1668 for (row
= 0; row
< srcHeight
; row
++) {
1671 for (col
= 0; col
< srcWidth
; col
++) {
1672 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1673 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1674 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1679 for (col
= 0; col
< srcWidth
; col
++) {
1680 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1681 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1682 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1687 for (col
= 0; col
< srcWidth
; col
++) {
1688 dstRow
[col
* 3 + 0] = src
[BCOMP
];
1689 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1690 dstRow
[col
* 3 + 2] = src
[RCOMP
];
1694 dstRow
+= dstRowStride
;
1697 free((void *) tempImage
);
1704 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1706 const GLboolean littleEndian
= _mesa_little_endian();
1707 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1708 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1710 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1711 ASSERT(texelBytes
== 3);
1713 if (!ctx
->_ImageTransferState
&&
1714 !srcPacking
->SwapBytes
&&
1715 baseInternalFormat
== GL_RGB
&&
1716 srcFormat
== GL_RGB
&&
1717 srcType
== GL_UNSIGNED_BYTE
&&
1719 /* simple memcpy path */
1720 memcpy_texture(ctx
, dims
,
1721 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1722 dstRowStride
, dstSlices
,
1723 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1724 srcAddr
, srcPacking
);
1726 else if (!ctx
->_ImageTransferState
&&
1727 !srcPacking
->SwapBytes
&&
1728 srcFormat
== GL_RGBA
&&
1729 srcType
== GL_UNSIGNED_BYTE
) {
1730 /* extract BGR from RGBA */
1732 for (img
= 0; img
< srcDepth
; img
++) {
1733 const GLint srcRowStride
=
1734 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1735 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1736 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1737 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1738 + dstYoffset
* dstRowStride
1739 + dstXoffset
* texelBytes
;
1740 for (row
= 0; row
< srcHeight
; row
++) {
1741 for (col
= 0; col
< srcWidth
; col
++) {
1742 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1743 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1744 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1746 dstRow
+= dstRowStride
;
1747 srcRow
+= srcRowStride
;
1751 else if (!ctx
->_ImageTransferState
&&
1752 srcType
== GL_UNSIGNED_BYTE
&&
1753 can_swizzle(baseInternalFormat
) &&
1754 can_swizzle(srcFormat
)) {
1758 /* dstmap - how to swizzle from RGBA to dst format:
1763 dstmap
[3] = ONE
; /* ? */
1765 _mesa_swizzle_ubyte_image(ctx
, dims
,
1770 dstXoffset
, dstYoffset
, dstZoffset
,
1771 dstRowStride
, dstSlices
,
1772 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1777 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1780 srcWidth
, srcHeight
, srcDepth
,
1781 srcFormat
, srcType
, srcAddr
,
1783 const GLubyte
*src
= (const GLubyte
*) tempImage
;
1784 GLint img
, row
, col
;
1787 for (img
= 0; img
< srcDepth
; img
++) {
1788 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1789 + dstYoffset
* dstRowStride
1790 + dstXoffset
* texelBytes
;
1791 for (row
= 0; row
< srcHeight
; row
++) {
1792 for (col
= 0; col
< srcWidth
; col
++) {
1793 dstRow
[col
* 3 + 0] = src
[RCOMP
];
1794 dstRow
[col
* 3 + 1] = src
[GCOMP
];
1795 dstRow
[col
* 3 + 2] = src
[BCOMP
];
1798 dstRow
+= dstRowStride
;
1801 free((void *) tempImage
);
1808 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1810 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1811 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1813 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1814 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1815 ASSERT(texelBytes
== 2);
1817 if (!ctx
->_ImageTransferState
&&
1818 !srcPacking
->SwapBytes
&&
1819 dstFormat
== MESA_FORMAT_ARGB4444
&&
1820 baseInternalFormat
== GL_RGBA
&&
1821 srcFormat
== GL_BGRA
&&
1822 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1823 /* simple memcpy path */
1824 memcpy_texture(ctx
, dims
,
1825 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1826 dstRowStride
, dstSlices
,
1827 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1828 srcAddr
, srcPacking
);
1832 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1835 srcWidth
, srcHeight
, srcDepth
,
1836 srcFormat
, srcType
, srcAddr
,
1838 const GLubyte
*src
= tempImage
;
1839 GLint img
, row
, col
;
1842 for (img
= 0; img
< srcDepth
; img
++) {
1843 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1844 + dstYoffset
* dstRowStride
1845 + dstXoffset
* texelBytes
;
1846 for (row
= 0; row
< srcHeight
; row
++) {
1847 GLushort
*dstUS
= (GLushort
*) dstRow
;
1848 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1849 for (col
= 0; col
< srcWidth
; col
++) {
1850 dstUS
[col
] = PACK_COLOR_4444( src
[ACOMP
],
1858 for (col
= 0; col
< srcWidth
; col
++) {
1859 dstUS
[col
] = PACK_COLOR_4444_REV( src
[ACOMP
],
1866 dstRow
+= dstRowStride
;
1869 free((void *) tempImage
);
1875 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1877 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1878 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1880 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1881 ASSERT(texelBytes
== 2);
1883 if (!ctx
->_ImageTransferState
&&
1884 !srcPacking
->SwapBytes
&&
1885 dstFormat
== MESA_FORMAT_RGBA5551
&&
1886 baseInternalFormat
== GL_RGBA
&&
1887 srcFormat
== GL_RGBA
&&
1888 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1889 /* simple memcpy path */
1890 memcpy_texture(ctx
, dims
,
1891 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1892 dstRowStride
, dstSlices
,
1893 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1894 srcAddr
, srcPacking
);
1898 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1901 srcWidth
, srcHeight
, srcDepth
,
1902 srcFormat
, srcType
, srcAddr
,
1904 const GLubyte
*src
=tempImage
;
1905 GLint img
, row
, col
;
1908 for (img
= 0; img
< srcDepth
; img
++) {
1909 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1910 + dstYoffset
* dstRowStride
1911 + dstXoffset
* texelBytes
;
1912 for (row
= 0; row
< srcHeight
; row
++) {
1913 GLushort
*dstUS
= (GLushort
*) dstRow
;
1914 for (col
= 0; col
< srcWidth
; col
++) {
1915 dstUS
[col
] = PACK_COLOR_5551( src
[RCOMP
],
1921 dstRow
+= dstRowStride
;
1924 free((void *) tempImage
);
1930 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1932 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1933 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1935 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1936 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1937 ASSERT(texelBytes
== 2);
1939 if (!ctx
->_ImageTransferState
&&
1940 !srcPacking
->SwapBytes
&&
1941 dstFormat
== MESA_FORMAT_ARGB1555
&&
1942 baseInternalFormat
== GL_RGBA
&&
1943 srcFormat
== GL_BGRA
&&
1944 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1945 /* simple memcpy path */
1946 memcpy_texture(ctx
, dims
,
1947 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
1948 dstRowStride
, dstSlices
,
1949 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1950 srcAddr
, srcPacking
);
1954 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1957 srcWidth
, srcHeight
, srcDepth
,
1958 srcFormat
, srcType
, srcAddr
,
1960 const GLubyte
*src
=tempImage
;
1961 GLint img
, row
, col
;
1964 for (img
= 0; img
< srcDepth
; img
++) {
1965 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
1966 + dstYoffset
* dstRowStride
1967 + dstXoffset
* texelBytes
;
1968 for (row
= 0; row
< srcHeight
; row
++) {
1969 GLushort
*dstUS
= (GLushort
*) dstRow
;
1970 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1971 for (col
= 0; col
< srcWidth
; col
++) {
1972 dstUS
[col
] = PACK_COLOR_1555( src
[ACOMP
],
1980 for (col
= 0; col
< srcWidth
; col
++) {
1981 dstUS
[col
] = PACK_COLOR_1555_REV( src
[ACOMP
],
1988 dstRow
+= dstRowStride
;
1991 free((void *) tempImage
);
1998 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
2000 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2001 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2003 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
2004 ASSERT(texelBytes
== 4);
2006 if (!ctx
->_ImageTransferState
&&
2007 !srcPacking
->SwapBytes
&&
2008 dstFormat
== MESA_FORMAT_ARGB2101010
&&
2009 srcFormat
== GL_BGRA
&&
2010 srcType
== GL_UNSIGNED_INT_2_10_10_10_REV
&&
2011 baseInternalFormat
== GL_RGBA
) {
2012 /* simple memcpy path */
2013 memcpy_texture(ctx
, dims
,
2014 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2015 dstRowStride
, dstSlices
,
2016 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2017 srcAddr
, srcPacking
);
2021 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2024 srcWidth
, srcHeight
, srcDepth
,
2025 srcFormat
, srcType
, srcAddr
,
2027 ctx
->_ImageTransferState
);
2028 const GLfloat
*src
= tempImage
;
2029 GLint img
, row
, col
;
2032 for (img
= 0; img
< srcDepth
; img
++) {
2033 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2034 + dstYoffset
* dstRowStride
2035 + dstXoffset
* texelBytes
;
2036 if (baseInternalFormat
== GL_RGBA
) {
2037 for (row
= 0; row
< srcHeight
; row
++) {
2038 GLuint
*dstUI
= (GLuint
*) dstRow
;
2039 for (col
= 0; col
< srcWidth
; col
++) {
2042 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
2043 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2044 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2045 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2046 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
2049 dstRow
+= dstRowStride
;
2051 } else if (baseInternalFormat
== GL_RGB
) {
2052 for (row
= 0; row
< srcHeight
; row
++) {
2053 GLuint
*dstUI
= (GLuint
*) dstRow
;
2054 for (col
= 0; col
< srcWidth
; col
++) {
2057 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
2058 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
2059 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
2060 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
2063 dstRow
+= dstRowStride
;
2069 free((void *) tempImage
);
2076 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
2079 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
2081 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2082 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2084 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
2085 ASSERT(texelBytes
== 1);
2089 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2092 srcWidth
, srcHeight
, srcDepth
,
2093 srcFormat
, srcType
, srcAddr
,
2095 const GLubyte
*src
= tempImage
;
2096 GLint img
, row
, col
;
2099 for (img
= 0; img
< srcDepth
; img
++) {
2100 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2101 + dstYoffset
* dstRowStride
2102 + dstXoffset
* texelBytes
;
2103 for (row
= 0; row
< srcHeight
; row
++) {
2104 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
2105 for (col
= 0; col
< srcWidth
; col
++) {
2106 /* src[0] is luminance, src[1] is alpha */
2107 dstUS
[col
] = PACK_COLOR_44( src
[1],
2111 dstRow
+= dstRowStride
;
2114 free((void *) tempImage
);
2121 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
2124 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
2126 const GLboolean littleEndian
= _mesa_little_endian();
2127 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2128 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2130 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
2131 dstFormat
== MESA_FORMAT_AL88_REV
||
2132 dstFormat
== MESA_FORMAT_RG88
||
2133 dstFormat
== MESA_FORMAT_RG88_REV
);
2134 ASSERT(texelBytes
== 2);
2136 if (!ctx
->_ImageTransferState
&&
2137 !srcPacking
->SwapBytes
&&
2138 ((dstFormat
== MESA_FORMAT_AL88
&&
2139 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2140 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2141 (dstFormat
== MESA_FORMAT_RG88
&&
2142 baseInternalFormat
== srcFormat
)) &&
2143 srcType
== GL_UNSIGNED_BYTE
&&
2145 /* simple memcpy path */
2146 memcpy_texture(ctx
, dims
,
2147 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2148 dstRowStride
, dstSlices
,
2149 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2150 srcAddr
, srcPacking
);
2152 else if (!ctx
->_ImageTransferState
&&
2154 srcType
== GL_UNSIGNED_BYTE
&&
2155 can_swizzle(baseInternalFormat
) &&
2156 can_swizzle(srcFormat
)) {
2159 /* dstmap - how to swizzle from RGBA to dst format:
2161 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
2162 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2163 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2173 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
2174 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
2183 dstmap
[2] = ZERO
; /* ? */
2184 dstmap
[3] = ONE
; /* ? */
2186 _mesa_swizzle_ubyte_image(ctx
, dims
,
2191 dstXoffset
, dstYoffset
, dstZoffset
,
2192 dstRowStride
, dstSlices
,
2193 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2198 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2201 srcWidth
, srcHeight
, srcDepth
,
2202 srcFormat
, srcType
, srcAddr
,
2204 const GLubyte
*src
= tempImage
;
2205 GLint img
, row
, col
;
2208 for (img
= 0; img
< srcDepth
; img
++) {
2209 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2210 + dstYoffset
* dstRowStride
2211 + dstXoffset
* texelBytes
;
2212 for (row
= 0; row
< srcHeight
; row
++) {
2213 GLushort
*dstUS
= (GLushort
*) dstRow
;
2214 if (dstFormat
== MESA_FORMAT_AL88
||
2215 dstFormat
== MESA_FORMAT_RG88
) {
2216 for (col
= 0; col
< srcWidth
; col
++) {
2217 /* src[0] is luminance, src[1] is alpha */
2218 dstUS
[col
] = PACK_COLOR_88( src
[1],
2224 for (col
= 0; col
< srcWidth
; col
++) {
2225 /* src[0] is luminance, src[1] is alpha */
2226 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
2231 dstRow
+= dstRowStride
;
2234 free((void *) tempImage
);
2241 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2244 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2246 const GLboolean littleEndian
= _mesa_little_endian();
2247 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2248 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2250 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2251 dstFormat
== MESA_FORMAT_AL1616_REV
||
2252 dstFormat
== MESA_FORMAT_RG1616
||
2253 dstFormat
== MESA_FORMAT_RG1616_REV
);
2254 ASSERT(texelBytes
== 4);
2256 if (!ctx
->_ImageTransferState
&&
2257 !srcPacking
->SwapBytes
&&
2258 ((dstFormat
== MESA_FORMAT_AL1616
&&
2259 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
2260 srcFormat
== GL_LUMINANCE_ALPHA
) ||
2261 (dstFormat
== MESA_FORMAT_RG1616
&&
2262 baseInternalFormat
== srcFormat
)) &&
2263 srcType
== GL_UNSIGNED_SHORT
&&
2265 /* simple memcpy path */
2266 memcpy_texture(ctx
, dims
,
2267 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2268 dstRowStride
, dstSlices
,
2269 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2270 srcAddr
, srcPacking
);
2274 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2277 srcWidth
, srcHeight
, srcDepth
,
2278 srcFormat
, srcType
, srcAddr
,
2280 ctx
->_ImageTransferState
);
2281 const GLfloat
*src
= tempImage
;
2282 GLint img
, row
, col
;
2285 for (img
= 0; img
< srcDepth
; img
++) {
2286 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2287 + dstYoffset
* dstRowStride
2288 + dstXoffset
* texelBytes
;
2289 for (row
= 0; row
< srcHeight
; row
++) {
2290 GLuint
*dstUI
= (GLuint
*) dstRow
;
2291 if (dstFormat
== MESA_FORMAT_AL1616
||
2292 dstFormat
== MESA_FORMAT_RG1616
) {
2293 for (col
= 0; col
< srcWidth
; col
++) {
2296 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2297 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2298 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2303 for (col
= 0; col
< srcWidth
; col
++) {
2306 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2307 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2308 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2312 dstRow
+= dstRowStride
;
2315 free((void *) tempImage
);
2321 /* Texstore for R16, A16, L16, I16. */
2323 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2325 const GLboolean littleEndian
= _mesa_little_endian();
2326 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2327 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2329 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2330 dstFormat
== MESA_FORMAT_A16
||
2331 dstFormat
== MESA_FORMAT_L16
||
2332 dstFormat
== MESA_FORMAT_I16
);
2333 ASSERT(texelBytes
== 2);
2335 if (!ctx
->_ImageTransferState
&&
2336 !srcPacking
->SwapBytes
&&
2337 baseInternalFormat
== srcFormat
&&
2338 srcType
== GL_UNSIGNED_SHORT
&&
2340 /* simple memcpy path */
2341 memcpy_texture(ctx
, dims
,
2342 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2343 dstRowStride
, dstSlices
,
2344 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2345 srcAddr
, srcPacking
);
2349 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2352 srcWidth
, srcHeight
, srcDepth
,
2353 srcFormat
, srcType
, srcAddr
,
2355 ctx
->_ImageTransferState
);
2356 const GLfloat
*src
= tempImage
;
2357 GLint img
, row
, col
;
2360 for (img
= 0; img
< srcDepth
; img
++) {
2361 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2362 + dstYoffset
* dstRowStride
2363 + dstXoffset
* texelBytes
;
2364 for (row
= 0; row
< srcHeight
; row
++) {
2365 GLushort
*dstUS
= (GLushort
*) dstRow
;
2366 for (col
= 0; col
< srcWidth
; col
++) {
2369 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2373 dstRow
+= dstRowStride
;
2376 free((void *) tempImage
);
2383 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2385 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2386 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2388 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2389 ASSERT(texelBytes
== 8);
2391 if (!ctx
->_ImageTransferState
&&
2392 !srcPacking
->SwapBytes
&&
2393 baseInternalFormat
== GL_RGBA
&&
2394 srcFormat
== GL_RGBA
&&
2395 srcType
== GL_UNSIGNED_SHORT
) {
2396 /* simple memcpy path */
2397 memcpy_texture(ctx
, dims
,
2398 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
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 GLint img
, row
, col
;
2416 for (img
= 0; img
< srcDepth
; img
++) {
2417 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2418 + dstYoffset
* dstRowStride
2419 + dstXoffset
* texelBytes
;
2420 for (row
= 0; row
< srcHeight
; row
++) {
2421 GLushort
*dstUS
= (GLushort
*) dstRow
;
2422 for (col
= 0; col
< srcWidth
; col
++) {
2423 GLushort r
, g
, b
, a
;
2425 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2426 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2427 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2428 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2435 dstRow
+= dstRowStride
;
2438 free((void *) tempImage
);
2445 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2447 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2448 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2450 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2451 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2453 if (!ctx
->_ImageTransferState
&&
2454 !srcPacking
->SwapBytes
&&
2455 baseInternalFormat
== GL_RGBA
&&
2456 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2457 srcFormat
== GL_RGBA
&&
2458 srcType
== GL_SHORT
) {
2459 /* simple memcpy path */
2460 memcpy_texture(ctx
, dims
,
2461 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2462 dstRowStride
, dstSlices
,
2463 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2464 srcAddr
, srcPacking
);
2468 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2471 srcWidth
, srcHeight
, srcDepth
,
2472 srcFormat
, srcType
, srcAddr
,
2474 ctx
->_ImageTransferState
);
2475 const GLfloat
*src
= tempImage
;
2476 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2477 GLint img
, row
, col
;
2482 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2483 * 3 or 4 components/pixel here.
2485 for (img
= 0; img
< srcDepth
; img
++) {
2486 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2487 + dstYoffset
* dstRowStride
2488 + dstXoffset
* texelBytes
;
2489 for (row
= 0; row
< srcHeight
; row
++) {
2490 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2491 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2492 for (col
= 0; col
< srcWidth
; col
++) {
2494 for (c
= 0; c
< comps
; c
++) {
2496 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2497 dstRowS
[col
* comps
+ c
] = p
;
2500 dstRow
+= dstRowStride
;
2501 src
+= 4 * srcWidth
;
2503 for (col
= 0; col
< srcWidth
; col
++) {
2505 for (c
= 0; c
< comps
; c
++) {
2507 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2508 dstRowS
[col
* comps
+ c
] = p
;
2511 dstRow
+= dstRowStride
;
2512 src
+= 3 * srcWidth
;
2516 free((void *) tempImage
);
2523 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2525 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2526 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2528 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2529 ASSERT(texelBytes
== 1);
2531 if (!ctx
->_ImageTransferState
&&
2532 !srcPacking
->SwapBytes
&&
2533 baseInternalFormat
== GL_RGB
&&
2534 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2535 /* simple memcpy path */
2536 memcpy_texture(ctx
, dims
,
2537 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2538 dstRowStride
, dstSlices
,
2539 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2540 srcAddr
, srcPacking
);
2544 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2547 srcWidth
, srcHeight
, srcDepth
,
2548 srcFormat
, srcType
, srcAddr
,
2550 const GLubyte
*src
= tempImage
;
2551 GLint img
, row
, col
;
2554 for (img
= 0; img
< srcDepth
; img
++) {
2555 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2556 + dstYoffset
* dstRowStride
2557 + dstXoffset
* texelBytes
;
2558 for (row
= 0; row
< srcHeight
; row
++) {
2559 for (col
= 0; col
< srcWidth
; col
++) {
2560 dstRow
[col
] = PACK_COLOR_332( src
[RCOMP
],
2565 dstRow
+= dstRowStride
;
2568 free((void *) tempImage
);
2575 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2578 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2580 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2581 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2583 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2584 dstFormat
== MESA_FORMAT_L8
||
2585 dstFormat
== MESA_FORMAT_I8
||
2586 dstFormat
== MESA_FORMAT_R8
);
2587 ASSERT(texelBytes
== 1);
2589 if (!ctx
->_ImageTransferState
&&
2590 !srcPacking
->SwapBytes
&&
2591 baseInternalFormat
== srcFormat
&&
2592 srcType
== GL_UNSIGNED_BYTE
) {
2593 /* simple memcpy path */
2594 memcpy_texture(ctx
, dims
,
2595 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2596 dstRowStride
, dstSlices
,
2597 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2598 srcAddr
, srcPacking
);
2600 else if (!ctx
->_ImageTransferState
&&
2601 srcType
== GL_UNSIGNED_BYTE
&&
2602 can_swizzle(baseInternalFormat
) &&
2603 can_swizzle(srcFormat
)) {
2606 /* dstmap - how to swizzle from RGBA to dst format:
2608 if (dstFormat
== MESA_FORMAT_A8
) {
2614 dstmap
[1] = ZERO
; /* ? */
2615 dstmap
[2] = ZERO
; /* ? */
2616 dstmap
[3] = ONE
; /* ? */
2618 _mesa_swizzle_ubyte_image(ctx
, dims
,
2623 dstXoffset
, dstYoffset
, dstZoffset
,
2624 dstRowStride
, dstSlices
,
2625 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2630 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2633 srcWidth
, srcHeight
, srcDepth
,
2634 srcFormat
, srcType
, srcAddr
,
2636 const GLubyte
*src
= tempImage
;
2637 GLint img
, row
, col
;
2640 for (img
= 0; img
< srcDepth
; img
++) {
2641 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2642 + dstYoffset
* dstRowStride
2643 + dstXoffset
* texelBytes
;
2644 for (row
= 0; row
< srcHeight
; row
++) {
2645 for (col
= 0; col
< srcWidth
; col
++) {
2646 dstRow
[col
] = src
[col
];
2648 dstRow
+= dstRowStride
;
2652 free((void *) tempImage
);
2660 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2663 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2665 const GLboolean littleEndian
= _mesa_little_endian();
2666 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2668 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2670 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2671 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2672 ASSERT(texelBytes
== 2);
2673 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2674 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2675 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2676 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2677 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2679 /* always just memcpy since no pixel transfer ops apply */
2680 memcpy_texture(ctx
, dims
,
2681 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2682 dstRowStride
, dstSlices
,
2683 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2684 srcAddr
, srcPacking
);
2686 /* Check if we need byte swapping */
2687 /* XXX the logic here _might_ be wrong */
2688 if (srcPacking
->SwapBytes
^
2689 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2690 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2693 for (img
= 0; img
< srcDepth
; img
++) {
2694 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2695 + dstYoffset
* dstRowStride
2696 + dstXoffset
* texelBytes
;
2697 for (row
= 0; row
< srcHeight
; row
++) {
2698 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2699 dstRow
+= dstRowStride
;
2707 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2709 const GLboolean littleEndian
= _mesa_little_endian();
2710 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2712 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2713 ASSERT(texelBytes
== 2);
2714 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2715 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2716 (srcFormat
== GL_DUDV_ATI
));
2717 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2719 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2721 /* simple memcpy path */
2722 memcpy_texture(ctx
, dims
,
2723 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2724 dstRowStride
, dstSlices
,
2725 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2726 srcAddr
, srcPacking
);
2728 else if (srcType
== GL_BYTE
) {
2731 /* dstmap - how to swizzle from RGBA to dst format:
2741 dstmap
[2] = ZERO
; /* ? */
2742 dstmap
[3] = ONE
; /* ? */
2744 _mesa_swizzle_ubyte_image(ctx
, dims
,
2745 GL_LUMINANCE_ALPHA
, /* hack */
2746 GL_UNSIGNED_BYTE
, /* hack */
2747 GL_LUMINANCE_ALPHA
, /* hack */
2749 dstXoffset
, dstYoffset
, dstZoffset
,
2750 dstRowStride
, dstSlices
,
2751 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2755 /* general path - note this is defined for 2d textures only */
2756 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2757 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2758 srcFormat
, srcType
);
2759 GLbyte
*tempImage
, *dst
, *src
;
2762 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2763 * components
* sizeof(GLbyte
));
2767 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2768 srcWidth
, srcHeight
,
2773 for (row
= 0; row
< srcHeight
; row
++) {
2774 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2775 dst
, srcFormat
, srcType
, src
,
2777 dst
+= srcWidth
* components
;
2782 dst
= (GLbyte
*) dstSlices
[0]
2783 + dstYoffset
* dstRowStride
2784 + dstXoffset
* texelBytes
;
2785 for (row
= 0; row
< srcHeight
; row
++) {
2786 memcpy(dst
, src
, srcWidth
* texelBytes
);
2787 dst
+= dstRowStride
;
2788 src
+= srcWidth
* texelBytes
;
2790 free((void *) tempImage
);
2797 * Store a texture in a signed normalized 8-bit format.
2800 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2802 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2803 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2805 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2806 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2807 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2808 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2809 ASSERT(texelBytes
== 1);
2811 if (!ctx
->_ImageTransferState
&&
2812 !srcPacking
->SwapBytes
&&
2813 baseInternalFormat
== srcFormat
&&
2814 srcType
== GL_BYTE
) {
2815 /* simple memcpy path */
2816 memcpy_texture(ctx
, dims
,
2817 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2818 dstRowStride
, dstSlices
,
2819 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2820 srcAddr
, srcPacking
);
2824 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2827 srcWidth
, srcHeight
, srcDepth
,
2828 srcFormat
, srcType
, srcAddr
,
2830 ctx
->_ImageTransferState
);
2831 const GLfloat
*src
= tempImage
;
2832 GLint img
, row
, col
;
2835 for (img
= 0; img
< srcDepth
; img
++) {
2836 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
2837 + dstYoffset
* dstRowStride
2838 + dstXoffset
* texelBytes
;
2839 for (row
= 0; row
< srcHeight
; row
++) {
2840 for (col
= 0; col
< srcWidth
; col
++) {
2841 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2843 dstRow
+= dstRowStride
;
2847 free((void *) tempImage
);
2854 * Store a texture in a signed normalized two-channel 16-bit format.
2857 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2859 const GLboolean littleEndian
= _mesa_little_endian();
2860 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2861 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2863 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2864 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2865 ASSERT(texelBytes
== 2);
2867 if (!ctx
->_ImageTransferState
&&
2868 !srcPacking
->SwapBytes
&&
2869 baseInternalFormat
== srcFormat
&&
2870 srcType
== GL_BYTE
&&
2872 /* simple memcpy path */
2873 memcpy_texture(ctx
, dims
,
2874 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2875 dstRowStride
, dstSlices
,
2876 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2877 srcAddr
, srcPacking
);
2881 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2884 srcWidth
, srcHeight
, srcDepth
,
2885 srcFormat
, srcType
, srcAddr
,
2887 ctx
->_ImageTransferState
);
2888 const GLfloat
*src
= tempImage
;
2889 GLint img
, row
, col
;
2892 for (img
= 0; img
< srcDepth
; img
++) {
2893 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
2894 + dstYoffset
* dstRowStride
2895 + dstXoffset
* texelBytes
;
2896 for (row
= 0; row
< srcHeight
; row
++) {
2897 GLbyte
*dst
= dstRow
;
2898 for (col
= 0; col
< srcWidth
; col
++) {
2899 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2900 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2904 dstRow
+= dstRowStride
;
2907 free((void *) tempImage
);
2912 /* Texstore for signed R16, A16, L16, I16. */
2914 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2916 const GLboolean littleEndian
= _mesa_little_endian();
2917 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2918 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2920 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2921 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2922 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2923 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2924 ASSERT(texelBytes
== 2);
2926 if (!ctx
->_ImageTransferState
&&
2927 !srcPacking
->SwapBytes
&&
2928 baseInternalFormat
== srcFormat
&&
2929 srcType
== GL_SHORT
&&
2931 /* simple memcpy path */
2932 memcpy_texture(ctx
, dims
,
2933 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2934 dstRowStride
, dstSlices
,
2935 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2936 srcAddr
, srcPacking
);
2940 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2943 srcWidth
, srcHeight
, srcDepth
,
2944 srcFormat
, srcType
, srcAddr
,
2946 ctx
->_ImageTransferState
);
2947 const GLfloat
*src
= tempImage
;
2948 GLint img
, row
, col
;
2951 for (img
= 0; img
< srcDepth
; img
++) {
2952 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
2953 + dstYoffset
* dstRowStride
2954 + dstXoffset
* texelBytes
;
2955 for (row
= 0; row
< srcHeight
; row
++) {
2956 GLshort
*dstUS
= (GLshort
*) dstRow
;
2957 for (col
= 0; col
< srcWidth
; col
++) {
2960 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2964 dstRow
+= dstRowStride
;
2967 free((void *) tempImage
);
2973 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2976 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2978 const GLboolean littleEndian
= _mesa_little_endian();
2979 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2980 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2982 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2983 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2984 ASSERT(texelBytes
== 4);
2986 if (!ctx
->_ImageTransferState
&&
2987 !srcPacking
->SwapBytes
&&
2988 baseInternalFormat
== srcFormat
&&
2989 srcType
== GL_SHORT
&&
2991 /* simple memcpy path */
2992 memcpy_texture(ctx
, dims
,
2993 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
2994 dstRowStride
, dstSlices
,
2995 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2996 srcAddr
, srcPacking
);
3000 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3003 srcWidth
, srcHeight
, srcDepth
,
3004 srcFormat
, srcType
, srcAddr
,
3006 ctx
->_ImageTransferState
);
3007 const GLfloat
*src
= tempImage
;
3008 GLint img
, row
, col
;
3011 for (img
= 0; img
< srcDepth
; img
++) {
3012 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3013 + dstYoffset
* dstRowStride
3014 + dstXoffset
* texelBytes
;
3015 for (row
= 0; row
< srcHeight
; row
++) {
3016 GLshort
*dst
= (GLshort
*) dstRow
;
3017 for (col
= 0; col
< srcWidth
; col
++) {
3020 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
3021 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
3027 dstRow
+= dstRowStride
;
3030 free((void *) tempImage
);
3036 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
3039 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
3041 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3042 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3044 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
3045 ASSERT(texelBytes
== 4);
3049 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3052 srcWidth
, srcHeight
, srcDepth
,
3053 srcFormat
, srcType
, srcAddr
,
3055 ctx
->_ImageTransferState
);
3056 const GLfloat
*srcRow
= tempImage
;
3057 GLint img
, row
, col
;
3060 for (img
= 0; img
< srcDepth
; img
++) {
3061 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
3062 + dstYoffset
* dstRowStride
3063 + dstXoffset
* texelBytes
;
3064 for (row
= 0; row
< srcHeight
; row
++) {
3065 GLbyte
*dst
= dstRow
;
3066 for (col
= 0; col
< srcWidth
; col
++) {
3067 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3068 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3069 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3074 dstRow
+= dstRowStride
;
3077 free((void *) tempImage
);
3085 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
3086 * MESA_FORMAT_SIGNED_RGBA8888_REV
3089 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
3091 const GLboolean littleEndian
= _mesa_little_endian();
3092 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3093 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3095 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
3096 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
3097 ASSERT(texelBytes
== 4);
3099 if (!ctx
->_ImageTransferState
&&
3100 !srcPacking
->SwapBytes
&&
3101 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
3102 baseInternalFormat
== GL_RGBA
&&
3103 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
3104 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
3105 /* simple memcpy path */
3106 memcpy_texture(ctx
, dims
,
3107 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3108 dstRowStride
, dstSlices
,
3109 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3110 srcAddr
, srcPacking
);
3112 else if (!ctx
->_ImageTransferState
&&
3113 !srcPacking
->SwapBytes
&&
3114 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
3115 baseInternalFormat
== GL_RGBA
&&
3116 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
3117 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
3118 /* simple memcpy path */
3119 memcpy_texture(ctx
, dims
,
3120 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3121 dstRowStride
, dstSlices
,
3122 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3123 srcAddr
, srcPacking
);
3127 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3130 srcWidth
, srcHeight
, srcDepth
,
3131 srcFormat
, srcType
, srcAddr
,
3133 ctx
->_ImageTransferState
);
3134 const GLfloat
*srcRow
= tempImage
;
3135 GLint img
, row
, col
;
3138 for (img
= 0; img
< srcDepth
; img
++) {
3139 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[dstZoffset
+ img
]
3140 + dstYoffset
* dstRowStride
3141 + dstXoffset
* texelBytes
;
3142 for (row
= 0; row
< srcHeight
; row
++) {
3143 GLbyte
*dst
= dstRow
;
3144 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
3145 for (col
= 0; col
< srcWidth
; col
++) {
3146 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3147 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3148 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3149 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3155 for (col
= 0; col
< srcWidth
; col
++) {
3156 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
3157 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
3158 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
3159 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
3164 dstRow
+= dstRowStride
;
3167 free((void *) tempImage
);
3174 * Store a combined depth/stencil texture image.
3177 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
3179 const GLuint depthScale
= 0xffffff;
3180 const GLint srcRowStride
3181 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3184 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
3185 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3186 srcFormat
== GL_DEPTH_COMPONENT
||
3187 srcFormat
== GL_STENCIL_INDEX
);
3188 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3190 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
3191 ctx
->Pixel
.DepthBias
== 0.0f
&&
3192 !srcPacking
->SwapBytes
) {
3194 memcpy_texture(ctx
, dims
,
3195 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3196 dstRowStride
, dstSlices
,
3197 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3198 srcAddr
, srcPacking
);
3200 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3201 srcFormat
== GL_STENCIL_INDEX
) {
3202 /* In case we only upload depth we need to preserve the stencil */
3203 for (img
= 0; img
< srcDepth
; img
++) {
3204 GLuint
*dstRow
= (GLuint
*) (dstSlices
[dstZoffset
+ img
]
3205 + dstYoffset
* dstRowStride
3208 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3209 srcWidth
, srcHeight
,
3212 for (row
= 0; row
< srcHeight
; row
++) {
3213 GLuint depth
[MAX_WIDTH
];
3214 GLubyte stencil
[MAX_WIDTH
];
3216 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3218 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3219 keepstencil
= GL_TRUE
;
3221 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3222 keepdepth
= GL_TRUE
;
3225 if (keepdepth
== GL_FALSE
)
3226 /* the 24 depth bits will be in the low position: */
3227 _mesa_unpack_depth_span(ctx
, srcWidth
,
3228 GL_UNSIGNED_INT
, /* dst type */
3229 keepstencil
? depth
: dstRow
, /* dst addr */
3231 srcType
, src
, srcPacking
);
3233 if (keepstencil
== GL_FALSE
)
3234 /* get the 8-bit stencil values */
3235 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3236 GL_UNSIGNED_BYTE
, /* dst type */
3237 stencil
, /* dst addr */
3238 srcType
, src
, srcPacking
,
3239 ctx
->_ImageTransferState
);
3241 for (i
= 0; i
< srcWidth
; i
++) {
3243 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
3245 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
3248 src
+= srcRowStride
;
3249 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3258 * Store a combined depth/stencil texture image.
3261 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
3263 const GLuint depthScale
= 0xffffff;
3264 const GLint srcRowStride
3265 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3268 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3269 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3270 srcFormat
== GL_DEPTH_COMPONENT
||
3271 srcFormat
== GL_STENCIL_INDEX
);
3272 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3273 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3275 for (img
= 0; img
< srcDepth
; img
++) {
3276 GLuint
*dstRow
= (GLuint
*) (dstSlices
[dstZoffset
+ img
]
3277 + dstYoffset
* dstRowStride
3280 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3281 srcWidth
, srcHeight
,
3284 for (row
= 0; row
< srcHeight
; row
++) {
3285 GLuint depth
[MAX_WIDTH
];
3286 GLubyte stencil
[MAX_WIDTH
];
3288 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3290 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3291 keepstencil
= GL_TRUE
;
3293 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3294 keepdepth
= GL_TRUE
;
3297 if (keepdepth
== GL_FALSE
)
3298 /* the 24 depth bits will be in the low position: */
3299 _mesa_unpack_depth_span(ctx
, srcWidth
,
3300 GL_UNSIGNED_INT
, /* dst type */
3301 keepstencil
? depth
: dstRow
, /* dst addr */
3303 srcType
, src
, srcPacking
);
3305 if (keepstencil
== GL_FALSE
)
3306 /* get the 8-bit stencil values */
3307 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3308 GL_UNSIGNED_BYTE
, /* dst type */
3309 stencil
, /* dst addr */
3310 srcType
, src
, srcPacking
,
3311 ctx
->_ImageTransferState
);
3313 /* merge stencil values into depth values */
3314 for (i
= 0; i
< srcWidth
; i
++) {
3316 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3318 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3321 src
+= srcRowStride
;
3322 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3330 * Store simple 8-bit/value stencil texture data.
3333 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3335 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3336 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3338 if (!ctx
->_ImageTransferState
&&
3339 !srcPacking
->SwapBytes
&&
3340 baseInternalFormat
== srcFormat
&&
3341 srcType
== GL_UNSIGNED_BYTE
) {
3342 /* simple memcpy path */
3343 memcpy_texture(ctx
, dims
,
3344 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3345 dstRowStride
, dstSlices
,
3346 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3347 srcAddr
, srcPacking
);
3350 const GLint srcRowStride
3351 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
3354 for (img
= 0; img
< srcDepth
; img
++) {
3355 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3356 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3359 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3360 srcWidth
, srcHeight
,
3363 for (row
= 0; row
< srcHeight
; row
++) {
3364 GLubyte stencil
[MAX_WIDTH
];
3367 /* get the 8-bit stencil values */
3368 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3369 GL_UNSIGNED_BYTE
, /* dst type */
3370 stencil
, /* dst addr */
3371 srcType
, src
, srcPacking
,
3372 ctx
->_ImageTransferState
);
3373 /* merge stencil values into depth values */
3374 for (i
= 0; i
< srcWidth
; i
++)
3375 dstRow
[i
] = stencil
[i
];
3377 src
+= srcRowStride
;
3378 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3389 * Store an image in any of the formats:
3390 * _mesa_texformat_rgba_float32
3391 * _mesa_texformat_rgb_float32
3392 * _mesa_texformat_alpha_float32
3393 * _mesa_texformat_luminance_float32
3394 * _mesa_texformat_luminance_alpha_float32
3395 * _mesa_texformat_intensity_float32
3398 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3400 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3401 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3402 const GLint components
= _mesa_components_in_format(baseFormat
);
3404 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3405 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3406 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3407 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3408 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3409 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3410 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3411 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3412 ASSERT(baseInternalFormat
== GL_RGBA
||
3413 baseInternalFormat
== GL_RGB
||
3414 baseInternalFormat
== GL_ALPHA
||
3415 baseInternalFormat
== GL_LUMINANCE
||
3416 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3417 baseInternalFormat
== GL_INTENSITY
||
3418 baseInternalFormat
== GL_RED
||
3419 baseInternalFormat
== GL_RG
);
3420 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3422 if (!ctx
->_ImageTransferState
&&
3423 !srcPacking
->SwapBytes
&&
3424 baseInternalFormat
== srcFormat
&&
3425 baseInternalFormat
== baseFormat
&&
3426 srcType
== GL_FLOAT
) {
3427 /* simple memcpy path */
3428 memcpy_texture(ctx
, dims
,
3429 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3430 dstRowStride
, dstSlices
,
3431 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3432 srcAddr
, srcPacking
);
3436 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3439 srcWidth
, srcHeight
, srcDepth
,
3440 srcFormat
, srcType
, srcAddr
,
3442 ctx
->_ImageTransferState
);
3443 const GLfloat
*srcRow
= tempImage
;
3448 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3449 for (img
= 0; img
< srcDepth
; img
++) {
3450 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3451 + dstYoffset
* dstRowStride
3452 + dstXoffset
* texelBytes
;
3453 for (row
= 0; row
< srcHeight
; row
++) {
3454 memcpy(dstRow
, srcRow
, bytesPerRow
);
3455 dstRow
+= dstRowStride
;
3456 srcRow
+= srcWidth
* components
;
3460 free((void *) tempImage
);
3468 * As above, but store 16-bit floats.
3471 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3473 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3474 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3475 const GLint components
= _mesa_components_in_format(baseFormat
);
3477 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3478 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3479 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3480 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3481 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3482 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3483 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3484 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3485 ASSERT(baseInternalFormat
== GL_RGBA
||
3486 baseInternalFormat
== GL_RGB
||
3487 baseInternalFormat
== GL_ALPHA
||
3488 baseInternalFormat
== GL_LUMINANCE
||
3489 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3490 baseInternalFormat
== GL_INTENSITY
||
3491 baseInternalFormat
== GL_RED
||
3492 baseInternalFormat
== GL_RG
);
3493 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3495 if (!ctx
->_ImageTransferState
&&
3496 !srcPacking
->SwapBytes
&&
3497 baseInternalFormat
== srcFormat
&&
3498 baseInternalFormat
== baseFormat
&&
3499 srcType
== GL_HALF_FLOAT_ARB
) {
3500 /* simple memcpy path */
3501 memcpy_texture(ctx
, dims
,
3502 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3503 dstRowStride
, dstSlices
,
3504 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3505 srcAddr
, srcPacking
);
3509 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3512 srcWidth
, srcHeight
, srcDepth
,
3513 srcFormat
, srcType
, srcAddr
,
3515 ctx
->_ImageTransferState
);
3516 const GLfloat
*src
= tempImage
;
3520 for (img
= 0; img
< srcDepth
; img
++) {
3521 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3522 + dstYoffset
* dstRowStride
3523 + dstXoffset
* texelBytes
;
3524 for (row
= 0; row
< srcHeight
; row
++) {
3525 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3527 for (i
= 0; i
< srcWidth
* components
; i
++) {
3528 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3530 dstRow
+= dstRowStride
;
3531 src
+= srcWidth
* components
;
3535 free((void *) tempImage
);
3541 /* non-normalized, signed int8 */
3543 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3545 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3546 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3547 const GLint components
= _mesa_components_in_format(baseFormat
);
3549 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3550 dstFormat
== MESA_FORMAT_RG_INT8
||
3551 dstFormat
== MESA_FORMAT_RGB_INT8
||
3552 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3553 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3554 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3555 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3556 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3557 ASSERT(baseInternalFormat
== GL_RGBA
||
3558 baseInternalFormat
== GL_RGB
||
3559 baseInternalFormat
== GL_ALPHA
||
3560 baseInternalFormat
== GL_LUMINANCE
||
3561 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3562 baseInternalFormat
== GL_INTENSITY
);
3563 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3565 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3566 * to integer formats.
3568 if (!srcPacking
->SwapBytes
&&
3569 baseInternalFormat
== srcFormat
&&
3570 srcType
== GL_BYTE
) {
3571 /* simple memcpy path */
3572 memcpy_texture(ctx
, dims
,
3573 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3574 dstRowStride
, dstSlices
,
3575 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3576 srcAddr
, srcPacking
);
3580 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3583 srcWidth
, srcHeight
, srcDepth
,
3584 srcFormat
, srcType
, srcAddr
,
3586 const GLfloat
*src
= tempImage
;
3590 for (img
= 0; img
< srcDepth
; img
++) {
3591 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3592 + dstYoffset
* dstRowStride
3593 + dstXoffset
* texelBytes
;
3594 for (row
= 0; row
< srcHeight
; row
++) {
3595 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3597 for (i
= 0; i
< srcWidth
* components
; i
++) {
3598 dstTexel
[i
] = (GLbyte
) src
[i
];
3600 dstRow
+= dstRowStride
;
3601 src
+= srcWidth
* components
;
3605 free((void *) tempImage
);
3611 /* non-normalized, signed int16 */
3613 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3615 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3616 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3617 const GLint components
= _mesa_components_in_format(baseFormat
);
3619 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3620 dstFormat
== MESA_FORMAT_RG_INT16
||
3621 dstFormat
== MESA_FORMAT_RGB_INT16
||
3622 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3623 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3624 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3625 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3626 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3627 ASSERT(baseInternalFormat
== GL_RGBA
||
3628 baseInternalFormat
== GL_RGB
||
3629 baseInternalFormat
== GL_ALPHA
||
3630 baseInternalFormat
== GL_LUMINANCE
||
3631 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3632 baseInternalFormat
== GL_INTENSITY
);
3633 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3635 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3636 * to integer formats.
3638 if (!srcPacking
->SwapBytes
&&
3639 baseInternalFormat
== srcFormat
&&
3640 srcType
== GL_SHORT
) {
3641 /* simple memcpy path */
3642 memcpy_texture(ctx
, dims
,
3643 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3644 dstRowStride
, dstSlices
,
3645 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3646 srcAddr
, srcPacking
);
3650 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3653 srcWidth
, srcHeight
, srcDepth
,
3654 srcFormat
, srcType
, srcAddr
,
3656 const GLfloat
*src
= tempImage
;
3660 for (img
= 0; img
< srcDepth
; img
++) {
3661 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3662 + dstYoffset
* dstRowStride
3663 + dstXoffset
* texelBytes
;
3664 for (row
= 0; row
< srcHeight
; row
++) {
3665 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3667 for (i
= 0; i
< srcWidth
* components
; i
++) {
3668 dstTexel
[i
] = (GLint
) src
[i
];
3670 dstRow
+= dstRowStride
;
3671 src
+= srcWidth
* components
;
3675 free((void *) tempImage
);
3681 /* non-normalized, signed int32 */
3683 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3685 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3686 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3687 const GLint components
= _mesa_components_in_format(baseFormat
);
3689 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3690 dstFormat
== MESA_FORMAT_RG_INT32
||
3691 dstFormat
== MESA_FORMAT_RGB_INT32
||
3692 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3693 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3694 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3695 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3696 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3697 ASSERT(baseInternalFormat
== GL_RGBA
||
3698 baseInternalFormat
== GL_RGB
||
3699 baseInternalFormat
== GL_ALPHA
||
3700 baseInternalFormat
== GL_LUMINANCE
||
3701 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3702 baseInternalFormat
== GL_INTENSITY
);
3703 ASSERT(texelBytes
== components
* sizeof(GLint
));
3705 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3706 * to integer formats.
3708 if (!srcPacking
->SwapBytes
&&
3709 baseInternalFormat
== srcFormat
&&
3710 srcType
== GL_INT
) {
3711 /* simple memcpy path */
3712 memcpy_texture(ctx
, dims
,
3713 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3714 dstRowStride
, dstSlices
,
3715 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3716 srcAddr
, srcPacking
);
3720 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3723 srcWidth
, srcHeight
, srcDepth
,
3724 srcFormat
, srcType
, srcAddr
,
3726 const GLfloat
*src
= tempImage
;
3730 for (img
= 0; img
< srcDepth
; img
++) {
3731 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3732 + dstYoffset
* dstRowStride
3733 + dstXoffset
* texelBytes
;
3734 for (row
= 0; row
< srcHeight
; row
++) {
3735 GLint
*dstTexel
= (GLint
*) dstRow
;
3737 for (i
= 0; i
< srcWidth
* components
; i
++) {
3738 dstTexel
[i
] = (GLint
) src
[i
];
3740 dstRow
+= dstRowStride
;
3741 src
+= srcWidth
* components
;
3745 free((void *) tempImage
);
3751 /* non-normalized, unsigned int8 */
3753 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3755 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3756 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3757 const GLint components
= _mesa_components_in_format(baseFormat
);
3759 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3760 dstFormat
== MESA_FORMAT_RG_UINT8
||
3761 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3762 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3763 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3764 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3765 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3766 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3767 ASSERT(baseInternalFormat
== GL_RGBA
||
3768 baseInternalFormat
== GL_RGB
||
3769 baseInternalFormat
== GL_ALPHA
||
3770 baseInternalFormat
== GL_LUMINANCE
||
3771 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3772 baseInternalFormat
== GL_INTENSITY
);
3773 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3775 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3776 * to integer formats.
3778 if (!srcPacking
->SwapBytes
&&
3779 baseInternalFormat
== srcFormat
&&
3780 srcType
== GL_UNSIGNED_BYTE
) {
3781 /* simple memcpy path */
3782 memcpy_texture(ctx
, dims
,
3783 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3784 dstRowStride
, dstSlices
,
3785 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3786 srcAddr
, srcPacking
);
3790 const GLuint
*tempImage
=
3791 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3792 srcWidth
, srcHeight
, srcDepth
,
3793 srcFormat
, srcType
, srcAddr
, srcPacking
);
3794 const GLuint
*src
= tempImage
;
3798 for (img
= 0; img
< srcDepth
; img
++) {
3799 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3800 + dstYoffset
* dstRowStride
3801 + dstXoffset
* texelBytes
;
3802 for (row
= 0; row
< srcHeight
; row
++) {
3803 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3805 for (i
= 0; i
< srcWidth
* components
; i
++) {
3806 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3808 dstRow
+= dstRowStride
;
3809 src
+= srcWidth
* components
;
3813 free((void *) tempImage
);
3819 /* non-normalized, unsigned int16 */
3821 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3823 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3824 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3825 const GLint components
= _mesa_components_in_format(baseFormat
);
3827 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3828 dstFormat
== MESA_FORMAT_RG_UINT16
||
3829 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3830 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3831 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3832 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3833 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3834 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3835 ASSERT(baseInternalFormat
== GL_RGBA
||
3836 baseInternalFormat
== GL_RGB
||
3837 baseInternalFormat
== GL_ALPHA
||
3838 baseInternalFormat
== GL_LUMINANCE
||
3839 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3840 baseInternalFormat
== GL_INTENSITY
);
3841 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3843 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3844 * to integer formats.
3846 if (!srcPacking
->SwapBytes
&&
3847 baseInternalFormat
== srcFormat
&&
3848 srcType
== GL_UNSIGNED_SHORT
) {
3849 /* simple memcpy path */
3850 memcpy_texture(ctx
, dims
,
3851 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3852 dstRowStride
, dstSlices
,
3853 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3854 srcAddr
, srcPacking
);
3858 const GLuint
*tempImage
=
3859 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3860 srcWidth
, srcHeight
, srcDepth
,
3861 srcFormat
, srcType
, srcAddr
, srcPacking
);
3862 const GLuint
*src
= tempImage
;
3866 for (img
= 0; img
< srcDepth
; img
++) {
3867 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3868 + dstYoffset
* dstRowStride
3869 + dstXoffset
* texelBytes
;
3870 for (row
= 0; row
< srcHeight
; row
++) {
3871 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3873 for (i
= 0; i
< srcWidth
* components
; i
++) {
3874 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3876 dstRow
+= dstRowStride
;
3877 src
+= srcWidth
* components
;
3881 free((void *) tempImage
);
3887 /* non-normalized, unsigned int32 */
3889 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3891 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3892 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3893 const GLint components
= _mesa_components_in_format(baseFormat
);
3895 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3896 dstFormat
== MESA_FORMAT_RG_UINT32
||
3897 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3898 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3899 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3900 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3901 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3902 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3903 ASSERT(baseInternalFormat
== GL_RGBA
||
3904 baseInternalFormat
== GL_RGB
||
3905 baseInternalFormat
== GL_ALPHA
||
3906 baseInternalFormat
== GL_LUMINANCE
||
3907 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3908 baseInternalFormat
== GL_INTENSITY
);
3909 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3911 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3912 * to integer formats.
3914 if (!srcPacking
->SwapBytes
&&
3915 baseInternalFormat
== srcFormat
&&
3916 srcType
== GL_UNSIGNED_INT
) {
3917 /* simple memcpy path */
3918 memcpy_texture(ctx
, dims
,
3919 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
3920 dstRowStride
, dstSlices
,
3921 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3922 srcAddr
, srcPacking
);
3926 const GLuint
*tempImage
=
3927 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3928 srcWidth
, srcHeight
, srcDepth
,
3929 srcFormat
, srcType
, srcAddr
, srcPacking
);
3930 const GLuint
*src
= tempImage
;
3934 for (img
= 0; img
< srcDepth
; img
++) {
3935 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
3936 + dstYoffset
* dstRowStride
3937 + dstXoffset
* texelBytes
;
3938 for (row
= 0; row
< srcHeight
; row
++) {
3939 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3941 for (i
= 0; i
< srcWidth
* components
; i
++) {
3942 dstTexel
[i
] = src
[i
];
3944 dstRow
+= dstRowStride
;
3945 src
+= srcWidth
* components
;
3949 free((void *) tempImage
);
3957 #if FEATURE_EXT_texture_sRGB
3959 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3961 gl_format newDstFormat
;
3964 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3966 /* reuse normal rgb texstore code */
3967 newDstFormat
= MESA_FORMAT_RGB888
;
3969 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3971 dstXoffset
, dstYoffset
, dstZoffset
,
3972 dstRowStride
, dstSlices
,
3973 srcWidth
, srcHeight
, srcDepth
,
3975 srcAddr
, srcPacking
);
3981 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3983 gl_format newDstFormat
;
3986 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3988 /* reuse normal rgba texstore code */
3989 newDstFormat
= MESA_FORMAT_RGBA8888
;
3990 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3992 dstXoffset
, dstYoffset
, dstZoffset
,
3993 dstRowStride
, dstSlices
,
3994 srcWidth
, srcHeight
, srcDepth
,
3996 srcAddr
, srcPacking
);
4002 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
4004 gl_format newDstFormat
;
4007 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
4009 /* reuse normal rgba texstore code */
4010 newDstFormat
= MESA_FORMAT_ARGB8888
;
4012 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
4014 dstXoffset
, dstYoffset
, dstZoffset
,
4015 dstRowStride
, dstSlices
,
4016 srcWidth
, srcHeight
, srcDepth
,
4018 srcAddr
, srcPacking
);
4024 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
4026 gl_format newDstFormat
;
4029 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
4031 newDstFormat
= MESA_FORMAT_L8
;
4033 /* _mesa_textore_a8 handles luminance8 too */
4034 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
4036 dstXoffset
, dstYoffset
, dstZoffset
,
4037 dstRowStride
, dstSlices
,
4038 srcWidth
, srcHeight
, srcDepth
,
4040 srcAddr
, srcPacking
);
4046 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
4048 gl_format newDstFormat
;
4051 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
4053 /* reuse normal luminance/alpha texstore code */
4054 newDstFormat
= MESA_FORMAT_AL88
;
4056 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
4058 dstXoffset
, dstYoffset
, dstZoffset
,
4059 dstRowStride
, dstSlices
,
4060 srcWidth
, srcHeight
, srcDepth
,
4062 srcAddr
, srcPacking
);
4068 /* these are used only in texstore_funcs[] below */
4069 #define _mesa_texstore_srgb8 NULL
4070 #define _mesa_texstore_srgba8 NULL
4071 #define _mesa_texstore_sargb8 NULL
4072 #define _mesa_texstore_sl8 NULL
4073 #define _mesa_texstore_sla8 NULL
4075 #endif /* FEATURE_EXT_texture_sRGB */
4078 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
4080 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4082 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
4083 ASSERT(baseInternalFormat
== GL_RGB
);
4085 if (!ctx
->_ImageTransferState
&&
4086 !srcPacking
->SwapBytes
&&
4087 srcFormat
== GL_RGB
&&
4088 srcType
== GL_UNSIGNED_INT_5_9_9_9_REV
) {
4089 /* simple memcpy path */
4090 memcpy_texture(ctx
, dims
,
4091 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4092 dstRowStride
, dstSlices
,
4093 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4094 srcAddr
, srcPacking
);
4098 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4101 srcWidth
, srcHeight
, srcDepth
,
4102 srcFormat
, srcType
, srcAddr
,
4104 ctx
->_ImageTransferState
);
4105 const GLfloat
*srcRow
= tempImage
;
4106 GLint img
, row
, col
;
4109 for (img
= 0; img
< srcDepth
; img
++) {
4110 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
4111 + dstYoffset
* dstRowStride
4113 for (row
= 0; row
< srcHeight
; row
++) {
4114 GLuint
*dstUI
= (GLuint
*)dstRow
;
4115 for (col
= 0; col
< srcWidth
; col
++) {
4116 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
4118 dstRow
+= dstRowStride
;
4119 srcRow
+= srcWidth
* 3;
4123 free((void *) tempImage
);
4129 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
4131 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
4133 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
4134 ASSERT(baseInternalFormat
== GL_RGB
);
4136 if (!ctx
->_ImageTransferState
&&
4137 !srcPacking
->SwapBytes
&&
4138 srcFormat
== GL_RGB
&&
4139 srcType
== GL_UNSIGNED_INT_10F_11F_11F_REV
) {
4140 /* simple memcpy path */
4141 memcpy_texture(ctx
, dims
,
4142 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4143 dstRowStride
, dstSlices
,
4144 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4145 srcAddr
, srcPacking
);
4149 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
4152 srcWidth
, srcHeight
, srcDepth
,
4153 srcFormat
, srcType
, srcAddr
,
4155 ctx
->_ImageTransferState
);
4156 const GLfloat
*srcRow
= tempImage
;
4157 GLint img
, row
, col
;
4160 for (img
= 0; img
< srcDepth
; img
++) {
4161 GLubyte
*dstRow
= dstSlices
[dstZoffset
+ img
]
4162 + dstYoffset
* dstRowStride
4164 for (row
= 0; row
< srcHeight
; row
++) {
4165 GLuint
*dstUI
= (GLuint
*)dstRow
;
4166 for (col
= 0; col
< srcWidth
; col
++) {
4167 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
4169 dstRow
+= dstRowStride
;
4170 srcRow
+= srcWidth
* 3;
4174 free((void *) tempImage
);
4181 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
4183 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
4184 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
4185 srcFormat
== GL_DEPTH_COMPONENT
||
4186 srcFormat
== GL_STENCIL_INDEX
);
4187 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
4188 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
4190 if (srcFormat
== GL_DEPTH_STENCIL
&&
4191 ctx
->Pixel
.DepthScale
== 1.0f
&&
4192 ctx
->Pixel
.DepthBias
== 0.0f
&&
4193 !srcPacking
->SwapBytes
) {
4195 memcpy_texture(ctx
, dims
,
4196 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4197 dstRowStride
, dstSlices
,
4198 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4199 srcAddr
, srcPacking
);
4201 else if (srcFormat
== GL_DEPTH_COMPONENT
||
4202 srcFormat
== GL_STENCIL_INDEX
) {
4204 const GLint srcRowStride
4205 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
4208 /* In case we only upload depth we need to preserve the stencil */
4209 for (img
= 0; img
< srcDepth
; img
++) {
4210 uint64_t *dstRow
= (uint64_t *) (dstSlices
[dstZoffset
+ img
]
4211 + dstYoffset
* dstRowStride
4214 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
4215 srcWidth
, srcHeight
,
4218 for (row
= 0; row
< srcHeight
; row
++) {
4219 /* The unpack functions with:
4220 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
4221 * only write their own dword, so the other dword (stencil
4222 * or depth) is preserved. */
4223 if (srcFormat
!= GL_STENCIL_INDEX
)
4224 _mesa_unpack_depth_span(ctx
, srcWidth
,
4225 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4226 dstRow
, /* dst addr */
4227 1.0f
, srcType
, src
, srcPacking
);
4229 if (srcFormat
!= GL_DEPTH_COMPONENT
)
4230 _mesa_unpack_stencil_span(ctx
, srcWidth
,
4231 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
4232 dstRow
, /* dst addr */
4233 srcType
, src
, srcPacking
,
4234 ctx
->_ImageTransferState
);
4236 src
+= srcRowStride
;
4237 dstRow
+= dstRowStride
/ sizeof(uint64_t);
4245 _mesa_texstore_null(TEXSTORE_PARAMS
)
4247 (void) ctx
; (void) dims
;
4248 (void) baseInternalFormat
;
4250 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
4251 (void) dstRowStride
; (void) dstSlices
,
4252 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
4253 (void) srcFormat
; (void) srcType
;
4257 /* should never happen */
4258 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
4264 * Return the StoreTexImageFunc pointer to store an image in the given format.
4266 static StoreTexImageFunc
4267 _mesa_get_texstore_func(gl_format format
)
4269 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
4270 static GLboolean initialized
= GL_FALSE
;
4273 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
4275 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
4276 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
4277 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
4278 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
4279 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
4280 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
4281 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
4282 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
4283 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
4284 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
4285 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
4286 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
4287 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
4288 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
4289 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
4290 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
4291 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
4292 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
4293 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
4294 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
4295 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
4296 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
4297 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
4298 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
4299 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
4300 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
4301 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
4302 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
4303 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
4304 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
4305 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
4306 table
[MESA_FORMAT_RG88_REV
] = _mesa_texstore_unorm88
;
4307 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
4308 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
4309 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
4310 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
4311 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
4312 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
4313 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
4314 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
4315 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
4316 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
4317 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
4318 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
4319 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
4320 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
4321 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
4322 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
4323 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4324 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4325 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4326 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4327 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
4328 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
4329 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
4330 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
4331 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
4332 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
4333 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4334 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4335 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
4336 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
4337 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4338 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4339 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
4340 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
4341 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
4342 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
4343 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
4344 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
4345 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
4346 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
4347 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
4348 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
4349 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4350 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4351 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4352 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4353 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4354 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4355 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4356 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4357 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4358 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4359 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4360 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4361 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4362 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4363 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4364 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4365 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4366 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4367 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4368 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4369 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4370 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4371 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4372 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4373 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4374 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4375 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4376 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4377 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4378 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4379 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4381 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4382 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4383 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4384 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4385 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4386 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4388 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4389 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4390 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4391 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4392 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4393 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4395 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4396 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4397 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4398 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4399 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4400 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4402 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4403 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4404 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4405 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4406 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4407 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4409 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4410 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4411 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4412 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4413 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4414 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4415 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4416 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4417 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4418 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4419 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4420 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4422 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4423 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4424 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4425 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4426 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4427 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4428 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4429 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4430 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4431 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4432 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4433 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4435 initialized
= GL_TRUE
;
4438 ASSERT(table
[format
]);
4439 return table
[format
];
4444 * Store user data into texture memory.
4445 * Called via glTex[Sub]Image1/2/3D()
4448 _mesa_texstore(TEXSTORE_PARAMS
)
4450 StoreTexImageFunc storeImage
;
4453 storeImage
= _mesa_get_texstore_func(dstFormat
);
4455 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4456 dstFormat
, dstXoffset
, dstYoffset
, dstZoffset
,
4457 dstRowStride
, dstSlices
,
4458 srcWidth
, srcHeight
, srcDepth
,
4459 srcFormat
, srcType
, srcAddr
, srcPacking
);
4465 * Normally, we'll only _write_ texel data to a texture when we map it.
4466 * But if the user is providing depth or stencil values and the texture
4467 * image is a combined depth/stencil format, we'll actually read from
4468 * the texture buffer too (in order to insert the depth or stencil values.
4469 * \param userFormat the user-provided image format
4470 * \param texFormat the destination texture format
4473 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4475 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4476 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4477 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4479 return GL_MAP_WRITE_BIT
;
4483 * This is the software fallback for Driver.TexImage1D().
4484 * \sa _mesa_store_teximage2d()
4487 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4488 GLint internalFormat
,
4489 GLint width
, GLint border
,
4490 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4491 const struct gl_pixelstore_attrib
*packing
,
4492 struct gl_texture_object
*texObj
,
4493 struct gl_texture_image
*texImage
)
4495 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4502 /* allocate storage for texture data */
4503 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4505 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4509 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4510 pixels
, packing
, "glTexImage1D");
4512 /* Note: we check for a NULL image pointer here, _after_ we allocated
4513 * memory for the texture. That's what the GL spec calls for.
4518 /* Map dest texture buffer (write to whole region) */
4519 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4522 &dstMap
, &dstRowStride
);
4524 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4525 texImage
->TexFormat
,
4526 0, 0, 0, /* dstX/Y/Zoffset */
4527 0, /* dstRowStride */
4530 format
, type
, pixels
, packing
);
4532 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4535 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4537 _mesa_unmap_teximage_pbo(ctx
, packing
);
4542 * This is the software fallback for Driver.TexImage2D().
4544 * This function is oriented toward storing images in main memory, rather
4545 * than VRAM. Device driver's can easily plug in their own replacement.
4548 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4549 GLint internalFormat
,
4550 GLint width
, GLint height
, GLint border
,
4551 GLenum format
, GLenum type
, const void *pixels
,
4552 const struct gl_pixelstore_attrib
*packing
,
4553 struct gl_texture_object
*texObj
,
4554 struct gl_texture_image
*texImage
)
4556 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4563 /* allocate storage for texture data */
4564 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4565 width
, height
, 1)) {
4566 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4570 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4571 pixels
, packing
, "glTexImage2D");
4573 /* Note: we check for a NULL image pointer here, _after_ we allocated
4574 * memory for the texture. That's what the GL spec calls for.
4579 if (target
== GL_TEXTURE_1D_ARRAY
) {
4580 const GLint srcStride
=
4581 _mesa_image_row_stride(packing
, width
, format
, type
);
4586 for (y
= 0; y
< height
; y
++) {
4587 /* Map dest texture buffer (write to whole region) */
4588 ctx
->Driver
.MapTextureImage(ctx
, texImage
, y
,
4591 &dstMap
, &dstRowStride
);
4593 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4594 texImage
->TexFormat
,
4595 0, 0, 0, /* dstX/Y/Zoffset */
4599 format
, type
, pixels
, packing
);
4600 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, y
);
4605 pixels
= (const GLubyte
*) pixels
+ srcStride
;
4608 /* Map dest texture buffer (write to whole region) */
4609 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4610 0, 0, width
, height
,
4612 &dstMap
, &dstRowStride
);
4614 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4615 texImage
->TexFormat
,
4616 0, 0, 0, /* dstX/Y/Zoffset */
4620 format
, type
, pixels
, packing
);
4622 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4626 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4628 _mesa_unmap_teximage_pbo(ctx
, packing
);
4634 * This is the software fallback for Driver.TexImage3D().
4635 * \sa _mesa_store_teximage2d()
4638 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4639 GLint internalFormat
,
4640 GLint width
, GLint height
, GLint depth
, GLint border
,
4641 GLenum format
, GLenum type
, const void *pixels
,
4642 const struct gl_pixelstore_attrib
*packing
,
4643 struct gl_texture_object
*texObj
,
4644 struct gl_texture_image
*texImage
)
4646 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4649 GLubyte
**sliceMaps
;
4654 /* allocate storage for texture data */
4655 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4656 width
, height
, depth
)) {
4657 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4661 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
,
4663 pixels
, packing
, "glTexImage3D");
4665 /* Note: we check for a NULL image pointer here, _after_ we allocated
4666 * memory for the texture. That's what the GL spec calls for.
4671 if (target
== GL_TEXTURE_1D_ARRAY
) {
4676 sliceMaps
= (GLubyte
**) malloc(depth
* sizeof(GLubyte
*));
4678 /* Map dest texture buffer slices */
4679 for (slice
= 0; slice
< depth
; slice
++) {
4680 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
,
4681 0, 0, width
, height
,
4683 &sliceMaps
[slice
], &dstRowStride
);
4686 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4687 texImage
->TexFormat
,
4688 0, 0, 0, /* dstX/Y/Zoffset */
4691 width
, height
, depth
,
4692 format
, type
, pixels
, packing
);
4694 /* Unmap dest texture buffer slices */
4695 for (slice
= 0; slice
< depth
; slice
++) {
4696 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
);
4700 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4702 _mesa_unmap_teximage_pbo(ctx
, packing
);
4711 * This is the software fallback for Driver.TexSubImage1D()
4712 * and Driver.CopyTexSubImage1D().
4715 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4716 GLint xoffset
, GLint width
,
4717 GLenum format
, GLenum type
, const void *pixels
,
4718 const struct gl_pixelstore_attrib
*packing
,
4719 struct gl_texture_object
*texObj
,
4720 struct gl_texture_image
*texImage
)
4722 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4727 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4728 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4729 pixels
, packing
, "glTexSubImage1D");
4733 /* Map dest texture buffer (write to whole region) */
4734 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4735 xoffset
, 0, width
, 1,
4737 &dstMap
, &dstRowStride
);
4739 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4740 texImage
->TexFormat
,
4741 0, 0, 0, /* dstX/Y/Zoffset */
4745 format
, type
, pixels
, packing
);
4747 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4750 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4752 _mesa_unmap_teximage_pbo(ctx
, packing
);
4758 * This is the software fallback for Driver.TexSubImage2D()
4759 * and Driver.CopyTexSubImage2D().
4762 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4763 GLint xoffset
, GLint yoffset
,
4764 GLint width
, GLint height
,
4765 GLenum format
, GLenum type
, const void *pixels
,
4766 const struct gl_pixelstore_attrib
*packing
,
4767 struct gl_texture_object
*texObj
,
4768 struct gl_texture_image
*texImage
)
4770 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4775 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4776 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4777 pixels
, packing
, "glTexSubImage2D");
4781 /* Map dest texture buffer (write to whole region) */
4782 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4783 xoffset
, yoffset
, width
, height
,
4785 &dstMap
, &dstRowStride
);
4787 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4788 texImage
->TexFormat
,
4789 0, 0, 0, /* dstX/Y/Zoffset */
4793 format
, type
, pixels
, packing
);
4795 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4798 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4800 _mesa_unmap_teximage_pbo(ctx
, packing
);
4805 * This is the software fallback for Driver.TexSubImage3D().
4806 * and Driver.CopyTexSubImage3D().
4809 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4810 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4811 GLint width
, GLint height
, GLint depth
,
4812 GLenum format
, GLenum type
, const void *pixels
,
4813 const struct gl_pixelstore_attrib
*packing
,
4814 struct gl_texture_object
*texObj
,
4815 struct gl_texture_image
*texImage
)
4817 const GLbitfield rwMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4820 GLubyte
**sliceMaps
;
4823 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4824 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4825 type
, pixels
, packing
,
4830 sliceMaps
= (GLubyte
**) malloc(depth
* sizeof(GLubyte
*));
4832 /* Map dest texture buffer slices */
4833 for (slice
= 0; slice
< depth
; slice
++) {
4834 ctx
->Driver
.MapTextureImage(ctx
, texImage
, zoffset
+ slice
,
4835 xoffset
, yoffset
, width
, height
,
4837 &sliceMaps
[slice
], &dstRowStride
);
4840 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4841 texImage
->TexFormat
,
4845 width
, height
, depth
,
4846 format
, type
, pixels
, packing
);
4848 /* Unmap dest texture buffer slices */
4849 for (slice
= 0; slice
< depth
; slice
++) {
4850 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, zoffset
+ slice
);
4854 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4856 _mesa_unmap_teximage_pbo(ctx
, packing
);
4863 * Fallback for Driver.CompressedTexImage1D()
4866 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4867 GLenum target
, GLint level
,
4868 GLint internalFormat
,
4869 GLint width
, GLint border
,
4870 GLsizei imageSize
, const GLvoid
*data
,
4871 struct gl_texture_object
*texObj
,
4872 struct gl_texture_image
*texImage
)
4874 /* this space intentionally left blank */
4876 (void) target
; (void) level
;
4877 (void) internalFormat
;
4878 (void) width
; (void) border
;
4879 (void) imageSize
; (void) data
;
4887 * Fallback for Driver.CompressedTexImage2D()
4890 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4891 GLenum target
, GLint level
,
4892 GLint internalFormat
,
4893 GLint width
, GLint height
, GLint border
,
4894 GLsizei imageSize
, const GLvoid
*data
,
4895 struct gl_texture_object
*texObj
,
4896 struct gl_texture_image
*texImage
)
4901 /* This is pretty simple, basically just do a memcpy without worrying
4902 * about the usual image unpacking or image transfer operations.
4906 ASSERT(texImage
->Width
> 0);
4907 ASSERT(texImage
->Height
> 0);
4908 ASSERT(texImage
->Depth
== 1);
4910 /* allocate storage for texture data */
4911 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4912 width
, height
, 1)) {
4913 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4917 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4919 "glCompressedTexImage2D");
4924 /* Map dest texture buffer (write to whole region) */
4925 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4926 0, 0, width
, height
,
4928 &dstMap
, &dstRowStride
);
4931 memcpy(dstMap
, data
, imageSize
);
4933 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4935 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4941 * Fallback for Driver.CompressedTexImage3D()
4944 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4945 GLenum target
, GLint level
,
4946 GLint internalFormat
,
4947 GLint width
, GLint height
, GLint depth
,
4949 GLsizei imageSize
, const GLvoid
*data
,
4950 struct gl_texture_object
*texObj
,
4951 struct gl_texture_image
*texImage
)
4953 /* this space intentionally left blank */
4955 (void) target
; (void) level
;
4956 (void) internalFormat
;
4957 (void) width
; (void) height
; (void) depth
;
4959 (void) imageSize
; (void) data
;
4967 * Fallback for Driver.CompressedTexSubImage1D()
4970 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4972 GLint xoffset
, GLsizei width
,
4974 GLsizei imageSize
, const GLvoid
*data
,
4975 struct gl_texture_object
*texObj
,
4976 struct gl_texture_image
*texImage
)
4978 /* there are no compressed 1D texture formats yet */
4980 (void) target
; (void) level
;
4981 (void) xoffset
; (void) width
;
4983 (void) imageSize
; (void) data
;
4990 * Fallback for Driver.CompressedTexSubImage2D()
4993 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4995 GLint xoffset
, GLint yoffset
,
4996 GLsizei width
, GLsizei height
,
4998 GLsizei imageSize
, const GLvoid
*data
,
4999 struct gl_texture_object
*texObj
,
5000 struct gl_texture_image
*texImage
)
5002 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
5006 const gl_format texFormat
= texImage
->TexFormat
;
5009 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
5011 /* these should have been caught sooner */
5012 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
5013 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
5014 ASSERT((xoffset
% bw
) == 0);
5015 ASSERT((yoffset
% bh
) == 0);
5017 /* get pointer to src pixels (may be in a pbo which we'll map here) */
5018 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
5020 "glCompressedTexSubImage2D");
5024 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
5025 src
= (const GLubyte
*) data
;
5027 /* Map dest texture buffer (write to whole region) */
5028 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
5029 xoffset
, yoffset
, width
, height
,
5031 &dstMap
, &dstRowStride
);
5033 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
5034 rows
= height
/ bh
; /* rows in blocks */
5036 /* copy rows of blocks */
5037 for (i
= 0; i
< rows
; i
++) {
5038 memcpy(dstMap
, src
, bytesPerRow
);
5039 dstMap
+= dstRowStride
;
5040 src
+= srcRowStride
;
5043 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
5045 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
5050 * Fallback for Driver.CompressedTexSubImage3D()
5053 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
5055 GLint xoffset
, GLint yoffset
, GLint zoffset
,
5056 GLsizei width
, GLsizei height
, GLsizei depth
,
5058 GLsizei imageSize
, const GLvoid
*data
,
5059 struct gl_texture_object
*texObj
,
5060 struct gl_texture_image
*texImage
)
5062 /* there are no compressed 3D texture formats yet */
5064 (void) target
; (void) level
;
5065 (void) xoffset
; (void) yoffset
; (void) zoffset
;
5066 (void) width
; (void) height
; (void) depth
;
5068 (void) imageSize
; (void) data
;