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"
58 #include "format_pack.h"
62 #include "mfeatures.h"
67 #include "texcompress.h"
68 #include "texcompress_fxt1.h"
69 #include "texcompress_rgtc.h"
70 #include "texcompress_s3tc.h"
71 #include "texcompress_etc.h"
75 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
76 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
86 * Texture image storage function.
88 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
92 * Return GL_TRUE if the given image format is one that be converted
93 * to another format by swizzling.
96 can_swizzle(GLenum logicalBaseFormat
)
98 switch (logicalBaseFormat
) {
101 case GL_LUMINANCE_ALPHA
:
137 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
138 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
139 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
140 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
143 static const struct {
146 GLubyte from_rgba
[6];
147 } mappings
[MAX_IDX
] =
157 MAP4(ZERO
, ZERO
, ZERO
, 0),
187 MAP4(0, ZERO
, ZERO
, ONE
),
193 MAP4(ZERO
, 0, ZERO
, ONE
),
199 MAP4(ZERO
, ZERO
, 0, ONE
),
223 MAP4(0, 1, ZERO
, ONE
),
231 * Convert a GL image format enum to an IDX_* value (see above).
234 get_map_idx(GLenum value
)
237 case GL_LUMINANCE
: return IDX_LUMINANCE
;
238 case GL_ALPHA
: return IDX_ALPHA
;
239 case GL_INTENSITY
: return IDX_INTENSITY
;
240 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
241 case GL_RGB
: return IDX_RGB
;
242 case GL_RGBA
: return IDX_RGBA
;
243 case GL_RED
: return IDX_RED
;
244 case GL_GREEN
: return IDX_GREEN
;
245 case GL_BLUE
: return IDX_BLUE
;
246 case GL_BGR
: return IDX_BGR
;
247 case GL_BGRA
: return IDX_BGRA
;
248 case GL_ABGR_EXT
: return IDX_ABGR
;
249 case GL_RG
: return IDX_RG
;
251 _mesa_problem(NULL
, "Unexpected inFormat");
258 * When promoting texture formats (see below) we need to compute the
259 * mapping of dest components back to source components.
260 * This function does that.
261 * \param inFormat the incoming format of the texture
262 * \param outFormat the final texture format
263 * \return map[6] a full 6-component map
266 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
269 const int inFmt
= get_map_idx(inFormat
);
270 const int outFmt
= get_map_idx(outFormat
);
271 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
272 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
275 for (i
= 0; i
< 4; i
++)
276 map
[i
] = in2rgba
[rgba2out
[i
]];
282 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
283 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
284 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
296 * Make a temporary (color) texture image with GLfloat components.
297 * Apply all needed pixel unpacking and pixel transfer operations.
298 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
299 * Suppose the user specifies GL_LUMINANCE as the internal texture format
300 * but the graphics hardware doesn't support luminance textures. So, we might
301 * use an RGB hardware format instead.
302 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
304 * \param ctx the rendering context
305 * \param dims image dimensions: 1, 2 or 3
306 * \param logicalBaseFormat basic texture derived from the user's
307 * internal texture format value
308 * \param textureBaseFormat the actual basic format of the texture
309 * \param srcWidth source image width
310 * \param srcHeight source image height
311 * \param srcDepth source image depth
312 * \param srcFormat source image format
313 * \param srcType source image type
314 * \param srcAddr source image address
315 * \param srcPacking source image pixel packing
316 * \return resulting image with format = textureBaseFormat and type = GLfloat.
319 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
320 GLenum logicalBaseFormat
,
321 GLenum textureBaseFormat
,
322 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
323 GLenum srcFormat
, GLenum srcType
,
324 const GLvoid
*srcAddr
,
325 const struct gl_pixelstore_attrib
*srcPacking
,
326 GLbitfield transferOps
)
329 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
330 const GLint srcStride
=
331 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
335 ASSERT(dims
>= 1 && dims
<= 3);
337 ASSERT(logicalBaseFormat
== GL_RGBA
||
338 logicalBaseFormat
== GL_RGB
||
339 logicalBaseFormat
== GL_RG
||
340 logicalBaseFormat
== GL_RED
||
341 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
342 logicalBaseFormat
== GL_LUMINANCE
||
343 logicalBaseFormat
== GL_ALPHA
||
344 logicalBaseFormat
== GL_INTENSITY
||
345 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
347 ASSERT(textureBaseFormat
== GL_RGBA
||
348 textureBaseFormat
== GL_RGB
||
349 textureBaseFormat
== GL_RG
||
350 textureBaseFormat
== GL_RED
||
351 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
352 textureBaseFormat
== GL_LUMINANCE
||
353 textureBaseFormat
== GL_ALPHA
||
354 textureBaseFormat
== GL_INTENSITY
||
355 textureBaseFormat
== GL_DEPTH_COMPONENT
);
357 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
358 * components
* sizeof(GLfloat
));
363 for (img
= 0; img
< srcDepth
; img
++) {
365 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
369 for (row
= 0; row
< srcHeight
; row
++) {
370 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
371 dst
, srcFormat
, srcType
, src
,
372 srcPacking
, transferOps
);
373 dst
+= srcWidth
* components
;
378 if (logicalBaseFormat
!= textureBaseFormat
) {
380 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
381 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
386 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
387 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
388 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
390 /* The actual texture format should have at least as many components
391 * as the logical texture format.
393 ASSERT(texComponents
>= logComponents
);
395 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
396 * texComponents
* sizeof(GLfloat
));
402 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
404 n
= srcWidth
* srcHeight
* srcDepth
;
405 for (i
= 0; i
< n
; i
++) {
407 for (k
= 0; k
< texComponents
; k
++) {
410 newImage
[i
* texComponents
+ k
] = 0.0F
;
412 newImage
[i
* texComponents
+ k
] = 1.0F
;
414 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
419 tempImage
= newImage
;
427 * Make temporary image with uint pixel values. Used for unsigned
428 * integer-valued textures.
431 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
432 GLenum logicalBaseFormat
,
433 GLenum textureBaseFormat
,
434 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
435 GLenum srcFormat
, GLenum srcType
,
436 const GLvoid
*srcAddr
,
437 const struct gl_pixelstore_attrib
*srcPacking
)
440 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
441 const GLint srcStride
=
442 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
446 ASSERT(dims
>= 1 && dims
<= 3);
448 ASSERT(logicalBaseFormat
== GL_RGBA
||
449 logicalBaseFormat
== GL_RGB
||
450 logicalBaseFormat
== GL_RG
||
451 logicalBaseFormat
== GL_RED
||
452 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
453 logicalBaseFormat
== GL_LUMINANCE
||
454 logicalBaseFormat
== GL_INTENSITY
||
455 logicalBaseFormat
== GL_ALPHA
);
457 ASSERT(textureBaseFormat
== GL_RGBA
||
458 textureBaseFormat
== GL_RGB
||
459 textureBaseFormat
== GL_RG
||
460 textureBaseFormat
== GL_RED
||
461 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
462 textureBaseFormat
== GL_LUMINANCE
||
463 textureBaseFormat
== GL_INTENSITY
||
464 textureBaseFormat
== GL_ALPHA
);
466 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
467 * components
* sizeof(GLuint
));
472 for (img
= 0; img
< srcDepth
; img
++) {
474 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
478 for (row
= 0; row
< srcHeight
; row
++) {
479 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
480 dst
, srcFormat
, srcType
, src
,
482 dst
+= srcWidth
* components
;
487 if (logicalBaseFormat
!= textureBaseFormat
) {
489 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
490 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
495 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
496 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
497 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
499 /* The actual texture format should have at least as many components
500 * as the logical texture format.
502 ASSERT(texComponents
>= logComponents
);
504 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
505 * texComponents
* sizeof(GLuint
));
511 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
513 n
= srcWidth
* srcHeight
* srcDepth
;
514 for (i
= 0; i
< n
; i
++) {
516 for (k
= 0; k
< texComponents
; k
++) {
519 newImage
[i
* texComponents
+ k
] = 0;
521 newImage
[i
* texComponents
+ k
] = 1;
523 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
528 tempImage
= newImage
;
537 * Make a temporary (color) texture image with GLubyte components.
538 * Apply all needed pixel unpacking and pixel transfer operations.
539 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
540 * Suppose the user specifies GL_LUMINANCE as the internal texture format
541 * but the graphics hardware doesn't support luminance textures. So, we might
542 * use an RGB hardware format instead.
543 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
545 * \param ctx the rendering context
546 * \param dims image dimensions: 1, 2 or 3
547 * \param logicalBaseFormat basic texture derived from the user's
548 * internal texture format value
549 * \param textureBaseFormat the actual basic format of the texture
550 * \param srcWidth source image width
551 * \param srcHeight source image height
552 * \param srcDepth source image depth
553 * \param srcFormat source image format
554 * \param srcType source image type
555 * \param srcAddr source image address
556 * \param srcPacking source image pixel packing
557 * \return resulting image with format = textureBaseFormat and type = GLubyte.
560 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
561 GLenum logicalBaseFormat
,
562 GLenum textureBaseFormat
,
563 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
564 GLenum srcFormat
, GLenum srcType
,
565 const GLvoid
*srcAddr
,
566 const struct gl_pixelstore_attrib
*srcPacking
)
568 GLuint transferOps
= ctx
->_ImageTransferState
;
569 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
571 GLubyte
*tempImage
, *dst
;
573 ASSERT(dims
>= 1 && dims
<= 3);
575 ASSERT(logicalBaseFormat
== GL_RGBA
||
576 logicalBaseFormat
== GL_RGB
||
577 logicalBaseFormat
== GL_RG
||
578 logicalBaseFormat
== GL_RED
||
579 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
580 logicalBaseFormat
== GL_LUMINANCE
||
581 logicalBaseFormat
== GL_ALPHA
||
582 logicalBaseFormat
== GL_INTENSITY
);
584 ASSERT(textureBaseFormat
== GL_RGBA
||
585 textureBaseFormat
== GL_RGB
||
586 textureBaseFormat
== GL_RG
||
587 textureBaseFormat
== GL_RED
||
588 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
589 textureBaseFormat
== GL_LUMINANCE
||
590 textureBaseFormat
== GL_ALPHA
||
591 textureBaseFormat
== GL_INTENSITY
);
593 /* unpack and transfer the source image */
594 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
595 * components
* sizeof(GLubyte
));
601 for (img
= 0; img
< srcDepth
; img
++) {
602 const GLint srcStride
=
603 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
605 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
609 for (row
= 0; row
< srcHeight
; row
++) {
610 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
611 srcFormat
, srcType
, src
, srcPacking
,
613 dst
+= srcWidth
* components
;
618 if (logicalBaseFormat
!= textureBaseFormat
) {
619 /* one more conversion step */
620 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
621 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
626 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
627 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
628 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
630 /* The actual texture format should have at least as many components
631 * as the logical texture format.
633 ASSERT(texComponents
>= logComponents
);
635 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
636 * texComponents
* sizeof(GLubyte
));
642 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
644 n
= srcWidth
* srcHeight
* srcDepth
;
645 for (i
= 0; i
< n
; i
++) {
647 for (k
= 0; k
< texComponents
; k
++) {
650 newImage
[i
* texComponents
+ k
] = 0;
652 newImage
[i
* texComponents
+ k
] = 255;
654 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
659 tempImage
= newImage
;
667 * Copy GLubyte pixels from <src> to <dst> with swizzling.
668 * \param dst destination pixels
669 * \param dstComponents number of color components in destination pixels
670 * \param src source pixels
671 * \param srcComponents number of color components in source pixels
672 * \param map the swizzle mapping. map[X] says where to find the X component
673 * in the source image's pixels. For example, if the source image
674 * is GL_BGRA and X = red, map[0] yields 2.
675 * \param count number of pixels to copy/swizzle.
678 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
679 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
681 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
684 for (i = 0; i < count; i++) { \
686 if (srcComps == 4) { \
687 COPY_4UBV(tmp, src); \
690 for (j = 0; j < srcComps; j++) { \
695 for (j = 0; j < dstComps; j++) { \
696 dst[j] = tmp[map[j]]; \
707 ASSERT(srcComponents
<= 4);
708 ASSERT(dstComponents
<= 4);
710 switch (dstComponents
) {
712 switch (srcComponents
) {
714 SWZ_CPY(dst
, src
, count
, 4, 4);
717 SWZ_CPY(dst
, src
, count
, 4, 3);
720 SWZ_CPY(dst
, src
, count
, 4, 2);
723 SWZ_CPY(dst
, src
, count
, 4, 1);
730 switch (srcComponents
) {
732 SWZ_CPY(dst
, src
, count
, 3, 4);
735 SWZ_CPY(dst
, src
, count
, 3, 3);
738 SWZ_CPY(dst
, src
, count
, 3, 2);
741 SWZ_CPY(dst
, src
, count
, 3, 1);
748 switch (srcComponents
) {
750 SWZ_CPY(dst
, src
, count
, 2, 4);
753 SWZ_CPY(dst
, src
, count
, 2, 3);
756 SWZ_CPY(dst
, src
, count
, 2, 2);
759 SWZ_CPY(dst
, src
, count
, 2, 1);
766 switch (srcComponents
) {
768 SWZ_CPY(dst
, src
, count
, 1, 4);
771 SWZ_CPY(dst
, src
, count
, 1, 3);
774 SWZ_CPY(dst
, src
, count
, 1, 2);
777 SWZ_CPY(dst
, src
, count
, 1, 1);
791 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
792 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
796 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
797 * mapping array depending on endianness.
799 static const GLubyte
*
800 type_mapping( GLenum srcType
)
804 case GL_UNSIGNED_BYTE
:
806 case GL_UNSIGNED_INT_8_8_8_8
:
807 return _mesa_little_endian() ? map_3210
: map_identity
;
808 case GL_UNSIGNED_INT_8_8_8_8_REV
:
809 return _mesa_little_endian() ? map_identity
: map_3210
;
817 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
818 * mapping array depending on pixelstore byte swapping state.
820 static const GLubyte
*
821 byteswap_mapping( GLboolean swapBytes
,
829 case GL_UNSIGNED_BYTE
:
831 case GL_UNSIGNED_INT_8_8_8_8
:
832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
842 * Transfer a GLubyte texture image with component swizzling.
845 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
850 GLenum baseInternalFormat
,
852 const GLubyte
*rgba2dst
,
853 GLuint dstComponents
,
858 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
859 const GLvoid
*srcAddr
,
860 const struct gl_pixelstore_attrib
*srcPacking
)
862 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
863 const GLubyte
*srctype2ubyte
, *swap
;
864 GLubyte map
[4], src2base
[6], base2rgba
[6];
866 const GLint srcRowStride
=
867 _mesa_image_row_stride(srcPacking
, srcWidth
,
868 srcFormat
, GL_UNSIGNED_BYTE
);
869 const GLint srcImageStride
870 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
872 const GLubyte
*srcImage
873 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
874 srcWidth
, srcHeight
, srcFormat
,
875 GL_UNSIGNED_BYTE
, 0, 0, 0);
879 /* Translate from src->baseInternal->GL_RGBA->dst. This will
880 * correctly deal with RGBA->RGB->RGBA conversions where the final
881 * A value must be 0xff regardless of the incoming alpha values.
883 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
884 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
885 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
886 srctype2ubyte
= type_mapping(srcType
);
889 for (i
= 0; i
< 4; i
++)
890 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
892 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
894 if (srcComponents
== dstComponents
&&
895 srcRowStride
== dstRowStride
&&
896 srcRowStride
== srcWidth
* srcComponents
&&
898 /* 1 and 2D images only */
899 GLubyte
*dstImage
= dstSlices
[0];
900 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
901 srcWidth
* srcHeight
);
905 for (img
= 0; img
< srcDepth
; img
++) {
906 const GLubyte
*srcRow
= srcImage
;
907 GLubyte
*dstRow
= dstSlices
[img
];
908 for (row
= 0; row
< srcHeight
; row
++) {
909 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
910 dstRow
+= dstRowStride
;
911 srcRow
+= srcRowStride
;
913 srcImage
+= srcImageStride
;
920 * Teximage storage routine for when a simple memcpy will do.
921 * No pixel transfer operations or special texel encodings allowed.
922 * 1D, 2D and 3D images supported.
925 memcpy_texture(struct gl_context
*ctx
,
930 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
931 GLenum srcFormat
, GLenum srcType
,
932 const GLvoid
*srcAddr
,
933 const struct gl_pixelstore_attrib
*srcPacking
)
935 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
937 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
938 srcWidth
, srcHeight
, srcFormat
, srcType
);
939 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
940 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
941 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
942 const GLint bytesPerRow
= srcWidth
* texelBytes
;
944 if (dstRowStride
== srcRowStride
&&
945 dstRowStride
== bytesPerRow
) {
946 /* memcpy image by image */
948 for (img
= 0; img
< srcDepth
; img
++) {
949 GLubyte
*dstImage
= dstSlices
[img
];
950 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
951 srcImage
+= srcImageStride
;
955 /* memcpy row by row */
957 for (img
= 0; img
< srcDepth
; img
++) {
958 const GLubyte
*srcRow
= srcImage
;
959 GLubyte
*dstRow
= dstSlices
[img
];
960 for (row
= 0; row
< srcHeight
; row
++) {
961 memcpy(dstRow
, srcRow
, bytesPerRow
);
962 dstRow
+= dstRowStride
;
963 srcRow
+= srcRowStride
;
965 srcImage
+= srcImageStride
;
972 * General-case function for storing a color texture images with
973 * components that can be represented with ubytes. Example destination
974 * texture formats are MESA_FORMAT_ARGB888, ARGB4444, RGB565.
977 store_ubyte_texture(TEXSTORE_PARAMS
)
979 const GLint srcRowStride
= srcWidth
* 4 * sizeof(GLubyte
);
980 GLubyte
*tempImage
, *src
;
983 tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
986 srcWidth
, srcHeight
, srcDepth
,
987 srcFormat
, srcType
, srcAddr
,
993 for (img
= 0; img
< srcDepth
; img
++) {
994 _mesa_pack_ubyte_rgba_rect(dstFormat
, srcWidth
, srcHeight
,
996 dstSlices
[img
], dstRowStride
);
997 src
+= srcHeight
* srcRowStride
;
1008 * Store a 32-bit integer or float depth component texture image.
1011 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1013 const GLuint depthScale
= 0xffffffff;
1016 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
1017 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
1018 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
1020 if (dstFormat
== MESA_FORMAT_Z32
)
1021 dstType
= GL_UNSIGNED_INT
;
1025 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1026 ctx
->Pixel
.DepthBias
== 0.0f
&&
1027 !srcPacking
->SwapBytes
&&
1028 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1029 srcFormat
== GL_DEPTH_COMPONENT
&&
1030 srcType
== dstType
) {
1031 /* simple memcpy path */
1032 memcpy_texture(ctx
, dims
,
1034 dstRowStride
, dstSlices
,
1035 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1036 srcAddr
, srcPacking
);
1041 for (img
= 0; img
< srcDepth
; img
++) {
1042 GLubyte
*dstRow
= dstSlices
[img
];
1043 for (row
= 0; row
< srcHeight
; row
++) {
1044 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1045 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1046 _mesa_unpack_depth_span(ctx
, srcWidth
,
1048 depthScale
, srcType
, src
, srcPacking
);
1049 dstRow
+= dstRowStride
;
1058 * Store a 24-bit integer depth component texture image.
1061 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1063 const GLuint depthScale
= 0xffffff;
1066 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1071 for (img
= 0; img
< srcDepth
; img
++) {
1072 GLubyte
*dstRow
= dstSlices
[img
];
1073 for (row
= 0; row
< srcHeight
; row
++) {
1074 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1075 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1076 _mesa_unpack_depth_span(ctx
, srcWidth
,
1077 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1078 depthScale
, srcType
, src
, srcPacking
);
1079 dstRow
+= dstRowStride
;
1088 * Store a 24-bit integer depth component texture image.
1091 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1093 const GLuint depthScale
= 0xffffff;
1096 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1101 for (img
= 0; img
< srcDepth
; img
++) {
1102 GLubyte
*dstRow
= dstSlices
[img
];
1103 for (row
= 0; row
< srcHeight
; row
++) {
1104 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1105 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1106 GLuint
*dst
= (GLuint
*) dstRow
;
1108 _mesa_unpack_depth_span(ctx
, srcWidth
,
1109 GL_UNSIGNED_INT
, dst
,
1110 depthScale
, srcType
, src
, srcPacking
);
1111 for (i
= 0; i
< srcWidth
; i
++)
1113 dstRow
+= dstRowStride
;
1122 * Store a 16-bit integer depth component texture image.
1125 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1127 const GLuint depthScale
= 0xffff;
1129 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1130 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1132 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1133 ctx
->Pixel
.DepthBias
== 0.0f
&&
1134 !srcPacking
->SwapBytes
&&
1135 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1136 srcFormat
== GL_DEPTH_COMPONENT
&&
1137 srcType
== GL_UNSIGNED_SHORT
) {
1138 /* simple memcpy path */
1139 memcpy_texture(ctx
, dims
,
1141 dstRowStride
, dstSlices
,
1142 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1143 srcAddr
, srcPacking
);
1148 for (img
= 0; img
< srcDepth
; img
++) {
1149 GLubyte
*dstRow
= dstSlices
[img
];
1150 for (row
= 0; row
< srcHeight
; row
++) {
1151 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1152 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1153 GLushort
*dst16
= (GLushort
*) dstRow
;
1154 _mesa_unpack_depth_span(ctx
, srcWidth
,
1155 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1156 srcType
, src
, srcPacking
);
1157 dstRow
+= dstRowStride
;
1166 * Store an rgb565 or rgb565_rev texture image.
1169 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1171 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1172 dstFormat
== MESA_FORMAT_RGB565_REV
);
1173 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1175 if (!ctx
->_ImageTransferState
&&
1176 baseInternalFormat
== GL_RGB
&&
1177 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1178 srcPacking
->SwapBytes
)) {
1179 /* simple memcpy path */
1180 memcpy_texture(ctx
, dims
,
1182 dstRowStride
, dstSlices
,
1183 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1184 srcAddr
, srcPacking
);
1186 else if (!ctx
->_ImageTransferState
&&
1187 !srcPacking
->SwapBytes
&&
1188 baseInternalFormat
== GL_RGB
&&
1189 srcFormat
== GL_RGB
&&
1190 srcType
== GL_UNSIGNED_BYTE
&&
1192 /* do optimized tex store */
1193 const GLint srcRowStride
=
1194 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1195 const GLubyte
*src
= (const GLubyte
*)
1196 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1197 srcFormat
, srcType
, 0, 0, 0);
1198 GLubyte
*dst
= dstSlices
[0];
1200 for (row
= 0; row
< srcHeight
; row
++) {
1201 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1202 GLushort
*dstUS
= (GLushort
*) dst
;
1203 /* check for byteswapped format */
1204 if (dstFormat
== MESA_FORMAT_RGB565
) {
1205 for (col
= 0; col
< srcWidth
; col
++) {
1206 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1211 for (col
= 0; col
< srcWidth
; col
++) {
1212 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1216 dst
+= dstRowStride
;
1217 src
+= srcRowStride
;
1221 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1222 dstFormat
, dstRowStride
, dstSlices
,
1223 srcWidth
, srcHeight
, srcDepth
,
1224 srcFormat
, srcType
, srcAddr
, srcPacking
);
1231 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1234 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1236 const GLboolean littleEndian
= _mesa_little_endian();
1238 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1239 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1240 dstFormat
== MESA_FORMAT_RGBX8888
||
1241 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1242 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1244 if (!ctx
->_ImageTransferState
&&
1245 baseInternalFormat
== GL_RGBA
&&
1246 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1247 srcPacking
->SwapBytes
)) {
1248 /* simple memcpy path */
1249 memcpy_texture(ctx
, dims
,
1251 dstRowStride
, dstSlices
,
1252 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1253 srcAddr
, srcPacking
);
1255 else if (!ctx
->_ImageTransferState
&&
1256 (srcType
== GL_UNSIGNED_BYTE
||
1257 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1258 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1259 can_swizzle(baseInternalFormat
) &&
1260 can_swizzle(srcFormat
)) {
1264 /* dstmap - how to swizzle from RGBA to dst format:
1266 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1267 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1268 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1269 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1282 _mesa_swizzle_ubyte_image(ctx
, dims
,
1287 dstRowStride
, dstSlices
,
1288 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1292 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1293 dstFormat
, dstRowStride
, dstSlices
,
1294 srcWidth
, srcHeight
, srcDepth
,
1295 srcFormat
, srcType
, srcAddr
, srcPacking
);
1302 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1304 const GLboolean littleEndian
= _mesa_little_endian();
1306 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1307 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1308 dstFormat
== MESA_FORMAT_XRGB8888
||
1309 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1310 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1312 if (!ctx
->_ImageTransferState
&&
1313 baseInternalFormat
== GL_RGBA
&&
1314 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1315 srcPacking
->SwapBytes
)) {
1316 /* simple memcpy path (big endian) */
1317 memcpy_texture(ctx
, dims
,
1319 dstRowStride
, dstSlices
,
1320 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1321 srcAddr
, srcPacking
);
1323 else if (!ctx
->_ImageTransferState
&&
1324 !srcPacking
->SwapBytes
&&
1325 (dstFormat
== MESA_FORMAT_ARGB8888
||
1326 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1327 srcFormat
== GL_RGB
&&
1328 (baseInternalFormat
== GL_RGBA
||
1329 baseInternalFormat
== GL_RGB
) &&
1330 srcType
== GL_UNSIGNED_BYTE
) {
1332 for (img
= 0; img
< srcDepth
; img
++) {
1333 const GLint srcRowStride
=
1334 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1335 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1336 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1337 GLubyte
*dstRow
= dstSlices
[img
];
1338 for (row
= 0; row
< srcHeight
; row
++) {
1339 GLuint
*d4
= (GLuint
*) dstRow
;
1340 for (col
= 0; col
< srcWidth
; col
++) {
1341 d4
[col
] = PACK_COLOR_8888(0xff,
1342 srcRow
[col
* 3 + RCOMP
],
1343 srcRow
[col
* 3 + GCOMP
],
1344 srcRow
[col
* 3 + BCOMP
]);
1346 dstRow
+= dstRowStride
;
1347 srcRow
+= srcRowStride
;
1351 else if (!ctx
->_ImageTransferState
&&
1352 !srcPacking
->SwapBytes
&&
1353 dstFormat
== MESA_FORMAT_ARGB8888
&&
1354 srcFormat
== GL_RGBA
&&
1355 baseInternalFormat
== GL_RGBA
&&
1356 srcType
== GL_UNSIGNED_BYTE
) {
1357 /* same as above case, but src data has alpha too */
1358 GLint img
, row
, col
;
1359 /* For some reason, streaming copies to write-combined regions
1360 * are extremely sensitive to the characteristics of how the
1361 * source data is retrieved. By reordering the source reads to
1362 * be in-order, the speed of this operation increases by half.
1363 * Strangely the same isn't required for the RGB path, above.
1365 for (img
= 0; img
< srcDepth
; img
++) {
1366 const GLint srcRowStride
=
1367 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1368 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1369 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1370 GLubyte
*dstRow
= dstSlices
[img
];
1371 for (row
= 0; row
< srcHeight
; row
++) {
1372 GLuint
*d4
= (GLuint
*) dstRow
;
1373 for (col
= 0; col
< srcWidth
; col
++) {
1374 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1375 srcRow
[col
* 4 + RCOMP
],
1376 srcRow
[col
* 4 + GCOMP
],
1377 srcRow
[col
* 4 + BCOMP
]);
1379 dstRow
+= dstRowStride
;
1380 srcRow
+= srcRowStride
;
1384 else if (!ctx
->_ImageTransferState
&&
1385 (srcType
== GL_UNSIGNED_BYTE
||
1386 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1387 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1388 can_swizzle(baseInternalFormat
) &&
1389 can_swizzle(srcFormat
)) {
1393 /* dstmap - how to swizzle from RGBA to dst format:
1395 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1396 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1397 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1398 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1399 dstmap
[3] = 3; /* alpha */
1400 dstmap
[2] = 0; /* red */
1401 dstmap
[1] = 1; /* green */
1402 dstmap
[0] = 2; /* blue */
1405 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1406 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1407 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1408 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1415 _mesa_swizzle_ubyte_image(ctx
, dims
,
1422 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1426 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1427 dstFormat
, dstRowStride
, dstSlices
,
1428 srcWidth
, srcHeight
, srcDepth
,
1429 srcFormat
, srcType
, srcAddr
, srcPacking
);
1436 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1438 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1439 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1441 if (!ctx
->_ImageTransferState
&&
1442 baseInternalFormat
== GL_RGB
&&
1443 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1444 srcPacking
->SwapBytes
)) {
1445 /* simple memcpy path */
1446 memcpy_texture(ctx
, dims
,
1448 dstRowStride
, dstSlices
,
1449 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1450 srcAddr
, srcPacking
);
1452 else if (!ctx
->_ImageTransferState
&&
1453 !srcPacking
->SwapBytes
&&
1454 srcFormat
== GL_RGBA
&&
1455 srcType
== GL_UNSIGNED_BYTE
) {
1456 /* extract RGB from RGBA */
1457 GLint img
, row
, col
;
1458 for (img
= 0; img
< srcDepth
; img
++) {
1459 const GLint srcRowStride
=
1460 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1461 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1462 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1463 GLubyte
*dstRow
= dstSlices
[img
];
1464 for (row
= 0; row
< srcHeight
; row
++) {
1465 for (col
= 0; col
< srcWidth
; col
++) {
1466 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1467 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1468 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1470 dstRow
+= dstRowStride
;
1471 srcRow
+= srcRowStride
;
1475 else if (!ctx
->_ImageTransferState
&&
1476 srcType
== GL_UNSIGNED_BYTE
&&
1477 can_swizzle(baseInternalFormat
) &&
1478 can_swizzle(srcFormat
)) {
1482 /* dstmap - how to swizzle from RGBA to dst format:
1487 dstmap
[3] = ONE
; /* ? */
1489 _mesa_swizzle_ubyte_image(ctx
, dims
,
1494 dstRowStride
, dstSlices
,
1495 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1499 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1500 dstFormat
, dstRowStride
, dstSlices
,
1501 srcWidth
, srcHeight
, srcDepth
,
1502 srcFormat
, srcType
, srcAddr
, srcPacking
);
1509 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1511 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1512 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1514 if (!ctx
->_ImageTransferState
&&
1515 baseInternalFormat
== GL_RGB
&&
1516 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1517 srcPacking
->SwapBytes
)) {
1518 /* simple memcpy path */
1519 memcpy_texture(ctx
, dims
,
1521 dstRowStride
, dstSlices
,
1522 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1523 srcAddr
, srcPacking
);
1525 else if (!ctx
->_ImageTransferState
&&
1526 !srcPacking
->SwapBytes
&&
1527 srcFormat
== GL_RGBA
&&
1528 srcType
== GL_UNSIGNED_BYTE
) {
1529 /* extract BGR from RGBA */
1531 for (img
= 0; img
< srcDepth
; img
++) {
1532 const GLint srcRowStride
=
1533 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1534 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1535 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1536 GLubyte
*dstRow
= dstSlices
[img
];
1537 for (row
= 0; row
< srcHeight
; row
++) {
1538 for (col
= 0; col
< srcWidth
; col
++) {
1539 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1540 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1541 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1543 dstRow
+= dstRowStride
;
1544 srcRow
+= srcRowStride
;
1548 else if (!ctx
->_ImageTransferState
&&
1549 srcType
== GL_UNSIGNED_BYTE
&&
1550 can_swizzle(baseInternalFormat
) &&
1551 can_swizzle(srcFormat
)) {
1555 /* dstmap - how to swizzle from RGBA to dst format:
1560 dstmap
[3] = ONE
; /* ? */
1562 _mesa_swizzle_ubyte_image(ctx
, dims
,
1567 dstRowStride
, dstSlices
,
1568 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1572 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1573 dstFormat
, dstRowStride
, dstSlices
,
1574 srcWidth
, srcHeight
, srcDepth
,
1575 srcFormat
, srcType
, srcAddr
, srcPacking
);
1582 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1584 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1585 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1586 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1588 if (!ctx
->_ImageTransferState
&&
1589 baseInternalFormat
== GL_RGBA
&&
1590 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1591 srcPacking
->SwapBytes
)) {
1592 /* simple memcpy path */
1593 memcpy_texture(ctx
, dims
,
1595 dstRowStride
, dstSlices
,
1596 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1597 srcAddr
, srcPacking
);
1600 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1601 dstFormat
, dstRowStride
, dstSlices
,
1602 srcWidth
, srcHeight
, srcDepth
,
1603 srcFormat
, srcType
, srcAddr
, srcPacking
);
1609 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1611 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1612 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1614 if (!ctx
->_ImageTransferState
&&
1615 baseInternalFormat
== GL_RGBA
&&
1616 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1617 srcPacking
->SwapBytes
)) {
1618 /* simple memcpy path */
1619 memcpy_texture(ctx
, dims
,
1621 dstRowStride
, dstSlices
,
1622 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1623 srcAddr
, srcPacking
);
1626 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1627 dstFormat
, dstRowStride
, dstSlices
,
1628 srcWidth
, srcHeight
, srcDepth
,
1629 srcFormat
, srcType
, srcAddr
, srcPacking
);
1635 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1637 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1638 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1639 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1641 if (!ctx
->_ImageTransferState
&&
1642 baseInternalFormat
== GL_RGBA
&&
1643 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1644 srcPacking
->SwapBytes
)) {
1645 /* simple memcpy path */
1646 memcpy_texture(ctx
, dims
,
1648 dstRowStride
, dstSlices
,
1649 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1650 srcAddr
, srcPacking
);
1653 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1654 dstFormat
, dstRowStride
, dstSlices
,
1655 srcWidth
, srcHeight
, srcDepth
,
1656 srcFormat
, srcType
, srcAddr
, srcPacking
);
1663 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1665 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1667 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
1668 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1670 if (!ctx
->_ImageTransferState
&&
1671 baseInternalFormat
== GL_RGBA
&&
1672 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1673 srcPacking
->SwapBytes
)) {
1674 /* simple memcpy path */
1675 memcpy_texture(ctx
, dims
,
1677 dstRowStride
, dstSlices
,
1678 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1679 srcAddr
, srcPacking
);
1683 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1686 srcWidth
, srcHeight
, srcDepth
,
1687 srcFormat
, srcType
, srcAddr
,
1689 ctx
->_ImageTransferState
);
1690 const GLfloat
*src
= tempImage
;
1691 GLint img
, row
, col
;
1694 for (img
= 0; img
< srcDepth
; img
++) {
1695 GLubyte
*dstRow
= dstSlices
[img
];
1696 if (baseInternalFormat
== GL_RGBA
) {
1697 for (row
= 0; row
< srcHeight
; row
++) {
1698 GLuint
*dstUI
= (GLuint
*) dstRow
;
1699 for (col
= 0; col
< srcWidth
; col
++) {
1702 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1703 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1704 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1705 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1706 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1709 dstRow
+= dstRowStride
;
1711 } else if (baseInternalFormat
== GL_RGB
) {
1712 for (row
= 0; row
< srcHeight
; row
++) {
1713 GLuint
*dstUI
= (GLuint
*) dstRow
;
1714 for (col
= 0; col
< srcWidth
; col
++) {
1717 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1718 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1719 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1720 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
1723 dstRow
+= dstRowStride
;
1729 free((void *) tempImage
);
1736 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1739 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1741 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1743 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
1744 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1748 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1751 srcWidth
, srcHeight
, srcDepth
,
1752 srcFormat
, srcType
, srcAddr
,
1754 const GLubyte
*src
= tempImage
;
1755 GLint img
, row
, col
;
1758 for (img
= 0; img
< srcDepth
; img
++) {
1759 GLubyte
*dstRow
= dstSlices
[img
];
1760 for (row
= 0; row
< srcHeight
; row
++) {
1761 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1762 for (col
= 0; col
< srcWidth
; col
++) {
1763 /* src[0] is luminance, src[1] is alpha */
1764 dstUS
[col
] = PACK_COLOR_44( src
[1],
1768 dstRow
+= dstRowStride
;
1771 free((void *) tempImage
);
1778 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1781 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1783 const GLboolean littleEndian
= _mesa_little_endian();
1784 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1786 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1787 dstFormat
== MESA_FORMAT_AL88_REV
||
1788 dstFormat
== MESA_FORMAT_GR88
||
1789 dstFormat
== MESA_FORMAT_RG88
);
1790 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1792 if (!ctx
->_ImageTransferState
&&
1793 !srcPacking
->SwapBytes
&&
1794 ((dstFormat
== MESA_FORMAT_AL88
&&
1795 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1796 srcFormat
== GL_LUMINANCE_ALPHA
) ||
1797 (dstFormat
== MESA_FORMAT_GR88
&&
1798 baseInternalFormat
== srcFormat
)) &&
1799 srcType
== GL_UNSIGNED_BYTE
&&
1801 /* simple memcpy path */
1802 memcpy_texture(ctx
, dims
,
1804 dstRowStride
, dstSlices
,
1805 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1806 srcAddr
, srcPacking
);
1808 else if (!ctx
->_ImageTransferState
&&
1810 srcType
== GL_UNSIGNED_BYTE
&&
1811 can_swizzle(baseInternalFormat
) &&
1812 can_swizzle(srcFormat
)) {
1815 /* dstmap - how to swizzle from RGBA to dst format:
1817 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
1818 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
1819 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
1829 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
1830 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
1839 dstmap
[2] = ZERO
; /* ? */
1840 dstmap
[3] = ONE
; /* ? */
1842 _mesa_swizzle_ubyte_image(ctx
, dims
,
1847 dstRowStride
, dstSlices
,
1848 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1853 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1856 srcWidth
, srcHeight
, srcDepth
,
1857 srcFormat
, srcType
, srcAddr
,
1859 const GLubyte
*src
= tempImage
;
1860 GLint img
, row
, col
;
1863 for (img
= 0; img
< srcDepth
; img
++) {
1864 GLubyte
*dstRow
= dstSlices
[img
];
1865 for (row
= 0; row
< srcHeight
; row
++) {
1866 GLushort
*dstUS
= (GLushort
*) dstRow
;
1867 if (dstFormat
== MESA_FORMAT_AL88
||
1868 dstFormat
== MESA_FORMAT_GR88
) {
1869 for (col
= 0; col
< srcWidth
; col
++) {
1870 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1871 dstUS
[col
] = PACK_COLOR_88( src
[1],
1877 for (col
= 0; col
< srcWidth
; col
++) {
1878 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1879 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
1884 dstRow
+= dstRowStride
;
1887 free((void *) tempImage
);
1894 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
1897 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
1899 const GLboolean littleEndian
= _mesa_little_endian();
1900 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1902 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
1903 dstFormat
== MESA_FORMAT_AL1616_REV
||
1904 dstFormat
== MESA_FORMAT_RG1616
||
1905 dstFormat
== MESA_FORMAT_RG1616_REV
);
1906 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1908 if (!ctx
->_ImageTransferState
&&
1909 !srcPacking
->SwapBytes
&&
1910 ((dstFormat
== MESA_FORMAT_AL1616
&&
1911 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1912 srcFormat
== GL_LUMINANCE_ALPHA
) ||
1913 (dstFormat
== MESA_FORMAT_RG1616
&&
1914 baseInternalFormat
== srcFormat
)) &&
1915 srcType
== GL_UNSIGNED_SHORT
&&
1917 /* simple memcpy path */
1918 memcpy_texture(ctx
, dims
,
1920 dstRowStride
, dstSlices
,
1921 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1922 srcAddr
, srcPacking
);
1926 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1929 srcWidth
, srcHeight
, srcDepth
,
1930 srcFormat
, srcType
, srcAddr
,
1932 ctx
->_ImageTransferState
);
1933 const GLfloat
*src
= tempImage
;
1934 GLint img
, row
, col
;
1937 for (img
= 0; img
< srcDepth
; img
++) {
1938 GLubyte
*dstRow
= dstSlices
[img
];
1939 for (row
= 0; row
< srcHeight
; row
++) {
1940 GLuint
*dstUI
= (GLuint
*) dstRow
;
1941 if (dstFormat
== MESA_FORMAT_AL1616
||
1942 dstFormat
== MESA_FORMAT_RG1616
) {
1943 for (col
= 0; col
< srcWidth
; col
++) {
1946 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1947 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1948 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
1953 for (col
= 0; col
< srcWidth
; col
++) {
1956 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1957 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1958 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
1962 dstRow
+= dstRowStride
;
1965 free((void *) tempImage
);
1971 /* Texstore for R16, A16, L16, I16. */
1973 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
1975 const GLboolean littleEndian
= _mesa_little_endian();
1976 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1978 ASSERT(dstFormat
== MESA_FORMAT_R16
||
1979 dstFormat
== MESA_FORMAT_A16
||
1980 dstFormat
== MESA_FORMAT_L16
||
1981 dstFormat
== MESA_FORMAT_I16
);
1982 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1984 if (!ctx
->_ImageTransferState
&&
1985 !srcPacking
->SwapBytes
&&
1986 baseInternalFormat
== srcFormat
&&
1987 srcType
== GL_UNSIGNED_SHORT
&&
1989 /* simple memcpy path */
1990 memcpy_texture(ctx
, dims
,
1992 dstRowStride
, dstSlices
,
1993 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1994 srcAddr
, srcPacking
);
1998 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2001 srcWidth
, srcHeight
, srcDepth
,
2002 srcFormat
, srcType
, srcAddr
,
2004 ctx
->_ImageTransferState
);
2005 const GLfloat
*src
= tempImage
;
2006 GLint img
, row
, col
;
2009 for (img
= 0; img
< srcDepth
; img
++) {
2010 GLubyte
*dstRow
= dstSlices
[img
];
2011 for (row
= 0; row
< srcHeight
; row
++) {
2012 GLushort
*dstUS
= (GLushort
*) dstRow
;
2013 for (col
= 0; col
< srcWidth
; col
++) {
2016 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2020 dstRow
+= dstRowStride
;
2023 free((void *) tempImage
);
2030 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2032 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2034 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2035 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2037 if (!ctx
->_ImageTransferState
&&
2038 !srcPacking
->SwapBytes
&&
2039 baseInternalFormat
== GL_RGBA
&&
2040 srcFormat
== GL_RGBA
&&
2041 srcType
== GL_UNSIGNED_SHORT
) {
2042 /* simple memcpy path */
2043 memcpy_texture(ctx
, dims
,
2045 dstRowStride
, dstSlices
,
2046 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2047 srcAddr
, srcPacking
);
2051 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2054 srcWidth
, srcHeight
, srcDepth
,
2055 srcFormat
, srcType
, srcAddr
,
2057 ctx
->_ImageTransferState
);
2058 const GLfloat
*src
= tempImage
;
2059 GLint img
, row
, col
;
2062 for (img
= 0; img
< srcDepth
; img
++) {
2063 GLubyte
*dstRow
= dstSlices
[img
];
2064 for (row
= 0; row
< srcHeight
; row
++) {
2065 GLushort
*dstUS
= (GLushort
*) dstRow
;
2066 for (col
= 0; col
< srcWidth
; col
++) {
2067 GLushort r
, g
, b
, a
;
2069 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2070 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2071 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2072 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2079 dstRow
+= dstRowStride
;
2082 free((void *) tempImage
);
2089 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2091 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2093 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2094 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2096 if (!ctx
->_ImageTransferState
&&
2097 !srcPacking
->SwapBytes
&&
2098 baseInternalFormat
== GL_RGBA
&&
2099 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2100 srcFormat
== GL_RGBA
&&
2101 srcType
== GL_SHORT
) {
2102 /* simple memcpy path */
2103 memcpy_texture(ctx
, dims
,
2105 dstRowStride
, dstSlices
,
2106 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2107 srcAddr
, srcPacking
);
2111 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2114 srcWidth
, srcHeight
, srcDepth
,
2115 srcFormat
, srcType
, srcAddr
,
2117 ctx
->_ImageTransferState
);
2118 const GLfloat
*src
= tempImage
;
2119 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2120 GLint img
, row
, col
;
2125 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2126 * 3 or 4 components/pixel here.
2128 for (img
= 0; img
< srcDepth
; img
++) {
2129 GLubyte
*dstRow
= dstSlices
[img
];
2130 for (row
= 0; row
< srcHeight
; row
++) {
2131 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2132 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2133 for (col
= 0; col
< srcWidth
; col
++) {
2135 for (c
= 0; c
< comps
; c
++) {
2137 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2138 dstRowS
[col
* comps
+ c
] = p
;
2141 dstRow
+= dstRowStride
;
2142 src
+= 4 * srcWidth
;
2144 for (col
= 0; col
< srcWidth
; col
++) {
2146 for (c
= 0; c
< comps
; c
++) {
2148 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2149 dstRowS
[col
* comps
+ c
] = p
;
2152 dstRow
+= dstRowStride
;
2153 src
+= 3 * srcWidth
;
2157 free((void *) tempImage
);
2164 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2166 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2167 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2169 if (!ctx
->_ImageTransferState
&&
2170 baseInternalFormat
== GL_RGB
&&
2171 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2172 srcPacking
->SwapBytes
)) {
2173 /* simple memcpy path */
2174 memcpy_texture(ctx
, dims
,
2176 dstRowStride
, dstSlices
,
2177 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2178 srcAddr
, srcPacking
);
2181 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
2182 dstFormat
, dstRowStride
, dstSlices
,
2183 srcWidth
, srcHeight
, srcDepth
,
2184 srcFormat
, srcType
, srcAddr
, srcPacking
);
2191 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2194 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2196 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2198 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2199 dstFormat
== MESA_FORMAT_L8
||
2200 dstFormat
== MESA_FORMAT_I8
||
2201 dstFormat
== MESA_FORMAT_R8
);
2202 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2204 if (!ctx
->_ImageTransferState
&&
2205 !srcPacking
->SwapBytes
&&
2206 baseInternalFormat
== srcFormat
&&
2207 srcType
== GL_UNSIGNED_BYTE
) {
2208 /* simple memcpy path */
2209 memcpy_texture(ctx
, dims
,
2211 dstRowStride
, dstSlices
,
2212 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2213 srcAddr
, srcPacking
);
2215 else if (!ctx
->_ImageTransferState
&&
2216 srcType
== GL_UNSIGNED_BYTE
&&
2217 can_swizzle(baseInternalFormat
) &&
2218 can_swizzle(srcFormat
)) {
2221 /* dstmap - how to swizzle from RGBA to dst format:
2223 if (dstFormat
== MESA_FORMAT_A8
) {
2229 dstmap
[1] = ZERO
; /* ? */
2230 dstmap
[2] = ZERO
; /* ? */
2231 dstmap
[3] = ONE
; /* ? */
2233 _mesa_swizzle_ubyte_image(ctx
, dims
,
2238 dstRowStride
, dstSlices
,
2239 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2244 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2247 srcWidth
, srcHeight
, srcDepth
,
2248 srcFormat
, srcType
, srcAddr
,
2250 const GLubyte
*src
= tempImage
;
2251 GLint img
, row
, col
;
2254 for (img
= 0; img
< srcDepth
; img
++) {
2255 GLubyte
*dstRow
= dstSlices
[img
];
2256 for (row
= 0; row
< srcHeight
; row
++) {
2257 for (col
= 0; col
< srcWidth
; col
++) {
2258 dstRow
[col
] = src
[col
];
2260 dstRow
+= dstRowStride
;
2264 free((void *) tempImage
);
2272 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2275 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2277 const GLboolean littleEndian
= _mesa_little_endian();
2279 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2281 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2282 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2283 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2284 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2285 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2286 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2287 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2288 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2290 /* always just memcpy since no pixel transfer ops apply */
2291 memcpy_texture(ctx
, dims
,
2293 dstRowStride
, dstSlices
,
2294 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2295 srcAddr
, srcPacking
);
2297 /* Check if we need byte swapping */
2298 /* XXX the logic here _might_ be wrong */
2299 if (srcPacking
->SwapBytes
^
2300 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2301 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2304 for (img
= 0; img
< srcDepth
; img
++) {
2305 GLubyte
*dstRow
= dstSlices
[img
];
2306 for (row
= 0; row
< srcHeight
; row
++) {
2307 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2308 dstRow
+= dstRowStride
;
2316 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2318 const GLboolean littleEndian
= _mesa_little_endian();
2319 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2321 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2322 ASSERT(texelBytes
== 2);
2323 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2324 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2325 (srcFormat
== GL_DUDV_ATI
));
2326 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2328 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2330 /* simple memcpy path */
2331 memcpy_texture(ctx
, dims
,
2333 dstRowStride
, dstSlices
,
2334 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2335 srcAddr
, srcPacking
);
2337 else if (srcType
== GL_BYTE
) {
2340 /* dstmap - how to swizzle from RGBA to dst format:
2350 dstmap
[2] = ZERO
; /* ? */
2351 dstmap
[3] = ONE
; /* ? */
2353 _mesa_swizzle_ubyte_image(ctx
, dims
,
2354 GL_LUMINANCE_ALPHA
, /* hack */
2355 GL_UNSIGNED_BYTE
, /* hack */
2356 GL_LUMINANCE_ALPHA
, /* hack */
2358 dstRowStride
, dstSlices
,
2359 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2363 /* general path - note this is defined for 2d textures only */
2364 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2365 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2366 srcFormat
, srcType
);
2367 GLbyte
*tempImage
, *dst
, *src
;
2370 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2371 * components
* sizeof(GLbyte
));
2375 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2376 srcWidth
, srcHeight
,
2381 for (row
= 0; row
< srcHeight
; row
++) {
2382 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2383 dst
, srcFormat
, srcType
, src
,
2385 dst
+= srcWidth
* components
;
2390 dst
= (GLbyte
*) dstSlices
[0];
2391 for (row
= 0; row
< srcHeight
; row
++) {
2392 memcpy(dst
, src
, srcWidth
* texelBytes
);
2393 dst
+= dstRowStride
;
2394 src
+= srcWidth
* texelBytes
;
2396 free((void *) tempImage
);
2403 * Store a texture in a signed normalized 8-bit format.
2406 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2408 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2410 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2411 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2412 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2413 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2414 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2416 if (!ctx
->_ImageTransferState
&&
2417 !srcPacking
->SwapBytes
&&
2418 baseInternalFormat
== srcFormat
&&
2419 srcType
== GL_BYTE
) {
2420 /* simple memcpy path */
2421 memcpy_texture(ctx
, dims
,
2423 dstRowStride
, dstSlices
,
2424 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2425 srcAddr
, srcPacking
);
2429 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2432 srcWidth
, srcHeight
, srcDepth
,
2433 srcFormat
, srcType
, srcAddr
,
2435 ctx
->_ImageTransferState
);
2436 const GLfloat
*src
= tempImage
;
2437 GLint img
, row
, col
;
2440 for (img
= 0; img
< srcDepth
; img
++) {
2441 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2442 for (row
= 0; row
< srcHeight
; row
++) {
2443 for (col
= 0; col
< srcWidth
; col
++) {
2444 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2446 dstRow
+= dstRowStride
;
2450 free((void *) tempImage
);
2457 * Store a texture in a signed normalized two-channel 16-bit format.
2460 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2462 const GLboolean littleEndian
= _mesa_little_endian();
2463 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2465 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2466 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2467 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2469 if (!ctx
->_ImageTransferState
&&
2470 !srcPacking
->SwapBytes
&&
2471 baseInternalFormat
== srcFormat
&&
2472 srcType
== GL_BYTE
&&
2474 /* simple memcpy path */
2475 memcpy_texture(ctx
, dims
,
2477 dstRowStride
, dstSlices
,
2478 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2479 srcAddr
, srcPacking
);
2483 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2486 srcWidth
, srcHeight
, srcDepth
,
2487 srcFormat
, srcType
, srcAddr
,
2489 ctx
->_ImageTransferState
);
2490 const GLfloat
*src
= tempImage
;
2491 GLint img
, row
, col
;
2494 for (img
= 0; img
< srcDepth
; img
++) {
2495 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2496 for (row
= 0; row
< srcHeight
; row
++) {
2497 GLbyte
*dst
= dstRow
;
2498 for (col
= 0; col
< srcWidth
; col
++) {
2499 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2500 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2504 dstRow
+= dstRowStride
;
2507 free((void *) tempImage
);
2512 /* Texstore for signed R16, A16, L16, I16. */
2514 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2516 const GLboolean littleEndian
= _mesa_little_endian();
2517 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2519 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2520 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2521 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2522 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2523 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2525 if (!ctx
->_ImageTransferState
&&
2526 !srcPacking
->SwapBytes
&&
2527 baseInternalFormat
== srcFormat
&&
2528 srcType
== GL_SHORT
&&
2530 /* simple memcpy path */
2531 memcpy_texture(ctx
, dims
,
2533 dstRowStride
, dstSlices
,
2534 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2535 srcAddr
, srcPacking
);
2539 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2542 srcWidth
, srcHeight
, srcDepth
,
2543 srcFormat
, srcType
, srcAddr
,
2545 ctx
->_ImageTransferState
);
2546 const GLfloat
*src
= tempImage
;
2547 GLint img
, row
, col
;
2550 for (img
= 0; img
< srcDepth
; img
++) {
2551 GLubyte
*dstRow
= dstSlices
[img
];
2552 for (row
= 0; row
< srcHeight
; row
++) {
2553 GLshort
*dstUS
= (GLshort
*) dstRow
;
2554 for (col
= 0; col
< srcWidth
; col
++) {
2557 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2561 dstRow
+= dstRowStride
;
2564 free((void *) tempImage
);
2570 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2573 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2575 const GLboolean littleEndian
= _mesa_little_endian();
2576 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2578 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2579 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2580 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2582 if (!ctx
->_ImageTransferState
&&
2583 !srcPacking
->SwapBytes
&&
2584 baseInternalFormat
== srcFormat
&&
2585 srcType
== GL_SHORT
&&
2587 /* simple memcpy path */
2588 memcpy_texture(ctx
, dims
,
2590 dstRowStride
, dstSlices
,
2591 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2592 srcAddr
, srcPacking
);
2596 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2599 srcWidth
, srcHeight
, srcDepth
,
2600 srcFormat
, srcType
, srcAddr
,
2602 ctx
->_ImageTransferState
);
2603 const GLfloat
*src
= tempImage
;
2604 GLint img
, row
, col
;
2607 for (img
= 0; img
< srcDepth
; img
++) {
2608 GLubyte
*dstRow
= dstSlices
[img
];
2609 for (row
= 0; row
< srcHeight
; row
++) {
2610 GLshort
*dst
= (GLshort
*) dstRow
;
2611 for (col
= 0; col
< srcWidth
; col
++) {
2614 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2615 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2621 dstRow
+= dstRowStride
;
2624 free((void *) tempImage
);
2630 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2633 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2635 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2637 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2638 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2642 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2645 srcWidth
, srcHeight
, srcDepth
,
2646 srcFormat
, srcType
, srcAddr
,
2648 ctx
->_ImageTransferState
);
2649 const GLfloat
*srcRow
= tempImage
;
2650 GLint img
, row
, col
;
2653 for (img
= 0; img
< srcDepth
; img
++) {
2654 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2655 for (row
= 0; row
< srcHeight
; row
++) {
2656 GLbyte
*dst
= dstRow
;
2657 for (col
= 0; col
< srcWidth
; col
++) {
2658 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2659 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2660 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2665 dstRow
+= dstRowStride
;
2668 free((void *) tempImage
);
2676 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2677 * MESA_FORMAT_SIGNED_RGBA8888_REV
2680 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2682 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2684 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2685 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2686 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2688 if (!ctx
->_ImageTransferState
&&
2689 baseInternalFormat
== GL_RGBA
&&
2690 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2691 srcPacking
->SwapBytes
)) {
2692 /* simple memcpy path */
2693 memcpy_texture(ctx
, dims
,
2695 dstRowStride
, dstSlices
,
2696 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2697 srcAddr
, srcPacking
);
2701 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2704 srcWidth
, srcHeight
, srcDepth
,
2705 srcFormat
, srcType
, srcAddr
,
2707 ctx
->_ImageTransferState
);
2708 const GLfloat
*srcRow
= tempImage
;
2709 GLint img
, row
, col
;
2712 for (img
= 0; img
< srcDepth
; img
++) {
2713 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2714 for (row
= 0; row
< srcHeight
; row
++) {
2715 GLbyte
*dst
= dstRow
;
2716 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2717 for (col
= 0; col
< srcWidth
; col
++) {
2718 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2719 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2720 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2721 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2727 for (col
= 0; col
< srcWidth
; col
++) {
2728 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2729 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2730 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2731 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2736 dstRow
+= dstRowStride
;
2739 free((void *) tempImage
);
2746 * Store a combined depth/stencil texture image.
2749 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2751 const GLuint depthScale
= 0xffffff;
2752 const GLint srcRowStride
2753 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2756 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2757 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2758 srcFormat
== GL_DEPTH_COMPONENT
||
2759 srcFormat
== GL_STENCIL_INDEX
);
2760 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2762 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
2763 ctx
->Pixel
.DepthBias
== 0.0f
&&
2764 !srcPacking
->SwapBytes
) {
2766 memcpy_texture(ctx
, dims
,
2768 dstRowStride
, dstSlices
,
2769 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2770 srcAddr
, srcPacking
);
2772 else if (srcFormat
== GL_DEPTH_COMPONENT
||
2773 srcFormat
== GL_STENCIL_INDEX
) {
2774 /* In case we only upload depth we need to preserve the stencil */
2775 for (img
= 0; img
< srcDepth
; img
++) {
2776 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2778 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2779 srcWidth
, srcHeight
,
2782 for (row
= 0; row
< srcHeight
; row
++) {
2783 GLuint depth
[MAX_WIDTH
];
2784 GLubyte stencil
[MAX_WIDTH
];
2786 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2788 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2789 keepstencil
= GL_TRUE
;
2791 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2792 keepdepth
= GL_TRUE
;
2795 if (keepdepth
== GL_FALSE
)
2796 /* the 24 depth bits will be in the low position: */
2797 _mesa_unpack_depth_span(ctx
, srcWidth
,
2798 GL_UNSIGNED_INT
, /* dst type */
2799 keepstencil
? depth
: dstRow
, /* dst addr */
2801 srcType
, src
, srcPacking
);
2803 if (keepstencil
== GL_FALSE
)
2804 /* get the 8-bit stencil values */
2805 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2806 GL_UNSIGNED_BYTE
, /* dst type */
2807 stencil
, /* dst addr */
2808 srcType
, src
, srcPacking
,
2809 ctx
->_ImageTransferState
);
2811 for (i
= 0; i
< srcWidth
; i
++) {
2813 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2815 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2818 src
+= srcRowStride
;
2819 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2828 * Store a combined depth/stencil texture image.
2831 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2833 const GLuint depthScale
= 0xffffff;
2834 const GLint srcRowStride
2835 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2838 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2839 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2840 srcFormat
== GL_DEPTH_COMPONENT
||
2841 srcFormat
== GL_STENCIL_INDEX
);
2842 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2843 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2845 for (img
= 0; img
< srcDepth
; img
++) {
2846 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2848 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2849 srcWidth
, srcHeight
,
2852 for (row
= 0; row
< srcHeight
; row
++) {
2853 GLuint depth
[MAX_WIDTH
];
2854 GLubyte stencil
[MAX_WIDTH
];
2856 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2858 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2859 keepstencil
= GL_TRUE
;
2861 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2862 keepdepth
= GL_TRUE
;
2865 if (keepdepth
== GL_FALSE
)
2866 /* the 24 depth bits will be in the low position: */
2867 _mesa_unpack_depth_span(ctx
, srcWidth
,
2868 GL_UNSIGNED_INT
, /* dst type */
2869 keepstencil
? depth
: dstRow
, /* dst addr */
2871 srcType
, src
, srcPacking
);
2873 if (keepstencil
== GL_FALSE
)
2874 /* get the 8-bit stencil values */
2875 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2876 GL_UNSIGNED_BYTE
, /* dst type */
2877 stencil
, /* dst addr */
2878 srcType
, src
, srcPacking
,
2879 ctx
->_ImageTransferState
);
2881 /* merge stencil values into depth values */
2882 for (i
= 0; i
< srcWidth
; i
++) {
2884 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2886 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
2889 src
+= srcRowStride
;
2890 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2898 * Store simple 8-bit/value stencil texture data.
2901 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2903 ASSERT(dstFormat
== MESA_FORMAT_S8
);
2904 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2906 if (!ctx
->_ImageTransferState
&&
2907 !srcPacking
->SwapBytes
&&
2908 baseInternalFormat
== srcFormat
&&
2909 srcType
== GL_UNSIGNED_BYTE
) {
2910 /* simple memcpy path */
2911 memcpy_texture(ctx
, dims
,
2913 dstRowStride
, dstSlices
,
2914 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2915 srcAddr
, srcPacking
);
2918 const GLint srcRowStride
2919 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2922 for (img
= 0; img
< srcDepth
; img
++) {
2923 GLubyte
*dstRow
= dstSlices
[img
];
2925 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2926 srcWidth
, srcHeight
,
2929 for (row
= 0; row
< srcHeight
; row
++) {
2930 GLubyte stencil
[MAX_WIDTH
];
2933 /* get the 8-bit stencil values */
2934 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2935 GL_UNSIGNED_BYTE
, /* dst type */
2936 stencil
, /* dst addr */
2937 srcType
, src
, srcPacking
,
2938 ctx
->_ImageTransferState
);
2939 /* merge stencil values into depth values */
2940 for (i
= 0; i
< srcWidth
; i
++)
2941 dstRow
[i
] = stencil
[i
];
2943 src
+= srcRowStride
;
2944 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
2955 * Store an image in any of the formats:
2956 * _mesa_texformat_rgba_float32
2957 * _mesa_texformat_rgb_float32
2958 * _mesa_texformat_alpha_float32
2959 * _mesa_texformat_luminance_float32
2960 * _mesa_texformat_luminance_alpha_float32
2961 * _mesa_texformat_intensity_float32
2964 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2966 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2967 const GLint components
= _mesa_components_in_format(baseFormat
);
2969 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2970 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2971 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2972 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2973 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2974 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
2975 dstFormat
== MESA_FORMAT_R_FLOAT32
||
2976 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
2977 ASSERT(baseInternalFormat
== GL_RGBA
||
2978 baseInternalFormat
== GL_RGB
||
2979 baseInternalFormat
== GL_ALPHA
||
2980 baseInternalFormat
== GL_LUMINANCE
||
2981 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2982 baseInternalFormat
== GL_INTENSITY
||
2983 baseInternalFormat
== GL_RED
||
2984 baseInternalFormat
== GL_RG
);
2985 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
2987 if (!ctx
->_ImageTransferState
&&
2988 !srcPacking
->SwapBytes
&&
2989 baseInternalFormat
== srcFormat
&&
2990 baseInternalFormat
== baseFormat
&&
2991 srcType
== GL_FLOAT
) {
2992 /* simple memcpy path */
2993 memcpy_texture(ctx
, dims
,
2995 dstRowStride
, dstSlices
,
2996 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2997 srcAddr
, srcPacking
);
3001 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3004 srcWidth
, srcHeight
, srcDepth
,
3005 srcFormat
, srcType
, srcAddr
,
3007 ctx
->_ImageTransferState
);
3008 const GLfloat
*srcRow
= tempImage
;
3013 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3014 for (img
= 0; img
< srcDepth
; img
++) {
3015 GLubyte
*dstRow
= dstSlices
[img
];
3016 for (row
= 0; row
< srcHeight
; row
++) {
3017 memcpy(dstRow
, srcRow
, bytesPerRow
);
3018 dstRow
+= dstRowStride
;
3019 srcRow
+= srcWidth
* components
;
3023 free((void *) tempImage
);
3031 * As above, but store 16-bit floats.
3034 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3036 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3037 const GLint components
= _mesa_components_in_format(baseFormat
);
3039 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3040 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3041 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3042 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3043 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3044 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3045 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3046 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3047 ASSERT(baseInternalFormat
== GL_RGBA
||
3048 baseInternalFormat
== GL_RGB
||
3049 baseInternalFormat
== GL_ALPHA
||
3050 baseInternalFormat
== GL_LUMINANCE
||
3051 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3052 baseInternalFormat
== GL_INTENSITY
||
3053 baseInternalFormat
== GL_RED
||
3054 baseInternalFormat
== GL_RG
);
3055 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
3057 if (!ctx
->_ImageTransferState
&&
3058 !srcPacking
->SwapBytes
&&
3059 baseInternalFormat
== srcFormat
&&
3060 baseInternalFormat
== baseFormat
&&
3061 srcType
== GL_HALF_FLOAT_ARB
) {
3062 /* simple memcpy path */
3063 memcpy_texture(ctx
, dims
,
3065 dstRowStride
, dstSlices
,
3066 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3067 srcAddr
, srcPacking
);
3071 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3074 srcWidth
, srcHeight
, srcDepth
,
3075 srcFormat
, srcType
, srcAddr
,
3077 ctx
->_ImageTransferState
);
3078 const GLfloat
*src
= tempImage
;
3082 for (img
= 0; img
< srcDepth
; img
++) {
3083 GLubyte
*dstRow
= dstSlices
[img
];
3084 for (row
= 0; row
< srcHeight
; row
++) {
3085 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3087 for (i
= 0; i
< srcWidth
* components
; i
++) {
3088 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3090 dstRow
+= dstRowStride
;
3091 src
+= srcWidth
* components
;
3095 free((void *) tempImage
);
3101 /* non-normalized, signed int8 */
3103 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3105 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3106 const GLint components
= _mesa_components_in_format(baseFormat
);
3108 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3109 dstFormat
== MESA_FORMAT_RG_INT8
||
3110 dstFormat
== MESA_FORMAT_RGB_INT8
||
3111 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3112 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3113 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3114 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3115 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3116 ASSERT(baseInternalFormat
== GL_RGBA
||
3117 baseInternalFormat
== GL_RGB
||
3118 baseInternalFormat
== GL_RG
||
3119 baseInternalFormat
== GL_RED
||
3120 baseInternalFormat
== GL_ALPHA
||
3121 baseInternalFormat
== GL_LUMINANCE
||
3122 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3123 baseInternalFormat
== GL_INTENSITY
);
3124 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
3126 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3127 * to integer formats.
3129 if (!srcPacking
->SwapBytes
&&
3130 baseInternalFormat
== srcFormat
&&
3131 srcType
== GL_BYTE
) {
3132 /* simple memcpy path */
3133 memcpy_texture(ctx
, dims
,
3135 dstRowStride
, dstSlices
,
3136 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3137 srcAddr
, srcPacking
);
3141 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3144 srcWidth
, srcHeight
, srcDepth
,
3148 const GLuint
*src
= tempImage
;
3152 for (img
= 0; img
< srcDepth
; img
++) {
3153 GLubyte
*dstRow
= dstSlices
[img
];
3154 for (row
= 0; row
< srcHeight
; row
++) {
3155 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3157 for (i
= 0; i
< srcWidth
* components
; i
++) {
3158 dstTexel
[i
] = (GLbyte
) src
[i
];
3160 dstRow
+= dstRowStride
;
3161 src
+= srcWidth
* components
;
3165 free((void *) tempImage
);
3171 /* non-normalized, signed int16 */
3173 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3175 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3176 const GLint components
= _mesa_components_in_format(baseFormat
);
3178 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3179 dstFormat
== MESA_FORMAT_RG_INT16
||
3180 dstFormat
== MESA_FORMAT_RGB_INT16
||
3181 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3182 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3183 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3184 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3185 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3186 ASSERT(baseInternalFormat
== GL_RGBA
||
3187 baseInternalFormat
== GL_RGB
||
3188 baseInternalFormat
== GL_RG
||
3189 baseInternalFormat
== GL_RED
||
3190 baseInternalFormat
== GL_ALPHA
||
3191 baseInternalFormat
== GL_LUMINANCE
||
3192 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3193 baseInternalFormat
== GL_INTENSITY
);
3194 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
3196 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3197 * to integer formats.
3199 if (!srcPacking
->SwapBytes
&&
3200 baseInternalFormat
== srcFormat
&&
3201 srcType
== GL_SHORT
) {
3202 /* simple memcpy path */
3203 memcpy_texture(ctx
, dims
,
3205 dstRowStride
, dstSlices
,
3206 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3207 srcAddr
, srcPacking
);
3211 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3214 srcWidth
, srcHeight
, srcDepth
,
3218 const GLuint
*src
= tempImage
;
3222 for (img
= 0; img
< srcDepth
; img
++) {
3223 GLubyte
*dstRow
= dstSlices
[img
];
3224 for (row
= 0; row
< srcHeight
; row
++) {
3225 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3227 for (i
= 0; i
< srcWidth
* components
; i
++) {
3228 dstTexel
[i
] = (GLint
) src
[i
];
3230 dstRow
+= dstRowStride
;
3231 src
+= srcWidth
* components
;
3235 free((void *) tempImage
);
3241 /* non-normalized, signed int32 */
3243 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3245 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3246 const GLint components
= _mesa_components_in_format(baseFormat
);
3248 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3249 dstFormat
== MESA_FORMAT_RG_INT32
||
3250 dstFormat
== MESA_FORMAT_RGB_INT32
||
3251 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3252 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3253 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3254 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3255 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3256 ASSERT(baseInternalFormat
== GL_RGBA
||
3257 baseInternalFormat
== GL_RGB
||
3258 baseInternalFormat
== GL_RG
||
3259 baseInternalFormat
== GL_RED
||
3260 baseInternalFormat
== GL_ALPHA
||
3261 baseInternalFormat
== GL_LUMINANCE
||
3262 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3263 baseInternalFormat
== GL_INTENSITY
);
3264 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
3266 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3267 * to integer formats.
3269 if (!srcPacking
->SwapBytes
&&
3270 baseInternalFormat
== srcFormat
&&
3271 srcType
== GL_INT
) {
3272 /* simple memcpy path */
3273 memcpy_texture(ctx
, dims
,
3275 dstRowStride
, dstSlices
,
3276 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3277 srcAddr
, srcPacking
);
3281 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3284 srcWidth
, srcHeight
, srcDepth
,
3288 const GLuint
*src
= tempImage
;
3292 for (img
= 0; img
< srcDepth
; img
++) {
3293 GLubyte
*dstRow
= dstSlices
[img
];
3294 for (row
= 0; row
< srcHeight
; row
++) {
3295 GLint
*dstTexel
= (GLint
*) dstRow
;
3297 for (i
= 0; i
< srcWidth
* components
; i
++) {
3298 dstTexel
[i
] = (GLint
) src
[i
];
3300 dstRow
+= dstRowStride
;
3301 src
+= srcWidth
* components
;
3305 free((void *) tempImage
);
3311 /* non-normalized, unsigned int8 */
3313 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3315 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3316 const GLint components
= _mesa_components_in_format(baseFormat
);
3318 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3319 dstFormat
== MESA_FORMAT_RG_UINT8
||
3320 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3321 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3322 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3323 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3324 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3325 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3326 ASSERT(baseInternalFormat
== GL_RGBA
||
3327 baseInternalFormat
== GL_RGB
||
3328 baseInternalFormat
== GL_RG
||
3329 baseInternalFormat
== GL_RED
||
3330 baseInternalFormat
== GL_ALPHA
||
3331 baseInternalFormat
== GL_LUMINANCE
||
3332 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3333 baseInternalFormat
== GL_INTENSITY
);
3334 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3336 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3337 * to integer formats.
3339 if (!srcPacking
->SwapBytes
&&
3340 baseInternalFormat
== srcFormat
&&
3341 srcType
== GL_UNSIGNED_BYTE
) {
3342 /* simple memcpy path */
3343 memcpy_texture(ctx
, dims
,
3345 dstRowStride
, dstSlices
,
3346 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3347 srcAddr
, srcPacking
);
3351 const GLuint
*tempImage
=
3352 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3353 srcWidth
, srcHeight
, srcDepth
,
3354 srcFormat
, srcType
, srcAddr
, srcPacking
);
3355 const GLuint
*src
= tempImage
;
3359 for (img
= 0; img
< srcDepth
; img
++) {
3360 GLubyte
*dstRow
= dstSlices
[img
];
3361 for (row
= 0; row
< srcHeight
; row
++) {
3362 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3364 for (i
= 0; i
< srcWidth
* components
; i
++) {
3365 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3367 dstRow
+= dstRowStride
;
3368 src
+= srcWidth
* components
;
3372 free((void *) tempImage
);
3378 /* non-normalized, unsigned int16 */
3380 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3382 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3383 const GLint components
= _mesa_components_in_format(baseFormat
);
3385 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3386 dstFormat
== MESA_FORMAT_RG_UINT16
||
3387 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3388 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3389 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3390 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3391 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3392 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3393 ASSERT(baseInternalFormat
== GL_RGBA
||
3394 baseInternalFormat
== GL_RGB
||
3395 baseInternalFormat
== GL_RG
||
3396 baseInternalFormat
== GL_RED
||
3397 baseInternalFormat
== GL_ALPHA
||
3398 baseInternalFormat
== GL_LUMINANCE
||
3399 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3400 baseInternalFormat
== GL_INTENSITY
);
3401 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3403 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3404 * to integer formats.
3406 if (!srcPacking
->SwapBytes
&&
3407 baseInternalFormat
== srcFormat
&&
3408 srcType
== GL_UNSIGNED_SHORT
) {
3409 /* simple memcpy path */
3410 memcpy_texture(ctx
, dims
,
3412 dstRowStride
, dstSlices
,
3413 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3414 srcAddr
, srcPacking
);
3418 const GLuint
*tempImage
=
3419 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3420 srcWidth
, srcHeight
, srcDepth
,
3421 srcFormat
, srcType
, srcAddr
, srcPacking
);
3422 const GLuint
*src
= tempImage
;
3426 for (img
= 0; img
< srcDepth
; img
++) {
3427 GLubyte
*dstRow
= dstSlices
[img
];
3428 for (row
= 0; row
< srcHeight
; row
++) {
3429 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3431 for (i
= 0; i
< srcWidth
* components
; i
++) {
3432 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3434 dstRow
+= dstRowStride
;
3435 src
+= srcWidth
* components
;
3439 free((void *) tempImage
);
3445 /* non-normalized, unsigned int32 */
3447 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3449 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3450 const GLint components
= _mesa_components_in_format(baseFormat
);
3452 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3453 dstFormat
== MESA_FORMAT_RG_UINT32
||
3454 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3455 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3456 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3457 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3458 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3459 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3460 ASSERT(baseInternalFormat
== GL_RGBA
||
3461 baseInternalFormat
== GL_RGB
||
3462 baseInternalFormat
== GL_RG
||
3463 baseInternalFormat
== GL_RED
||
3464 baseInternalFormat
== GL_ALPHA
||
3465 baseInternalFormat
== GL_LUMINANCE
||
3466 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3467 baseInternalFormat
== GL_INTENSITY
);
3468 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3470 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3471 * to integer formats.
3473 if (!srcPacking
->SwapBytes
&&
3474 baseInternalFormat
== srcFormat
&&
3475 srcType
== GL_UNSIGNED_INT
) {
3476 /* simple memcpy path */
3477 memcpy_texture(ctx
, dims
,
3479 dstRowStride
, dstSlices
,
3480 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3481 srcAddr
, srcPacking
);
3485 const GLuint
*tempImage
=
3486 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3487 srcWidth
, srcHeight
, srcDepth
,
3488 srcFormat
, srcType
, srcAddr
, srcPacking
);
3489 const GLuint
*src
= tempImage
;
3493 for (img
= 0; img
< srcDepth
; img
++) {
3494 GLubyte
*dstRow
= dstSlices
[img
];
3495 for (row
= 0; row
< srcHeight
; row
++) {
3496 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3498 for (i
= 0; i
< srcWidth
* components
; i
++) {
3499 dstTexel
[i
] = src
[i
];
3501 dstRow
+= dstRowStride
;
3502 src
+= srcWidth
* components
;
3506 free((void *) tempImage
);
3514 #if FEATURE_EXT_texture_sRGB
3516 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3518 gl_format newDstFormat
;
3521 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3523 /* reuse normal rgb texstore code */
3524 newDstFormat
= MESA_FORMAT_RGB888
;
3526 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3528 dstRowStride
, dstSlices
,
3529 srcWidth
, srcHeight
, srcDepth
,
3531 srcAddr
, srcPacking
);
3537 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3539 gl_format newDstFormat
;
3542 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3544 /* reuse normal rgba texstore code */
3545 newDstFormat
= MESA_FORMAT_RGBA8888
;
3546 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3548 dstRowStride
, dstSlices
,
3549 srcWidth
, srcHeight
, srcDepth
,
3551 srcAddr
, srcPacking
);
3557 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3559 gl_format newDstFormat
;
3562 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3564 /* reuse normal rgba texstore code */
3565 newDstFormat
= MESA_FORMAT_ARGB8888
;
3567 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3569 dstRowStride
, dstSlices
,
3570 srcWidth
, srcHeight
, srcDepth
,
3572 srcAddr
, srcPacking
);
3578 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3580 gl_format newDstFormat
;
3583 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3585 newDstFormat
= MESA_FORMAT_L8
;
3587 /* _mesa_textore_a8 handles luminance8 too */
3588 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3590 dstRowStride
, dstSlices
,
3591 srcWidth
, srcHeight
, srcDepth
,
3593 srcAddr
, srcPacking
);
3599 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3601 gl_format newDstFormat
;
3604 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3606 /* reuse normal luminance/alpha texstore code */
3607 newDstFormat
= MESA_FORMAT_AL88
;
3609 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3611 dstRowStride
, dstSlices
,
3612 srcWidth
, srcHeight
, srcDepth
,
3614 srcAddr
, srcPacking
);
3620 /* these are used only in texstore_funcs[] below */
3621 #define _mesa_texstore_srgb8 NULL
3622 #define _mesa_texstore_srgba8 NULL
3623 #define _mesa_texstore_sargb8 NULL
3624 #define _mesa_texstore_sl8 NULL
3625 #define _mesa_texstore_sla8 NULL
3627 #endif /* FEATURE_EXT_texture_sRGB */
3630 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3632 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3634 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3635 ASSERT(baseInternalFormat
== GL_RGB
);
3637 if (!ctx
->_ImageTransferState
&&
3638 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3639 srcPacking
->SwapBytes
)) {
3640 /* simple memcpy path */
3641 memcpy_texture(ctx
, dims
,
3643 dstRowStride
, dstSlices
,
3644 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3645 srcAddr
, srcPacking
);
3649 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3652 srcWidth
, srcHeight
, srcDepth
,
3653 srcFormat
, srcType
, srcAddr
,
3655 ctx
->_ImageTransferState
);
3656 const GLfloat
*srcRow
= tempImage
;
3657 GLint img
, row
, col
;
3660 for (img
= 0; img
< srcDepth
; img
++) {
3661 GLubyte
*dstRow
= dstSlices
[img
];
3662 for (row
= 0; row
< srcHeight
; row
++) {
3663 GLuint
*dstUI
= (GLuint
*)dstRow
;
3664 for (col
= 0; col
< srcWidth
; col
++) {
3665 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3667 dstRow
+= dstRowStride
;
3668 srcRow
+= srcWidth
* 3;
3672 free((void *) tempImage
);
3678 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3680 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3682 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
3683 ASSERT(baseInternalFormat
== GL_RGB
);
3685 if (!ctx
->_ImageTransferState
&&
3686 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3687 srcPacking
->SwapBytes
)) {
3688 /* simple memcpy path */
3689 memcpy_texture(ctx
, dims
,
3691 dstRowStride
, dstSlices
,
3692 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3693 srcAddr
, srcPacking
);
3697 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3700 srcWidth
, srcHeight
, srcDepth
,
3701 srcFormat
, srcType
, srcAddr
,
3703 ctx
->_ImageTransferState
);
3704 const GLfloat
*srcRow
= tempImage
;
3705 GLint img
, row
, col
;
3708 for (img
= 0; img
< srcDepth
; img
++) {
3709 GLubyte
*dstRow
= dstSlices
[img
];
3710 for (row
= 0; row
< srcHeight
; row
++) {
3711 GLuint
*dstUI
= (GLuint
*)dstRow
;
3712 for (col
= 0; col
< srcWidth
; col
++) {
3713 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3715 dstRow
+= dstRowStride
;
3716 srcRow
+= srcWidth
* 3;
3720 free((void *) tempImage
);
3727 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3729 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
3730 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3731 srcFormat
== GL_DEPTH_COMPONENT
||
3732 srcFormat
== GL_STENCIL_INDEX
);
3733 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3734 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3736 if (srcFormat
== GL_DEPTH_STENCIL
&&
3737 ctx
->Pixel
.DepthScale
== 1.0f
&&
3738 ctx
->Pixel
.DepthBias
== 0.0f
&&
3739 !srcPacking
->SwapBytes
) {
3741 memcpy_texture(ctx
, dims
,
3743 dstRowStride
, dstSlices
,
3744 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3745 srcAddr
, srcPacking
);
3747 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3748 srcFormat
== GL_STENCIL_INDEX
) {
3750 const GLint srcRowStride
3751 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3754 /* In case we only upload depth we need to preserve the stencil */
3755 for (img
= 0; img
< srcDepth
; img
++) {
3756 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
3758 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3759 srcWidth
, srcHeight
,
3762 for (row
= 0; row
< srcHeight
; row
++) {
3763 /* The unpack functions with:
3764 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
3765 * only write their own dword, so the other dword (stencil
3766 * or depth) is preserved. */
3767 if (srcFormat
!= GL_STENCIL_INDEX
)
3768 _mesa_unpack_depth_span(ctx
, srcWidth
,
3769 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3770 dstRow
, /* dst addr */
3771 ~0U, srcType
, src
, srcPacking
);
3773 if (srcFormat
!= GL_DEPTH_COMPONENT
)
3774 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3775 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3776 dstRow
, /* dst addr */
3777 srcType
, src
, srcPacking
,
3778 ctx
->_ImageTransferState
);
3780 src
+= srcRowStride
;
3781 dstRow
+= dstRowStride
/ sizeof(uint64_t);
3789 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
3791 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3793 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
3794 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3796 if (baseInternalFormat
== GL_RGBA
&&
3797 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3798 srcPacking
->SwapBytes
)) {
3799 /* simple memcpy path */
3800 memcpy_texture(ctx
, dims
,
3802 dstRowStride
, dstSlices
,
3803 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3804 srcAddr
, srcPacking
);
3808 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3811 srcWidth
, srcHeight
,
3812 srcDepth
, srcFormat
,
3815 const GLuint
*src
= tempImage
;
3816 GLint img
, row
, col
;
3819 for (img
= 0; img
< srcDepth
; img
++) {
3820 GLubyte
*dstRow
= dstSlices
[img
];
3822 for (row
= 0; row
< srcHeight
; row
++) {
3823 GLuint
*dstUI
= (GLuint
*) dstRow
;
3824 for (col
= 0; col
< srcWidth
; col
++) {
3830 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3833 dstRow
+= dstRowStride
;
3836 free((void *) tempImage
);
3842 _mesa_texstore_null(TEXSTORE_PARAMS
)
3844 (void) ctx
; (void) dims
;
3845 (void) baseInternalFormat
;
3847 (void) dstRowStride
; (void) dstSlices
,
3848 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3849 (void) srcFormat
; (void) srcType
;
3853 /* should never happen */
3854 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3860 * Return the StoreTexImageFunc pointer to store an image in the given format.
3862 static StoreTexImageFunc
3863 _mesa_get_texstore_func(gl_format format
)
3865 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3866 static GLboolean initialized
= GL_FALSE
;
3869 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
3871 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
3872 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
3873 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
3874 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
3875 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
3876 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
3877 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
3878 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
3879 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
3880 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
3881 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
3882 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
3883 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
3884 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
3885 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
3886 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
3887 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
3888 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
3889 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
3890 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
3891 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
3892 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
3893 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
3894 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
3895 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
3896 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
3897 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
3898 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
3899 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
3900 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3901 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3902 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
3903 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
3904 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
3905 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
3906 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
3907 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
3908 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
3909 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
3910 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
3911 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
3912 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
3913 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
3914 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
3915 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
3916 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
3917 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
3918 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
3919 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
3920 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
3921 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3922 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3923 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3924 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3925 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
3926 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
3927 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3928 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3929 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3930 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3931 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3932 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3933 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3934 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3935 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3936 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3937 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
3938 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
3939 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3940 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3941 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
3942 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
3943 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
3944 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
3945 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
3946 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
3947 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
3948 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
3949 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
3950 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
3951 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
3952 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
3953 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
3954 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
3955 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
3956 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
3957 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
3958 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
3959 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
3960 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
3961 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
3962 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
3963 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
3964 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
3965 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
3966 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
3967 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
3968 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
3969 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
3970 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
3971 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
3972 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
3973 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
3974 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
3975 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
3976 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
3977 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
3978 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
3980 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
3981 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
3982 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
3983 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
3984 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
3985 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
3987 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
3988 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
3989 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
3990 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
3991 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
3992 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
3994 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
3995 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
3996 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
3997 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
3998 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
3999 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4001 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4002 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4003 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4004 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4005 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4006 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4008 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4009 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4010 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4011 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4012 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4013 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4014 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4015 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4016 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4017 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4018 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4019 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4021 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4022 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4023 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4024 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4025 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4026 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4027 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4028 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4029 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4030 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4031 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4032 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4034 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4035 initialized
= GL_TRUE
;
4038 ASSERT(table
[format
]);
4039 return table
[format
];
4044 * Store user data into texture memory.
4045 * Called via glTex[Sub]Image1/2/3D()
4048 _mesa_texstore(TEXSTORE_PARAMS
)
4050 StoreTexImageFunc storeImage
;
4053 storeImage
= _mesa_get_texstore_func(dstFormat
);
4055 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4057 dstRowStride
, dstSlices
,
4058 srcWidth
, srcHeight
, srcDepth
,
4059 srcFormat
, srcType
, srcAddr
, srcPacking
);
4065 * Normally, we'll only _write_ texel data to a texture when we map it.
4066 * But if the user is providing depth or stencil values and the texture
4067 * image is a combined depth/stencil format, we'll actually read from
4068 * the texture buffer too (in order to insert the depth or stencil values.
4069 * \param userFormat the user-provided image format
4070 * \param texFormat the destination texture format
4073 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4075 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4076 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4077 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4079 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
4084 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4086 * The source of the image data may be user memory or a PBO. In the later
4087 * case, we'll map the PBO, copy from it, then unmap it.
4090 store_texsubimage(struct gl_context
*ctx
,
4091 struct gl_texture_image
*texImage
,
4092 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4093 GLint width
, GLint height
, GLint depth
,
4094 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4095 const struct gl_pixelstore_attrib
*packing
,
4099 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4100 const GLenum target
= texImage
->TexObject
->Target
;
4101 GLboolean success
= GL_FALSE
;
4102 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4103 GLint srcImageStride
= 0;
4106 assert(xoffset
+ width
<= texImage
->Width
);
4107 assert(yoffset
+ height
<= texImage
->Height
);
4108 assert(zoffset
+ depth
<= texImage
->Depth
);
4114 case GL_TEXTURE_2D_ARRAY
:
4122 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4123 src
= (const GLubyte
*)
4124 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4125 format
, type
, pixels
, packing
, caller
);
4129 /* compute slice info (and do some sanity checks) */
4132 case GL_TEXTURE_RECTANGLE
:
4133 case GL_TEXTURE_CUBE_MAP
:
4134 /* one image slice, nothing special needs to be done */
4137 assert(height
== 1);
4139 assert(yoffset
== 0);
4140 assert(zoffset
== 0);
4142 case GL_TEXTURE_1D_ARRAY
:
4144 assert(zoffset
== 0);
4146 sliceOffset
= yoffset
;
4149 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4151 case GL_TEXTURE_2D_ARRAY
:
4153 sliceOffset
= zoffset
;
4156 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4160 /* we'll store 3D images as a series of slices */
4162 sliceOffset
= zoffset
;
4163 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4167 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4171 assert(numSlices
== 1 || srcImageStride
!= 0);
4173 for (slice
= 0; slice
< numSlices
; slice
++) {
4177 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4178 slice
+ sliceOffset
,
4179 xoffset
, yoffset
, width
, height
,
4180 mapMode
, &dstMap
, &dstRowStride
);
4182 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4183 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4184 * used for 3D images.
4186 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4187 texImage
->TexFormat
,
4190 width
, height
, 1, /* w, h, d */
4191 format
, type
, src
, packing
);
4193 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4196 src
+= srcImageStride
;
4203 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4205 _mesa_unmap_teximage_pbo(ctx
, packing
);
4211 * This is the fallback for Driver.TexImage1D().
4214 _mesa_store_teximage1d(struct gl_context
*ctx
,
4215 struct gl_texture_image
*texImage
,
4216 GLint internalFormat
,
4217 GLint width
, GLint border
,
4218 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4219 const struct gl_pixelstore_attrib
*packing
)
4224 /* allocate storage for texture data */
4225 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4227 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4231 store_texsubimage(ctx
, texImage
,
4232 0, 0, 0, width
, 1, 1,
4233 format
, type
, pixels
, packing
, "glTexImage1D");
4238 * This is the fallback for Driver.TexImage2D().
4241 _mesa_store_teximage2d(struct gl_context
*ctx
,
4242 struct gl_texture_image
*texImage
,
4243 GLint internalFormat
,
4244 GLint width
, GLint height
, GLint border
,
4245 GLenum format
, GLenum type
, const void *pixels
,
4246 const struct gl_pixelstore_attrib
*packing
)
4248 if (width
== 0 || height
== 0)
4251 /* allocate storage for texture data */
4252 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4253 width
, height
, 1)) {
4254 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4258 store_texsubimage(ctx
, texImage
,
4259 0, 0, 0, width
, height
, 1,
4260 format
, type
, pixels
, packing
, "glTexImage2D");
4266 * This is the fallback for Driver.TexImage3D().
4269 _mesa_store_teximage3d(struct gl_context
*ctx
,
4270 struct gl_texture_image
*texImage
,
4271 GLint internalFormat
,
4272 GLint width
, GLint height
, GLint depth
, GLint border
,
4273 GLenum format
, GLenum type
, const void *pixels
,
4274 const struct gl_pixelstore_attrib
*packing
)
4276 if (width
== 0 || height
== 0 || depth
== 0)
4279 /* allocate storage for texture data */
4280 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4281 width
, height
, depth
)) {
4282 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4286 store_texsubimage(ctx
, texImage
,
4287 0, 0, 0, width
, height
, depth
,
4288 format
, type
, pixels
, packing
, "glTexImage3D");
4295 * This is the fallback for Driver.TexSubImage1D().
4298 _mesa_store_texsubimage1d(struct gl_context
*ctx
,
4299 struct gl_texture_image
*texImage
,
4300 GLint xoffset
, GLint width
,
4301 GLenum format
, GLenum type
, const void *pixels
,
4302 const struct gl_pixelstore_attrib
*packing
)
4304 store_texsubimage(ctx
, texImage
,
4305 xoffset
, 0, 0, width
, 1, 1,
4306 format
, type
, pixels
, packing
, "glTexSubImage1D");
4312 * This is the fallback for Driver.TexSubImage2D().
4315 _mesa_store_texsubimage2d(struct gl_context
*ctx
,
4316 struct gl_texture_image
*texImage
,
4317 GLint xoffset
, GLint yoffset
,
4318 GLint width
, GLint height
,
4319 GLenum format
, GLenum type
, const void *pixels
,
4320 const struct gl_pixelstore_attrib
*packing
)
4322 store_texsubimage(ctx
, texImage
,
4323 xoffset
, yoffset
, 0, width
, height
, 1,
4324 format
, type
, pixels
, packing
, "glTexSubImage2D");
4329 * This is the fallback for Driver.TexSubImage3D().
4332 _mesa_store_texsubimage3d(struct gl_context
*ctx
,
4333 struct gl_texture_image
*texImage
,
4334 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4335 GLint width
, GLint height
, GLint depth
,
4336 GLenum format
, GLenum type
, const void *pixels
,
4337 const struct gl_pixelstore_attrib
*packing
)
4339 store_texsubimage(ctx
, texImage
,
4340 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4341 format
, type
, pixels
, packing
, "glTexSubImage3D");
4346 * Fallback for Driver.CompressedTexImage1D()
4349 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
,
4350 struct gl_texture_image
*texImage
,
4351 GLint internalFormat
,
4352 GLint width
, GLint border
,
4353 GLsizei imageSize
, const GLvoid
*data
)
4355 /* no compressed 1D image formats at this time */
4357 (void) internalFormat
;
4358 (void) width
; (void) border
;
4359 (void) imageSize
; (void) data
;
4366 * Fallback for Driver.CompressedTexImage2D()
4369 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
,
4370 struct gl_texture_image
*texImage
,
4371 GLint internalFormat
,
4372 GLint width
, GLint height
, GLint border
,
4373 GLsizei imageSize
, const GLvoid
*data
)
4375 /* This is pretty simple, because unlike the general texstore path we don't
4376 * have to worry about the usual image unpacking or image transfer
4380 ASSERT(texImage
->Width
> 0);
4381 ASSERT(texImage
->Height
> 0);
4382 ASSERT(texImage
->Depth
== 1);
4384 /* allocate storage for texture data */
4385 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4386 width
, height
, 1)) {
4387 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4391 _mesa_store_compressed_texsubimage2d(ctx
, texImage
,
4394 texImage
->TexFormat
,
4401 * Fallback for Driver.CompressedTexImage3D()
4404 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
,
4405 struct gl_texture_image
*texImage
,
4406 GLint internalFormat
,
4407 GLint width
, GLint height
, GLint depth
,
4409 GLsizei imageSize
, const GLvoid
*data
)
4411 /* this space intentionally left blank */
4413 (void) internalFormat
;
4414 (void) width
; (void) height
; (void) depth
;
4416 (void) imageSize
; (void) data
;
4423 * Fallback for Driver.CompressedTexSubImage1D()
4426 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
,
4427 struct gl_texture_image
*texImage
,
4428 GLint xoffset
, GLsizei width
,
4430 GLsizei imageSize
, const GLvoid
*data
)
4432 /* there are no compressed 1D texture formats yet */
4434 (void) xoffset
; (void) width
;
4436 (void) imageSize
; (void) data
;
4442 * Fallback for Driver.CompressedTexSubImage2D()
4445 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
,
4446 struct gl_texture_image
*texImage
,
4447 GLint xoffset
, GLint yoffset
,
4448 GLsizei width
, GLsizei height
,
4450 GLsizei imageSize
, const GLvoid
*data
)
4452 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4456 const gl_format texFormat
= texImage
->TexFormat
;
4459 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4461 /* these should have been caught sooner */
4462 ASSERT((width
% bw
) == 0 || width
< bw
);
4463 ASSERT((height
% bh
) == 0 || height
< bh
);
4464 ASSERT((xoffset
% bw
) == 0);
4465 ASSERT((yoffset
% bh
) == 0);
4467 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4468 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4470 "glCompressedTexSubImage2D");
4474 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4475 src
= (const GLubyte
*) data
;
4477 /* Map dest texture buffer */
4478 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4479 xoffset
, yoffset
, width
, height
,
4480 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4481 &dstMap
, &dstRowStride
);
4484 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4485 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4487 /* copy rows of blocks */
4488 for (i
= 0; i
< rows
; i
++) {
4489 memcpy(dstMap
, src
, bytesPerRow
);
4490 dstMap
+= dstRowStride
;
4491 src
+= srcRowStride
;
4494 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4497 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
4500 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4505 * Fallback for Driver.CompressedTexSubImage3D()
4508 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
,
4509 struct gl_texture_image
*texImage
,
4510 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4511 GLsizei width
, GLsizei height
, GLsizei depth
,
4513 GLsizei imageSize
, const GLvoid
*data
)
4515 /* there are no compressed 3D texture formats yet */
4517 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4518 (void) width
; (void) height
; (void) depth
;
4520 (void) imageSize
; (void) data
;