2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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.TexImage = _mesa_store_teximage;
41 * ctx->Driver.TexSubImage = _mesa_store_texsubimage;
44 * Texture image processing is actually kind of complicated. We have to do:
45 * Format/type conversions
47 * pixel transfer (scale, bais, lookup, etc)
49 * These functions can handle most everything, including processing full
50 * images and sub-images.
55 #include "bufferobj.h"
57 #include "format_pack.h"
58 #include "format_utils.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
74 #include "glformats.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
)
238 case GL_LUMINANCE_INTEGER_EXT
:
239 return IDX_LUMINANCE
;
241 case GL_ALPHA_INTEGER
:
244 return IDX_INTENSITY
;
245 case GL_LUMINANCE_ALPHA
:
246 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
247 return IDX_LUMINANCE_ALPHA
;
252 case GL_RGBA_INTEGER
:
265 case GL_BGRA_INTEGER
:
273 _mesa_problem(NULL
, "Unexpected inFormat %s",
274 _mesa_lookup_enum_by_nr(value
));
281 * When promoting texture formats (see below) we need to compute the
282 * mapping of dest components back to source components.
283 * This function does that.
284 * \param inFormat the incoming format of the texture
285 * \param outFormat the final texture format
286 * \return map[6] a full 6-component map
289 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
292 const int inFmt
= get_map_idx(inFormat
);
293 const int outFmt
= get_map_idx(outFormat
);
294 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
295 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
298 for (i
= 0; i
< 4; i
++)
299 map
[i
] = in2rgba
[rgba2out
[i
]];
305 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
306 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
307 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
319 * Make a temporary (color) texture image with GLfloat components.
320 * Apply all needed pixel unpacking and pixel transfer operations.
321 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
322 * Suppose the user specifies GL_LUMINANCE as the internal texture format
323 * but the graphics hardware doesn't support luminance textures. So, we might
324 * use an RGB hardware format instead.
325 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
327 * \param ctx the rendering context
328 * \param dims image dimensions: 1, 2 or 3
329 * \param logicalBaseFormat basic texture derived from the user's
330 * internal texture format value
331 * \param textureBaseFormat the actual basic format of the texture
332 * \param srcWidth source image width
333 * \param srcHeight source image height
334 * \param srcDepth source image depth
335 * \param srcFormat source image format
336 * \param srcType source image type
337 * \param srcAddr source image address
338 * \param srcPacking source image pixel packing
339 * \return resulting image with format = textureBaseFormat and type = GLfloat.
342 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
343 GLenum logicalBaseFormat
,
344 GLenum textureBaseFormat
,
345 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
346 GLenum srcFormat
, GLenum srcType
,
347 const GLvoid
*srcAddr
,
348 const struct gl_pixelstore_attrib
*srcPacking
,
349 GLbitfield transferOps
)
352 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
353 const GLint srcStride
=
354 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
358 ASSERT(dims
>= 1 && dims
<= 3);
360 ASSERT(logicalBaseFormat
== GL_RGBA
||
361 logicalBaseFormat
== GL_RGB
||
362 logicalBaseFormat
== GL_RG
||
363 logicalBaseFormat
== GL_RED
||
364 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
365 logicalBaseFormat
== GL_LUMINANCE
||
366 logicalBaseFormat
== GL_ALPHA
||
367 logicalBaseFormat
== GL_INTENSITY
||
368 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
370 ASSERT(textureBaseFormat
== GL_RGBA
||
371 textureBaseFormat
== GL_RGB
||
372 textureBaseFormat
== GL_RG
||
373 textureBaseFormat
== GL_RED
||
374 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
375 textureBaseFormat
== GL_LUMINANCE
||
376 textureBaseFormat
== GL_ALPHA
||
377 textureBaseFormat
== GL_INTENSITY
||
378 textureBaseFormat
== GL_DEPTH_COMPONENT
);
380 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
381 * components
* sizeof(GLfloat
));
386 for (img
= 0; img
< srcDepth
; img
++) {
388 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
392 for (row
= 0; row
< srcHeight
; row
++) {
393 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
394 dst
, srcFormat
, srcType
, src
,
395 srcPacking
, transferOps
);
396 dst
+= srcWidth
* components
;
401 if (logicalBaseFormat
!= textureBaseFormat
) {
403 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
404 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
409 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
410 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
411 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
413 /* The actual texture format should have at least as many components
414 * as the logical texture format.
416 ASSERT(texComponents
>= logComponents
);
418 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
419 * texComponents
* sizeof(GLfloat
));
425 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
427 n
= srcWidth
* srcHeight
* srcDepth
;
428 for (i
= 0; i
< n
; i
++) {
430 for (k
= 0; k
< texComponents
; k
++) {
433 newImage
[i
* texComponents
+ k
] = 0.0F
;
435 newImage
[i
* texComponents
+ k
] = 1.0F
;
437 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
442 tempImage
= newImage
;
450 * Make temporary image with uint pixel values. Used for unsigned
451 * integer-valued textures.
454 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
455 GLenum logicalBaseFormat
,
456 GLenum textureBaseFormat
,
457 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
458 GLenum srcFormat
, GLenum srcType
,
459 const GLvoid
*srcAddr
,
460 const struct gl_pixelstore_attrib
*srcPacking
)
463 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
464 const GLint srcStride
=
465 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
469 ASSERT(dims
>= 1 && dims
<= 3);
471 ASSERT(logicalBaseFormat
== GL_RGBA
||
472 logicalBaseFormat
== GL_RGB
||
473 logicalBaseFormat
== GL_RG
||
474 logicalBaseFormat
== GL_RED
||
475 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
476 logicalBaseFormat
== GL_LUMINANCE
||
477 logicalBaseFormat
== GL_INTENSITY
||
478 logicalBaseFormat
== GL_ALPHA
);
480 ASSERT(textureBaseFormat
== GL_RGBA
||
481 textureBaseFormat
== GL_RGB
||
482 textureBaseFormat
== GL_RG
||
483 textureBaseFormat
== GL_RED
||
484 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
485 textureBaseFormat
== GL_LUMINANCE
||
486 textureBaseFormat
== GL_INTENSITY
||
487 textureBaseFormat
== GL_ALPHA
);
489 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
490 * components
* sizeof(GLuint
));
495 for (img
= 0; img
< srcDepth
; img
++) {
497 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
501 for (row
= 0; row
< srcHeight
; row
++) {
502 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
503 dst
, srcFormat
, srcType
, src
,
505 dst
+= srcWidth
* components
;
510 if (logicalBaseFormat
!= textureBaseFormat
) {
512 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
513 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
518 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
519 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
520 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
522 /* The actual texture format should have at least as many components
523 * as the logical texture format.
525 ASSERT(texComponents
>= logComponents
);
527 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
528 * texComponents
* sizeof(GLuint
));
534 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
536 n
= srcWidth
* srcHeight
* srcDepth
;
537 for (i
= 0; i
< n
; i
++) {
539 for (k
= 0; k
< texComponents
; k
++) {
542 newImage
[i
* texComponents
+ k
] = 0;
544 newImage
[i
* texComponents
+ k
] = 1;
546 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
551 tempImage
= newImage
;
560 * Make a temporary (color) texture image with GLubyte components.
561 * Apply all needed pixel unpacking and pixel transfer operations.
562 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
563 * Suppose the user specifies GL_LUMINANCE as the internal texture format
564 * but the graphics hardware doesn't support luminance textures. So, we might
565 * use an RGB hardware format instead.
566 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
568 * \param ctx the rendering context
569 * \param dims image dimensions: 1, 2 or 3
570 * \param logicalBaseFormat basic texture derived from the user's
571 * internal texture format value
572 * \param textureBaseFormat the actual basic format of the texture
573 * \param srcWidth source image width
574 * \param srcHeight source image height
575 * \param srcDepth source image depth
576 * \param srcFormat source image format
577 * \param srcType source image type
578 * \param srcAddr source image address
579 * \param srcPacking source image pixel packing
580 * \return resulting image with format = textureBaseFormat and type = GLubyte.
583 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
584 GLenum logicalBaseFormat
,
585 GLenum textureBaseFormat
,
586 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
587 GLenum srcFormat
, GLenum srcType
,
588 const GLvoid
*srcAddr
,
589 const struct gl_pixelstore_attrib
*srcPacking
)
591 GLuint transferOps
= ctx
->_ImageTransferState
;
592 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
594 GLubyte
*tempImage
, *dst
;
596 ASSERT(dims
>= 1 && dims
<= 3);
598 ASSERT(logicalBaseFormat
== GL_RGBA
||
599 logicalBaseFormat
== GL_RGB
||
600 logicalBaseFormat
== GL_RG
||
601 logicalBaseFormat
== GL_RED
||
602 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
603 logicalBaseFormat
== GL_LUMINANCE
||
604 logicalBaseFormat
== GL_ALPHA
||
605 logicalBaseFormat
== GL_INTENSITY
);
607 ASSERT(textureBaseFormat
== GL_RGBA
||
608 textureBaseFormat
== GL_RGB
||
609 textureBaseFormat
== GL_RG
||
610 textureBaseFormat
== GL_RED
||
611 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
612 textureBaseFormat
== GL_LUMINANCE
||
613 textureBaseFormat
== GL_ALPHA
||
614 textureBaseFormat
== GL_INTENSITY
);
616 /* unpack and transfer the source image */
617 tempImage
= malloc(srcWidth
* srcHeight
* srcDepth
618 * components
* sizeof(GLubyte
));
624 for (img
= 0; img
< srcDepth
; img
++) {
625 const GLint srcStride
=
626 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
628 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
632 for (row
= 0; row
< srcHeight
; row
++) {
633 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
634 srcFormat
, srcType
, src
, srcPacking
,
636 dst
+= srcWidth
* components
;
641 if (logicalBaseFormat
!= textureBaseFormat
) {
642 /* one more conversion step */
643 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
644 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
649 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
650 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
651 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
653 /* The actual texture format should have at least as many components
654 * as the logical texture format.
656 ASSERT(texComponents
>= logComponents
);
658 newImage
= malloc(srcWidth
* srcHeight
* srcDepth
659 * texComponents
* sizeof(GLubyte
));
665 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
667 n
= srcWidth
* srcHeight
* srcDepth
;
668 for (i
= 0; i
< n
; i
++) {
670 for (k
= 0; k
< texComponents
; k
++) {
673 newImage
[i
* texComponents
+ k
] = 0;
675 newImage
[i
* texComponents
+ k
] = 255;
677 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
682 tempImage
= newImage
;
690 * Copy GLubyte pixels from <src> to <dst> with swizzling.
691 * \param dst destination pixels
692 * \param dstComponents number of color components in destination pixels
693 * \param src source pixels
694 * \param srcComponents number of color components in source pixels
695 * \param map the swizzle mapping. map[X] says where to find the X component
696 * in the source image's pixels. For example, if the source image
697 * is GL_BGRA and X = red, map[0] yields 2.
698 * \param count number of pixels to copy/swizzle.
701 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
702 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
704 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
707 for (i = 0; i < count; i++) { \
709 if (srcComps == 4) { \
710 COPY_4UBV(tmp, src); \
713 for (j = 0; j < srcComps; j++) { \
718 for (j = 0; j < dstComps; j++) { \
719 dst[j] = tmp[map[j]]; \
730 ASSERT(srcComponents
<= 4);
731 ASSERT(dstComponents
<= 4);
733 switch (dstComponents
) {
735 switch (srcComponents
) {
737 SWZ_CPY(dst
, src
, count
, 4, 4);
740 SWZ_CPY(dst
, src
, count
, 4, 3);
743 SWZ_CPY(dst
, src
, count
, 4, 2);
746 SWZ_CPY(dst
, src
, count
, 4, 1);
753 switch (srcComponents
) {
755 SWZ_CPY(dst
, src
, count
, 3, 4);
758 SWZ_CPY(dst
, src
, count
, 3, 3);
761 SWZ_CPY(dst
, src
, count
, 3, 2);
764 SWZ_CPY(dst
, src
, count
, 3, 1);
771 switch (srcComponents
) {
773 SWZ_CPY(dst
, src
, count
, 2, 4);
776 SWZ_CPY(dst
, src
, count
, 2, 3);
779 SWZ_CPY(dst
, src
, count
, 2, 2);
782 SWZ_CPY(dst
, src
, count
, 2, 1);
789 switch (srcComponents
) {
791 SWZ_CPY(dst
, src
, count
, 1, 4);
794 SWZ_CPY(dst
, src
, count
, 1, 3);
797 SWZ_CPY(dst
, src
, count
, 1, 2);
800 SWZ_CPY(dst
, src
, count
, 1, 1);
814 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
815 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
816 static const GLubyte map_1032
[6] = { 1, 0, 3, 2, ZERO
, ONE
};
820 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
821 * mapping array depending on endianness.
823 static const GLubyte
*
824 type_mapping( GLenum srcType
)
828 case GL_UNSIGNED_BYTE
:
830 case GL_UNSIGNED_INT_8_8_8_8
:
831 return _mesa_little_endian() ? map_3210
: map_identity
;
832 case GL_UNSIGNED_INT_8_8_8_8_REV
:
833 return _mesa_little_endian() ? map_identity
: map_3210
;
841 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
842 * mapping array depending on pixelstore byte swapping state.
844 static const GLubyte
*
845 byteswap_mapping( GLboolean swapBytes
,
853 case GL_UNSIGNED_BYTE
:
855 case GL_UNSIGNED_SHORT
:
857 case GL_UNSIGNED_INT
:
861 case GL_UNSIGNED_INT_8_8_8_8
:
862 case GL_UNSIGNED_INT_8_8_8_8_REV
:
872 * Transfer a GLubyte texture image with component swizzling.
875 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
880 GLenum baseInternalFormat
,
882 const GLubyte
*rgba2dst
,
883 GLuint dstComponents
,
888 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
889 const GLvoid
*srcAddr
,
890 const struct gl_pixelstore_attrib
*srcPacking
)
892 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
893 const GLubyte
*srctype2ubyte
, *swap
;
894 GLubyte map
[4], src2base
[6], base2rgba
[6];
896 const GLint srcRowStride
=
897 _mesa_image_row_stride(srcPacking
, srcWidth
,
898 srcFormat
, GL_UNSIGNED_BYTE
);
899 const GLint srcImageStride
900 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
902 const GLubyte
*srcImage
903 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
904 srcWidth
, srcHeight
, srcFormat
,
905 GL_UNSIGNED_BYTE
, 0, 0, 0);
909 /* Translate from src->baseInternal->GL_RGBA->dst. This will
910 * correctly deal with RGBA->RGB->RGBA conversions where the final
911 * A value must be 0xff regardless of the incoming alpha values.
913 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
914 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
915 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
916 srctype2ubyte
= type_mapping(srcType
);
919 for (i
= 0; i
< 4; i
++)
920 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
922 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
924 if (srcComponents
== dstComponents
&&
925 srcRowStride
== dstRowStride
&&
926 srcRowStride
== srcWidth
* srcComponents
&&
928 /* 1 and 2D images only */
929 GLubyte
*dstImage
= dstSlices
[0];
930 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
931 srcWidth
* srcHeight
);
935 for (img
= 0; img
< srcDepth
; img
++) {
936 const GLubyte
*srcRow
= srcImage
;
937 GLubyte
*dstRow
= dstSlices
[img
];
938 for (row
= 0; row
< srcHeight
; row
++) {
939 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
940 dstRow
+= dstRowStride
;
941 srcRow
+= srcRowStride
;
943 srcImage
+= srcImageStride
;
950 * Teximage storage routine for when a simple memcpy will do.
951 * No pixel transfer operations or special texel encodings allowed.
952 * 1D, 2D and 3D images supported.
955 memcpy_texture(struct gl_context
*ctx
,
957 mesa_format dstFormat
,
960 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
961 GLenum srcFormat
, GLenum srcType
,
962 const GLvoid
*srcAddr
,
963 const struct gl_pixelstore_attrib
*srcPacking
)
965 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
967 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
968 srcWidth
, srcHeight
, srcFormat
, srcType
);
969 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
970 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
971 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
972 const GLint bytesPerRow
= srcWidth
* texelBytes
;
974 if (dstRowStride
== srcRowStride
&&
975 dstRowStride
== bytesPerRow
) {
976 /* memcpy image by image */
978 for (img
= 0; img
< srcDepth
; img
++) {
979 GLubyte
*dstImage
= dstSlices
[img
];
980 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
981 srcImage
+= srcImageStride
;
985 /* memcpy row by row */
987 for (img
= 0; img
< srcDepth
; img
++) {
988 const GLubyte
*srcRow
= srcImage
;
989 GLubyte
*dstRow
= dstSlices
[img
];
990 for (row
= 0; row
< srcHeight
; row
++) {
991 memcpy(dstRow
, srcRow
, bytesPerRow
);
992 dstRow
+= dstRowStride
;
993 srcRow
+= srcRowStride
;
995 srcImage
+= srcImageStride
;
1002 * General-case function for storing a color texture images with
1003 * components that can be represented with ubytes. Example destination
1004 * texture formats are MESA_FORMAT_ARGB888, ARGB4444, RGB565.
1007 store_ubyte_texture(TEXSTORE_PARAMS
)
1009 const GLint srcRowStride
= srcWidth
* 4 * sizeof(GLubyte
);
1010 GLubyte
*tempImage
, *src
;
1013 tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1016 srcWidth
, srcHeight
, srcDepth
,
1017 srcFormat
, srcType
, srcAddr
,
1023 for (img
= 0; img
< srcDepth
; img
++) {
1024 _mesa_pack_ubyte_rgba_rect(dstFormat
, srcWidth
, srcHeight
,
1026 dstSlices
[img
], dstRowStride
);
1027 src
+= srcHeight
* srcRowStride
;
1038 * Store a 32-bit integer or float depth component texture image.
1041 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1043 const GLuint depthScale
= 0xffffffff;
1046 ASSERT(dstFormat
== MESA_FORMAT_Z_UNORM32
||
1047 dstFormat
== MESA_FORMAT_Z_FLOAT32
);
1048 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
1050 if (dstFormat
== MESA_FORMAT_Z_UNORM32
)
1051 dstType
= GL_UNSIGNED_INT
;
1058 for (img
= 0; img
< srcDepth
; img
++) {
1059 GLubyte
*dstRow
= dstSlices
[img
];
1060 for (row
= 0; row
< srcHeight
; row
++) {
1061 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1062 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1063 _mesa_unpack_depth_span(ctx
, srcWidth
,
1065 depthScale
, srcType
, src
, srcPacking
);
1066 dstRow
+= dstRowStride
;
1075 * Store a 24-bit integer depth component texture image.
1078 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1080 const GLuint depthScale
= 0xffffff;
1083 ASSERT(dstFormat
== MESA_FORMAT_Z24_UNORM_X8_UINT
);
1088 for (img
= 0; img
< srcDepth
; img
++) {
1089 GLubyte
*dstRow
= dstSlices
[img
];
1090 for (row
= 0; row
< srcHeight
; row
++) {
1091 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1092 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1093 _mesa_unpack_depth_span(ctx
, srcWidth
,
1094 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1095 depthScale
, srcType
, src
, srcPacking
);
1096 dstRow
+= dstRowStride
;
1105 * Store a 24-bit integer depth component texture image.
1108 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1110 const GLuint depthScale
= 0xffffff;
1113 ASSERT(dstFormat
== MESA_FORMAT_X8_UINT_Z24_UNORM
);
1118 for (img
= 0; img
< srcDepth
; img
++) {
1119 GLubyte
*dstRow
= dstSlices
[img
];
1120 for (row
= 0; row
< srcHeight
; row
++) {
1121 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1122 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1123 GLuint
*dst
= (GLuint
*) dstRow
;
1125 _mesa_unpack_depth_span(ctx
, srcWidth
,
1126 GL_UNSIGNED_INT
, dst
,
1127 depthScale
, srcType
, src
, srcPacking
);
1128 for (i
= 0; i
< srcWidth
; i
++)
1130 dstRow
+= dstRowStride
;
1139 * Store a 16-bit integer depth component texture image.
1142 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1144 const GLuint depthScale
= 0xffff;
1146 ASSERT(dstFormat
== MESA_FORMAT_Z_UNORM16
);
1147 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1152 for (img
= 0; img
< srcDepth
; img
++) {
1153 GLubyte
*dstRow
= dstSlices
[img
];
1154 for (row
= 0; row
< srcHeight
; row
++) {
1155 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1156 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1157 GLushort
*dst16
= (GLushort
*) dstRow
;
1158 _mesa_unpack_depth_span(ctx
, srcWidth
,
1159 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1160 srcType
, src
, srcPacking
);
1161 dstRow
+= dstRowStride
;
1170 * Store an rgb565 or rgb565_rev texture image.
1173 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1175 ASSERT(dstFormat
== MESA_FORMAT_B5G6R5_UNORM
||
1176 dstFormat
== MESA_FORMAT_R5G6B5_UNORM
);
1177 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1179 if (!ctx
->_ImageTransferState
&&
1180 !srcPacking
->SwapBytes
&&
1181 baseInternalFormat
== GL_RGB
&&
1182 srcFormat
== GL_RGB
&&
1183 srcType
== GL_UNSIGNED_BYTE
&&
1185 /* do optimized tex store */
1186 const GLint srcRowStride
=
1187 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1188 const GLubyte
*src
= (const GLubyte
*)
1189 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1190 srcFormat
, srcType
, 0, 0, 0);
1191 GLubyte
*dst
= dstSlices
[0];
1193 for (row
= 0; row
< srcHeight
; row
++) {
1194 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1195 GLushort
*dstUS
= (GLushort
*) dst
;
1196 /* check for byteswapped format */
1197 if (dstFormat
== MESA_FORMAT_B5G6R5_UNORM
) {
1198 for (col
= 0; col
< srcWidth
; col
++) {
1199 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1204 for (col
= 0; col
< srcWidth
; col
++) {
1205 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1209 dst
+= dstRowStride
;
1210 src
+= srcRowStride
;
1214 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1215 dstFormat
, dstRowStride
, dstSlices
,
1216 srcWidth
, srcHeight
, srcDepth
,
1217 srcFormat
, srcType
, srcAddr
, srcPacking
);
1224 * Store a texture in MESA_FORMAT_A8B8G8R8_UNORM or MESA_FORMAT_R8G8B8A8_UNORM.
1227 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1229 const GLboolean littleEndian
= _mesa_little_endian();
1231 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_UNORM
||
1232 dstFormat
== MESA_FORMAT_R8G8B8A8_UNORM
||
1233 dstFormat
== MESA_FORMAT_X8B8G8R8_UNORM
||
1234 dstFormat
== MESA_FORMAT_R8G8B8X8_UNORM
);
1235 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1237 if (!ctx
->_ImageTransferState
&&
1238 (srcType
== GL_UNSIGNED_BYTE
||
1239 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1240 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1241 can_swizzle(baseInternalFormat
) &&
1242 can_swizzle(srcFormat
)) {
1246 /* dstmap - how to swizzle from RGBA to dst format:
1248 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_A8B8G8R8_UNORM
||
1249 dstFormat
== MESA_FORMAT_X8B8G8R8_UNORM
)) ||
1250 (!littleEndian
&& (dstFormat
== MESA_FORMAT_R8G8B8A8_UNORM
||
1251 dstFormat
== MESA_FORMAT_R8G8B8X8_UNORM
))) {
1264 _mesa_swizzle_ubyte_image(ctx
, dims
,
1269 dstRowStride
, dstSlices
,
1270 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1274 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1275 dstFormat
, dstRowStride
, dstSlices
,
1276 srcWidth
, srcHeight
, srcDepth
,
1277 srcFormat
, srcType
, srcAddr
, srcPacking
);
1284 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1286 const GLboolean littleEndian
= _mesa_little_endian();
1288 ASSERT(dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
||
1289 dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
||
1290 dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
||
1291 dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
);
1292 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1294 if (!ctx
->_ImageTransferState
&&
1295 !srcPacking
->SwapBytes
&&
1296 (dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
||
1297 dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
) &&
1298 srcFormat
== GL_RGB
&&
1299 (baseInternalFormat
== GL_RGBA
||
1300 baseInternalFormat
== GL_RGB
) &&
1301 srcType
== GL_UNSIGNED_BYTE
) {
1303 for (img
= 0; img
< srcDepth
; img
++) {
1304 const GLint srcRowStride
=
1305 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1306 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1307 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1308 GLubyte
*dstRow
= dstSlices
[img
];
1309 for (row
= 0; row
< srcHeight
; row
++) {
1310 GLuint
*d4
= (GLuint
*) dstRow
;
1311 for (col
= 0; col
< srcWidth
; col
++) {
1312 d4
[col
] = PACK_COLOR_8888(0xff,
1313 srcRow
[col
* 3 + RCOMP
],
1314 srcRow
[col
* 3 + GCOMP
],
1315 srcRow
[col
* 3 + BCOMP
]);
1317 dstRow
+= dstRowStride
;
1318 srcRow
+= srcRowStride
;
1322 else if (!ctx
->_ImageTransferState
&&
1323 !srcPacking
->SwapBytes
&&
1324 dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
&&
1325 srcFormat
== GL_LUMINANCE_ALPHA
&&
1326 baseInternalFormat
== GL_RGBA
&&
1327 srcType
== GL_UNSIGNED_BYTE
) {
1328 /* special case of storing LA -> ARGB8888 */
1330 const GLint srcRowStride
=
1331 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1332 for (img
= 0; img
< srcDepth
; img
++) {
1333 const GLubyte
*srcRow
= (const GLubyte
*)
1334 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
,
1335 srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1336 GLubyte
*dstRow
= dstSlices
[img
];
1337 for (row
= 0; row
< srcHeight
; row
++) {
1338 GLuint
*d4
= (GLuint
*) dstRow
;
1339 for (col
= 0; col
< srcWidth
; col
++) {
1340 GLubyte l
= srcRow
[col
* 2 + 0], a
= srcRow
[col
* 2 + 1];
1341 d4
[col
] = PACK_COLOR_8888(a
, l
, l
, l
);
1343 dstRow
+= dstRowStride
;
1344 srcRow
+= srcRowStride
;
1348 else if (!ctx
->_ImageTransferState
&&
1349 !srcPacking
->SwapBytes
&&
1350 dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
&&
1351 srcFormat
== GL_RGBA
&&
1352 baseInternalFormat
== GL_RGBA
&&
1353 srcType
== GL_UNSIGNED_BYTE
) {
1354 /* same as above case, but src data has alpha too */
1355 GLint img
, row
, col
;
1356 /* For some reason, streaming copies to write-combined regions
1357 * are extremely sensitive to the characteristics of how the
1358 * source data is retrieved. By reordering the source reads to
1359 * be in-order, the speed of this operation increases by half.
1360 * Strangely the same isn't required for the RGB path, above.
1362 for (img
= 0; img
< srcDepth
; img
++) {
1363 const GLint srcRowStride
=
1364 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1365 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1366 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1367 GLubyte
*dstRow
= dstSlices
[img
];
1368 for (row
= 0; row
< srcHeight
; row
++) {
1369 GLuint
*d4
= (GLuint
*) dstRow
;
1370 for (col
= 0; col
< srcWidth
; col
++) {
1371 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1372 srcRow
[col
* 4 + RCOMP
],
1373 srcRow
[col
* 4 + GCOMP
],
1374 srcRow
[col
* 4 + BCOMP
]);
1376 dstRow
+= dstRowStride
;
1377 srcRow
+= srcRowStride
;
1381 else if (!ctx
->_ImageTransferState
&&
1382 (srcType
== GL_UNSIGNED_BYTE
||
1383 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1384 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1385 can_swizzle(baseInternalFormat
) &&
1386 can_swizzle(srcFormat
)) {
1390 /* dstmap - how to swizzle from RGBA to dst format:
1392 if ((littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
) ||
1393 (littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
) ||
1394 (!littleEndian
&& dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
) ||
1395 (!littleEndian
&& dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
)) {
1396 dstmap
[3] = 3; /* alpha */
1397 dstmap
[2] = 0; /* red */
1398 dstmap
[1] = 1; /* green */
1399 dstmap
[0] = 2; /* blue */
1402 assert((littleEndian
&& dstFormat
== MESA_FORMAT_A8R8G8B8_UNORM
) ||
1403 (!littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8A8_UNORM
) ||
1404 (littleEndian
&& dstFormat
== MESA_FORMAT_X8R8G8B8_UNORM
) ||
1405 (!littleEndian
&& dstFormat
== MESA_FORMAT_B8G8R8X8_UNORM
));
1412 _mesa_swizzle_ubyte_image(ctx
, dims
,
1419 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1423 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1424 dstFormat
, dstRowStride
, dstSlices
,
1425 srcWidth
, srcHeight
, srcDepth
,
1426 srcFormat
, srcType
, srcAddr
, srcPacking
);
1433 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1435 ASSERT(dstFormat
== MESA_FORMAT_BGR_UNORM8
);
1436 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1438 if (!ctx
->_ImageTransferState
&&
1439 !srcPacking
->SwapBytes
&&
1440 srcFormat
== GL_RGBA
&&
1441 srcType
== GL_UNSIGNED_BYTE
) {
1442 /* extract RGB from RGBA */
1443 GLint img
, row
, col
;
1444 for (img
= 0; img
< srcDepth
; img
++) {
1445 const GLint srcRowStride
=
1446 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1447 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1448 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1449 GLubyte
*dstRow
= dstSlices
[img
];
1450 for (row
= 0; row
< srcHeight
; row
++) {
1451 for (col
= 0; col
< srcWidth
; col
++) {
1452 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1453 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1454 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1456 dstRow
+= dstRowStride
;
1457 srcRow
+= srcRowStride
;
1461 else if (!ctx
->_ImageTransferState
&&
1462 srcType
== GL_UNSIGNED_BYTE
&&
1463 can_swizzle(baseInternalFormat
) &&
1464 can_swizzle(srcFormat
)) {
1468 /* dstmap - how to swizzle from RGBA to dst format:
1473 dstmap
[3] = ONE
; /* ? */
1475 _mesa_swizzle_ubyte_image(ctx
, dims
,
1480 dstRowStride
, dstSlices
,
1481 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1485 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1486 dstFormat
, dstRowStride
, dstSlices
,
1487 srcWidth
, srcHeight
, srcDepth
,
1488 srcFormat
, srcType
, srcAddr
, srcPacking
);
1495 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1497 ASSERT(dstFormat
== MESA_FORMAT_RGB_UNORM8
);
1498 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1500 if (!ctx
->_ImageTransferState
&&
1501 !srcPacking
->SwapBytes
&&
1502 srcFormat
== GL_RGBA
&&
1503 srcType
== GL_UNSIGNED_BYTE
) {
1504 /* extract BGR from RGBA */
1506 for (img
= 0; img
< srcDepth
; img
++) {
1507 const GLint srcRowStride
=
1508 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1509 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1510 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1511 GLubyte
*dstRow
= dstSlices
[img
];
1512 for (row
= 0; row
< srcHeight
; row
++) {
1513 for (col
= 0; col
< srcWidth
; col
++) {
1514 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1515 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1516 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1518 dstRow
+= dstRowStride
;
1519 srcRow
+= srcRowStride
;
1523 else if (!ctx
->_ImageTransferState
&&
1524 srcType
== GL_UNSIGNED_BYTE
&&
1525 can_swizzle(baseInternalFormat
) &&
1526 can_swizzle(srcFormat
)) {
1530 /* dstmap - how to swizzle from RGBA to dst format:
1535 dstmap
[3] = ONE
; /* ? */
1537 _mesa_swizzle_ubyte_image(ctx
, dims
,
1542 dstRowStride
, dstSlices
,
1543 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1547 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1548 dstFormat
, dstRowStride
, dstSlices
,
1549 srcWidth
, srcHeight
, srcDepth
,
1550 srcFormat
, srcType
, srcAddr
, srcPacking
);
1557 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1559 ASSERT(dstFormat
== MESA_FORMAT_B10G10R10A2_UNORM
||
1560 dstFormat
== MESA_FORMAT_B10G10R10X2_UNORM
);
1561 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1565 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1566 * if the internal format is RGB. */
1567 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1570 srcWidth
, srcHeight
, srcDepth
,
1571 srcFormat
, srcType
, srcAddr
,
1573 ctx
->_ImageTransferState
);
1574 const GLfloat
*src
= tempImage
;
1575 GLint img
, row
, col
;
1578 for (img
= 0; img
< srcDepth
; img
++) {
1579 GLubyte
*dstRow
= dstSlices
[img
];
1580 if (baseInternalFormat
== GL_RGBA
|| baseInternalFormat
== GL_RGB
) {
1581 for (row
= 0; row
< srcHeight
; row
++) {
1582 GLuint
*dstUI
= (GLuint
*) dstRow
;
1583 for (col
= 0; col
< srcWidth
; col
++) {
1586 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1587 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1588 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1589 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1590 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1593 dstRow
+= dstRowStride
;
1599 free((void *) tempImage
);
1606 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1609 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1611 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1613 ASSERT(dstFormat
== MESA_FORMAT_L4A4_UNORM
);
1614 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1618 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1621 srcWidth
, srcHeight
, srcDepth
,
1622 srcFormat
, srcType
, srcAddr
,
1624 const GLubyte
*src
= tempImage
;
1625 GLint img
, row
, col
;
1628 for (img
= 0; img
< srcDepth
; img
++) {
1629 GLubyte
*dstRow
= dstSlices
[img
];
1630 for (row
= 0; row
< srcHeight
; row
++) {
1631 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1632 for (col
= 0; col
< srcWidth
; col
++) {
1633 /* src[0] is luminance, src[1] is alpha */
1634 dstUS
[col
] = PACK_COLOR_44( src
[1],
1638 dstRow
+= dstRowStride
;
1641 free((void *) tempImage
);
1648 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1651 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1653 const GLboolean littleEndian
= _mesa_little_endian();
1654 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1656 ASSERT(dstFormat
== MESA_FORMAT_L8A8_UNORM
||
1657 dstFormat
== MESA_FORMAT_A8L8_UNORM
||
1658 dstFormat
== MESA_FORMAT_R8G8_UNORM
||
1659 dstFormat
== MESA_FORMAT_G8R8_UNORM
);
1660 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1662 if (!ctx
->_ImageTransferState
&&
1664 srcType
== GL_UNSIGNED_BYTE
&&
1665 can_swizzle(baseInternalFormat
) &&
1666 can_swizzle(srcFormat
)) {
1669 /* dstmap - how to swizzle from RGBA to dst format:
1671 if (dstFormat
== MESA_FORMAT_L8A8_UNORM
|| dstFormat
== MESA_FORMAT_A8L8_UNORM
) {
1672 if ((littleEndian
&& dstFormat
== MESA_FORMAT_L8A8_UNORM
) ||
1673 (!littleEndian
&& dstFormat
== MESA_FORMAT_A8L8_UNORM
)) {
1683 if ((littleEndian
&& dstFormat
== MESA_FORMAT_R8G8_UNORM
) ||
1684 (!littleEndian
&& dstFormat
== MESA_FORMAT_G8R8_UNORM
)) {
1693 dstmap
[2] = ZERO
; /* ? */
1694 dstmap
[3] = ONE
; /* ? */
1696 _mesa_swizzle_ubyte_image(ctx
, dims
,
1701 dstRowStride
, dstSlices
,
1702 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1707 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1710 srcWidth
, srcHeight
, srcDepth
,
1711 srcFormat
, srcType
, srcAddr
,
1713 const GLubyte
*src
= tempImage
;
1714 GLint img
, row
, col
;
1717 for (img
= 0; img
< srcDepth
; img
++) {
1718 GLubyte
*dstRow
= dstSlices
[img
];
1719 for (row
= 0; row
< srcHeight
; row
++) {
1720 GLushort
*dstUS
= (GLushort
*) dstRow
;
1721 if (dstFormat
== MESA_FORMAT_L8A8_UNORM
||
1722 dstFormat
== MESA_FORMAT_R8G8_UNORM
) {
1723 for (col
= 0; col
< srcWidth
; col
++) {
1724 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1725 dstUS
[col
] = PACK_COLOR_88( src
[1],
1731 for (col
= 0; col
< srcWidth
; col
++) {
1732 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1733 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
1738 dstRow
+= dstRowStride
;
1741 free((void *) tempImage
);
1748 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
1751 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
1753 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1755 ASSERT(dstFormat
== MESA_FORMAT_L16A16_UNORM
||
1756 dstFormat
== MESA_FORMAT_A16L16_UNORM
||
1757 dstFormat
== MESA_FORMAT_R16G16_UNORM
||
1758 dstFormat
== MESA_FORMAT_G16R16_UNORM
);
1759 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1763 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1766 srcWidth
, srcHeight
, srcDepth
,
1767 srcFormat
, srcType
, srcAddr
,
1769 ctx
->_ImageTransferState
);
1770 const GLfloat
*src
= tempImage
;
1771 GLint img
, row
, col
;
1774 for (img
= 0; img
< srcDepth
; img
++) {
1775 GLubyte
*dstRow
= dstSlices
[img
];
1776 for (row
= 0; row
< srcHeight
; row
++) {
1777 GLuint
*dstUI
= (GLuint
*) dstRow
;
1778 if (dstFormat
== MESA_FORMAT_L16A16_UNORM
||
1779 dstFormat
== MESA_FORMAT_R16G16_UNORM
) {
1780 for (col
= 0; col
< srcWidth
; col
++) {
1783 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1784 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1785 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
1790 for (col
= 0; col
< srcWidth
; col
++) {
1793 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1794 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1795 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
1799 dstRow
+= dstRowStride
;
1802 free((void *) tempImage
);
1808 /* Texstore for R16, A16, L16, I16. */
1810 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
1812 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1814 ASSERT(dstFormat
== MESA_FORMAT_R_UNORM16
||
1815 dstFormat
== MESA_FORMAT_A_UNORM16
||
1816 dstFormat
== MESA_FORMAT_L_UNORM16
||
1817 dstFormat
== MESA_FORMAT_I_UNORM16
);
1818 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1822 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1825 srcWidth
, srcHeight
, srcDepth
,
1826 srcFormat
, srcType
, srcAddr
,
1828 ctx
->_ImageTransferState
);
1829 const GLfloat
*src
= tempImage
;
1830 GLint img
, row
, col
;
1833 for (img
= 0; img
< srcDepth
; img
++) {
1834 GLubyte
*dstRow
= dstSlices
[img
];
1835 for (row
= 0; row
< srcHeight
; row
++) {
1836 GLushort
*dstUS
= (GLushort
*) dstRow
;
1837 for (col
= 0; col
< srcWidth
; col
++) {
1840 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1844 dstRow
+= dstRowStride
;
1847 free((void *) tempImage
);
1854 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
1856 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UNORM16
||
1857 dstFormat
== MESA_FORMAT_RGBX_UNORM16
);
1858 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
1862 /* Hardcode GL_RGBA as the base format, which forces alpha to 1.0
1863 * if the internal format is RGB. */
1864 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1867 srcWidth
, srcHeight
, srcDepth
,
1868 srcFormat
, srcType
, srcAddr
,
1870 ctx
->_ImageTransferState
);
1871 const GLfloat
*src
= tempImage
;
1872 GLint img
, row
, col
;
1877 for (img
= 0; img
< srcDepth
; img
++) {
1878 GLubyte
*dstRow
= dstSlices
[img
];
1879 for (row
= 0; row
< srcHeight
; row
++) {
1880 GLushort
*dstUS
= (GLushort
*) dstRow
;
1881 for (col
= 0; col
< srcWidth
; col
++) {
1882 GLushort r
, g
, b
, a
;
1884 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
1885 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
1886 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
1887 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
1894 dstRow
+= dstRowStride
;
1897 free((void *) tempImage
);
1904 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
1906 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1908 ASSERT(dstFormat
== MESA_FORMAT_RGB_SNORM16
||
1909 dstFormat
== MESA_FORMAT_RGBA_SNORM16
||
1910 dstFormat
== MESA_FORMAT_RGBX_SNORM16
);
1914 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1917 srcWidth
, srcHeight
, srcDepth
,
1918 srcFormat
, srcType
, srcAddr
,
1920 ctx
->_ImageTransferState
);
1921 const GLfloat
*src
= tempImage
;
1922 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
1923 GLint img
, row
, col
;
1928 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
1929 * 3 or 4 components/pixel here.
1931 for (img
= 0; img
< srcDepth
; img
++) {
1932 GLubyte
*dstRow
= dstSlices
[img
];
1933 for (row
= 0; row
< srcHeight
; row
++) {
1934 GLshort
*dstRowS
= (GLshort
*) dstRow
;
1935 if (dstFormat
== MESA_FORMAT_RGBA_SNORM16
) {
1936 for (col
= 0; col
< srcWidth
; col
++) {
1938 for (c
= 0; c
< comps
; c
++) {
1940 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
1941 dstRowS
[col
* comps
+ c
] = p
;
1944 dstRow
+= dstRowStride
;
1945 src
+= 4 * srcWidth
;
1947 else if (dstFormat
== MESA_FORMAT_RGBX_SNORM16
) {
1948 for (col
= 0; col
< srcWidth
; col
++) {
1951 for (c
= 0; c
< 3; c
++) {
1953 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1954 dstRowS
[col
* comps
+ c
] = p
;
1956 dstRowS
[col
* comps
+ 3] = 32767;
1958 dstRow
+= dstRowStride
;
1959 src
+= 3 * srcWidth
;
1962 for (col
= 0; col
< srcWidth
; col
++) {
1964 for (c
= 0; c
< comps
; c
++) {
1966 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
1967 dstRowS
[col
* comps
+ c
] = p
;
1970 dstRow
+= dstRowStride
;
1971 src
+= 3 * srcWidth
;
1975 free((void *) tempImage
);
1982 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
1985 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
1987 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1989 ASSERT(dstFormat
== MESA_FORMAT_A_UNORM8
||
1990 dstFormat
== MESA_FORMAT_L_UNORM8
||
1991 dstFormat
== MESA_FORMAT_I_UNORM8
||
1992 dstFormat
== MESA_FORMAT_R_UNORM8
);
1993 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1995 if (!ctx
->_ImageTransferState
&&
1996 srcType
== GL_UNSIGNED_BYTE
&&
1997 can_swizzle(baseInternalFormat
) &&
1998 can_swizzle(srcFormat
)) {
2001 /* dstmap - how to swizzle from RGBA to dst format:
2003 if (dstFormat
== MESA_FORMAT_A_UNORM8
) {
2009 dstmap
[1] = ZERO
; /* ? */
2010 dstmap
[2] = ZERO
; /* ? */
2011 dstmap
[3] = ONE
; /* ? */
2013 _mesa_swizzle_ubyte_image(ctx
, dims
,
2018 dstRowStride
, dstSlices
,
2019 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2024 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2027 srcWidth
, srcHeight
, srcDepth
,
2028 srcFormat
, srcType
, srcAddr
,
2030 const GLubyte
*src
= tempImage
;
2031 GLint img
, row
, col
;
2034 for (img
= 0; img
< srcDepth
; img
++) {
2035 GLubyte
*dstRow
= dstSlices
[img
];
2036 for (row
= 0; row
< srcHeight
; row
++) {
2037 for (col
= 0; col
< srcWidth
; col
++) {
2038 dstRow
[col
] = src
[col
];
2040 dstRow
+= dstRowStride
;
2044 free((void *) tempImage
);
2052 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2055 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2057 const GLboolean littleEndian
= _mesa_little_endian();
2059 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2061 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2062 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2063 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2064 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2065 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2066 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2067 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2068 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2070 /* always just memcpy since no pixel transfer ops apply */
2071 memcpy_texture(ctx
, dims
,
2073 dstRowStride
, dstSlices
,
2074 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2075 srcAddr
, srcPacking
);
2077 /* Check if we need byte swapping */
2078 /* XXX the logic here _might_ be wrong */
2079 if (srcPacking
->SwapBytes
^
2080 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2081 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2084 for (img
= 0; img
< srcDepth
; img
++) {
2085 GLubyte
*dstRow
= dstSlices
[img
];
2086 for (row
= 0; row
< srcHeight
; row
++) {
2087 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2088 dstRow
+= dstRowStride
;
2097 * Store a texture in a signed normalized 8-bit format.
2100 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2102 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2104 ASSERT(dstFormat
== MESA_FORMAT_A_SNORM8
||
2105 dstFormat
== MESA_FORMAT_L_SNORM8
||
2106 dstFormat
== MESA_FORMAT_I_SNORM8
||
2107 dstFormat
== MESA_FORMAT_R_SNORM8
);
2108 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2112 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2115 srcWidth
, srcHeight
, srcDepth
,
2116 srcFormat
, srcType
, srcAddr
,
2118 ctx
->_ImageTransferState
);
2119 const GLfloat
*src
= tempImage
;
2120 GLint img
, row
, col
;
2123 for (img
= 0; img
< srcDepth
; img
++) {
2124 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2125 for (row
= 0; row
< srcHeight
; row
++) {
2126 for (col
= 0; col
< srcWidth
; col
++) {
2127 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2129 dstRow
+= dstRowStride
;
2133 free((void *) tempImage
);
2140 * Store a texture in a signed normalized two-channel 16-bit format.
2143 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2145 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2147 ASSERT(dstFormat
== MESA_FORMAT_L8A8_SNORM
||
2148 dstFormat
== MESA_FORMAT_G8R8_SNORM
||
2149 dstFormat
== MESA_FORMAT_R8G8_SNORM
);
2150 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2154 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2157 srcWidth
, srcHeight
, srcDepth
,
2158 srcFormat
, srcType
, srcAddr
,
2160 ctx
->_ImageTransferState
);
2161 const GLfloat
*src
= tempImage
;
2162 GLint img
, row
, col
;
2165 for (img
= 0; img
< srcDepth
; img
++) {
2166 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2167 for (row
= 0; row
< srcHeight
; row
++) {
2168 GLushort
*dst
= (GLushort
*) dstRow
;
2170 if (dstFormat
== MESA_FORMAT_L8A8_SNORM
||
2171 dstFormat
== MESA_FORMAT_R8G8_SNORM
) {
2172 for (col
= 0; col
< srcWidth
; col
++) {
2173 GLubyte l
= FLOAT_TO_BYTE_TEX(src
[0]);
2174 GLubyte a
= FLOAT_TO_BYTE_TEX(src
[1]);
2176 dst
[col
] = PACK_COLOR_88_REV(l
, a
);
2180 for (col
= 0; col
< srcWidth
; col
++) {
2181 GLubyte l
= FLOAT_TO_BYTE_TEX(src
[0]);
2182 GLubyte a
= FLOAT_TO_BYTE_TEX(src
[1]);
2184 dst
[col
] = PACK_COLOR_88(l
, a
);
2189 dstRow
+= dstRowStride
;
2192 free((void *) tempImage
);
2197 /* Texstore for signed R16, A16, L16, I16. */
2199 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2201 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2203 ASSERT(dstFormat
== MESA_FORMAT_R_SNORM16
||
2204 dstFormat
== MESA_FORMAT_A_SNORM16
||
2205 dstFormat
== MESA_FORMAT_L_SNORM16
||
2206 dstFormat
== MESA_FORMAT_I_SNORM16
);
2207 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2211 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2214 srcWidth
, srcHeight
, srcDepth
,
2215 srcFormat
, srcType
, srcAddr
,
2217 ctx
->_ImageTransferState
);
2218 const GLfloat
*src
= tempImage
;
2219 GLint img
, row
, col
;
2222 for (img
= 0; img
< srcDepth
; img
++) {
2223 GLubyte
*dstRow
= dstSlices
[img
];
2224 for (row
= 0; row
< srcHeight
; row
++) {
2225 GLshort
*dstUS
= (GLshort
*) dstRow
;
2226 for (col
= 0; col
< srcWidth
; col
++) {
2229 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2233 dstRow
+= dstRowStride
;
2236 free((void *) tempImage
);
2242 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2245 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2247 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2249 ASSERT(dstFormat
== MESA_FORMAT_LA_SNORM16
||
2250 dstFormat
== MESA_FORMAT_G16R16_SNORM
||
2251 dstFormat
== MESA_FORMAT_R16G16_SNORM
);
2252 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2256 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2259 srcWidth
, srcHeight
, srcDepth
,
2260 srcFormat
, srcType
, srcAddr
,
2262 ctx
->_ImageTransferState
);
2263 const GLfloat
*src
= tempImage
;
2264 GLint img
, row
, col
;
2267 for (img
= 0; img
< srcDepth
; img
++) {
2268 GLubyte
*dstRow
= dstSlices
[img
];
2269 for (row
= 0; row
< srcHeight
; row
++) {
2270 GLuint
*dst
= (GLuint
*) dstRow
;
2272 if (dstFormat
== MESA_FORMAT_LA_SNORM16
||
2273 dstFormat
== MESA_FORMAT_R16G16_SNORM
) {
2274 for (col
= 0; col
< srcWidth
; col
++) {
2277 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2278 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2279 dst
[col
] = PACK_COLOR_1616_REV(l
, a
);
2283 for (col
= 0; col
< srcWidth
; col
++) {
2286 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2287 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2288 dst
[col
] = PACK_COLOR_1616_REV(l
, a
);
2293 dstRow
+= dstRowStride
;
2296 free((void *) tempImage
);
2302 * Store a texture in MESA_FORMAT_X8B8G8R8_SNORM or
2303 * MESA_FORMAT_R8G8B8X8_SNORM.
2306 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2308 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2310 ASSERT(dstFormat
== MESA_FORMAT_X8B8G8R8_SNORM
||
2311 dstFormat
== MESA_FORMAT_R8G8B8X8_SNORM
);
2312 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2316 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2319 srcWidth
, srcHeight
, srcDepth
,
2320 srcFormat
, srcType
, srcAddr
,
2322 ctx
->_ImageTransferState
);
2323 const GLfloat
*srcRow
= tempImage
;
2324 GLint img
, row
, col
;
2327 for (img
= 0; img
< srcDepth
; img
++) {
2328 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2329 for (row
= 0; row
< srcHeight
; row
++) {
2330 GLbyte
*dst
= dstRow
;
2331 if (dstFormat
== MESA_FORMAT_X8B8G8R8_SNORM
) {
2332 for (col
= 0; col
< srcWidth
; col
++) {
2333 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2334 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2335 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2342 for (col
= 0; col
< srcWidth
; col
++) {
2343 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2344 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2345 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2351 dstRow
+= dstRowStride
;
2354 free((void *) tempImage
);
2362 * Store a texture in MESA_FORMAT_A8B8G8R8_SNORM or
2363 * MESA_FORMAT_R8G8B8A8_SNORM
2366 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2368 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2370 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_SNORM
||
2371 dstFormat
== MESA_FORMAT_R8G8B8A8_SNORM
);
2372 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2376 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2379 srcWidth
, srcHeight
, srcDepth
,
2380 srcFormat
, srcType
, srcAddr
,
2382 ctx
->_ImageTransferState
);
2383 const GLfloat
*srcRow
= tempImage
;
2384 GLint img
, row
, col
;
2387 for (img
= 0; img
< srcDepth
; img
++) {
2388 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2389 for (row
= 0; row
< srcHeight
; row
++) {
2390 GLbyte
*dst
= dstRow
;
2391 if (dstFormat
== MESA_FORMAT_A8B8G8R8_SNORM
) {
2392 for (col
= 0; col
< srcWidth
; col
++) {
2393 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2394 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2395 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2396 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2402 for (col
= 0; col
< srcWidth
; col
++) {
2403 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2404 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2405 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2406 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2411 dstRow
+= dstRowStride
;
2414 free((void *) tempImage
);
2421 * Store a combined depth/stencil texture image.
2424 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2426 const GLuint depthScale
= 0xffffff;
2427 const GLint srcRowStride
2428 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2430 GLuint
*depth
= malloc(srcWidth
* sizeof(GLuint
));
2431 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2433 ASSERT(dstFormat
== MESA_FORMAT_S8_UINT_Z24_UNORM
);
2434 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2435 srcFormat
== GL_DEPTH_COMPONENT
||
2436 srcFormat
== GL_STENCIL_INDEX
);
2437 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2438 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2439 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
2441 if (!depth
|| !stencil
) {
2447 /* In case we only upload depth we need to preserve the stencil */
2448 for (img
= 0; img
< srcDepth
; img
++) {
2449 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2451 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2452 srcWidth
, srcHeight
,
2455 for (row
= 0; row
< srcHeight
; row
++) {
2457 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2459 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2460 keepstencil
= GL_TRUE
;
2462 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2463 keepdepth
= GL_TRUE
;
2466 if (keepdepth
== GL_FALSE
)
2467 /* the 24 depth bits will be in the low position: */
2468 _mesa_unpack_depth_span(ctx
, srcWidth
,
2469 GL_UNSIGNED_INT
, /* dst type */
2470 keepstencil
? depth
: dstRow
, /* dst addr */
2472 srcType
, src
, srcPacking
);
2474 if (keepstencil
== GL_FALSE
)
2475 /* get the 8-bit stencil values */
2476 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2477 GL_UNSIGNED_BYTE
, /* dst type */
2478 stencil
, /* dst addr */
2479 srcType
, src
, srcPacking
,
2480 ctx
->_ImageTransferState
);
2482 for (i
= 0; i
< srcWidth
; i
++) {
2484 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2486 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2488 src
+= srcRowStride
;
2489 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2500 * Store a combined depth/stencil texture image.
2503 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2505 const GLuint depthScale
= 0xffffff;
2506 const GLint srcRowStride
2507 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2512 ASSERT(dstFormat
== MESA_FORMAT_Z24_UNORM_S8_UINT
);
2513 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2514 srcFormat
== GL_DEPTH_COMPONENT
||
2515 srcFormat
== GL_STENCIL_INDEX
);
2516 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2517 srcType
== GL_UNSIGNED_INT_24_8_EXT
||
2518 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
2520 depth
= malloc(srcWidth
* sizeof(GLuint
));
2521 stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2523 if (!depth
|| !stencil
) {
2529 for (img
= 0; img
< srcDepth
; img
++) {
2530 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2532 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2533 srcWidth
, srcHeight
,
2536 for (row
= 0; row
< srcHeight
; row
++) {
2538 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2540 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2541 keepstencil
= GL_TRUE
;
2543 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2544 keepdepth
= GL_TRUE
;
2547 if (keepdepth
== GL_FALSE
)
2548 /* the 24 depth bits will be in the low position: */
2549 _mesa_unpack_depth_span(ctx
, srcWidth
,
2550 GL_UNSIGNED_INT
, /* dst type */
2551 keepstencil
? depth
: dstRow
, /* dst addr */
2553 srcType
, src
, srcPacking
);
2555 if (keepstencil
== GL_FALSE
)
2556 /* get the 8-bit stencil values */
2557 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2558 GL_UNSIGNED_BYTE
, /* dst type */
2559 stencil
, /* dst addr */
2560 srcType
, src
, srcPacking
,
2561 ctx
->_ImageTransferState
);
2563 /* merge stencil values into depth values */
2564 for (i
= 0; i
< srcWidth
; i
++) {
2566 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2568 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
2571 src
+= srcRowStride
;
2572 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2584 * Store simple 8-bit/value stencil texture data.
2587 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2589 ASSERT(dstFormat
== MESA_FORMAT_S_UINT8
);
2590 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2593 const GLint srcRowStride
2594 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2596 GLubyte
*stencil
= malloc(srcWidth
* sizeof(GLubyte
));
2601 for (img
= 0; img
< srcDepth
; img
++) {
2602 GLubyte
*dstRow
= dstSlices
[img
];
2604 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2605 srcWidth
, srcHeight
,
2608 for (row
= 0; row
< srcHeight
; row
++) {
2611 /* get the 8-bit stencil values */
2612 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2613 GL_UNSIGNED_BYTE
, /* dst type */
2614 stencil
, /* dst addr */
2615 srcType
, src
, srcPacking
,
2616 ctx
->_ImageTransferState
);
2617 /* merge stencil values into depth values */
2618 for (i
= 0; i
< srcWidth
; i
++)
2619 dstRow
[i
] = stencil
[i
];
2621 src
+= srcRowStride
;
2622 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
2634 * Store an image in any of the formats:
2635 * _mesa_texformat_rgba_float32
2636 * _mesa_texformat_rgb_float32
2637 * _mesa_texformat_alpha_float32
2638 * _mesa_texformat_luminance_float32
2639 * _mesa_texformat_luminance_alpha_float32
2640 * _mesa_texformat_intensity_float32
2643 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2645 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2646 GLint components
= _mesa_components_in_format(baseFormat
);
2648 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2649 if (dstFormat
== MESA_FORMAT_RGBX_FLOAT32
) {
2650 baseFormat
= GL_RGBA
;
2654 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2655 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2656 dstFormat
== MESA_FORMAT_A_FLOAT32
||
2657 dstFormat
== MESA_FORMAT_L_FLOAT32
||
2658 dstFormat
== MESA_FORMAT_LA_FLOAT32
||
2659 dstFormat
== MESA_FORMAT_I_FLOAT32
||
2660 dstFormat
== MESA_FORMAT_R_FLOAT32
||
2661 dstFormat
== MESA_FORMAT_RG_FLOAT32
||
2662 dstFormat
== MESA_FORMAT_RGBX_FLOAT32
);
2663 ASSERT(baseInternalFormat
== GL_RGBA
||
2664 baseInternalFormat
== GL_RGB
||
2665 baseInternalFormat
== GL_ALPHA
||
2666 baseInternalFormat
== GL_LUMINANCE
||
2667 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2668 baseInternalFormat
== GL_INTENSITY
||
2669 baseInternalFormat
== GL_RED
||
2670 baseInternalFormat
== GL_RG
);
2671 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
2675 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2678 srcWidth
, srcHeight
, srcDepth
,
2679 srcFormat
, srcType
, srcAddr
,
2681 ctx
->_ImageTransferState
);
2682 const GLfloat
*srcRow
= tempImage
;
2687 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2688 for (img
= 0; img
< srcDepth
; img
++) {
2689 GLubyte
*dstRow
= dstSlices
[img
];
2690 for (row
= 0; row
< srcHeight
; row
++) {
2691 memcpy(dstRow
, srcRow
, bytesPerRow
);
2692 dstRow
+= dstRowStride
;
2693 srcRow
+= srcWidth
* components
;
2697 free((void *) tempImage
);
2705 * As above, but store 16-bit floats.
2708 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2710 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2711 GLint components
= _mesa_components_in_format(baseFormat
);
2713 /* this forces alpha to 1 in _mesa_make_temp_float_image */
2714 if (dstFormat
== MESA_FORMAT_RGBX_FLOAT16
) {
2715 baseFormat
= GL_RGBA
;
2719 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2720 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2721 dstFormat
== MESA_FORMAT_A_FLOAT16
||
2722 dstFormat
== MESA_FORMAT_L_FLOAT16
||
2723 dstFormat
== MESA_FORMAT_LA_FLOAT16
||
2724 dstFormat
== MESA_FORMAT_I_FLOAT16
||
2725 dstFormat
== MESA_FORMAT_R_FLOAT16
||
2726 dstFormat
== MESA_FORMAT_RG_FLOAT16
||
2727 dstFormat
== MESA_FORMAT_RGBX_FLOAT16
);
2728 ASSERT(baseInternalFormat
== GL_RGBA
||
2729 baseInternalFormat
== GL_RGB
||
2730 baseInternalFormat
== GL_ALPHA
||
2731 baseInternalFormat
== GL_LUMINANCE
||
2732 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2733 baseInternalFormat
== GL_INTENSITY
||
2734 baseInternalFormat
== GL_RED
||
2735 baseInternalFormat
== GL_RG
);
2736 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
2740 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2743 srcWidth
, srcHeight
, srcDepth
,
2744 srcFormat
, srcType
, srcAddr
,
2746 ctx
->_ImageTransferState
);
2747 const GLfloat
*src
= tempImage
;
2751 for (img
= 0; img
< srcDepth
; img
++) {
2752 GLubyte
*dstRow
= dstSlices
[img
];
2753 for (row
= 0; row
< srcHeight
; row
++) {
2754 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2756 for (i
= 0; i
< srcWidth
* components
; i
++) {
2757 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2759 dstRow
+= dstRowStride
;
2760 src
+= srcWidth
* components
;
2764 free((void *) tempImage
);
2770 /* non-normalized, signed int8 */
2772 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
2774 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2775 GLint components
= _mesa_components_in_format(baseFormat
);
2777 /* this forces alpha to 1 in make_temp_uint_image */
2778 if (dstFormat
== MESA_FORMAT_RGBX_SINT8
) {
2779 baseFormat
= GL_RGBA
;
2783 ASSERT(dstFormat
== MESA_FORMAT_R_SINT8
||
2784 dstFormat
== MESA_FORMAT_RG_SINT8
||
2785 dstFormat
== MESA_FORMAT_RGB_SINT8
||
2786 dstFormat
== MESA_FORMAT_RGBA_SINT8
||
2787 dstFormat
== MESA_FORMAT_A_SINT8
||
2788 dstFormat
== MESA_FORMAT_I_SINT8
||
2789 dstFormat
== MESA_FORMAT_L_SINT8
||
2790 dstFormat
== MESA_FORMAT_LA_SINT8
||
2791 dstFormat
== MESA_FORMAT_RGBX_SINT8
);
2792 ASSERT(baseInternalFormat
== GL_RGBA
||
2793 baseInternalFormat
== GL_RGB
||
2794 baseInternalFormat
== GL_RG
||
2795 baseInternalFormat
== GL_RED
||
2796 baseInternalFormat
== GL_ALPHA
||
2797 baseInternalFormat
== GL_LUMINANCE
||
2798 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2799 baseInternalFormat
== GL_INTENSITY
);
2800 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
2804 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2807 srcWidth
, srcHeight
, srcDepth
,
2811 const GLuint
*src
= tempImage
;
2813 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2816 for (img
= 0; img
< srcDepth
; img
++) {
2817 GLubyte
*dstRow
= dstSlices
[img
];
2818 for (row
= 0; row
< srcHeight
; row
++) {
2819 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
2822 for (i
= 0; i
< srcWidth
* components
; i
++) {
2823 dstTexel
[i
] = (GLbyte
) MIN2(src
[i
], 0x7f);
2826 for (i
= 0; i
< srcWidth
* components
; i
++) {
2827 dstTexel
[i
] = (GLbyte
) CLAMP((GLint
) src
[i
], -0x80, 0x7f);
2830 dstRow
+= dstRowStride
;
2831 src
+= srcWidth
* components
;
2835 free((void *) tempImage
);
2841 /* non-normalized, signed int16 */
2843 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
2845 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2846 GLint components
= _mesa_components_in_format(baseFormat
);
2848 /* this forces alpha to 1 in make_temp_uint_image */
2849 if (dstFormat
== MESA_FORMAT_RGBX_SINT16
) {
2850 baseFormat
= GL_RGBA
;
2854 ASSERT(dstFormat
== MESA_FORMAT_R_SINT16
||
2855 dstFormat
== MESA_FORMAT_RG_SINT16
||
2856 dstFormat
== MESA_FORMAT_RGB_SINT16
||
2857 dstFormat
== MESA_FORMAT_RGBA_SINT16
||
2858 dstFormat
== MESA_FORMAT_A_SINT16
||
2859 dstFormat
== MESA_FORMAT_L_SINT16
||
2860 dstFormat
== MESA_FORMAT_I_SINT16
||
2861 dstFormat
== MESA_FORMAT_LA_SINT16
||
2862 dstFormat
== MESA_FORMAT_RGBX_SINT16
);
2863 ASSERT(baseInternalFormat
== GL_RGBA
||
2864 baseInternalFormat
== GL_RGB
||
2865 baseInternalFormat
== GL_RG
||
2866 baseInternalFormat
== GL_RED
||
2867 baseInternalFormat
== GL_ALPHA
||
2868 baseInternalFormat
== GL_LUMINANCE
||
2869 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2870 baseInternalFormat
== GL_INTENSITY
);
2871 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
2875 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2878 srcWidth
, srcHeight
, srcDepth
,
2882 const GLuint
*src
= tempImage
;
2884 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2887 for (img
= 0; img
< srcDepth
; img
++) {
2888 GLubyte
*dstRow
= dstSlices
[img
];
2889 for (row
= 0; row
< srcHeight
; row
++) {
2890 GLshort
*dstTexel
= (GLshort
*) dstRow
;
2893 for (i
= 0; i
< srcWidth
* components
; i
++) {
2894 dstTexel
[i
] = (GLshort
) MIN2(src
[i
], 0x7fff);
2897 for (i
= 0; i
< srcWidth
* components
; i
++) {
2898 dstTexel
[i
] = (GLshort
)CLAMP((GLint
) src
[i
], -0x8000, 0x7fff);
2901 dstRow
+= dstRowStride
;
2902 src
+= srcWidth
* components
;
2906 free((void *) tempImage
);
2912 /* non-normalized, signed int32 */
2914 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
2916 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2917 GLint components
= _mesa_components_in_format(baseFormat
);
2919 /* this forces alpha to 1 in make_temp_uint_image */
2920 if (dstFormat
== MESA_FORMAT_RGBX_SINT32
) {
2921 baseFormat
= GL_RGBA
;
2925 ASSERT(dstFormat
== MESA_FORMAT_R_SINT32
||
2926 dstFormat
== MESA_FORMAT_RG_SINT32
||
2927 dstFormat
== MESA_FORMAT_RGB_SINT32
||
2928 dstFormat
== MESA_FORMAT_RGBA_SINT32
||
2929 dstFormat
== MESA_FORMAT_A_SINT32
||
2930 dstFormat
== MESA_FORMAT_I_SINT32
||
2931 dstFormat
== MESA_FORMAT_L_SINT32
||
2932 dstFormat
== MESA_FORMAT_LA_SINT32
||
2933 dstFormat
== MESA_FORMAT_RGBX_SINT32
);
2934 ASSERT(baseInternalFormat
== GL_RGBA
||
2935 baseInternalFormat
== GL_RGB
||
2936 baseInternalFormat
== GL_RG
||
2937 baseInternalFormat
== GL_RED
||
2938 baseInternalFormat
== GL_ALPHA
||
2939 baseInternalFormat
== GL_LUMINANCE
||
2940 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2941 baseInternalFormat
== GL_INTENSITY
);
2942 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
2946 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
2949 srcWidth
, srcHeight
, srcDepth
,
2953 const GLuint
*src
= tempImage
;
2955 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
2958 for (img
= 0; img
< srcDepth
; img
++) {
2959 GLubyte
*dstRow
= dstSlices
[img
];
2960 for (row
= 0; row
< srcHeight
; row
++) {
2961 GLint
*dstTexel
= (GLint
*) dstRow
;
2964 for (i
= 0; i
< srcWidth
* components
; i
++) {
2965 dstTexel
[i
] = (GLint
) MIN2(src
[i
], 0x7fffffff);
2968 for (i
= 0; i
< srcWidth
* components
; i
++) {
2969 dstTexel
[i
] = (GLint
) src
[i
];
2972 dstRow
+= dstRowStride
;
2973 src
+= srcWidth
* components
;
2977 free((void *) tempImage
);
2983 /* non-normalized, unsigned int8 */
2985 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
2987 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2988 GLint components
= _mesa_components_in_format(baseFormat
);
2990 /* this forces alpha to 1 in make_temp_uint_image */
2991 if (dstFormat
== MESA_FORMAT_RGBX_UINT8
) {
2992 baseFormat
= GL_RGBA
;
2996 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
2997 dstFormat
== MESA_FORMAT_RG_UINT8
||
2998 dstFormat
== MESA_FORMAT_RGB_UINT8
||
2999 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3000 dstFormat
== MESA_FORMAT_A_UINT8
||
3001 dstFormat
== MESA_FORMAT_I_UINT8
||
3002 dstFormat
== MESA_FORMAT_L_UINT8
||
3003 dstFormat
== MESA_FORMAT_LA_UINT8
||
3004 dstFormat
== MESA_FORMAT_RGBX_UINT8
);
3005 ASSERT(baseInternalFormat
== GL_RGBA
||
3006 baseInternalFormat
== GL_RGB
||
3007 baseInternalFormat
== GL_RG
||
3008 baseInternalFormat
== GL_RED
||
3009 baseInternalFormat
== GL_ALPHA
||
3010 baseInternalFormat
== GL_LUMINANCE
||
3011 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3012 baseInternalFormat
== GL_INTENSITY
);
3013 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3017 const GLuint
*tempImage
=
3018 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3019 srcWidth
, srcHeight
, srcDepth
,
3020 srcFormat
, srcType
, srcAddr
, srcPacking
);
3021 const GLuint
*src
= tempImage
;
3023 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3026 for (img
= 0; img
< srcDepth
; img
++) {
3027 GLubyte
*dstRow
= dstSlices
[img
];
3028 for (row
= 0; row
< srcHeight
; row
++) {
3029 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3032 for (i
= 0; i
< srcWidth
* components
; i
++) {
3033 dstTexel
[i
] = (GLubyte
) MIN2(src
[i
], 0xff);
3036 for (i
= 0; i
< srcWidth
* components
; i
++) {
3037 dstTexel
[i
] = (GLubyte
) CLAMP((GLint
) src
[i
], 0, 0xff);
3040 dstRow
+= dstRowStride
;
3041 src
+= srcWidth
* components
;
3045 free((void *) tempImage
);
3051 /* non-normalized, unsigned int16 */
3053 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3055 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3056 GLint components
= _mesa_components_in_format(baseFormat
);
3058 /* this forces alpha to 1 in make_temp_uint_image */
3059 if (dstFormat
== MESA_FORMAT_RGBX_UINT16
) {
3060 baseFormat
= GL_RGBA
;
3064 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3065 dstFormat
== MESA_FORMAT_RG_UINT16
||
3066 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3067 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3068 dstFormat
== MESA_FORMAT_A_UINT16
||
3069 dstFormat
== MESA_FORMAT_I_UINT16
||
3070 dstFormat
== MESA_FORMAT_L_UINT16
||
3071 dstFormat
== MESA_FORMAT_LA_UINT16
||
3072 dstFormat
== MESA_FORMAT_RGBX_UINT16
);
3073 ASSERT(baseInternalFormat
== GL_RGBA
||
3074 baseInternalFormat
== GL_RGB
||
3075 baseInternalFormat
== GL_RG
||
3076 baseInternalFormat
== GL_RED
||
3077 baseInternalFormat
== GL_ALPHA
||
3078 baseInternalFormat
== GL_LUMINANCE
||
3079 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3080 baseInternalFormat
== GL_INTENSITY
);
3081 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3085 const GLuint
*tempImage
=
3086 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3087 srcWidth
, srcHeight
, srcDepth
,
3088 srcFormat
, srcType
, srcAddr
, srcPacking
);
3089 const GLuint
*src
= tempImage
;
3091 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3094 for (img
= 0; img
< srcDepth
; img
++) {
3095 GLubyte
*dstRow
= dstSlices
[img
];
3096 for (row
= 0; row
< srcHeight
; row
++) {
3097 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3100 for (i
= 0; i
< srcWidth
* components
; i
++) {
3101 dstTexel
[i
] = (GLushort
) MIN2(src
[i
], 0xffff);
3104 for (i
= 0; i
< srcWidth
* components
; i
++) {
3105 dstTexel
[i
] = (GLushort
) CLAMP((GLint
) src
[i
], 0, 0xffff);
3108 dstRow
+= dstRowStride
;
3109 src
+= srcWidth
* components
;
3113 free((void *) tempImage
);
3119 /* non-normalized, unsigned int32 */
3121 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3123 GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3124 GLint components
= _mesa_components_in_format(baseFormat
);
3126 /* this forces alpha to 1 in make_temp_uint_image */
3127 if (dstFormat
== MESA_FORMAT_RGBX_UINT32
) {
3128 baseFormat
= GL_RGBA
;
3132 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3133 dstFormat
== MESA_FORMAT_RG_UINT32
||
3134 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3135 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3136 dstFormat
== MESA_FORMAT_A_UINT32
||
3137 dstFormat
== MESA_FORMAT_I_UINT32
||
3138 dstFormat
== MESA_FORMAT_L_UINT32
||
3139 dstFormat
== MESA_FORMAT_LA_UINT32
||
3140 dstFormat
== MESA_FORMAT_RGBX_UINT32
);
3141 ASSERT(baseInternalFormat
== GL_RGBA
||
3142 baseInternalFormat
== GL_RGB
||
3143 baseInternalFormat
== GL_RG
||
3144 baseInternalFormat
== GL_RED
||
3145 baseInternalFormat
== GL_ALPHA
||
3146 baseInternalFormat
== GL_LUMINANCE
||
3147 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3148 baseInternalFormat
== GL_INTENSITY
);
3149 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3153 const GLuint
*tempImage
=
3154 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3155 srcWidth
, srcHeight
, srcDepth
,
3156 srcFormat
, srcType
, srcAddr
, srcPacking
);
3157 const GLuint
*src
= tempImage
;
3158 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3162 for (img
= 0; img
< srcDepth
; img
++) {
3163 GLubyte
*dstRow
= dstSlices
[img
];
3164 for (row
= 0; row
< srcHeight
; row
++) {
3165 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3168 for (i
= 0; i
< srcWidth
* components
; i
++) {
3169 dstTexel
[i
] = src
[i
];
3172 for (i
= 0; i
< srcWidth
* components
; i
++) {
3173 dstTexel
[i
] = MAX2((GLint
) src
[i
], 0);
3176 dstRow
+= dstRowStride
;
3177 src
+= srcWidth
* components
;
3181 free((void *) tempImage
);
3188 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3190 mesa_format newDstFormat
;
3193 ASSERT(dstFormat
== MESA_FORMAT_BGR_SRGB8
);
3195 /* reuse normal rgb texstore code */
3196 newDstFormat
= MESA_FORMAT_BGR_UNORM8
;
3198 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3200 dstRowStride
, dstSlices
,
3201 srcWidth
, srcHeight
, srcDepth
,
3203 srcAddr
, srcPacking
);
3209 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3211 mesa_format newDstFormat
;
3214 ASSERT(dstFormat
== MESA_FORMAT_A8B8G8R8_SRGB
||
3215 dstFormat
== MESA_FORMAT_R8G8B8X8_SRGB
||
3216 dstFormat
== MESA_FORMAT_R8G8B8A8_SRGB
);
3218 newDstFormat
= _mesa_get_srgb_format_linear(dstFormat
);
3220 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3222 dstRowStride
, dstSlices
,
3223 srcWidth
, srcHeight
, srcDepth
,
3225 srcAddr
, srcPacking
);
3231 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3233 mesa_format newDstFormat
;
3236 assert(dstFormat
== MESA_FORMAT_B8G8R8A8_SRGB
||
3237 dstFormat
== MESA_FORMAT_B8G8R8X8_SRGB
);
3239 newDstFormat
= _mesa_get_srgb_format_linear(dstFormat
);
3241 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3243 dstRowStride
, dstSlices
,
3244 srcWidth
, srcHeight
, srcDepth
,
3246 srcAddr
, srcPacking
);
3252 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3254 mesa_format newDstFormat
;
3257 ASSERT(dstFormat
== MESA_FORMAT_L_SRGB8
);
3259 newDstFormat
= MESA_FORMAT_L_UNORM8
;
3261 /* _mesa_textore_a8 handles luminance8 too */
3262 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3264 dstRowStride
, dstSlices
,
3265 srcWidth
, srcHeight
, srcDepth
,
3267 srcAddr
, srcPacking
);
3273 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3275 mesa_format newDstFormat
;
3278 ASSERT(dstFormat
== MESA_FORMAT_L8A8_SRGB
);
3280 /* reuse normal luminance/alpha texstore code */
3281 newDstFormat
= MESA_FORMAT_L8A8_UNORM
;
3283 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3285 dstRowStride
, dstSlices
,
3286 srcWidth
, srcHeight
, srcDepth
,
3288 srcAddr
, srcPacking
);
3293 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3295 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3297 ASSERT(dstFormat
== MESA_FORMAT_R9G9B9E5_FLOAT
);
3298 ASSERT(baseInternalFormat
== GL_RGB
);
3302 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3305 srcWidth
, srcHeight
, srcDepth
,
3306 srcFormat
, srcType
, srcAddr
,
3308 ctx
->_ImageTransferState
);
3309 const GLfloat
*srcRow
= tempImage
;
3310 GLint img
, row
, col
;
3313 for (img
= 0; img
< srcDepth
; img
++) {
3314 GLubyte
*dstRow
= dstSlices
[img
];
3315 for (row
= 0; row
< srcHeight
; row
++) {
3316 GLuint
*dstUI
= (GLuint
*)dstRow
;
3317 for (col
= 0; col
< srcWidth
; col
++) {
3318 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3320 dstRow
+= dstRowStride
;
3321 srcRow
+= srcWidth
* 3;
3325 free((void *) tempImage
);
3331 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3333 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3335 ASSERT(dstFormat
== MESA_FORMAT_R11G11B10_FLOAT
);
3336 ASSERT(baseInternalFormat
== GL_RGB
);
3340 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3343 srcWidth
, srcHeight
, srcDepth
,
3344 srcFormat
, srcType
, srcAddr
,
3346 ctx
->_ImageTransferState
);
3347 const GLfloat
*srcRow
= tempImage
;
3348 GLint img
, row
, col
;
3351 for (img
= 0; img
< srcDepth
; img
++) {
3352 GLubyte
*dstRow
= dstSlices
[img
];
3353 for (row
= 0; row
< srcHeight
; row
++) {
3354 GLuint
*dstUI
= (GLuint
*)dstRow
;
3355 for (col
= 0; col
< srcWidth
; col
++) {
3356 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3358 dstRow
+= dstRowStride
;
3359 srcRow
+= srcWidth
* 3;
3363 free((void *) tempImage
);
3370 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3373 const GLint srcRowStride
3374 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3377 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_S8X24_UINT
);
3378 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3379 srcFormat
== GL_DEPTH_COMPONENT
||
3380 srcFormat
== GL_STENCIL_INDEX
);
3381 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3382 srcType
== GL_UNSIGNED_INT_24_8
||
3383 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3385 /* In case we only upload depth we need to preserve the stencil */
3386 for (img
= 0; img
< srcDepth
; img
++) {
3387 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
3389 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3390 srcWidth
, srcHeight
,
3393 for (row
= 0; row
< srcHeight
; row
++) {
3394 /* The unpack functions with:
3395 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
3396 * only write their own dword, so the other dword (stencil
3397 * or depth) is preserved. */
3398 if (srcFormat
!= GL_STENCIL_INDEX
)
3399 _mesa_unpack_depth_span(ctx
, srcWidth
,
3400 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3401 dstRow
, /* dst addr */
3402 ~0U, srcType
, src
, srcPacking
);
3404 if (srcFormat
!= GL_DEPTH_COMPONENT
)
3405 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3406 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3407 dstRow
, /* dst addr */
3408 srcType
, src
, srcPacking
,
3409 ctx
->_ImageTransferState
);
3411 src
+= srcRowStride
;
3412 dstRow
+= dstRowStride
/ sizeof(uint64_t);
3419 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
3421 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3423 ASSERT(dstFormat
== MESA_FORMAT_B10G10R10A2_UINT
);
3424 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3428 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3431 srcWidth
, srcHeight
,
3432 srcDepth
, srcFormat
,
3435 const GLuint
*src
= tempImage
;
3436 GLint img
, row
, col
;
3437 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3440 for (img
= 0; img
< srcDepth
; img
++) {
3441 GLubyte
*dstRow
= dstSlices
[img
];
3443 for (row
= 0; row
< srcHeight
; row
++) {
3444 GLuint
*dstUI
= (GLuint
*) dstRow
;
3446 for (col
= 0; col
< srcWidth
; col
++) {
3448 r
= MIN2(src
[RCOMP
], 0x3ff);
3449 g
= MIN2(src
[GCOMP
], 0x3ff);
3450 b
= MIN2(src
[BCOMP
], 0x3ff);
3451 a
= MIN2(src
[ACOMP
], 0x003);
3452 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3456 for (col
= 0; col
< srcWidth
; col
++) {
3458 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3459 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3460 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3461 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3462 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3466 dstRow
+= dstRowStride
;
3469 free((void *) tempImage
);
3475 _mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS
)
3477 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3479 ASSERT(dstFormat
== MESA_FORMAT_R10G10B10A2_UINT
);
3480 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3484 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3487 srcWidth
, srcHeight
,
3488 srcDepth
, srcFormat
,
3491 const GLuint
*src
= tempImage
;
3492 GLint img
, row
, col
;
3493 GLboolean is_unsigned
= _mesa_is_type_unsigned(srcType
);
3496 for (img
= 0; img
< srcDepth
; img
++) {
3497 GLubyte
*dstRow
= dstSlices
[img
];
3499 for (row
= 0; row
< srcHeight
; row
++) {
3500 GLuint
*dstUI
= (GLuint
*) dstRow
;
3502 for (col
= 0; col
< srcWidth
; col
++) {
3504 r
= MIN2(src
[RCOMP
], 0x3ff);
3505 g
= MIN2(src
[GCOMP
], 0x3ff);
3506 b
= MIN2(src
[BCOMP
], 0x3ff);
3507 a
= MIN2(src
[ACOMP
], 0x003);
3508 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3512 for (col
= 0; col
< srcWidth
; col
++) {
3514 r
= CLAMP((GLint
) src
[RCOMP
], 0, 0x3ff);
3515 g
= CLAMP((GLint
) src
[GCOMP
], 0, 0x3ff);
3516 b
= CLAMP((GLint
) src
[BCOMP
], 0, 0x3ff);
3517 a
= CLAMP((GLint
) src
[ACOMP
], 0, 0x003);
3518 dstUI
[col
] = (a
<< 30) | (b
<< 20) | (g
<< 10) | (r
);
3522 dstRow
+= dstRowStride
;
3525 free((void *) tempImage
);
3531 _mesa_texstore_abgr2101010(TEXSTORE_PARAMS
)
3533 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3535 ASSERT(dstFormat
== MESA_FORMAT_R10G10B10A2_UNORM
);
3536 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3540 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3543 srcWidth
, srcHeight
, srcDepth
,
3544 srcFormat
, srcType
, srcAddr
,
3546 ctx
->_ImageTransferState
);
3547 const GLfloat
*src
= tempImage
;
3548 GLint img
, row
, col
;
3551 for (img
= 0; img
< srcDepth
; img
++) {
3552 GLubyte
*dstRow
= dstSlices
[img
];
3554 for (row
= 0; row
< srcHeight
; row
++) {
3555 GLuint
*dstUI
= (GLuint
*) dstRow
;
3556 for (col
= 0; col
< srcWidth
; col
++) {
3559 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
3560 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
3561 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
3562 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
3563 dstUI
[col
] = PACK_COLOR_2101010_US(a
, b
, g
, r
);
3566 dstRow
+= dstRowStride
;
3569 free((void *) tempImage
);
3576 texstore_depth_stencil(TEXSTORE_PARAMS
)
3578 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3579 static GLboolean initialized
= GL_FALSE
;
3582 memset(table
, 0, sizeof table
);
3584 table
[MESA_FORMAT_S8_UINT_Z24_UNORM
] = _mesa_texstore_z24_s8
;
3585 table
[MESA_FORMAT_Z24_UNORM_S8_UINT
] = _mesa_texstore_s8_z24
;
3586 table
[MESA_FORMAT_Z_UNORM16
] = _mesa_texstore_z16
;
3587 table
[MESA_FORMAT_Z24_UNORM_X8_UINT
] = _mesa_texstore_x8_z24
;
3588 table
[MESA_FORMAT_X8_UINT_Z24_UNORM
] = _mesa_texstore_z24_x8
;
3589 table
[MESA_FORMAT_Z_UNORM32
] = _mesa_texstore_z32
;
3590 table
[MESA_FORMAT_S_UINT8
] = _mesa_texstore_s8
;
3591 table
[MESA_FORMAT_Z_FLOAT32
] = _mesa_texstore_z32
;
3592 table
[MESA_FORMAT_Z32_FLOAT_S8X24_UINT
] = _mesa_texstore_z32f_x24s8
;
3594 initialized
= GL_TRUE
;
3597 ASSERT(table
[dstFormat
]);
3598 return table
[dstFormat
](ctx
, dims
, baseInternalFormat
,
3599 dstFormat
, dstRowStride
, dstSlices
,
3600 srcWidth
, srcHeight
, srcDepth
,
3601 srcFormat
, srcType
, srcAddr
, srcPacking
);
3605 texstore_compressed(TEXSTORE_PARAMS
)
3607 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3608 static GLboolean initialized
= GL_FALSE
;
3611 memset(table
, 0, sizeof table
);
3613 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3614 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3615 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3616 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3617 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
3618 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
3619 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3620 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3621 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3622 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3623 table
[MESA_FORMAT_R_RGTC1_UNORM
] = _mesa_texstore_red_rgtc1
;
3624 table
[MESA_FORMAT_R_RGTC1_SNORM
] = _mesa_texstore_signed_red_rgtc1
;
3625 table
[MESA_FORMAT_RG_RGTC2_UNORM
] = _mesa_texstore_rg_rgtc2
;
3626 table
[MESA_FORMAT_RG_RGTC2_SNORM
] = _mesa_texstore_signed_rg_rgtc2
;
3627 table
[MESA_FORMAT_L_LATC1_UNORM
] = _mesa_texstore_red_rgtc1
;
3628 table
[MESA_FORMAT_L_LATC1_SNORM
] = _mesa_texstore_signed_red_rgtc1
;
3629 table
[MESA_FORMAT_LA_LATC2_UNORM
] = _mesa_texstore_rg_rgtc2
;
3630 table
[MESA_FORMAT_LA_LATC2_SNORM
] = _mesa_texstore_signed_rg_rgtc2
;
3631 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
3632 table
[MESA_FORMAT_ETC2_RGB8
] = _mesa_texstore_etc2_rgb8
;
3633 table
[MESA_FORMAT_ETC2_SRGB8
] = _mesa_texstore_etc2_srgb8
;
3634 table
[MESA_FORMAT_ETC2_RGBA8_EAC
] = _mesa_texstore_etc2_rgba8_eac
;
3635 table
[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC
] = _mesa_texstore_etc2_srgb8_alpha8_eac
;
3636 table
[MESA_FORMAT_ETC2_R11_EAC
] = _mesa_texstore_etc2_r11_eac
;
3637 table
[MESA_FORMAT_ETC2_RG11_EAC
] = _mesa_texstore_etc2_rg11_eac
;
3638 table
[MESA_FORMAT_ETC2_SIGNED_R11_EAC
] = _mesa_texstore_etc2_signed_r11_eac
;
3639 table
[MESA_FORMAT_ETC2_SIGNED_RG11_EAC
] = _mesa_texstore_etc2_signed_rg11_eac
;
3640 table
[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
] =
3641 _mesa_texstore_etc2_rgb8_punchthrough_alpha1
;
3642 table
[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
] =
3643 _mesa_texstore_etc2_srgb8_punchthrough_alpha1
;
3645 initialized
= GL_TRUE
;
3648 ASSERT(table
[dstFormat
]);
3649 return table
[dstFormat
](ctx
, dims
, baseInternalFormat
,
3650 dstFormat
, dstRowStride
, dstSlices
,
3651 srcWidth
, srcHeight
, srcDepth
,
3652 srcFormat
, srcType
, srcAddr
, srcPacking
);
3656 invert_swizzle(uint8_t dst
[4], const uint8_t src
[4])
3660 dst
[0] = MESA_FORMAT_SWIZZLE_NONE
;
3661 dst
[1] = MESA_FORMAT_SWIZZLE_NONE
;
3662 dst
[2] = MESA_FORMAT_SWIZZLE_NONE
;
3663 dst
[3] = MESA_FORMAT_SWIZZLE_NONE
;
3665 for (i
= 0; i
< 4; ++i
)
3666 for (j
= 0; j
< 4; ++j
)
3667 if (src
[j
] == i
&& dst
[i
] == MESA_FORMAT_SWIZZLE_NONE
)
3671 /** Store a texture by per-channel conversions and swizzling.
3673 * This function attempts to perform a texstore operation by doing simple
3674 * per-channel conversions and swizzling. This covers a huge chunk of the
3675 * texture storage operations that anyone cares about. If this function is
3676 * incapable of performing the operation, it bails and returns GL_FALSE.
3679 texstore_swizzle(TEXSTORE_PARAMS
)
3681 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
3682 srcFormat
, srcType
);
3683 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
3684 srcWidth
, srcHeight
, srcFormat
, srcType
);
3685 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dims
,
3686 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
3687 const int src_components
= _mesa_components_in_format(srcFormat
);
3689 GLubyte swizzle
[4], rgba2base
[6], base2src
[6], rgba2dst
[4], dst2rgba
[4];
3690 const GLubyte
*swap
;
3693 bool is_array
, normalized
, need_swap
;
3695 const GLubyte
*src_row
;
3698 is_array
= _mesa_format_to_array(dstFormat
, &dst_type
, &dst_components
,
3699 rgba2dst
, &normalized
);
3706 case GL_UNSIGNED_BYTE
:
3708 case GL_UNSIGNED_SHORT
:
3710 case GL_UNSIGNED_INT
:
3712 /* If wa have to swap bytes in a multi-byte datatype, that means
3713 * we're not doing an array conversion anymore */
3714 if (srcPacking
->SwapBytes
)
3718 case GL_UNSIGNED_INT_8_8_8_8
:
3719 need_swap
= srcPacking
->SwapBytes
;
3720 if (_mesa_little_endian())
3721 need_swap
= !need_swap
;
3722 srcType
= GL_UNSIGNED_BYTE
;
3724 case GL_UNSIGNED_INT_8_8_8_8_REV
:
3725 need_swap
= srcPacking
->SwapBytes
;
3726 if (!_mesa_little_endian())
3727 need_swap
= !need_swap
;
3728 srcType
= GL_UNSIGNED_BYTE
;
3733 swap
= need_swap
? map_3210
: map_identity
;
3735 compute_component_mapping(srcFormat
, baseInternalFormat
, base2src
);
3736 compute_component_mapping(baseInternalFormat
, GL_RGBA
, rgba2base
);
3737 invert_swizzle(dst2rgba
, rgba2dst
);
3739 for (i
= 0; i
< 4; i
++) {
3740 if (dst2rgba
[i
] == MESA_FORMAT_SWIZZLE_NONE
)
3741 swizzle
[i
] = MESA_FORMAT_SWIZZLE_NONE
;
3743 swizzle
[i
] = swap
[base2src
[rgba2base
[dst2rgba
[i
]]]];
3746 /* Is it normalized? */
3747 normalized
|= !_mesa_is_enum_format_integer(srcFormat
);
3749 for (img
= 0; img
< srcDepth
; img
++) {
3750 if (dstRowStride
== srcWidth
* dst_components
&&
3751 srcRowStride
== srcWidth
* src_components
) {
3752 _mesa_swizzle_and_convert(dstSlices
[img
], dst_type
, dst_components
,
3753 srcImage
, srcType
, src_components
,
3754 swizzle
, normalized
, srcWidth
* srcHeight
);
3757 dst_row
= dstSlices
[img
];
3758 for (row
= 0; row
< srcHeight
; row
++) {
3759 _mesa_swizzle_and_convert(dst_row
, dst_type
, dst_components
,
3760 src_row
, srcType
, src_components
,
3761 swizzle
, normalized
, srcWidth
);
3762 dst_row
+= dstRowStride
;
3763 src_row
+= srcRowStride
;
3766 srcImage
+= srcImageStride
;
3774 texstore_rgba(TEXSTORE_PARAMS
)
3776 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3777 static GLboolean initialized
= GL_FALSE
;
3780 memset(table
, 0, sizeof table
);
3782 table
[MESA_FORMAT_A8B8G8R8_UNORM
] = _mesa_texstore_rgba8888
;
3783 table
[MESA_FORMAT_R8G8B8A8_UNORM
] = _mesa_texstore_rgba8888
;
3784 table
[MESA_FORMAT_B8G8R8A8_UNORM
] = _mesa_texstore_argb8888
;
3785 table
[MESA_FORMAT_A8R8G8B8_UNORM
] = _mesa_texstore_argb8888
;
3786 table
[MESA_FORMAT_X8B8G8R8_UNORM
] = _mesa_texstore_rgba8888
;
3787 table
[MESA_FORMAT_R8G8B8X8_UNORM
] = _mesa_texstore_rgba8888
;
3788 table
[MESA_FORMAT_B8G8R8X8_UNORM
] = _mesa_texstore_argb8888
;
3789 table
[MESA_FORMAT_X8R8G8B8_UNORM
] = _mesa_texstore_argb8888
;
3790 table
[MESA_FORMAT_BGR_UNORM8
] = _mesa_texstore_rgb888
;
3791 table
[MESA_FORMAT_RGB_UNORM8
] = _mesa_texstore_bgr888
;
3792 table
[MESA_FORMAT_B5G6R5_UNORM
] = _mesa_texstore_rgb565
;
3793 table
[MESA_FORMAT_R5G6B5_UNORM
] = _mesa_texstore_rgb565
;
3794 table
[MESA_FORMAT_B4G4R4A4_UNORM
] = store_ubyte_texture
;
3795 table
[MESA_FORMAT_A4R4G4B4_UNORM
] = store_ubyte_texture
;
3796 table
[MESA_FORMAT_A1B5G5R5_UNORM
] = store_ubyte_texture
;
3797 table
[MESA_FORMAT_B5G5R5A1_UNORM
] = store_ubyte_texture
;
3798 table
[MESA_FORMAT_A1R5G5B5_UNORM
] = store_ubyte_texture
;
3799 table
[MESA_FORMAT_L4A4_UNORM
] = _mesa_texstore_unorm44
;
3800 table
[MESA_FORMAT_L8A8_UNORM
] = _mesa_texstore_unorm88
;
3801 table
[MESA_FORMAT_A8L8_UNORM
] = _mesa_texstore_unorm88
;
3802 table
[MESA_FORMAT_L16A16_UNORM
] = _mesa_texstore_unorm1616
;
3803 table
[MESA_FORMAT_A16L16_UNORM
] = _mesa_texstore_unorm1616
;
3804 table
[MESA_FORMAT_B2G3R3_UNORM
] = store_ubyte_texture
;
3805 table
[MESA_FORMAT_A_UNORM8
] = _mesa_texstore_unorm8
;
3806 table
[MESA_FORMAT_A_UNORM16
] = _mesa_texstore_unorm16
;
3807 table
[MESA_FORMAT_L_UNORM8
] = _mesa_texstore_unorm8
;
3808 table
[MESA_FORMAT_L_UNORM16
] = _mesa_texstore_unorm16
;
3809 table
[MESA_FORMAT_I_UNORM8
] = _mesa_texstore_unorm8
;
3810 table
[MESA_FORMAT_I_UNORM16
] = _mesa_texstore_unorm16
;
3811 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3812 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3813 table
[MESA_FORMAT_R_UNORM8
] = _mesa_texstore_unorm8
;
3814 table
[MESA_FORMAT_R8G8_UNORM
] = _mesa_texstore_unorm88
;
3815 table
[MESA_FORMAT_G8R8_UNORM
] = _mesa_texstore_unorm88
;
3816 table
[MESA_FORMAT_R_UNORM16
] = _mesa_texstore_unorm16
;
3817 table
[MESA_FORMAT_R16G16_UNORM
] = _mesa_texstore_unorm1616
;
3818 table
[MESA_FORMAT_G16R16_UNORM
] = _mesa_texstore_unorm1616
;
3819 table
[MESA_FORMAT_B10G10R10A2_UNORM
] = _mesa_texstore_argb2101010
;
3820 table
[MESA_FORMAT_BGR_SRGB8
] = _mesa_texstore_srgb8
;
3821 table
[MESA_FORMAT_A8B8G8R8_SRGB
] = _mesa_texstore_srgba8
;
3822 table
[MESA_FORMAT_B8G8R8A8_SRGB
] = _mesa_texstore_sargb8
;
3823 table
[MESA_FORMAT_L_SRGB8
] = _mesa_texstore_sl8
;
3824 table
[MESA_FORMAT_L8A8_SRGB
] = _mesa_texstore_sla8
;
3825 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3826 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3827 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3828 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3829 table
[MESA_FORMAT_A_FLOAT32
] = _mesa_texstore_rgba_float32
;
3830 table
[MESA_FORMAT_A_FLOAT16
] = _mesa_texstore_rgba_float16
;
3831 table
[MESA_FORMAT_L_FLOAT32
] = _mesa_texstore_rgba_float32
;
3832 table
[MESA_FORMAT_L_FLOAT16
] = _mesa_texstore_rgba_float16
;
3833 table
[MESA_FORMAT_LA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3834 table
[MESA_FORMAT_LA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3835 table
[MESA_FORMAT_I_FLOAT32
] = _mesa_texstore_rgba_float32
;
3836 table
[MESA_FORMAT_I_FLOAT16
] = _mesa_texstore_rgba_float16
;
3837 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
3838 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
3839 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
3840 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
3841 table
[MESA_FORMAT_R_SNORM8
] = _mesa_texstore_snorm8
;
3842 table
[MESA_FORMAT_R8G8_SNORM
] = _mesa_texstore_snorm88
;
3843 table
[MESA_FORMAT_X8B8G8R8_SNORM
] = _mesa_texstore_signed_rgbx8888
;
3844 table
[MESA_FORMAT_A8B8G8R8_SNORM
] = _mesa_texstore_signed_rgba8888
;
3845 table
[MESA_FORMAT_R8G8B8A8_SNORM
] = _mesa_texstore_signed_rgba8888
;
3846 table
[MESA_FORMAT_R_SNORM16
] = _mesa_texstore_snorm16
;
3847 table
[MESA_FORMAT_R16G16_SNORM
] = _mesa_texstore_snorm1616
;
3848 table
[MESA_FORMAT_RGB_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3849 table
[MESA_FORMAT_RGBA_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3850 table
[MESA_FORMAT_RGBA_UNORM16
] = _mesa_texstore_rgba_16
;
3851 table
[MESA_FORMAT_A_SNORM8
] = _mesa_texstore_snorm8
;
3852 table
[MESA_FORMAT_L_SNORM8
] = _mesa_texstore_snorm8
;
3853 table
[MESA_FORMAT_L8A8_SNORM
] = _mesa_texstore_snorm88
;
3854 table
[MESA_FORMAT_I_SNORM8
] = _mesa_texstore_snorm8
;
3855 table
[MESA_FORMAT_A_SNORM16
] = _mesa_texstore_snorm16
;
3856 table
[MESA_FORMAT_L_SNORM16
] = _mesa_texstore_snorm16
;
3857 table
[MESA_FORMAT_LA_SNORM16
] = _mesa_texstore_snorm1616
;
3858 table
[MESA_FORMAT_I_SNORM16
] = _mesa_texstore_snorm16
;
3859 table
[MESA_FORMAT_R9G9B9E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
3860 table
[MESA_FORMAT_R11G11B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
3861 table
[MESA_FORMAT_Z_FLOAT32
] = _mesa_texstore_z32
;
3862 table
[MESA_FORMAT_Z32_FLOAT_S8X24_UINT
] = _mesa_texstore_z32f_x24s8
;
3864 table
[MESA_FORMAT_A_UINT8
] = _mesa_texstore_rgba_uint8
;
3865 table
[MESA_FORMAT_A_UINT16
] = _mesa_texstore_rgba_uint16
;
3866 table
[MESA_FORMAT_A_UINT32
] = _mesa_texstore_rgba_uint32
;
3867 table
[MESA_FORMAT_A_SINT8
] = _mesa_texstore_rgba_int8
;
3868 table
[MESA_FORMAT_A_SINT16
] = _mesa_texstore_rgba_int16
;
3869 table
[MESA_FORMAT_A_SINT32
] = _mesa_texstore_rgba_int32
;
3871 table
[MESA_FORMAT_I_UINT8
] = _mesa_texstore_rgba_uint8
;
3872 table
[MESA_FORMAT_I_UINT16
] = _mesa_texstore_rgba_uint16
;
3873 table
[MESA_FORMAT_I_UINT32
] = _mesa_texstore_rgba_uint32
;
3874 table
[MESA_FORMAT_I_SINT8
] = _mesa_texstore_rgba_int8
;
3875 table
[MESA_FORMAT_I_SINT16
] = _mesa_texstore_rgba_int16
;
3876 table
[MESA_FORMAT_I_SINT32
] = _mesa_texstore_rgba_int32
;
3878 table
[MESA_FORMAT_L_UINT8
] = _mesa_texstore_rgba_uint8
;
3879 table
[MESA_FORMAT_L_UINT16
] = _mesa_texstore_rgba_uint16
;
3880 table
[MESA_FORMAT_L_UINT32
] = _mesa_texstore_rgba_uint32
;
3881 table
[MESA_FORMAT_L_SINT8
] = _mesa_texstore_rgba_int8
;
3882 table
[MESA_FORMAT_L_SINT16
] = _mesa_texstore_rgba_int16
;
3883 table
[MESA_FORMAT_L_SINT32
] = _mesa_texstore_rgba_int32
;
3885 table
[MESA_FORMAT_LA_UINT8
] = _mesa_texstore_rgba_uint8
;
3886 table
[MESA_FORMAT_LA_UINT16
] = _mesa_texstore_rgba_uint16
;
3887 table
[MESA_FORMAT_LA_UINT32
] = _mesa_texstore_rgba_uint32
;
3888 table
[MESA_FORMAT_LA_SINT8
] = _mesa_texstore_rgba_int8
;
3889 table
[MESA_FORMAT_LA_SINT16
] = _mesa_texstore_rgba_int16
;
3890 table
[MESA_FORMAT_LA_SINT32
] = _mesa_texstore_rgba_int32
;
3892 table
[MESA_FORMAT_R_SINT8
] = _mesa_texstore_rgba_int8
;
3893 table
[MESA_FORMAT_RG_SINT8
] = _mesa_texstore_rgba_int8
;
3894 table
[MESA_FORMAT_RGB_SINT8
] = _mesa_texstore_rgba_int8
;
3895 table
[MESA_FORMAT_RGBA_SINT8
] = _mesa_texstore_rgba_int8
;
3896 table
[MESA_FORMAT_R_SINT16
] = _mesa_texstore_rgba_int16
;
3897 table
[MESA_FORMAT_RG_SINT16
] = _mesa_texstore_rgba_int16
;
3898 table
[MESA_FORMAT_RGB_SINT16
] = _mesa_texstore_rgba_int16
;
3899 table
[MESA_FORMAT_RGBA_SINT16
] = _mesa_texstore_rgba_int16
;
3900 table
[MESA_FORMAT_R_SINT32
] = _mesa_texstore_rgba_int32
;
3901 table
[MESA_FORMAT_RG_SINT32
] = _mesa_texstore_rgba_int32
;
3902 table
[MESA_FORMAT_RGB_SINT32
] = _mesa_texstore_rgba_int32
;
3903 table
[MESA_FORMAT_RGBA_SINT32
] = _mesa_texstore_rgba_int32
;
3905 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
3906 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
3907 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
3908 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
3909 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
3910 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
3911 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
3912 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
3913 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
3914 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
3915 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
3916 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
3918 table
[MESA_FORMAT_B10G10R10A2_UINT
] = _mesa_texstore_argb2101010_uint
;
3919 table
[MESA_FORMAT_R10G10B10A2_UINT
] = _mesa_texstore_abgr2101010_uint
;
3921 table
[MESA_FORMAT_B4G4R4X4_UNORM
] = store_ubyte_texture
;
3922 table
[MESA_FORMAT_B5G5R5X1_UNORM
] = store_ubyte_texture
;
3923 table
[MESA_FORMAT_R8G8B8X8_SNORM
] = _mesa_texstore_signed_rgbx8888
;
3924 table
[MESA_FORMAT_R8G8B8X8_SRGB
] = _mesa_texstore_srgba8
;
3925 table
[MESA_FORMAT_R8G8B8A8_SRGB
] = _mesa_texstore_srgba8
;
3926 table
[MESA_FORMAT_RGBX_UINT8
] = _mesa_texstore_rgba_uint8
;
3927 table
[MESA_FORMAT_RGBX_SINT8
] = _mesa_texstore_rgba_int8
;
3928 table
[MESA_FORMAT_B10G10R10X2_UNORM
] = _mesa_texstore_argb2101010
;
3929 table
[MESA_FORMAT_RGBX_UNORM16
] = _mesa_texstore_rgba_16
;
3930 table
[MESA_FORMAT_RGBX_SNORM16
] = _mesa_texstore_signed_rgba_16
;
3931 table
[MESA_FORMAT_RGBX_FLOAT16
] = _mesa_texstore_rgba_float16
;
3932 table
[MESA_FORMAT_RGBX_UINT16
] = _mesa_texstore_rgba_uint16
;
3933 table
[MESA_FORMAT_RGBX_SINT16
] = _mesa_texstore_rgba_int16
;
3934 table
[MESA_FORMAT_RGBX_FLOAT32
] = _mesa_texstore_rgba_float32
;
3935 table
[MESA_FORMAT_RGBX_UINT32
] = _mesa_texstore_rgba_uint32
;
3936 table
[MESA_FORMAT_RGBX_SINT32
] = _mesa_texstore_rgba_int32
;
3938 table
[MESA_FORMAT_R10G10B10A2_UNORM
] = _mesa_texstore_abgr2101010
;
3940 table
[MESA_FORMAT_G8R8_SNORM
] = _mesa_texstore_snorm88
;
3941 table
[MESA_FORMAT_G16R16_SNORM
] = _mesa_texstore_snorm1616
;
3943 table
[MESA_FORMAT_B8G8R8X8_SRGB
] = _mesa_texstore_sargb8
;
3945 initialized
= GL_TRUE
;
3948 if (texstore_swizzle(ctx
, dims
, baseInternalFormat
,
3950 dstRowStride
, dstSlices
,
3951 srcWidth
, srcHeight
, srcDepth
,
3952 srcFormat
, srcType
, srcAddr
, srcPacking
)) {
3956 ASSERT(table
[dstFormat
]);
3957 return table
[dstFormat
](ctx
, dims
, baseInternalFormat
,
3958 dstFormat
, dstRowStride
, dstSlices
,
3959 srcWidth
, srcHeight
, srcDepth
,
3960 srcFormat
, srcType
, srcAddr
, srcPacking
);
3964 _mesa_texstore_needs_transfer_ops(struct gl_context
*ctx
,
3965 GLenum baseInternalFormat
,
3966 mesa_format dstFormat
)
3970 /* There are different rules depending on the base format. */
3971 switch (baseInternalFormat
) {
3972 case GL_DEPTH_COMPONENT
:
3973 case GL_DEPTH_STENCIL
:
3974 return ctx
->Pixel
.DepthScale
!= 1.0f
||
3975 ctx
->Pixel
.DepthBias
!= 0.0f
;
3977 case GL_STENCIL_INDEX
:
3982 * Pixel transfer ops (scale, bias, table lookup) do not apply
3983 * to integer formats.
3985 dstType
= _mesa_get_format_datatype(dstFormat
);
3987 return dstType
!= GL_INT
&& dstType
!= GL_UNSIGNED_INT
&&
3988 ctx
->_ImageTransferState
;
3994 _mesa_texstore_can_use_memcpy(struct gl_context
*ctx
,
3995 GLenum baseInternalFormat
, mesa_format dstFormat
,
3996 GLenum srcFormat
, GLenum srcType
,
3997 const struct gl_pixelstore_attrib
*srcPacking
)
3999 if (_mesa_texstore_needs_transfer_ops(ctx
, baseInternalFormat
, dstFormat
)) {
4003 /* The base internal format and the base Mesa format must match. */
4004 if (baseInternalFormat
!= _mesa_get_format_base_format(dstFormat
)) {
4008 /* The Mesa format must match the input format and type. */
4009 if (!_mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
4010 srcPacking
->SwapBytes
)) {
4014 /* Depth texture data needs clamping in following cases:
4015 * - Floating point dstFormat with signed srcType: clamp to [0.0, 1.0].
4016 * - Fixed point dstFormat with signed srcType: clamp to [0, 2^n -1].
4018 * All the cases except one (float dstFormat with float srcType) are ruled
4019 * out by _mesa_format_matches_format_and_type() check above. Handle the
4020 * remaining case here.
4022 if ((baseInternalFormat
== GL_DEPTH_COMPONENT
||
4023 baseInternalFormat
== GL_DEPTH_STENCIL
) &&
4024 (srcType
== GL_FLOAT
||
4025 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)) {
4033 _mesa_texstore_memcpy(TEXSTORE_PARAMS
)
4035 if (!_mesa_texstore_can_use_memcpy(ctx
, baseInternalFormat
, dstFormat
,
4036 srcFormat
, srcType
, srcPacking
)) {
4040 memcpy_texture(ctx
, dims
,
4042 dstRowStride
, dstSlices
,
4043 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
4044 srcAddr
, srcPacking
);
4049 * Store user data into texture memory.
4050 * Called via glTex[Sub]Image1/2/3D()
4051 * \return GL_TRUE for success, GL_FALSE for failure (out of memory).
4054 _mesa_texstore(TEXSTORE_PARAMS
)
4056 if (_mesa_texstore_memcpy(ctx
, dims
, baseInternalFormat
,
4058 dstRowStride
, dstSlices
,
4059 srcWidth
, srcHeight
, srcDepth
,
4060 srcFormat
, srcType
, srcAddr
, srcPacking
)) {
4064 if (_mesa_is_depth_or_stencil_format(baseInternalFormat
)) {
4065 return texstore_depth_stencil(ctx
, dims
, baseInternalFormat
,
4066 dstFormat
, dstRowStride
, dstSlices
,
4067 srcWidth
, srcHeight
, srcDepth
,
4068 srcFormat
, srcType
, srcAddr
, srcPacking
);
4069 } else if (_mesa_is_format_compressed(dstFormat
)) {
4070 return texstore_compressed(ctx
, dims
, baseInternalFormat
,
4071 dstFormat
, dstRowStride
, dstSlices
,
4072 srcWidth
, srcHeight
, srcDepth
,
4073 srcFormat
, srcType
, srcAddr
, srcPacking
);
4075 return texstore_rgba(ctx
, dims
, baseInternalFormat
,
4076 dstFormat
, dstRowStride
, dstSlices
,
4077 srcWidth
, srcHeight
, srcDepth
,
4078 srcFormat
, srcType
, srcAddr
, srcPacking
);
4084 * Normally, we'll only _write_ texel data to a texture when we map it.
4085 * But if the user is providing depth or stencil values and the texture
4086 * image is a combined depth/stencil format, we'll actually read from
4087 * the texture buffer too (in order to insert the depth or stencil values.
4088 * \param userFormat the user-provided image format
4089 * \param texFormat the destination texture format
4092 get_read_write_mode(GLenum userFormat
, mesa_format texFormat
)
4094 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4095 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4096 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4098 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
4103 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4105 * The source of the image data may be user memory or a PBO. In the later
4106 * case, we'll map the PBO, copy from it, then unmap it.
4109 store_texsubimage(struct gl_context
*ctx
,
4110 struct gl_texture_image
*texImage
,
4111 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4112 GLint width
, GLint height
, GLint depth
,
4113 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4114 const struct gl_pixelstore_attrib
*packing
,
4118 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4119 const GLenum target
= texImage
->TexObject
->Target
;
4120 GLboolean success
= GL_FALSE
;
4121 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4122 GLint srcImageStride
= 0;
4125 assert(xoffset
+ width
<= texImage
->Width
);
4126 assert(yoffset
+ height
<= texImage
->Height
);
4127 assert(zoffset
+ depth
<= texImage
->Depth
);
4133 case GL_TEXTURE_2D_ARRAY
:
4134 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4142 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4143 src
= (const GLubyte
*)
4144 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4145 format
, type
, pixels
, packing
, caller
);
4149 /* compute slice info (and do some sanity checks) */
4152 case GL_TEXTURE_RECTANGLE
:
4153 case GL_TEXTURE_CUBE_MAP
:
4154 case GL_TEXTURE_EXTERNAL_OES
:
4155 /* one image slice, nothing special needs to be done */
4158 assert(height
== 1);
4160 assert(yoffset
== 0);
4161 assert(zoffset
== 0);
4163 case GL_TEXTURE_1D_ARRAY
:
4165 assert(zoffset
== 0);
4167 sliceOffset
= yoffset
;
4170 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4172 case GL_TEXTURE_2D_ARRAY
:
4174 sliceOffset
= zoffset
;
4177 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4181 /* we'll store 3D images as a series of slices */
4183 sliceOffset
= zoffset
;
4184 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4187 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4189 sliceOffset
= zoffset
;
4190 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4194 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4198 assert(numSlices
== 1 || srcImageStride
!= 0);
4200 for (slice
= 0; slice
< numSlices
; slice
++) {
4204 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4205 slice
+ sliceOffset
,
4206 xoffset
, yoffset
, width
, height
,
4207 mapMode
, &dstMap
, &dstRowStride
);
4209 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4210 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4211 * used for 3D images.
4213 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4214 texImage
->TexFormat
,
4217 width
, height
, 1, /* w, h, d */
4218 format
, type
, src
, packing
);
4220 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4223 src
+= srcImageStride
;
4230 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4232 _mesa_unmap_teximage_pbo(ctx
, packing
);
4238 * Fallback code for ctx->Driver.TexImage().
4239 * Basically, allocate storage for the texture image, then copy the
4240 * user's image into it.
4243 _mesa_store_teximage(struct gl_context
*ctx
,
4245 struct gl_texture_image
*texImage
,
4246 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4247 const struct gl_pixelstore_attrib
*packing
)
4249 assert(dims
== 1 || dims
== 2 || dims
== 3);
4251 if (texImage
->Width
== 0 || texImage
->Height
== 0 || texImage
->Depth
== 0)
4254 /* allocate storage for texture data */
4255 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4256 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
4260 store_texsubimage(ctx
, texImage
,
4261 0, 0, 0, texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4262 format
, type
, pixels
, packing
, "glTexImage");
4267 * Fallback for Driver.TexSubImage().
4270 _mesa_store_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4271 struct gl_texture_image
*texImage
,
4272 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4273 GLint width
, GLint height
, GLint depth
,
4274 GLenum format
, GLenum type
, const void *pixels
,
4275 const struct gl_pixelstore_attrib
*packing
)
4277 store_texsubimage(ctx
, texImage
,
4278 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4279 format
, type
, pixels
, packing
, "glTexSubImage");
4283 clear_image_to_zero(GLubyte
*dstMap
, GLint dstRowStride
,
4284 GLsizei width
, GLsizei height
,
4285 GLsizei clearValueSize
)
4289 for (y
= 0; y
< height
; y
++) {
4290 memset(dstMap
, 0, clearValueSize
* width
);
4291 dstMap
+= dstRowStride
;
4296 clear_image_to_value(GLubyte
*dstMap
, GLint dstRowStride
,
4297 GLsizei width
, GLsizei height
,
4298 const GLvoid
*clearValue
,
4299 GLsizei clearValueSize
)
4303 for (y
= 0; y
< height
; y
++) {
4304 for (x
= 0; x
< width
; x
++) {
4305 memcpy(dstMap
, clearValue
, clearValueSize
);
4306 dstMap
+= clearValueSize
;
4308 dstMap
+= dstRowStride
- clearValueSize
* width
;
4313 * Fallback for Driver.ClearTexSubImage().
4316 _mesa_store_cleartexsubimage(struct gl_context
*ctx
,
4317 struct gl_texture_image
*texImage
,
4318 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4319 GLsizei width
, GLsizei height
, GLsizei depth
,
4320 const GLvoid
*clearValue
)
4324 GLsizeiptr clearValueSize
;
4327 clearValueSize
= _mesa_get_format_bytes(texImage
->TexFormat
);
4329 for (z
= 0; z
< depth
; z
++) {
4330 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4331 z
+ zoffset
, xoffset
, yoffset
,
4334 &dstMap
, &dstRowStride
);
4335 if (dstMap
== NULL
) {
4336 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glClearTex*Image");
4341 clear_image_to_value(dstMap
, dstRowStride
,
4346 clear_image_to_zero(dstMap
, dstRowStride
,
4351 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, z
+ zoffset
);
4356 * Fallback for Driver.CompressedTexImage()
4359 _mesa_store_compressed_teximage(struct gl_context
*ctx
, GLuint dims
,
4360 struct gl_texture_image
*texImage
,
4361 GLsizei imageSize
, const GLvoid
*data
)
4363 /* only 2D and 3D compressed images are supported at this time */
4365 _mesa_problem(ctx
, "Unexpected glCompressedTexImage1D call");
4369 /* This is pretty simple, because unlike the general texstore path we don't
4370 * have to worry about the usual image unpacking or image transfer
4374 ASSERT(texImage
->Width
> 0);
4375 ASSERT(texImage
->Height
> 0);
4376 ASSERT(texImage
->Depth
> 0);
4378 /* allocate storage for texture data */
4379 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
)) {
4380 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage%uD", dims
);
4384 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
4386 texImage
->Width
, texImage
->Height
, texImage
->Depth
,
4387 texImage
->TexFormat
,
4393 _mesa_compute_compressed_pixelstore(GLuint dims
, struct gl_texture_image
*texImage
,
4394 GLsizei width
, GLsizei height
, GLsizei depth
,
4395 const struct gl_pixelstore_attrib
*packing
,
4396 struct compressed_pixelstore
*store
)
4399 const mesa_format texFormat
= texImage
->TexFormat
;
4401 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4403 store
->SkipBytes
= 0;
4404 store
->TotalBytesPerRow
= store
->CopyBytesPerRow
=
4405 _mesa_format_row_stride(texFormat
, width
);
4406 store
->TotalRowsPerSlice
= store
->CopyRowsPerSlice
=
4407 (height
+ bh
- 1) / bh
;
4408 store
->CopySlices
= depth
;
4410 if (packing
->CompressedBlockWidth
&&
4411 packing
->CompressedBlockSize
) {
4413 bw
= packing
->CompressedBlockWidth
;
4415 if (packing
->RowLength
) {
4416 store
->TotalBytesPerRow
= packing
->CompressedBlockSize
*
4417 (packing
->RowLength
+ bw
- 1) / bw
;
4420 store
->SkipBytes
+= packing
->SkipPixels
* packing
->CompressedBlockSize
/ bw
;
4423 if (dims
> 1 && packing
->CompressedBlockHeight
&&
4424 packing
->CompressedBlockSize
) {
4426 bh
= packing
->CompressedBlockHeight
;
4428 store
->SkipBytes
+= packing
->SkipRows
* store
->TotalBytesPerRow
/ bh
;
4429 store
->CopyRowsPerSlice
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4431 if (packing
->ImageHeight
) {
4432 store
->TotalRowsPerSlice
= (packing
->ImageHeight
+ bh
- 1) / bh
;
4436 if (dims
> 2 && packing
->CompressedBlockDepth
&&
4437 packing
->CompressedBlockSize
) {
4439 int bd
= packing
->CompressedBlockDepth
;
4441 store
->SkipBytes
+= packing
->SkipImages
* store
->TotalBytesPerRow
*
4442 store
->TotalRowsPerSlice
/ bd
;
4448 * Fallback for Driver.CompressedTexSubImage()
4451 _mesa_store_compressed_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4452 struct gl_texture_image
*texImage
,
4453 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4454 GLsizei width
, GLsizei height
, GLsizei depth
,
4456 GLsizei imageSize
, const GLvoid
*data
)
4458 struct compressed_pixelstore store
;
4465 _mesa_problem(ctx
, "Unexpected 1D compressed texsubimage call");
4469 _mesa_compute_compressed_pixelstore(dims
, texImage
, width
, height
, depth
,
4470 &ctx
->Unpack
, &store
);
4472 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4473 data
= _mesa_validate_pbo_compressed_teximage(ctx
, dims
, imageSize
, data
,
4475 "glCompressedTexSubImage");
4479 src
= (const GLubyte
*) data
+ store
.SkipBytes
;
4481 for (slice
= 0; slice
< store
.CopySlices
; slice
++) {
4482 /* Map dest texture buffer */
4483 ctx
->Driver
.MapTextureImage(ctx
, texImage
, slice
+ zoffset
,
4484 xoffset
, yoffset
, width
, height
,
4485 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4486 &dstMap
, &dstRowStride
);
4490 /* copy rows of blocks */
4491 for (i
= 0; i
< store
.CopyRowsPerSlice
; i
++) {
4492 memcpy(dstMap
, src
, store
.CopyBytesPerRow
);
4493 dstMap
+= dstRowStride
;
4494 src
+= store
.TotalBytesPerRow
;
4497 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ zoffset
);
4499 /* advance to next slice */
4500 src
+= store
.TotalBytesPerRow
* (store
.TotalRowsPerSlice
- store
.CopyRowsPerSlice
);
4503 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage%uD",
4508 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);