2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.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"
61 #include "mfeatures.h"
66 #include "texcompress.h"
67 #include "texcompress_fxt1.h"
68 #include "texcompress_rgtc.h"
69 #include "texcompress_s3tc.h"
70 #include "texcompress_etc.h"
74 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
75 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
85 * Texture image storage function.
87 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
91 * Return GL_TRUE if the given image format is one that be converted
92 * to another format by swizzling.
95 can_swizzle(GLenum logicalBaseFormat
)
97 switch (logicalBaseFormat
) {
100 case GL_LUMINANCE_ALPHA
:
136 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
137 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
138 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
139 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
142 static const struct {
145 GLubyte from_rgba
[6];
146 } mappings
[MAX_IDX
] =
156 MAP4(ZERO
, ZERO
, ZERO
, 0),
186 MAP4(0, ZERO
, ZERO
, ONE
),
192 MAP4(ZERO
, 0, ZERO
, ONE
),
198 MAP4(ZERO
, ZERO
, 0, ONE
),
222 MAP4(0, 1, ZERO
, ONE
),
230 * Convert a GL image format enum to an IDX_* value (see above).
233 get_map_idx(GLenum value
)
236 case GL_LUMINANCE
: return IDX_LUMINANCE
;
237 case GL_ALPHA
: return IDX_ALPHA
;
238 case GL_INTENSITY
: return IDX_INTENSITY
;
239 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
240 case GL_RGB
: return IDX_RGB
;
241 case GL_RGBA
: return IDX_RGBA
;
242 case GL_RED
: return IDX_RED
;
243 case GL_GREEN
: return IDX_GREEN
;
244 case GL_BLUE
: return IDX_BLUE
;
245 case GL_BGR
: return IDX_BGR
;
246 case GL_BGRA
: return IDX_BGRA
;
247 case GL_ABGR_EXT
: return IDX_ABGR
;
248 case GL_RG
: return IDX_RG
;
250 _mesa_problem(NULL
, "Unexpected inFormat");
257 * When promoting texture formats (see below) we need to compute the
258 * mapping of dest components back to source components.
259 * This function does that.
260 * \param inFormat the incoming format of the texture
261 * \param outFormat the final texture format
262 * \return map[6] a full 6-component map
265 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
268 const int inFmt
= get_map_idx(inFormat
);
269 const int outFmt
= get_map_idx(outFormat
);
270 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
271 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
274 for (i
= 0; i
< 4; i
++)
275 map
[i
] = in2rgba
[rgba2out
[i
]];
281 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
282 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
283 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
295 * Make a temporary (color) texture image with GLfloat components.
296 * Apply all needed pixel unpacking and pixel transfer operations.
297 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
298 * Suppose the user specifies GL_LUMINANCE as the internal texture format
299 * but the graphics hardware doesn't support luminance textures. So, we might
300 * use an RGB hardware format instead.
301 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
303 * \param ctx the rendering context
304 * \param dims image dimensions: 1, 2 or 3
305 * \param logicalBaseFormat basic texture derived from the user's
306 * internal texture format value
307 * \param textureBaseFormat the actual basic format of the texture
308 * \param srcWidth source image width
309 * \param srcHeight source image height
310 * \param srcDepth source image depth
311 * \param srcFormat source image format
312 * \param srcType source image type
313 * \param srcAddr source image address
314 * \param srcPacking source image pixel packing
315 * \return resulting image with format = textureBaseFormat and type = GLfloat.
318 _mesa_make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
319 GLenum logicalBaseFormat
,
320 GLenum textureBaseFormat
,
321 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
322 GLenum srcFormat
, GLenum srcType
,
323 const GLvoid
*srcAddr
,
324 const struct gl_pixelstore_attrib
*srcPacking
,
325 GLbitfield transferOps
)
328 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
329 const GLint srcStride
=
330 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
334 ASSERT(dims
>= 1 && dims
<= 3);
336 ASSERT(logicalBaseFormat
== GL_RGBA
||
337 logicalBaseFormat
== GL_RGB
||
338 logicalBaseFormat
== GL_RG
||
339 logicalBaseFormat
== GL_RED
||
340 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
341 logicalBaseFormat
== GL_LUMINANCE
||
342 logicalBaseFormat
== GL_ALPHA
||
343 logicalBaseFormat
== GL_INTENSITY
||
344 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
346 ASSERT(textureBaseFormat
== GL_RGBA
||
347 textureBaseFormat
== GL_RGB
||
348 textureBaseFormat
== GL_RG
||
349 textureBaseFormat
== GL_RED
||
350 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
351 textureBaseFormat
== GL_LUMINANCE
||
352 textureBaseFormat
== GL_ALPHA
||
353 textureBaseFormat
== GL_INTENSITY
||
354 textureBaseFormat
== GL_DEPTH_COMPONENT
);
356 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
357 * components
* sizeof(GLfloat
));
362 for (img
= 0; img
< srcDepth
; img
++) {
364 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
368 for (row
= 0; row
< srcHeight
; row
++) {
369 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
370 dst
, srcFormat
, srcType
, src
,
371 srcPacking
, transferOps
);
372 dst
+= srcWidth
* components
;
377 if (logicalBaseFormat
!= textureBaseFormat
) {
379 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
380 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
385 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
386 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
387 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
389 /* The actual texture format should have at least as many components
390 * as the logical texture format.
392 ASSERT(texComponents
>= logComponents
);
394 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
395 * texComponents
* sizeof(GLfloat
));
401 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
403 n
= srcWidth
* srcHeight
* srcDepth
;
404 for (i
= 0; i
< n
; i
++) {
406 for (k
= 0; k
< texComponents
; k
++) {
409 newImage
[i
* texComponents
+ k
] = 0.0F
;
411 newImage
[i
* texComponents
+ k
] = 1.0F
;
413 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
418 tempImage
= newImage
;
426 * Make temporary image with uint pixel values. Used for unsigned
427 * integer-valued textures.
430 make_temp_uint_image(struct gl_context
*ctx
, GLuint dims
,
431 GLenum logicalBaseFormat
,
432 GLenum textureBaseFormat
,
433 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
434 GLenum srcFormat
, GLenum srcType
,
435 const GLvoid
*srcAddr
,
436 const struct gl_pixelstore_attrib
*srcPacking
)
439 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
440 const GLint srcStride
=
441 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
445 ASSERT(dims
>= 1 && dims
<= 3);
447 ASSERT(logicalBaseFormat
== GL_RGBA
||
448 logicalBaseFormat
== GL_RGB
||
449 logicalBaseFormat
== GL_RG
||
450 logicalBaseFormat
== GL_RED
||
451 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
452 logicalBaseFormat
== GL_LUMINANCE
||
453 logicalBaseFormat
== GL_INTENSITY
||
454 logicalBaseFormat
== GL_ALPHA
);
456 ASSERT(textureBaseFormat
== GL_RGBA
||
457 textureBaseFormat
== GL_RGB
||
458 textureBaseFormat
== GL_RG
||
459 textureBaseFormat
== GL_RED
||
460 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
461 textureBaseFormat
== GL_LUMINANCE
||
462 textureBaseFormat
== GL_INTENSITY
||
463 textureBaseFormat
== GL_ALPHA
);
465 tempImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
466 * components
* sizeof(GLuint
));
471 for (img
= 0; img
< srcDepth
; img
++) {
473 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
477 for (row
= 0; row
< srcHeight
; row
++) {
478 _mesa_unpack_color_span_uint(ctx
, srcWidth
, logicalBaseFormat
,
479 dst
, srcFormat
, srcType
, src
,
481 dst
+= srcWidth
* components
;
486 if (logicalBaseFormat
!= textureBaseFormat
) {
488 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
489 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
494 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
495 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
496 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
498 /* The actual texture format should have at least as many components
499 * as the logical texture format.
501 ASSERT(texComponents
>= logComponents
);
503 newImage
= (GLuint
*) malloc(srcWidth
* srcHeight
* srcDepth
504 * texComponents
* sizeof(GLuint
));
510 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
512 n
= srcWidth
* srcHeight
* srcDepth
;
513 for (i
= 0; i
< n
; i
++) {
515 for (k
= 0; k
< texComponents
; k
++) {
518 newImage
[i
* texComponents
+ k
] = 0;
520 newImage
[i
* texComponents
+ k
] = 1;
522 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
527 tempImage
= newImage
;
536 * Make a temporary (color) texture image with GLubyte components.
537 * Apply all needed pixel unpacking and pixel transfer operations.
538 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
539 * Suppose the user specifies GL_LUMINANCE as the internal texture format
540 * but the graphics hardware doesn't support luminance textures. So, we might
541 * use an RGB hardware format instead.
542 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
544 * \param ctx the rendering context
545 * \param dims image dimensions: 1, 2 or 3
546 * \param logicalBaseFormat basic texture derived from the user's
547 * internal texture format value
548 * \param textureBaseFormat the actual basic format of the texture
549 * \param srcWidth source image width
550 * \param srcHeight source image height
551 * \param srcDepth source image depth
552 * \param srcFormat source image format
553 * \param srcType source image type
554 * \param srcAddr source image address
555 * \param srcPacking source image pixel packing
556 * \return resulting image with format = textureBaseFormat and type = GLubyte.
559 _mesa_make_temp_ubyte_image(struct gl_context
*ctx
, GLuint dims
,
560 GLenum logicalBaseFormat
,
561 GLenum textureBaseFormat
,
562 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
563 GLenum srcFormat
, GLenum srcType
,
564 const GLvoid
*srcAddr
,
565 const struct gl_pixelstore_attrib
*srcPacking
)
567 GLuint transferOps
= ctx
->_ImageTransferState
;
568 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
570 GLubyte
*tempImage
, *dst
;
572 ASSERT(dims
>= 1 && dims
<= 3);
574 ASSERT(logicalBaseFormat
== GL_RGBA
||
575 logicalBaseFormat
== GL_RGB
||
576 logicalBaseFormat
== GL_RG
||
577 logicalBaseFormat
== GL_RED
||
578 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
579 logicalBaseFormat
== GL_LUMINANCE
||
580 logicalBaseFormat
== GL_ALPHA
||
581 logicalBaseFormat
== GL_INTENSITY
);
583 ASSERT(textureBaseFormat
== GL_RGBA
||
584 textureBaseFormat
== GL_RGB
||
585 textureBaseFormat
== GL_RG
||
586 textureBaseFormat
== GL_RED
||
587 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
588 textureBaseFormat
== GL_LUMINANCE
||
589 textureBaseFormat
== GL_ALPHA
||
590 textureBaseFormat
== GL_INTENSITY
);
592 /* unpack and transfer the source image */
593 tempImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
594 * components
* sizeof(GLubyte
));
600 for (img
= 0; img
< srcDepth
; img
++) {
601 const GLint srcStride
=
602 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
604 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
608 for (row
= 0; row
< srcHeight
; row
++) {
609 _mesa_unpack_color_span_ubyte(ctx
, srcWidth
, logicalBaseFormat
, dst
,
610 srcFormat
, srcType
, src
, srcPacking
,
612 dst
+= srcWidth
* components
;
617 if (logicalBaseFormat
!= textureBaseFormat
) {
618 /* one more conversion step */
619 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
620 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
625 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
626 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
627 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
629 /* The actual texture format should have at least as many components
630 * as the logical texture format.
632 ASSERT(texComponents
>= logComponents
);
634 newImage
= (GLubyte
*) malloc(srcWidth
* srcHeight
* srcDepth
635 * texComponents
* sizeof(GLubyte
));
641 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
643 n
= srcWidth
* srcHeight
* srcDepth
;
644 for (i
= 0; i
< n
; i
++) {
646 for (k
= 0; k
< texComponents
; k
++) {
649 newImage
[i
* texComponents
+ k
] = 0;
651 newImage
[i
* texComponents
+ k
] = 255;
653 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
658 tempImage
= newImage
;
666 * Copy GLubyte pixels from <src> to <dst> with swizzling.
667 * \param dst destination pixels
668 * \param dstComponents number of color components in destination pixels
669 * \param src source pixels
670 * \param srcComponents number of color components in source pixels
671 * \param map the swizzle mapping. map[X] says where to find the X component
672 * in the source image's pixels. For example, if the source image
673 * is GL_BGRA and X = red, map[0] yields 2.
674 * \param count number of pixels to copy/swizzle.
677 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
678 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
680 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
683 for (i = 0; i < count; i++) { \
685 if (srcComps == 4) { \
686 COPY_4UBV(tmp, src); \
689 for (j = 0; j < srcComps; j++) { \
694 for (j = 0; j < dstComps; j++) { \
695 dst[j] = tmp[map[j]]; \
706 ASSERT(srcComponents
<= 4);
707 ASSERT(dstComponents
<= 4);
709 switch (dstComponents
) {
711 switch (srcComponents
) {
713 SWZ_CPY(dst
, src
, count
, 4, 4);
716 SWZ_CPY(dst
, src
, count
, 4, 3);
719 SWZ_CPY(dst
, src
, count
, 4, 2);
722 SWZ_CPY(dst
, src
, count
, 4, 1);
729 switch (srcComponents
) {
731 SWZ_CPY(dst
, src
, count
, 3, 4);
734 SWZ_CPY(dst
, src
, count
, 3, 3);
737 SWZ_CPY(dst
, src
, count
, 3, 2);
740 SWZ_CPY(dst
, src
, count
, 3, 1);
747 switch (srcComponents
) {
749 SWZ_CPY(dst
, src
, count
, 2, 4);
752 SWZ_CPY(dst
, src
, count
, 2, 3);
755 SWZ_CPY(dst
, src
, count
, 2, 2);
758 SWZ_CPY(dst
, src
, count
, 2, 1);
765 switch (srcComponents
) {
767 SWZ_CPY(dst
, src
, count
, 1, 4);
770 SWZ_CPY(dst
, src
, count
, 1, 3);
773 SWZ_CPY(dst
, src
, count
, 1, 2);
776 SWZ_CPY(dst
, src
, count
, 1, 1);
790 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
791 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
795 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
796 * mapping array depending on endianness.
798 static const GLubyte
*
799 type_mapping( GLenum srcType
)
803 case GL_UNSIGNED_BYTE
:
805 case GL_UNSIGNED_INT_8_8_8_8
:
806 return _mesa_little_endian() ? map_3210
: map_identity
;
807 case GL_UNSIGNED_INT_8_8_8_8_REV
:
808 return _mesa_little_endian() ? map_identity
: map_3210
;
816 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
817 * mapping array depending on pixelstore byte swapping state.
819 static const GLubyte
*
820 byteswap_mapping( GLboolean swapBytes
,
828 case GL_UNSIGNED_BYTE
:
830 case GL_UNSIGNED_INT_8_8_8_8
:
831 case GL_UNSIGNED_INT_8_8_8_8_REV
:
841 * Transfer a GLubyte texture image with component swizzling.
844 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
849 GLenum baseInternalFormat
,
851 const GLubyte
*rgba2dst
,
852 GLuint dstComponents
,
857 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
858 const GLvoid
*srcAddr
,
859 const struct gl_pixelstore_attrib
*srcPacking
)
861 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
862 const GLubyte
*srctype2ubyte
, *swap
;
863 GLubyte map
[4], src2base
[6], base2rgba
[6];
865 const GLint srcRowStride
=
866 _mesa_image_row_stride(srcPacking
, srcWidth
,
867 srcFormat
, GL_UNSIGNED_BYTE
);
868 const GLint srcImageStride
869 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
871 const GLubyte
*srcImage
872 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
873 srcWidth
, srcHeight
, srcFormat
,
874 GL_UNSIGNED_BYTE
, 0, 0, 0);
878 /* Translate from src->baseInternal->GL_RGBA->dst. This will
879 * correctly deal with RGBA->RGB->RGBA conversions where the final
880 * A value must be 0xff regardless of the incoming alpha values.
882 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
883 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
884 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
885 srctype2ubyte
= type_mapping(srcType
);
888 for (i
= 0; i
< 4; i
++)
889 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
891 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
893 if (srcComponents
== dstComponents
&&
894 srcRowStride
== dstRowStride
&&
895 srcRowStride
== srcWidth
* srcComponents
&&
897 /* 1 and 2D images only */
898 GLubyte
*dstImage
= dstSlices
[0];
899 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
900 srcWidth
* srcHeight
);
904 for (img
= 0; img
< srcDepth
; img
++) {
905 const GLubyte
*srcRow
= srcImage
;
906 GLubyte
*dstRow
= dstSlices
[img
];
907 for (row
= 0; row
< srcHeight
; row
++) {
908 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
909 dstRow
+= dstRowStride
;
910 srcRow
+= srcRowStride
;
912 srcImage
+= srcImageStride
;
919 * Teximage storage routine for when a simple memcpy will do.
920 * No pixel transfer operations or special texel encodings allowed.
921 * 1D, 2D and 3D images supported.
924 memcpy_texture(struct gl_context
*ctx
,
929 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
930 GLenum srcFormat
, GLenum srcType
,
931 const GLvoid
*srcAddr
,
932 const struct gl_pixelstore_attrib
*srcPacking
)
934 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
936 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
937 srcWidth
, srcHeight
, srcFormat
, srcType
);
938 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
939 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
940 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
941 const GLint bytesPerRow
= srcWidth
* texelBytes
;
943 if (dstRowStride
== srcRowStride
&&
944 dstRowStride
== bytesPerRow
) {
945 /* memcpy image by image */
947 for (img
= 0; img
< srcDepth
; img
++) {
948 GLubyte
*dstImage
= dstSlices
[img
];
949 memcpy(dstImage
, srcImage
, bytesPerRow
* srcHeight
);
950 srcImage
+= srcImageStride
;
954 /* memcpy row by row */
956 for (img
= 0; img
< srcDepth
; img
++) {
957 const GLubyte
*srcRow
= srcImage
;
958 GLubyte
*dstRow
= dstSlices
[img
];
959 for (row
= 0; row
< srcHeight
; row
++) {
960 memcpy(dstRow
, srcRow
, bytesPerRow
);
961 dstRow
+= dstRowStride
;
962 srcRow
+= srcRowStride
;
964 srcImage
+= srcImageStride
;
971 * General-case function for storing a color texture images with
972 * components that can be represented with ubytes. Example destination
973 * texture formats are MESA_FORMAT_ARGB888, ARGB4444, RGB565.
976 store_ubyte_texture(TEXSTORE_PARAMS
)
978 const GLint srcRowStride
= srcWidth
* 4 * sizeof(GLubyte
);
979 GLubyte
*tempImage
, *src
;
982 tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
985 srcWidth
, srcHeight
, srcDepth
,
986 srcFormat
, srcType
, srcAddr
,
992 for (img
= 0; img
< srcDepth
; img
++) {
993 _mesa_pack_ubyte_rgba_rect(dstFormat
, srcWidth
, srcHeight
,
995 dstSlices
[img
], dstRowStride
);
996 src
+= srcHeight
* srcRowStride
;
1007 * Store a 32-bit integer or float depth component texture image.
1010 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1012 const GLuint depthScale
= 0xffffffff;
1015 ASSERT(dstFormat
== MESA_FORMAT_Z32
||
1016 dstFormat
== MESA_FORMAT_Z32_FLOAT
);
1017 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLuint
));
1019 if (dstFormat
== MESA_FORMAT_Z32
)
1020 dstType
= GL_UNSIGNED_INT
;
1024 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1025 ctx
->Pixel
.DepthBias
== 0.0f
&&
1026 !srcPacking
->SwapBytes
&&
1027 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1028 srcFormat
== GL_DEPTH_COMPONENT
&&
1029 srcType
== dstType
) {
1030 /* simple memcpy path */
1031 memcpy_texture(ctx
, dims
,
1033 dstRowStride
, dstSlices
,
1034 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1035 srcAddr
, srcPacking
);
1040 for (img
= 0; img
< srcDepth
; img
++) {
1041 GLubyte
*dstRow
= dstSlices
[img
];
1042 for (row
= 0; row
< srcHeight
; row
++) {
1043 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1044 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1045 _mesa_unpack_depth_span(ctx
, srcWidth
,
1047 depthScale
, srcType
, src
, srcPacking
);
1048 dstRow
+= dstRowStride
;
1057 * Store a 24-bit integer depth component texture image.
1060 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
1062 const GLuint depthScale
= 0xffffff;
1065 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
1070 for (img
= 0; img
< srcDepth
; img
++) {
1071 GLubyte
*dstRow
= dstSlices
[img
];
1072 for (row
= 0; row
< srcHeight
; row
++) {
1073 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1074 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1075 _mesa_unpack_depth_span(ctx
, srcWidth
,
1076 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1077 depthScale
, srcType
, src
, srcPacking
);
1078 dstRow
+= dstRowStride
;
1087 * Store a 24-bit integer depth component texture image.
1090 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
1092 const GLuint depthScale
= 0xffffff;
1095 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
1100 for (img
= 0; img
< srcDepth
; img
++) {
1101 GLubyte
*dstRow
= dstSlices
[img
];
1102 for (row
= 0; row
< srcHeight
; row
++) {
1103 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1104 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1105 GLuint
*dst
= (GLuint
*) dstRow
;
1107 _mesa_unpack_depth_span(ctx
, srcWidth
,
1108 GL_UNSIGNED_INT
, dst
,
1109 depthScale
, srcType
, src
, srcPacking
);
1110 for (i
= 0; i
< srcWidth
; i
++)
1112 dstRow
+= dstRowStride
;
1121 * Store a 16-bit integer depth component texture image.
1124 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1126 const GLuint depthScale
= 0xffff;
1128 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1129 ASSERT(_mesa_get_format_bytes(dstFormat
) == sizeof(GLushort
));
1131 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1132 ctx
->Pixel
.DepthBias
== 0.0f
&&
1133 !srcPacking
->SwapBytes
&&
1134 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1135 srcFormat
== GL_DEPTH_COMPONENT
&&
1136 srcType
== GL_UNSIGNED_SHORT
) {
1137 /* simple memcpy path */
1138 memcpy_texture(ctx
, dims
,
1140 dstRowStride
, dstSlices
,
1141 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1142 srcAddr
, srcPacking
);
1147 for (img
= 0; img
< srcDepth
; img
++) {
1148 GLubyte
*dstRow
= dstSlices
[img
];
1149 for (row
= 0; row
< srcHeight
; row
++) {
1150 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1151 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1152 GLushort
*dst16
= (GLushort
*) dstRow
;
1153 _mesa_unpack_depth_span(ctx
, srcWidth
,
1154 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1155 srcType
, src
, srcPacking
);
1156 dstRow
+= dstRowStride
;
1165 * Store an rgb565 or rgb565_rev texture image.
1168 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1170 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1171 dstFormat
== MESA_FORMAT_RGB565_REV
);
1172 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1174 if (!ctx
->_ImageTransferState
&&
1175 baseInternalFormat
== GL_RGB
&&
1176 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1177 srcPacking
->SwapBytes
)) {
1178 /* simple memcpy path */
1179 memcpy_texture(ctx
, dims
,
1181 dstRowStride
, dstSlices
,
1182 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1183 srcAddr
, srcPacking
);
1185 else if (!ctx
->_ImageTransferState
&&
1186 !srcPacking
->SwapBytes
&&
1187 baseInternalFormat
== GL_RGB
&&
1188 srcFormat
== GL_RGB
&&
1189 srcType
== GL_UNSIGNED_BYTE
&&
1191 /* do optimized tex store */
1192 const GLint srcRowStride
=
1193 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1194 const GLubyte
*src
= (const GLubyte
*)
1195 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1196 srcFormat
, srcType
, 0, 0, 0);
1197 GLubyte
*dst
= dstSlices
[0];
1199 for (row
= 0; row
< srcHeight
; row
++) {
1200 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1201 GLushort
*dstUS
= (GLushort
*) dst
;
1202 /* check for byteswapped format */
1203 if (dstFormat
== MESA_FORMAT_RGB565
) {
1204 for (col
= 0; col
< srcWidth
; col
++) {
1205 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1210 for (col
= 0; col
< srcWidth
; col
++) {
1211 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1215 dst
+= dstRowStride
;
1216 src
+= srcRowStride
;
1220 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1221 dstFormat
, dstRowStride
, dstSlices
,
1222 srcWidth
, srcHeight
, srcDepth
,
1223 srcFormat
, srcType
, srcAddr
, srcPacking
);
1230 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1233 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1235 const GLboolean littleEndian
= _mesa_little_endian();
1237 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1238 dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1239 dstFormat
== MESA_FORMAT_RGBX8888
||
1240 dstFormat
== MESA_FORMAT_RGBX8888_REV
);
1241 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1243 if (!ctx
->_ImageTransferState
&&
1244 baseInternalFormat
== GL_RGBA
&&
1245 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1246 srcPacking
->SwapBytes
)) {
1247 /* simple memcpy path */
1248 memcpy_texture(ctx
, dims
,
1250 dstRowStride
, dstSlices
,
1251 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1252 srcAddr
, srcPacking
);
1254 else if (!ctx
->_ImageTransferState
&&
1255 (srcType
== GL_UNSIGNED_BYTE
||
1256 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1257 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1258 can_swizzle(baseInternalFormat
) &&
1259 can_swizzle(srcFormat
)) {
1263 /* dstmap - how to swizzle from RGBA to dst format:
1265 if ((littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888
||
1266 dstFormat
== MESA_FORMAT_RGBX8888
)) ||
1267 (!littleEndian
&& (dstFormat
== MESA_FORMAT_RGBA8888_REV
||
1268 dstFormat
== MESA_FORMAT_RGBX8888_REV
))) {
1281 _mesa_swizzle_ubyte_image(ctx
, dims
,
1286 dstRowStride
, dstSlices
,
1287 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1291 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1292 dstFormat
, dstRowStride
, dstSlices
,
1293 srcWidth
, srcHeight
, srcDepth
,
1294 srcFormat
, srcType
, srcAddr
, srcPacking
);
1301 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1303 const GLboolean littleEndian
= _mesa_little_endian();
1305 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1306 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1307 dstFormat
== MESA_FORMAT_XRGB8888
||
1308 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1309 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1311 if (!ctx
->_ImageTransferState
&&
1312 baseInternalFormat
== GL_RGBA
&&
1313 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1314 srcPacking
->SwapBytes
)) {
1315 /* simple memcpy path (big endian) */
1316 memcpy_texture(ctx
, dims
,
1318 dstRowStride
, dstSlices
,
1319 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1320 srcAddr
, srcPacking
);
1322 else if (!ctx
->_ImageTransferState
&&
1323 !srcPacking
->SwapBytes
&&
1324 (dstFormat
== MESA_FORMAT_ARGB8888
||
1325 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1326 srcFormat
== GL_RGB
&&
1327 (baseInternalFormat
== GL_RGBA
||
1328 baseInternalFormat
== GL_RGB
) &&
1329 srcType
== GL_UNSIGNED_BYTE
) {
1331 for (img
= 0; img
< srcDepth
; img
++) {
1332 const GLint srcRowStride
=
1333 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1334 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1335 srcAddr
, srcWidth
, 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 d4
[col
] = PACK_COLOR_8888(0xff,
1341 srcRow
[col
* 3 + RCOMP
],
1342 srcRow
[col
* 3 + GCOMP
],
1343 srcRow
[col
* 3 + BCOMP
]);
1345 dstRow
+= dstRowStride
;
1346 srcRow
+= srcRowStride
;
1350 else if (!ctx
->_ImageTransferState
&&
1351 !srcPacking
->SwapBytes
&&
1352 dstFormat
== MESA_FORMAT_ARGB8888
&&
1353 srcFormat
== GL_LUMINANCE_ALPHA
&&
1354 baseInternalFormat
== GL_RGBA
&&
1355 srcType
== GL_UNSIGNED_BYTE
) {
1356 /* special case of storing LA -> ARGB8888 */
1358 const GLint srcRowStride
=
1359 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1360 for (img
= 0; img
< srcDepth
; img
++) {
1361 const GLubyte
*srcRow
= (const GLubyte
*)
1362 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
,
1363 srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1364 GLubyte
*dstRow
= dstSlices
[img
];
1365 for (row
= 0; row
< srcHeight
; row
++) {
1366 GLuint
*d4
= (GLuint
*) dstRow
;
1367 for (col
= 0; col
< srcWidth
; col
++) {
1368 GLubyte l
= srcRow
[col
* 2 + 0], a
= srcRow
[col
* 2 + 1];
1369 d4
[col
] = PACK_COLOR_8888(a
, l
, l
, l
);
1371 dstRow
+= dstRowStride
;
1372 srcRow
+= srcRowStride
;
1376 else if (!ctx
->_ImageTransferState
&&
1377 !srcPacking
->SwapBytes
&&
1378 dstFormat
== MESA_FORMAT_ARGB8888
&&
1379 srcFormat
== GL_RGBA
&&
1380 baseInternalFormat
== GL_RGBA
&&
1381 srcType
== GL_UNSIGNED_BYTE
) {
1382 /* same as above case, but src data has alpha too */
1383 GLint img
, row
, col
;
1384 /* For some reason, streaming copies to write-combined regions
1385 * are extremely sensitive to the characteristics of how the
1386 * source data is retrieved. By reordering the source reads to
1387 * be in-order, the speed of this operation increases by half.
1388 * Strangely the same isn't required for the RGB path, above.
1390 for (img
= 0; img
< srcDepth
; img
++) {
1391 const GLint srcRowStride
=
1392 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1393 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1394 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1395 GLubyte
*dstRow
= dstSlices
[img
];
1396 for (row
= 0; row
< srcHeight
; row
++) {
1397 GLuint
*d4
= (GLuint
*) dstRow
;
1398 for (col
= 0; col
< srcWidth
; col
++) {
1399 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1400 srcRow
[col
* 4 + RCOMP
],
1401 srcRow
[col
* 4 + GCOMP
],
1402 srcRow
[col
* 4 + BCOMP
]);
1404 dstRow
+= dstRowStride
;
1405 srcRow
+= srcRowStride
;
1409 else if (!ctx
->_ImageTransferState
&&
1410 (srcType
== GL_UNSIGNED_BYTE
||
1411 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1412 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1413 can_swizzle(baseInternalFormat
) &&
1414 can_swizzle(srcFormat
)) {
1418 /* dstmap - how to swizzle from RGBA to dst format:
1420 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1421 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1422 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1423 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1424 dstmap
[3] = 3; /* alpha */
1425 dstmap
[2] = 0; /* red */
1426 dstmap
[1] = 1; /* green */
1427 dstmap
[0] = 2; /* blue */
1430 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1431 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1432 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1433 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1440 _mesa_swizzle_ubyte_image(ctx
, dims
,
1447 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1451 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1452 dstFormat
, dstRowStride
, dstSlices
,
1453 srcWidth
, srcHeight
, srcDepth
,
1454 srcFormat
, srcType
, srcAddr
, srcPacking
);
1461 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1463 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1464 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1466 if (!ctx
->_ImageTransferState
&&
1467 baseInternalFormat
== GL_RGB
&&
1468 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1469 srcPacking
->SwapBytes
)) {
1470 /* simple memcpy path */
1471 memcpy_texture(ctx
, dims
,
1473 dstRowStride
, dstSlices
,
1474 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1475 srcAddr
, srcPacking
);
1477 else if (!ctx
->_ImageTransferState
&&
1478 !srcPacking
->SwapBytes
&&
1479 srcFormat
== GL_RGBA
&&
1480 srcType
== GL_UNSIGNED_BYTE
) {
1481 /* extract RGB from RGBA */
1482 GLint img
, row
, col
;
1483 for (img
= 0; img
< srcDepth
; img
++) {
1484 const GLint srcRowStride
=
1485 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1486 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1487 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1488 GLubyte
*dstRow
= dstSlices
[img
];
1489 for (row
= 0; row
< srcHeight
; row
++) {
1490 for (col
= 0; col
< srcWidth
; col
++) {
1491 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1492 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1493 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1495 dstRow
+= dstRowStride
;
1496 srcRow
+= srcRowStride
;
1500 else if (!ctx
->_ImageTransferState
&&
1501 srcType
== GL_UNSIGNED_BYTE
&&
1502 can_swizzle(baseInternalFormat
) &&
1503 can_swizzle(srcFormat
)) {
1507 /* dstmap - how to swizzle from RGBA to dst format:
1512 dstmap
[3] = ONE
; /* ? */
1514 _mesa_swizzle_ubyte_image(ctx
, dims
,
1519 dstRowStride
, dstSlices
,
1520 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1524 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1525 dstFormat
, dstRowStride
, dstSlices
,
1526 srcWidth
, srcHeight
, srcDepth
,
1527 srcFormat
, srcType
, srcAddr
, srcPacking
);
1534 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1536 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1537 ASSERT(_mesa_get_format_bytes(dstFormat
) == 3);
1539 if (!ctx
->_ImageTransferState
&&
1540 baseInternalFormat
== GL_RGB
&&
1541 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1542 srcPacking
->SwapBytes
)) {
1543 /* simple memcpy path */
1544 memcpy_texture(ctx
, dims
,
1546 dstRowStride
, dstSlices
,
1547 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1548 srcAddr
, srcPacking
);
1550 else if (!ctx
->_ImageTransferState
&&
1551 !srcPacking
->SwapBytes
&&
1552 srcFormat
== GL_RGBA
&&
1553 srcType
== GL_UNSIGNED_BYTE
) {
1554 /* extract BGR from RGBA */
1556 for (img
= 0; img
< srcDepth
; img
++) {
1557 const GLint srcRowStride
=
1558 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1559 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1560 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1561 GLubyte
*dstRow
= dstSlices
[img
];
1562 for (row
= 0; row
< srcHeight
; row
++) {
1563 for (col
= 0; col
< srcWidth
; col
++) {
1564 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1565 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1566 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1568 dstRow
+= dstRowStride
;
1569 srcRow
+= srcRowStride
;
1573 else if (!ctx
->_ImageTransferState
&&
1574 srcType
== GL_UNSIGNED_BYTE
&&
1575 can_swizzle(baseInternalFormat
) &&
1576 can_swizzle(srcFormat
)) {
1580 /* dstmap - how to swizzle from RGBA to dst format:
1585 dstmap
[3] = ONE
; /* ? */
1587 _mesa_swizzle_ubyte_image(ctx
, dims
,
1592 dstRowStride
, dstSlices
,
1593 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1597 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1598 dstFormat
, dstRowStride
, dstSlices
,
1599 srcWidth
, srcHeight
, srcDepth
,
1600 srcFormat
, srcType
, srcAddr
, srcPacking
);
1607 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1609 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1610 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1611 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1613 if (!ctx
->_ImageTransferState
&&
1614 baseInternalFormat
== GL_RGBA
&&
1615 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1616 srcPacking
->SwapBytes
)) {
1617 /* simple memcpy path */
1618 memcpy_texture(ctx
, dims
,
1620 dstRowStride
, dstSlices
,
1621 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1622 srcAddr
, srcPacking
);
1625 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1626 dstFormat
, dstRowStride
, dstSlices
,
1627 srcWidth
, srcHeight
, srcDepth
,
1628 srcFormat
, srcType
, srcAddr
, srcPacking
);
1634 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1636 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1637 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1639 if (!ctx
->_ImageTransferState
&&
1640 baseInternalFormat
== GL_RGBA
&&
1641 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1642 srcPacking
->SwapBytes
)) {
1643 /* simple memcpy path */
1644 memcpy_texture(ctx
, dims
,
1646 dstRowStride
, dstSlices
,
1647 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1648 srcAddr
, srcPacking
);
1651 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1652 dstFormat
, dstRowStride
, dstSlices
,
1653 srcWidth
, srcHeight
, srcDepth
,
1654 srcFormat
, srcType
, srcAddr
, srcPacking
);
1660 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1662 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1663 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1664 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1666 if (!ctx
->_ImageTransferState
&&
1667 baseInternalFormat
== GL_RGBA
&&
1668 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1669 srcPacking
->SwapBytes
)) {
1670 /* simple memcpy path */
1671 memcpy_texture(ctx
, dims
,
1673 dstRowStride
, dstSlices
,
1674 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1675 srcAddr
, srcPacking
);
1678 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
1679 dstFormat
, dstRowStride
, dstSlices
,
1680 srcWidth
, srcHeight
, srcDepth
,
1681 srcFormat
, srcType
, srcAddr
, srcPacking
);
1688 _mesa_texstore_argb2101010(TEXSTORE_PARAMS
)
1690 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1692 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010
);
1693 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1695 if (!ctx
->_ImageTransferState
&&
1696 baseInternalFormat
== GL_RGBA
&&
1697 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
1698 srcPacking
->SwapBytes
)) {
1699 /* simple memcpy path */
1700 memcpy_texture(ctx
, dims
,
1702 dstRowStride
, dstSlices
,
1703 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1704 srcAddr
, srcPacking
);
1708 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1711 srcWidth
, srcHeight
, srcDepth
,
1712 srcFormat
, srcType
, srcAddr
,
1714 ctx
->_ImageTransferState
);
1715 const GLfloat
*src
= tempImage
;
1716 GLint img
, row
, col
;
1719 for (img
= 0; img
< srcDepth
; img
++) {
1720 GLubyte
*dstRow
= dstSlices
[img
];
1721 if (baseInternalFormat
== GL_RGBA
) {
1722 for (row
= 0; row
< srcHeight
; row
++) {
1723 GLuint
*dstUI
= (GLuint
*) dstRow
;
1724 for (col
= 0; col
< srcWidth
; col
++) {
1727 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[ACOMP
]);
1728 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1729 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1730 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1731 dstUI
[col
] = PACK_COLOR_2101010_US(a
, r
, g
, b
);
1734 dstRow
+= dstRowStride
;
1736 } else if (baseInternalFormat
== GL_RGB
) {
1737 for (row
= 0; row
< srcHeight
; row
++) {
1738 GLuint
*dstUI
= (GLuint
*) dstRow
;
1739 for (col
= 0; col
< srcWidth
; col
++) {
1742 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[RCOMP
]);
1743 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[GCOMP
]);
1744 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[BCOMP
]);
1745 dstUI
[col
] = PACK_COLOR_2101010_US(0xffff, r
, g
, b
);
1748 dstRow
+= dstRowStride
;
1754 free((void *) tempImage
);
1761 * Do texstore for 2-channel, 4-bit/channel, unsigned normalized formats.
1764 _mesa_texstore_unorm44(TEXSTORE_PARAMS
)
1766 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1768 ASSERT(dstFormat
== MESA_FORMAT_AL44
);
1769 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
1773 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1776 srcWidth
, srcHeight
, srcDepth
,
1777 srcFormat
, srcType
, srcAddr
,
1779 const GLubyte
*src
= tempImage
;
1780 GLint img
, row
, col
;
1783 for (img
= 0; img
< srcDepth
; img
++) {
1784 GLubyte
*dstRow
= dstSlices
[img
];
1785 for (row
= 0; row
< srcHeight
; row
++) {
1786 GLubyte
*dstUS
= (GLubyte
*) dstRow
;
1787 for (col
= 0; col
< srcWidth
; col
++) {
1788 /* src[0] is luminance, src[1] is alpha */
1789 dstUS
[col
] = PACK_COLOR_44( src
[1],
1793 dstRow
+= dstRowStride
;
1796 free((void *) tempImage
);
1803 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1806 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1808 const GLboolean littleEndian
= _mesa_little_endian();
1809 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1811 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1812 dstFormat
== MESA_FORMAT_AL88_REV
||
1813 dstFormat
== MESA_FORMAT_GR88
||
1814 dstFormat
== MESA_FORMAT_RG88
);
1815 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
1817 if (!ctx
->_ImageTransferState
&&
1818 !srcPacking
->SwapBytes
&&
1819 ((dstFormat
== MESA_FORMAT_AL88
&&
1820 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1821 srcFormat
== GL_LUMINANCE_ALPHA
) ||
1822 (dstFormat
== MESA_FORMAT_GR88
&&
1823 baseInternalFormat
== srcFormat
)) &&
1824 srcType
== GL_UNSIGNED_BYTE
&&
1826 /* simple memcpy path */
1827 memcpy_texture(ctx
, dims
,
1829 dstRowStride
, dstSlices
,
1830 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1831 srcAddr
, srcPacking
);
1833 else if (!ctx
->_ImageTransferState
&&
1835 srcType
== GL_UNSIGNED_BYTE
&&
1836 can_swizzle(baseInternalFormat
) &&
1837 can_swizzle(srcFormat
)) {
1840 /* dstmap - how to swizzle from RGBA to dst format:
1842 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
1843 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
1844 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
1854 if ((littleEndian
&& dstFormat
== MESA_FORMAT_GR88
) ||
1855 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88
)) {
1864 dstmap
[2] = ZERO
; /* ? */
1865 dstmap
[3] = ONE
; /* ? */
1867 _mesa_swizzle_ubyte_image(ctx
, dims
,
1872 dstRowStride
, dstSlices
,
1873 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1878 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
1881 srcWidth
, srcHeight
, srcDepth
,
1882 srcFormat
, srcType
, srcAddr
,
1884 const GLubyte
*src
= tempImage
;
1885 GLint img
, row
, col
;
1888 for (img
= 0; img
< srcDepth
; img
++) {
1889 GLubyte
*dstRow
= dstSlices
[img
];
1890 for (row
= 0; row
< srcHeight
; row
++) {
1891 GLushort
*dstUS
= (GLushort
*) dstRow
;
1892 if (dstFormat
== MESA_FORMAT_AL88
||
1893 dstFormat
== MESA_FORMAT_GR88
) {
1894 for (col
= 0; col
< srcWidth
; col
++) {
1895 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1896 dstUS
[col
] = PACK_COLOR_88( src
[1],
1902 for (col
= 0; col
< srcWidth
; col
++) {
1903 /* src[0] is luminance (or R), src[1] is alpha (or G) */
1904 dstUS
[col
] = PACK_COLOR_88_REV( src
[1],
1909 dstRow
+= dstRowStride
;
1912 free((void *) tempImage
);
1919 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
1922 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
1924 const GLboolean littleEndian
= _mesa_little_endian();
1925 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1927 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
1928 dstFormat
== MESA_FORMAT_AL1616_REV
||
1929 dstFormat
== MESA_FORMAT_RG1616
||
1930 dstFormat
== MESA_FORMAT_RG1616_REV
);
1931 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
1933 if (!ctx
->_ImageTransferState
&&
1934 !srcPacking
->SwapBytes
&&
1935 ((dstFormat
== MESA_FORMAT_AL1616
&&
1936 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1937 srcFormat
== GL_LUMINANCE_ALPHA
) ||
1938 (dstFormat
== MESA_FORMAT_RG1616
&&
1939 baseInternalFormat
== srcFormat
)) &&
1940 srcType
== GL_UNSIGNED_SHORT
&&
1942 /* simple memcpy path */
1943 memcpy_texture(ctx
, dims
,
1945 dstRowStride
, dstSlices
,
1946 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1947 srcAddr
, srcPacking
);
1951 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
1954 srcWidth
, srcHeight
, srcDepth
,
1955 srcFormat
, srcType
, srcAddr
,
1957 ctx
->_ImageTransferState
);
1958 const GLfloat
*src
= tempImage
;
1959 GLint img
, row
, col
;
1962 for (img
= 0; img
< srcDepth
; img
++) {
1963 GLubyte
*dstRow
= dstSlices
[img
];
1964 for (row
= 0; row
< srcHeight
; row
++) {
1965 GLuint
*dstUI
= (GLuint
*) dstRow
;
1966 if (dstFormat
== MESA_FORMAT_AL1616
||
1967 dstFormat
== MESA_FORMAT_RG1616
) {
1968 for (col
= 0; col
< srcWidth
; col
++) {
1971 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1972 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1973 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
1978 for (col
= 0; col
< srcWidth
; col
++) {
1981 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
1982 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
1983 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
1987 dstRow
+= dstRowStride
;
1990 free((void *) tempImage
);
1996 /* Texstore for R16, A16, L16, I16. */
1998 _mesa_texstore_unorm16(TEXSTORE_PARAMS
)
2000 const GLboolean littleEndian
= _mesa_little_endian();
2001 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2003 ASSERT(dstFormat
== MESA_FORMAT_R16
||
2004 dstFormat
== MESA_FORMAT_A16
||
2005 dstFormat
== MESA_FORMAT_L16
||
2006 dstFormat
== MESA_FORMAT_I16
);
2007 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2009 if (!ctx
->_ImageTransferState
&&
2010 !srcPacking
->SwapBytes
&&
2011 baseInternalFormat
== srcFormat
&&
2012 srcType
== GL_UNSIGNED_SHORT
&&
2014 /* simple memcpy path */
2015 memcpy_texture(ctx
, dims
,
2017 dstRowStride
, dstSlices
,
2018 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2019 srcAddr
, srcPacking
);
2023 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2026 srcWidth
, srcHeight
, srcDepth
,
2027 srcFormat
, srcType
, srcAddr
,
2029 ctx
->_ImageTransferState
);
2030 const GLfloat
*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 GLushort
*dstUS
= (GLushort
*) dstRow
;
2038 for (col
= 0; col
< srcWidth
; col
++) {
2041 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2045 dstRow
+= dstRowStride
;
2048 free((void *) tempImage
);
2055 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2057 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2059 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2060 ASSERT(_mesa_get_format_bytes(dstFormat
) == 8);
2062 if (!ctx
->_ImageTransferState
&&
2063 !srcPacking
->SwapBytes
&&
2064 baseInternalFormat
== GL_RGBA
&&
2065 srcFormat
== GL_RGBA
&&
2066 srcType
== GL_UNSIGNED_SHORT
) {
2067 /* simple memcpy path */
2068 memcpy_texture(ctx
, dims
,
2070 dstRowStride
, dstSlices
,
2071 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2072 srcAddr
, srcPacking
);
2076 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2079 srcWidth
, srcHeight
, srcDepth
,
2080 srcFormat
, srcType
, srcAddr
,
2082 ctx
->_ImageTransferState
);
2083 const GLfloat
*src
= tempImage
;
2084 GLint img
, row
, col
;
2087 for (img
= 0; img
< srcDepth
; img
++) {
2088 GLubyte
*dstRow
= dstSlices
[img
];
2089 for (row
= 0; row
< srcHeight
; row
++) {
2090 GLushort
*dstUS
= (GLushort
*) dstRow
;
2091 for (col
= 0; col
< srcWidth
; col
++) {
2092 GLushort r
, g
, b
, a
;
2094 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2095 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2096 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2097 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2104 dstRow
+= dstRowStride
;
2107 free((void *) tempImage
);
2114 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2116 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2118 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2119 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2121 if (!ctx
->_ImageTransferState
&&
2122 !srcPacking
->SwapBytes
&&
2123 baseInternalFormat
== GL_RGBA
&&
2124 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2125 srcFormat
== GL_RGBA
&&
2126 srcType
== GL_SHORT
) {
2127 /* simple memcpy path */
2128 memcpy_texture(ctx
, dims
,
2130 dstRowStride
, dstSlices
,
2131 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2132 srcAddr
, srcPacking
);
2136 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2139 srcWidth
, srcHeight
, srcDepth
,
2140 srcFormat
, srcType
, srcAddr
,
2142 ctx
->_ImageTransferState
);
2143 const GLfloat
*src
= tempImage
;
2144 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2145 GLint img
, row
, col
;
2150 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2151 * 3 or 4 components/pixel here.
2153 for (img
= 0; img
< srcDepth
; img
++) {
2154 GLubyte
*dstRow
= dstSlices
[img
];
2155 for (row
= 0; row
< srcHeight
; row
++) {
2156 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2157 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
) {
2158 for (col
= 0; col
< srcWidth
; col
++) {
2160 for (c
= 0; c
< comps
; c
++) {
2162 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2163 dstRowS
[col
* comps
+ c
] = p
;
2166 dstRow
+= dstRowStride
;
2167 src
+= 4 * srcWidth
;
2169 for (col
= 0; col
< srcWidth
; col
++) {
2171 for (c
= 0; c
< comps
; c
++) {
2173 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 3 + c
]);
2174 dstRowS
[col
* comps
+ c
] = p
;
2177 dstRow
+= dstRowStride
;
2178 src
+= 3 * srcWidth
;
2182 free((void *) tempImage
);
2189 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2191 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2192 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2194 if (!ctx
->_ImageTransferState
&&
2195 baseInternalFormat
== GL_RGB
&&
2196 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2197 srcPacking
->SwapBytes
)) {
2198 /* simple memcpy path */
2199 memcpy_texture(ctx
, dims
,
2201 dstRowStride
, dstSlices
,
2202 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2203 srcAddr
, srcPacking
);
2206 return store_ubyte_texture(ctx
, dims
, baseInternalFormat
,
2207 dstFormat
, dstRowStride
, dstSlices
,
2208 srcWidth
, srcHeight
, srcDepth
,
2209 srcFormat
, srcType
, srcAddr
, srcPacking
);
2216 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2219 _mesa_texstore_unorm8(TEXSTORE_PARAMS
)
2221 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2223 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2224 dstFormat
== MESA_FORMAT_L8
||
2225 dstFormat
== MESA_FORMAT_I8
||
2226 dstFormat
== MESA_FORMAT_R8
);
2227 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2229 if (!ctx
->_ImageTransferState
&&
2230 !srcPacking
->SwapBytes
&&
2231 baseInternalFormat
== srcFormat
&&
2232 srcType
== GL_UNSIGNED_BYTE
) {
2233 /* simple memcpy path */
2234 memcpy_texture(ctx
, dims
,
2236 dstRowStride
, dstSlices
,
2237 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2238 srcAddr
, srcPacking
);
2240 else if (!ctx
->_ImageTransferState
&&
2241 srcType
== GL_UNSIGNED_BYTE
&&
2242 can_swizzle(baseInternalFormat
) &&
2243 can_swizzle(srcFormat
)) {
2246 /* dstmap - how to swizzle from RGBA to dst format:
2248 if (dstFormat
== MESA_FORMAT_A8
) {
2254 dstmap
[1] = ZERO
; /* ? */
2255 dstmap
[2] = ZERO
; /* ? */
2256 dstmap
[3] = ONE
; /* ? */
2258 _mesa_swizzle_ubyte_image(ctx
, dims
,
2263 dstRowStride
, dstSlices
,
2264 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2269 const GLubyte
*tempImage
= _mesa_make_temp_ubyte_image(ctx
, dims
,
2272 srcWidth
, srcHeight
, srcDepth
,
2273 srcFormat
, srcType
, srcAddr
,
2275 const GLubyte
*src
= tempImage
;
2276 GLint img
, row
, col
;
2279 for (img
= 0; img
< srcDepth
; img
++) {
2280 GLubyte
*dstRow
= dstSlices
[img
];
2281 for (row
= 0; row
< srcHeight
; row
++) {
2282 for (col
= 0; col
< srcWidth
; col
++) {
2283 dstRow
[col
] = src
[col
];
2285 dstRow
+= dstRowStride
;
2289 free((void *) tempImage
);
2297 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2300 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2302 const GLboolean littleEndian
= _mesa_little_endian();
2304 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2306 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2307 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2308 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2309 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2310 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2311 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2312 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2313 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2315 /* always just memcpy since no pixel transfer ops apply */
2316 memcpy_texture(ctx
, dims
,
2318 dstRowStride
, dstSlices
,
2319 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2320 srcAddr
, srcPacking
);
2322 /* Check if we need byte swapping */
2323 /* XXX the logic here _might_ be wrong */
2324 if (srcPacking
->SwapBytes
^
2325 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2326 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2329 for (img
= 0; img
< srcDepth
; img
++) {
2330 GLubyte
*dstRow
= dstSlices
[img
];
2331 for (row
= 0; row
< srcHeight
; row
++) {
2332 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2333 dstRow
+= dstRowStride
;
2341 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2343 const GLboolean littleEndian
= _mesa_little_endian();
2344 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2346 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2347 ASSERT(texelBytes
== 2);
2348 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2349 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2350 (srcFormat
== GL_DUDV_ATI
));
2351 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2353 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2355 /* simple memcpy path */
2356 memcpy_texture(ctx
, dims
,
2358 dstRowStride
, dstSlices
,
2359 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2360 srcAddr
, srcPacking
);
2362 else if (srcType
== GL_BYTE
) {
2365 /* dstmap - how to swizzle from RGBA to dst format:
2375 dstmap
[2] = ZERO
; /* ? */
2376 dstmap
[3] = ONE
; /* ? */
2378 _mesa_swizzle_ubyte_image(ctx
, dims
,
2379 GL_LUMINANCE_ALPHA
, /* hack */
2380 GL_UNSIGNED_BYTE
, /* hack */
2381 GL_LUMINANCE_ALPHA
, /* hack */
2383 dstRowStride
, dstSlices
,
2384 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2388 /* general path - note this is defined for 2d textures only */
2389 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2390 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2391 srcFormat
, srcType
);
2392 GLbyte
*tempImage
, *dst
, *src
;
2395 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2396 * components
* sizeof(GLbyte
));
2400 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2401 srcWidth
, srcHeight
,
2406 for (row
= 0; row
< srcHeight
; row
++) {
2407 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2408 dst
, srcFormat
, srcType
, src
,
2410 dst
+= srcWidth
* components
;
2415 dst
= (GLbyte
*) dstSlices
[0];
2416 for (row
= 0; row
< srcHeight
; row
++) {
2417 memcpy(dst
, src
, srcWidth
* texelBytes
);
2418 dst
+= dstRowStride
;
2419 src
+= srcWidth
* texelBytes
;
2421 free((void *) tempImage
);
2428 * Store a texture in a signed normalized 8-bit format.
2431 _mesa_texstore_snorm8(TEXSTORE_PARAMS
)
2433 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2435 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_A8
||
2436 dstFormat
== MESA_FORMAT_SIGNED_L8
||
2437 dstFormat
== MESA_FORMAT_SIGNED_I8
||
2438 dstFormat
== MESA_FORMAT_SIGNED_R8
);
2439 ASSERT(_mesa_get_format_bytes(dstFormat
) == 1);
2441 if (!ctx
->_ImageTransferState
&&
2442 !srcPacking
->SwapBytes
&&
2443 baseInternalFormat
== srcFormat
&&
2444 srcType
== GL_BYTE
) {
2445 /* simple memcpy path */
2446 memcpy_texture(ctx
, dims
,
2448 dstRowStride
, dstSlices
,
2449 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2450 srcAddr
, srcPacking
);
2454 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2457 srcWidth
, srcHeight
, srcDepth
,
2458 srcFormat
, srcType
, srcAddr
,
2460 ctx
->_ImageTransferState
);
2461 const GLfloat
*src
= tempImage
;
2462 GLint img
, row
, col
;
2465 for (img
= 0; img
< srcDepth
; img
++) {
2466 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2467 for (row
= 0; row
< srcHeight
; row
++) {
2468 for (col
= 0; col
< srcWidth
; col
++) {
2469 dstRow
[col
] = FLOAT_TO_BYTE_TEX(src
[col
]);
2471 dstRow
+= dstRowStride
;
2475 free((void *) tempImage
);
2482 * Store a texture in a signed normalized two-channel 16-bit format.
2485 _mesa_texstore_snorm88(TEXSTORE_PARAMS
)
2487 const GLboolean littleEndian
= _mesa_little_endian();
2488 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2490 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL88
||
2491 dstFormat
== MESA_FORMAT_SIGNED_RG88_REV
);
2492 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2494 if (!ctx
->_ImageTransferState
&&
2495 !srcPacking
->SwapBytes
&&
2496 baseInternalFormat
== srcFormat
&&
2497 srcType
== GL_BYTE
&&
2499 /* simple memcpy path */
2500 memcpy_texture(ctx
, dims
,
2502 dstRowStride
, dstSlices
,
2503 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2504 srcAddr
, srcPacking
);
2508 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2511 srcWidth
, srcHeight
, srcDepth
,
2512 srcFormat
, srcType
, srcAddr
,
2514 ctx
->_ImageTransferState
);
2515 const GLfloat
*src
= tempImage
;
2516 GLint img
, row
, col
;
2519 for (img
= 0; img
< srcDepth
; img
++) {
2520 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2521 for (row
= 0; row
< srcHeight
; row
++) {
2522 GLbyte
*dst
= dstRow
;
2523 for (col
= 0; col
< srcWidth
; col
++) {
2524 dst
[0] = FLOAT_TO_BYTE_TEX(src
[0]);
2525 dst
[1] = FLOAT_TO_BYTE_TEX(src
[1]);
2529 dstRow
+= dstRowStride
;
2532 free((void *) tempImage
);
2537 /* Texstore for signed R16, A16, L16, I16. */
2539 _mesa_texstore_snorm16(TEXSTORE_PARAMS
)
2541 const GLboolean littleEndian
= _mesa_little_endian();
2542 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2544 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R16
||
2545 dstFormat
== MESA_FORMAT_SIGNED_A16
||
2546 dstFormat
== MESA_FORMAT_SIGNED_L16
||
2547 dstFormat
== MESA_FORMAT_SIGNED_I16
);
2548 ASSERT(_mesa_get_format_bytes(dstFormat
) == 2);
2550 if (!ctx
->_ImageTransferState
&&
2551 !srcPacking
->SwapBytes
&&
2552 baseInternalFormat
== srcFormat
&&
2553 srcType
== GL_SHORT
&&
2555 /* simple memcpy path */
2556 memcpy_texture(ctx
, dims
,
2558 dstRowStride
, dstSlices
,
2559 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2560 srcAddr
, srcPacking
);
2564 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2567 srcWidth
, srcHeight
, srcDepth
,
2568 srcFormat
, srcType
, srcAddr
,
2570 ctx
->_ImageTransferState
);
2571 const GLfloat
*src
= tempImage
;
2572 GLint img
, row
, col
;
2575 for (img
= 0; img
< srcDepth
; img
++) {
2576 GLubyte
*dstRow
= dstSlices
[img
];
2577 for (row
= 0; row
< srcHeight
; row
++) {
2578 GLshort
*dstUS
= (GLshort
*) dstRow
;
2579 for (col
= 0; col
< srcWidth
; col
++) {
2582 UNCLAMPED_FLOAT_TO_SHORT(r
, src
[0]);
2586 dstRow
+= dstRowStride
;
2589 free((void *) tempImage
);
2595 * Do texstore for 2-channel, 16-bit/channel, signed normalized formats.
2598 _mesa_texstore_snorm1616(TEXSTORE_PARAMS
)
2600 const GLboolean littleEndian
= _mesa_little_endian();
2601 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2603 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_AL1616
||
2604 dstFormat
== MESA_FORMAT_SIGNED_GR1616
);
2605 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2607 if (!ctx
->_ImageTransferState
&&
2608 !srcPacking
->SwapBytes
&&
2609 baseInternalFormat
== srcFormat
&&
2610 srcType
== GL_SHORT
&&
2612 /* simple memcpy path */
2613 memcpy_texture(ctx
, dims
,
2615 dstRowStride
, dstSlices
,
2616 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2617 srcAddr
, srcPacking
);
2621 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2624 srcWidth
, srcHeight
, srcDepth
,
2625 srcFormat
, srcType
, srcAddr
,
2627 ctx
->_ImageTransferState
);
2628 const GLfloat
*src
= tempImage
;
2629 GLint img
, row
, col
;
2632 for (img
= 0; img
< srcDepth
; img
++) {
2633 GLubyte
*dstRow
= dstSlices
[img
];
2634 for (row
= 0; row
< srcHeight
; row
++) {
2635 GLshort
*dst
= (GLshort
*) dstRow
;
2636 for (col
= 0; col
< srcWidth
; col
++) {
2639 UNCLAMPED_FLOAT_TO_SHORT(l
, src
[0]);
2640 UNCLAMPED_FLOAT_TO_SHORT(a
, src
[1]);
2646 dstRow
+= dstRowStride
;
2649 free((void *) tempImage
);
2655 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2658 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2660 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2662 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2663 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2667 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2670 srcWidth
, srcHeight
, srcDepth
,
2671 srcFormat
, srcType
, srcAddr
,
2673 ctx
->_ImageTransferState
);
2674 const GLfloat
*srcRow
= tempImage
;
2675 GLint img
, row
, col
;
2678 for (img
= 0; img
< srcDepth
; img
++) {
2679 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2680 for (row
= 0; row
< srcHeight
; row
++) {
2681 GLbyte
*dst
= dstRow
;
2682 for (col
= 0; col
< srcWidth
; col
++) {
2683 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2684 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2685 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2690 dstRow
+= dstRowStride
;
2693 free((void *) tempImage
);
2701 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2702 * MESA_FORMAT_SIGNED_RGBA8888_REV
2705 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2707 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2709 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2710 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2711 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
2713 if (!ctx
->_ImageTransferState
&&
2714 baseInternalFormat
== GL_RGBA
&&
2715 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
2716 srcPacking
->SwapBytes
)) {
2717 /* simple memcpy path */
2718 memcpy_texture(ctx
, dims
,
2720 dstRowStride
, dstSlices
,
2721 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2722 srcAddr
, srcPacking
);
2726 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
2729 srcWidth
, srcHeight
, srcDepth
,
2730 srcFormat
, srcType
, srcAddr
,
2732 ctx
->_ImageTransferState
);
2733 const GLfloat
*srcRow
= tempImage
;
2734 GLint img
, row
, col
;
2737 for (img
= 0; img
< srcDepth
; img
++) {
2738 GLbyte
*dstRow
= (GLbyte
*) dstSlices
[img
];
2739 for (row
= 0; row
< srcHeight
; row
++) {
2740 GLbyte
*dst
= dstRow
;
2741 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2742 for (col
= 0; col
< srcWidth
; col
++) {
2743 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2744 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2745 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2746 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2752 for (col
= 0; col
< srcWidth
; col
++) {
2753 dst
[0] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2754 dst
[1] = FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]);
2755 dst
[2] = FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]);
2756 dst
[3] = FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]);
2761 dstRow
+= dstRowStride
;
2764 free((void *) tempImage
);
2771 * Store a combined depth/stencil texture image.
2774 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2776 const GLuint depthScale
= 0xffffff;
2777 const GLint srcRowStride
2778 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2781 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2782 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2783 srcFormat
== GL_DEPTH_COMPONENT
||
2784 srcFormat
== GL_STENCIL_INDEX
);
2785 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2787 if (srcFormat
== GL_DEPTH_STENCIL
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
2788 ctx
->Pixel
.DepthBias
== 0.0f
&&
2789 !srcPacking
->SwapBytes
) {
2791 memcpy_texture(ctx
, dims
,
2793 dstRowStride
, dstSlices
,
2794 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2795 srcAddr
, srcPacking
);
2797 else if (srcFormat
== GL_DEPTH_COMPONENT
||
2798 srcFormat
== GL_STENCIL_INDEX
) {
2799 GLuint
*depth
= (GLuint
*) malloc(srcWidth
* sizeof(GLuint
));
2800 GLubyte
*stencil
= (GLubyte
*) malloc(srcWidth
* sizeof(GLubyte
));
2802 if (!depth
|| !stencil
) {
2808 /* In case we only upload depth we need to preserve the stencil */
2809 for (img
= 0; img
< srcDepth
; img
++) {
2810 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2812 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2813 srcWidth
, srcHeight
,
2816 for (row
= 0; row
< srcHeight
; row
++) {
2818 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2820 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2821 keepstencil
= GL_TRUE
;
2823 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2824 keepdepth
= GL_TRUE
;
2827 if (keepdepth
== GL_FALSE
)
2828 /* the 24 depth bits will be in the low position: */
2829 _mesa_unpack_depth_span(ctx
, srcWidth
,
2830 GL_UNSIGNED_INT
, /* dst type */
2831 keepstencil
? depth
: dstRow
, /* dst addr */
2833 srcType
, src
, srcPacking
);
2835 if (keepstencil
== GL_FALSE
)
2836 /* get the 8-bit stencil values */
2837 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2838 GL_UNSIGNED_BYTE
, /* dst type */
2839 stencil
, /* dst addr */
2840 srcType
, src
, srcPacking
,
2841 ctx
->_ImageTransferState
);
2843 for (i
= 0; i
< srcWidth
; i
++) {
2845 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2847 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2850 src
+= srcRowStride
;
2851 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2863 * Store a combined depth/stencil texture image.
2866 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2868 const GLuint depthScale
= 0xffffff;
2869 const GLint srcRowStride
2870 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2875 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2876 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
2877 srcFormat
== GL_DEPTH_COMPONENT
||
2878 srcFormat
== GL_STENCIL_INDEX
);
2879 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
2880 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2882 depth
= (GLuint
*) malloc(srcWidth
* sizeof(GLuint
));
2883 stencil
= (GLubyte
*) malloc(srcWidth
* sizeof(GLubyte
));
2885 if (!depth
|| !stencil
) {
2891 for (img
= 0; img
< srcDepth
; img
++) {
2892 GLuint
*dstRow
= (GLuint
*) dstSlices
[img
];
2894 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2895 srcWidth
, srcHeight
,
2898 for (row
= 0; row
< srcHeight
; row
++) {
2900 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2902 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2903 keepstencil
= GL_TRUE
;
2905 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2906 keepdepth
= GL_TRUE
;
2909 if (keepdepth
== GL_FALSE
)
2910 /* the 24 depth bits will be in the low position: */
2911 _mesa_unpack_depth_span(ctx
, srcWidth
,
2912 GL_UNSIGNED_INT
, /* dst type */
2913 keepstencil
? depth
: dstRow
, /* dst addr */
2915 srcType
, src
, srcPacking
);
2917 if (keepstencil
== GL_FALSE
)
2918 /* get the 8-bit stencil values */
2919 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2920 GL_UNSIGNED_BYTE
, /* dst type */
2921 stencil
, /* dst addr */
2922 srcType
, src
, srcPacking
,
2923 ctx
->_ImageTransferState
);
2925 /* merge stencil values into depth values */
2926 for (i
= 0; i
< srcWidth
; i
++) {
2928 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2930 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
2933 src
+= srcRowStride
;
2934 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2946 * Store simple 8-bit/value stencil texture data.
2949 _mesa_texstore_s8(TEXSTORE_PARAMS
)
2951 ASSERT(dstFormat
== MESA_FORMAT_S8
);
2952 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
2954 if (!ctx
->_ImageTransferState
&&
2955 !srcPacking
->SwapBytes
&&
2956 baseInternalFormat
== srcFormat
&&
2957 srcType
== GL_UNSIGNED_BYTE
) {
2958 /* simple memcpy path */
2959 memcpy_texture(ctx
, dims
,
2961 dstRowStride
, dstSlices
,
2962 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2963 srcAddr
, srcPacking
);
2966 const GLint srcRowStride
2967 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
2969 GLubyte
*stencil
= (GLubyte
*) malloc(srcWidth
* sizeof(GLubyte
));
2974 for (img
= 0; img
< srcDepth
; img
++) {
2975 GLubyte
*dstRow
= dstSlices
[img
];
2977 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2978 srcWidth
, srcHeight
,
2981 for (row
= 0; row
< srcHeight
; row
++) {
2984 /* get the 8-bit stencil values */
2985 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2986 GL_UNSIGNED_BYTE
, /* dst type */
2987 stencil
, /* dst addr */
2988 srcType
, src
, srcPacking
,
2989 ctx
->_ImageTransferState
);
2990 /* merge stencil values into depth values */
2991 for (i
= 0; i
< srcWidth
; i
++)
2992 dstRow
[i
] = stencil
[i
];
2994 src
+= srcRowStride
;
2995 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3007 * Store an image in any of the formats:
3008 * _mesa_texformat_rgba_float32
3009 * _mesa_texformat_rgb_float32
3010 * _mesa_texformat_alpha_float32
3011 * _mesa_texformat_luminance_float32
3012 * _mesa_texformat_luminance_alpha_float32
3013 * _mesa_texformat_intensity_float32
3016 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3018 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3019 const GLint components
= _mesa_components_in_format(baseFormat
);
3021 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3022 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3023 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3024 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3025 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3026 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
||
3027 dstFormat
== MESA_FORMAT_R_FLOAT32
||
3028 dstFormat
== MESA_FORMAT_RG_FLOAT32
);
3029 ASSERT(baseInternalFormat
== GL_RGBA
||
3030 baseInternalFormat
== GL_RGB
||
3031 baseInternalFormat
== GL_ALPHA
||
3032 baseInternalFormat
== GL_LUMINANCE
||
3033 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3034 baseInternalFormat
== GL_INTENSITY
||
3035 baseInternalFormat
== GL_RED
||
3036 baseInternalFormat
== GL_RG
);
3037 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLfloat
));
3039 if (!ctx
->_ImageTransferState
&&
3040 !srcPacking
->SwapBytes
&&
3041 baseInternalFormat
== srcFormat
&&
3042 baseInternalFormat
== baseFormat
&&
3043 srcType
== GL_FLOAT
) {
3044 /* simple memcpy path */
3045 memcpy_texture(ctx
, dims
,
3047 dstRowStride
, dstSlices
,
3048 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3049 srcAddr
, srcPacking
);
3053 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3056 srcWidth
, srcHeight
, srcDepth
,
3057 srcFormat
, srcType
, srcAddr
,
3059 ctx
->_ImageTransferState
);
3060 const GLfloat
*srcRow
= tempImage
;
3065 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3066 for (img
= 0; img
< srcDepth
; img
++) {
3067 GLubyte
*dstRow
= dstSlices
[img
];
3068 for (row
= 0; row
< srcHeight
; row
++) {
3069 memcpy(dstRow
, srcRow
, bytesPerRow
);
3070 dstRow
+= dstRowStride
;
3071 srcRow
+= srcWidth
* components
;
3075 free((void *) tempImage
);
3083 * As above, but store 16-bit floats.
3086 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3088 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3089 const GLint components
= _mesa_components_in_format(baseFormat
);
3091 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3092 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3093 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3094 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3095 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3096 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
||
3097 dstFormat
== MESA_FORMAT_R_FLOAT16
||
3098 dstFormat
== MESA_FORMAT_RG_FLOAT16
);
3099 ASSERT(baseInternalFormat
== GL_RGBA
||
3100 baseInternalFormat
== GL_RGB
||
3101 baseInternalFormat
== GL_ALPHA
||
3102 baseInternalFormat
== GL_LUMINANCE
||
3103 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3104 baseInternalFormat
== GL_INTENSITY
||
3105 baseInternalFormat
== GL_RED
||
3106 baseInternalFormat
== GL_RG
);
3107 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLhalfARB
));
3109 if (!ctx
->_ImageTransferState
&&
3110 !srcPacking
->SwapBytes
&&
3111 baseInternalFormat
== srcFormat
&&
3112 baseInternalFormat
== baseFormat
&&
3113 srcType
== GL_HALF_FLOAT_ARB
) {
3114 /* simple memcpy path */
3115 memcpy_texture(ctx
, dims
,
3117 dstRowStride
, dstSlices
,
3118 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3119 srcAddr
, srcPacking
);
3123 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3126 srcWidth
, srcHeight
, srcDepth
,
3127 srcFormat
, srcType
, srcAddr
,
3129 ctx
->_ImageTransferState
);
3130 const GLfloat
*src
= tempImage
;
3134 for (img
= 0; img
< srcDepth
; img
++) {
3135 GLubyte
*dstRow
= dstSlices
[img
];
3136 for (row
= 0; row
< srcHeight
; row
++) {
3137 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3139 for (i
= 0; i
< srcWidth
* components
; i
++) {
3140 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3142 dstRow
+= dstRowStride
;
3143 src
+= srcWidth
* components
;
3147 free((void *) tempImage
);
3153 /* non-normalized, signed int8 */
3155 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3157 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3158 const GLint components
= _mesa_components_in_format(baseFormat
);
3160 ASSERT(dstFormat
== MESA_FORMAT_R_INT8
||
3161 dstFormat
== MESA_FORMAT_RG_INT8
||
3162 dstFormat
== MESA_FORMAT_RGB_INT8
||
3163 dstFormat
== MESA_FORMAT_RGBA_INT8
||
3164 dstFormat
== MESA_FORMAT_ALPHA_INT8
||
3165 dstFormat
== MESA_FORMAT_INTENSITY_INT8
||
3166 dstFormat
== MESA_FORMAT_LUMINANCE_INT8
||
3167 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT8
);
3168 ASSERT(baseInternalFormat
== GL_RGBA
||
3169 baseInternalFormat
== GL_RGB
||
3170 baseInternalFormat
== GL_RG
||
3171 baseInternalFormat
== GL_RED
||
3172 baseInternalFormat
== GL_ALPHA
||
3173 baseInternalFormat
== GL_LUMINANCE
||
3174 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3175 baseInternalFormat
== GL_INTENSITY
);
3176 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLbyte
));
3178 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3179 * to integer formats.
3181 if (!srcPacking
->SwapBytes
&&
3182 baseInternalFormat
== srcFormat
&&
3183 srcType
== GL_BYTE
) {
3184 /* simple memcpy path */
3185 memcpy_texture(ctx
, dims
,
3187 dstRowStride
, dstSlices
,
3188 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3189 srcAddr
, srcPacking
);
3193 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3196 srcWidth
, srcHeight
, srcDepth
,
3200 const GLuint
*src
= tempImage
;
3204 for (img
= 0; img
< srcDepth
; img
++) {
3205 GLubyte
*dstRow
= dstSlices
[img
];
3206 for (row
= 0; row
< srcHeight
; row
++) {
3207 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3209 for (i
= 0; i
< srcWidth
* components
; i
++) {
3210 dstTexel
[i
] = (GLbyte
) src
[i
];
3212 dstRow
+= dstRowStride
;
3213 src
+= srcWidth
* components
;
3217 free((void *) tempImage
);
3223 /* non-normalized, signed int16 */
3225 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3227 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3228 const GLint components
= _mesa_components_in_format(baseFormat
);
3230 ASSERT(dstFormat
== MESA_FORMAT_R_INT16
||
3231 dstFormat
== MESA_FORMAT_RG_INT16
||
3232 dstFormat
== MESA_FORMAT_RGB_INT16
||
3233 dstFormat
== MESA_FORMAT_RGBA_INT16
||
3234 dstFormat
== MESA_FORMAT_ALPHA_INT16
||
3235 dstFormat
== MESA_FORMAT_LUMINANCE_INT16
||
3236 dstFormat
== MESA_FORMAT_INTENSITY_INT16
||
3237 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT16
);
3238 ASSERT(baseInternalFormat
== GL_RGBA
||
3239 baseInternalFormat
== GL_RGB
||
3240 baseInternalFormat
== GL_RG
||
3241 baseInternalFormat
== GL_RED
||
3242 baseInternalFormat
== GL_ALPHA
||
3243 baseInternalFormat
== GL_LUMINANCE
||
3244 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3245 baseInternalFormat
== GL_INTENSITY
);
3246 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLshort
));
3248 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3249 * to integer formats.
3251 if (!srcPacking
->SwapBytes
&&
3252 baseInternalFormat
== srcFormat
&&
3253 srcType
== GL_SHORT
) {
3254 /* simple memcpy path */
3255 memcpy_texture(ctx
, dims
,
3257 dstRowStride
, dstSlices
,
3258 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3259 srcAddr
, srcPacking
);
3263 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3266 srcWidth
, srcHeight
, srcDepth
,
3270 const GLuint
*src
= tempImage
;
3274 for (img
= 0; img
< srcDepth
; img
++) {
3275 GLubyte
*dstRow
= dstSlices
[img
];
3276 for (row
= 0; row
< srcHeight
; row
++) {
3277 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3279 for (i
= 0; i
< srcWidth
* components
; i
++) {
3280 dstTexel
[i
] = (GLint
) src
[i
];
3282 dstRow
+= dstRowStride
;
3283 src
+= srcWidth
* components
;
3287 free((void *) tempImage
);
3293 /* non-normalized, signed int32 */
3295 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3297 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3298 const GLint components
= _mesa_components_in_format(baseFormat
);
3300 ASSERT(dstFormat
== MESA_FORMAT_R_INT32
||
3301 dstFormat
== MESA_FORMAT_RG_INT32
||
3302 dstFormat
== MESA_FORMAT_RGB_INT32
||
3303 dstFormat
== MESA_FORMAT_RGBA_INT32
||
3304 dstFormat
== MESA_FORMAT_ALPHA_INT32
||
3305 dstFormat
== MESA_FORMAT_INTENSITY_INT32
||
3306 dstFormat
== MESA_FORMAT_LUMINANCE_INT32
||
3307 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_INT32
);
3308 ASSERT(baseInternalFormat
== GL_RGBA
||
3309 baseInternalFormat
== GL_RGB
||
3310 baseInternalFormat
== GL_RG
||
3311 baseInternalFormat
== GL_RED
||
3312 baseInternalFormat
== GL_ALPHA
||
3313 baseInternalFormat
== GL_LUMINANCE
||
3314 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3315 baseInternalFormat
== GL_INTENSITY
);
3316 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLint
));
3318 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3319 * to integer formats.
3321 if (!srcPacking
->SwapBytes
&&
3322 baseInternalFormat
== srcFormat
&&
3323 srcType
== GL_INT
) {
3324 /* simple memcpy path */
3325 memcpy_texture(ctx
, dims
,
3327 dstRowStride
, dstSlices
,
3328 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3329 srcAddr
, srcPacking
);
3333 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3336 srcWidth
, srcHeight
, srcDepth
,
3340 const GLuint
*src
= tempImage
;
3344 for (img
= 0; img
< srcDepth
; img
++) {
3345 GLubyte
*dstRow
= dstSlices
[img
];
3346 for (row
= 0; row
< srcHeight
; row
++) {
3347 GLint
*dstTexel
= (GLint
*) dstRow
;
3349 for (i
= 0; i
< srcWidth
* components
; i
++) {
3350 dstTexel
[i
] = (GLint
) src
[i
];
3352 dstRow
+= dstRowStride
;
3353 src
+= srcWidth
* components
;
3357 free((void *) tempImage
);
3363 /* non-normalized, unsigned int8 */
3365 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3367 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3368 const GLint components
= _mesa_components_in_format(baseFormat
);
3370 ASSERT(dstFormat
== MESA_FORMAT_R_UINT8
||
3371 dstFormat
== MESA_FORMAT_RG_UINT8
||
3372 dstFormat
== MESA_FORMAT_RGB_UINT8
||
3373 dstFormat
== MESA_FORMAT_RGBA_UINT8
||
3374 dstFormat
== MESA_FORMAT_ALPHA_UINT8
||
3375 dstFormat
== MESA_FORMAT_INTENSITY_UINT8
||
3376 dstFormat
== MESA_FORMAT_LUMINANCE_UINT8
||
3377 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT8
);
3378 ASSERT(baseInternalFormat
== GL_RGBA
||
3379 baseInternalFormat
== GL_RGB
||
3380 baseInternalFormat
== GL_RG
||
3381 baseInternalFormat
== GL_RED
||
3382 baseInternalFormat
== GL_ALPHA
||
3383 baseInternalFormat
== GL_LUMINANCE
||
3384 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3385 baseInternalFormat
== GL_INTENSITY
);
3386 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLubyte
));
3388 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3389 * to integer formats.
3391 if (!srcPacking
->SwapBytes
&&
3392 baseInternalFormat
== srcFormat
&&
3393 srcType
== GL_UNSIGNED_BYTE
) {
3394 /* simple memcpy path */
3395 memcpy_texture(ctx
, dims
,
3397 dstRowStride
, dstSlices
,
3398 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3399 srcAddr
, srcPacking
);
3403 const GLuint
*tempImage
=
3404 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3405 srcWidth
, srcHeight
, srcDepth
,
3406 srcFormat
, srcType
, srcAddr
, srcPacking
);
3407 const GLuint
*src
= tempImage
;
3411 for (img
= 0; img
< srcDepth
; img
++) {
3412 GLubyte
*dstRow
= dstSlices
[img
];
3413 for (row
= 0; row
< srcHeight
; row
++) {
3414 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3416 for (i
= 0; i
< srcWidth
* components
; i
++) {
3417 dstTexel
[i
] = (GLubyte
) CLAMP(src
[i
], 0, 0xff);
3419 dstRow
+= dstRowStride
;
3420 src
+= srcWidth
* components
;
3424 free((void *) tempImage
);
3430 /* non-normalized, unsigned int16 */
3432 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3434 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3435 const GLint components
= _mesa_components_in_format(baseFormat
);
3437 ASSERT(dstFormat
== MESA_FORMAT_R_UINT16
||
3438 dstFormat
== MESA_FORMAT_RG_UINT16
||
3439 dstFormat
== MESA_FORMAT_RGB_UINT16
||
3440 dstFormat
== MESA_FORMAT_RGBA_UINT16
||
3441 dstFormat
== MESA_FORMAT_ALPHA_UINT16
||
3442 dstFormat
== MESA_FORMAT_INTENSITY_UINT16
||
3443 dstFormat
== MESA_FORMAT_LUMINANCE_UINT16
||
3444 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT16
);
3445 ASSERT(baseInternalFormat
== GL_RGBA
||
3446 baseInternalFormat
== GL_RGB
||
3447 baseInternalFormat
== GL_RG
||
3448 baseInternalFormat
== GL_RED
||
3449 baseInternalFormat
== GL_ALPHA
||
3450 baseInternalFormat
== GL_LUMINANCE
||
3451 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3452 baseInternalFormat
== GL_INTENSITY
);
3453 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLushort
));
3455 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3456 * to integer formats.
3458 if (!srcPacking
->SwapBytes
&&
3459 baseInternalFormat
== srcFormat
&&
3460 srcType
== GL_UNSIGNED_SHORT
) {
3461 /* simple memcpy path */
3462 memcpy_texture(ctx
, dims
,
3464 dstRowStride
, dstSlices
,
3465 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3466 srcAddr
, srcPacking
);
3470 const GLuint
*tempImage
=
3471 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3472 srcWidth
, srcHeight
, srcDepth
,
3473 srcFormat
, srcType
, srcAddr
, srcPacking
);
3474 const GLuint
*src
= tempImage
;
3478 for (img
= 0; img
< srcDepth
; img
++) {
3479 GLubyte
*dstRow
= dstSlices
[img
];
3480 for (row
= 0; row
< srcHeight
; row
++) {
3481 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3483 for (i
= 0; i
< srcWidth
* components
; i
++) {
3484 dstTexel
[i
] = (GLushort
) CLAMP(src
[i
], 0, 0xffff);
3486 dstRow
+= dstRowStride
;
3487 src
+= srcWidth
* components
;
3491 free((void *) tempImage
);
3497 /* non-normalized, unsigned int32 */
3499 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3501 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3502 const GLint components
= _mesa_components_in_format(baseFormat
);
3504 ASSERT(dstFormat
== MESA_FORMAT_R_UINT32
||
3505 dstFormat
== MESA_FORMAT_RG_UINT32
||
3506 dstFormat
== MESA_FORMAT_RGB_UINT32
||
3507 dstFormat
== MESA_FORMAT_RGBA_UINT32
||
3508 dstFormat
== MESA_FORMAT_ALPHA_UINT32
||
3509 dstFormat
== MESA_FORMAT_INTENSITY_UINT32
||
3510 dstFormat
== MESA_FORMAT_LUMINANCE_UINT32
||
3511 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_UINT32
);
3512 ASSERT(baseInternalFormat
== GL_RGBA
||
3513 baseInternalFormat
== GL_RGB
||
3514 baseInternalFormat
== GL_RG
||
3515 baseInternalFormat
== GL_RED
||
3516 baseInternalFormat
== GL_ALPHA
||
3517 baseInternalFormat
== GL_LUMINANCE
||
3518 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3519 baseInternalFormat
== GL_INTENSITY
);
3520 ASSERT(_mesa_get_format_bytes(dstFormat
) == components
* sizeof(GLuint
));
3522 /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3523 * to integer formats.
3525 if (!srcPacking
->SwapBytes
&&
3526 baseInternalFormat
== srcFormat
&&
3527 srcType
== GL_UNSIGNED_INT
) {
3528 /* simple memcpy path */
3529 memcpy_texture(ctx
, dims
,
3531 dstRowStride
, dstSlices
,
3532 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3533 srcAddr
, srcPacking
);
3537 const GLuint
*tempImage
=
3538 make_temp_uint_image(ctx
, dims
, baseInternalFormat
, baseFormat
,
3539 srcWidth
, srcHeight
, srcDepth
,
3540 srcFormat
, srcType
, srcAddr
, srcPacking
);
3541 const GLuint
*src
= tempImage
;
3545 for (img
= 0; img
< srcDepth
; img
++) {
3546 GLubyte
*dstRow
= dstSlices
[img
];
3547 for (row
= 0; row
< srcHeight
; row
++) {
3548 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3550 for (i
= 0; i
< srcWidth
* components
; i
++) {
3551 dstTexel
[i
] = src
[i
];
3553 dstRow
+= dstRowStride
;
3554 src
+= srcWidth
* components
;
3558 free((void *) tempImage
);
3566 #if FEATURE_EXT_texture_sRGB
3568 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3570 gl_format newDstFormat
;
3573 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3575 /* reuse normal rgb texstore code */
3576 newDstFormat
= MESA_FORMAT_RGB888
;
3578 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3580 dstRowStride
, dstSlices
,
3581 srcWidth
, srcHeight
, srcDepth
,
3583 srcAddr
, srcPacking
);
3589 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3591 gl_format newDstFormat
;
3594 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3596 /* reuse normal rgba texstore code */
3597 newDstFormat
= MESA_FORMAT_RGBA8888
;
3598 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3600 dstRowStride
, dstSlices
,
3601 srcWidth
, srcHeight
, srcDepth
,
3603 srcAddr
, srcPacking
);
3609 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3611 gl_format newDstFormat
;
3614 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3616 /* reuse normal rgba texstore code */
3617 newDstFormat
= MESA_FORMAT_ARGB8888
;
3619 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3621 dstRowStride
, dstSlices
,
3622 srcWidth
, srcHeight
, srcDepth
,
3624 srcAddr
, srcPacking
);
3630 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3632 gl_format newDstFormat
;
3635 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3637 newDstFormat
= MESA_FORMAT_L8
;
3639 /* _mesa_textore_a8 handles luminance8 too */
3640 k
= _mesa_texstore_unorm8(ctx
, dims
, baseInternalFormat
,
3642 dstRowStride
, dstSlices
,
3643 srcWidth
, srcHeight
, srcDepth
,
3645 srcAddr
, srcPacking
);
3651 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3653 gl_format newDstFormat
;
3656 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3658 /* reuse normal luminance/alpha texstore code */
3659 newDstFormat
= MESA_FORMAT_AL88
;
3661 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3663 dstRowStride
, dstSlices
,
3664 srcWidth
, srcHeight
, srcDepth
,
3666 srcAddr
, srcPacking
);
3672 /* these are used only in texstore_funcs[] below */
3673 #define _mesa_texstore_srgb8 NULL
3674 #define _mesa_texstore_srgba8 NULL
3675 #define _mesa_texstore_sargb8 NULL
3676 #define _mesa_texstore_sl8 NULL
3677 #define _mesa_texstore_sla8 NULL
3679 #endif /* FEATURE_EXT_texture_sRGB */
3682 _mesa_texstore_rgb9_e5(TEXSTORE_PARAMS
)
3684 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3686 ASSERT(dstFormat
== MESA_FORMAT_RGB9_E5_FLOAT
);
3687 ASSERT(baseInternalFormat
== GL_RGB
);
3689 if (!ctx
->_ImageTransferState
&&
3690 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3691 srcPacking
->SwapBytes
)) {
3692 /* simple memcpy path */
3693 memcpy_texture(ctx
, dims
,
3695 dstRowStride
, dstSlices
,
3696 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3697 srcAddr
, srcPacking
);
3701 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3704 srcWidth
, srcHeight
, srcDepth
,
3705 srcFormat
, srcType
, srcAddr
,
3707 ctx
->_ImageTransferState
);
3708 const GLfloat
*srcRow
= tempImage
;
3709 GLint img
, row
, col
;
3712 for (img
= 0; img
< srcDepth
; img
++) {
3713 GLubyte
*dstRow
= dstSlices
[img
];
3714 for (row
= 0; row
< srcHeight
; row
++) {
3715 GLuint
*dstUI
= (GLuint
*)dstRow
;
3716 for (col
= 0; col
< srcWidth
; col
++) {
3717 dstUI
[col
] = float3_to_rgb9e5(&srcRow
[col
* 3]);
3719 dstRow
+= dstRowStride
;
3720 srcRow
+= srcWidth
* 3;
3724 free((void *) tempImage
);
3730 _mesa_texstore_r11_g11_b10f(TEXSTORE_PARAMS
)
3732 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3734 ASSERT(dstFormat
== MESA_FORMAT_R11_G11_B10_FLOAT
);
3735 ASSERT(baseInternalFormat
== GL_RGB
);
3737 if (!ctx
->_ImageTransferState
&&
3738 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3739 srcPacking
->SwapBytes
)) {
3740 /* simple memcpy path */
3741 memcpy_texture(ctx
, dims
,
3743 dstRowStride
, dstSlices
,
3744 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3745 srcAddr
, srcPacking
);
3749 const GLfloat
*tempImage
= _mesa_make_temp_float_image(ctx
, dims
,
3752 srcWidth
, srcHeight
, srcDepth
,
3753 srcFormat
, srcType
, srcAddr
,
3755 ctx
->_ImageTransferState
);
3756 const GLfloat
*srcRow
= tempImage
;
3757 GLint img
, row
, col
;
3760 for (img
= 0; img
< srcDepth
; img
++) {
3761 GLubyte
*dstRow
= dstSlices
[img
];
3762 for (row
= 0; row
< srcHeight
; row
++) {
3763 GLuint
*dstUI
= (GLuint
*)dstRow
;
3764 for (col
= 0; col
< srcWidth
; col
++) {
3765 dstUI
[col
] = float3_to_r11g11b10f(&srcRow
[col
* 3]);
3767 dstRow
+= dstRowStride
;
3768 srcRow
+= srcWidth
* 3;
3772 free((void *) tempImage
);
3779 _mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS
)
3781 ASSERT(dstFormat
== MESA_FORMAT_Z32_FLOAT_X24S8
);
3782 ASSERT(srcFormat
== GL_DEPTH_STENCIL
||
3783 srcFormat
== GL_DEPTH_COMPONENT
||
3784 srcFormat
== GL_STENCIL_INDEX
);
3785 ASSERT(srcFormat
!= GL_DEPTH_STENCIL
||
3786 srcType
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
);
3788 if (srcFormat
== GL_DEPTH_STENCIL
&&
3789 ctx
->Pixel
.DepthScale
== 1.0f
&&
3790 ctx
->Pixel
.DepthBias
== 0.0f
&&
3791 !srcPacking
->SwapBytes
) {
3793 memcpy_texture(ctx
, dims
,
3795 dstRowStride
, dstSlices
,
3796 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3797 srcAddr
, srcPacking
);
3799 else if (srcFormat
== GL_DEPTH_COMPONENT
||
3800 srcFormat
== GL_STENCIL_INDEX
) {
3802 const GLint srcRowStride
3803 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3806 /* In case we only upload depth we need to preserve the stencil */
3807 for (img
= 0; img
< srcDepth
; img
++) {
3808 uint64_t *dstRow
= (uint64_t *) dstSlices
[img
];
3810 = (const uint64_t *) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3811 srcWidth
, srcHeight
,
3814 for (row
= 0; row
< srcHeight
; row
++) {
3815 /* The unpack functions with:
3816 * dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
3817 * only write their own dword, so the other dword (stencil
3818 * or depth) is preserved. */
3819 if (srcFormat
!= GL_STENCIL_INDEX
)
3820 _mesa_unpack_depth_span(ctx
, srcWidth
,
3821 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3822 dstRow
, /* dst addr */
3823 ~0U, srcType
, src
, srcPacking
);
3825 if (srcFormat
!= GL_DEPTH_COMPONENT
)
3826 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3827 GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, /* dst type */
3828 dstRow
, /* dst addr */
3829 srcType
, src
, srcPacking
,
3830 ctx
->_ImageTransferState
);
3832 src
+= srcRowStride
;
3833 dstRow
+= dstRowStride
/ sizeof(uint64_t);
3841 _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS
)
3843 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3845 ASSERT(dstFormat
== MESA_FORMAT_ARGB2101010_UINT
);
3846 ASSERT(_mesa_get_format_bytes(dstFormat
) == 4);
3848 if (baseInternalFormat
== GL_RGBA
&&
3849 _mesa_format_matches_format_and_type(dstFormat
, srcFormat
, srcType
,
3850 srcPacking
->SwapBytes
)) {
3851 /* simple memcpy path */
3852 memcpy_texture(ctx
, dims
,
3854 dstRowStride
, dstSlices
,
3855 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3856 srcAddr
, srcPacking
);
3860 const GLuint
*tempImage
= make_temp_uint_image(ctx
, dims
,
3863 srcWidth
, srcHeight
,
3864 srcDepth
, srcFormat
,
3867 const GLuint
*src
= tempImage
;
3868 GLint img
, row
, col
;
3871 for (img
= 0; img
< srcDepth
; img
++) {
3872 GLubyte
*dstRow
= dstSlices
[img
];
3874 for (row
= 0; row
< srcHeight
; row
++) {
3875 GLuint
*dstUI
= (GLuint
*) dstRow
;
3876 for (col
= 0; col
< srcWidth
; col
++) {
3882 dstUI
[col
] = (a
<< 30) | (r
<< 20) | (g
<< 10) | (b
);
3885 dstRow
+= dstRowStride
;
3888 free((void *) tempImage
);
3894 _mesa_texstore_null(TEXSTORE_PARAMS
)
3896 (void) ctx
; (void) dims
;
3897 (void) baseInternalFormat
;
3899 (void) dstRowStride
; (void) dstSlices
,
3900 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3901 (void) srcFormat
; (void) srcType
;
3905 /* should never happen */
3906 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3912 * Return the StoreTexImageFunc pointer to store an image in the given format.
3914 static StoreTexImageFunc
3915 _mesa_get_texstore_func(gl_format format
)
3917 static StoreTexImageFunc table
[MESA_FORMAT_COUNT
];
3918 static GLboolean initialized
= GL_FALSE
;
3921 table
[MESA_FORMAT_NONE
] = _mesa_texstore_null
;
3923 table
[MESA_FORMAT_RGBA8888
] = _mesa_texstore_rgba8888
;
3924 table
[MESA_FORMAT_RGBA8888_REV
] = _mesa_texstore_rgba8888
;
3925 table
[MESA_FORMAT_ARGB8888
] = _mesa_texstore_argb8888
;
3926 table
[MESA_FORMAT_ARGB8888_REV
] = _mesa_texstore_argb8888
;
3927 table
[MESA_FORMAT_RGBX8888
] = _mesa_texstore_rgba8888
;
3928 table
[MESA_FORMAT_RGBX8888_REV
] = _mesa_texstore_rgba8888
;
3929 table
[MESA_FORMAT_XRGB8888
] = _mesa_texstore_argb8888
;
3930 table
[MESA_FORMAT_XRGB8888_REV
] = _mesa_texstore_argb8888
;
3931 table
[MESA_FORMAT_RGB888
] = _mesa_texstore_rgb888
;
3932 table
[MESA_FORMAT_BGR888
] = _mesa_texstore_bgr888
;
3933 table
[MESA_FORMAT_RGB565
] = _mesa_texstore_rgb565
;
3934 table
[MESA_FORMAT_RGB565_REV
] = _mesa_texstore_rgb565
;
3935 table
[MESA_FORMAT_ARGB4444
] = _mesa_texstore_argb4444
;
3936 table
[MESA_FORMAT_ARGB4444_REV
] = _mesa_texstore_argb4444
;
3937 table
[MESA_FORMAT_RGBA5551
] = _mesa_texstore_rgba5551
;
3938 table
[MESA_FORMAT_ARGB1555
] = _mesa_texstore_argb1555
;
3939 table
[MESA_FORMAT_ARGB1555_REV
] = _mesa_texstore_argb1555
;
3940 table
[MESA_FORMAT_AL44
] = _mesa_texstore_unorm44
;
3941 table
[MESA_FORMAT_AL88
] = _mesa_texstore_unorm88
;
3942 table
[MESA_FORMAT_AL88_REV
] = _mesa_texstore_unorm88
;
3943 table
[MESA_FORMAT_AL1616
] = _mesa_texstore_unorm1616
;
3944 table
[MESA_FORMAT_AL1616_REV
] = _mesa_texstore_unorm1616
;
3945 table
[MESA_FORMAT_RGB332
] = _mesa_texstore_rgb332
;
3946 table
[MESA_FORMAT_A8
] = _mesa_texstore_unorm8
;
3947 table
[MESA_FORMAT_A16
] = _mesa_texstore_unorm16
;
3948 table
[MESA_FORMAT_L8
] = _mesa_texstore_unorm8
;
3949 table
[MESA_FORMAT_L16
] = _mesa_texstore_unorm16
;
3950 table
[MESA_FORMAT_I8
] = _mesa_texstore_unorm8
;
3951 table
[MESA_FORMAT_I16
] = _mesa_texstore_unorm16
;
3952 table
[MESA_FORMAT_YCBCR
] = _mesa_texstore_ycbcr
;
3953 table
[MESA_FORMAT_YCBCR_REV
] = _mesa_texstore_ycbcr
;
3954 table
[MESA_FORMAT_R8
] = _mesa_texstore_unorm8
;
3955 table
[MESA_FORMAT_GR88
] = _mesa_texstore_unorm88
;
3956 table
[MESA_FORMAT_RG88
] = _mesa_texstore_unorm88
;
3957 table
[MESA_FORMAT_R16
] = _mesa_texstore_unorm16
;
3958 table
[MESA_FORMAT_RG1616
] = _mesa_texstore_unorm1616
;
3959 table
[MESA_FORMAT_RG1616_REV
] = _mesa_texstore_unorm1616
;
3960 table
[MESA_FORMAT_ARGB2101010
] = _mesa_texstore_argb2101010
;
3961 table
[MESA_FORMAT_Z24_S8
] = _mesa_texstore_z24_s8
;
3962 table
[MESA_FORMAT_S8_Z24
] = _mesa_texstore_s8_z24
;
3963 table
[MESA_FORMAT_Z16
] = _mesa_texstore_z16
;
3964 table
[MESA_FORMAT_X8_Z24
] = _mesa_texstore_x8_z24
;
3965 table
[MESA_FORMAT_Z24_X8
] = _mesa_texstore_z24_x8
;
3966 table
[MESA_FORMAT_Z32
] = _mesa_texstore_z32
;
3967 table
[MESA_FORMAT_S8
] = _mesa_texstore_s8
;
3968 table
[MESA_FORMAT_SRGB8
] = _mesa_texstore_srgb8
;
3969 table
[MESA_FORMAT_SRGBA8
] = _mesa_texstore_srgba8
;
3970 table
[MESA_FORMAT_SARGB8
] = _mesa_texstore_sargb8
;
3971 table
[MESA_FORMAT_SL8
] = _mesa_texstore_sl8
;
3972 table
[MESA_FORMAT_SLA8
] = _mesa_texstore_sla8
;
3973 table
[MESA_FORMAT_SRGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3974 table
[MESA_FORMAT_SRGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3975 table
[MESA_FORMAT_SRGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3976 table
[MESA_FORMAT_SRGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3977 table
[MESA_FORMAT_RGB_FXT1
] = _mesa_texstore_rgb_fxt1
;
3978 table
[MESA_FORMAT_RGBA_FXT1
] = _mesa_texstore_rgba_fxt1
;
3979 table
[MESA_FORMAT_RGB_DXT1
] = _mesa_texstore_rgb_dxt1
;
3980 table
[MESA_FORMAT_RGBA_DXT1
] = _mesa_texstore_rgba_dxt1
;
3981 table
[MESA_FORMAT_RGBA_DXT3
] = _mesa_texstore_rgba_dxt3
;
3982 table
[MESA_FORMAT_RGBA_DXT5
] = _mesa_texstore_rgba_dxt5
;
3983 table
[MESA_FORMAT_RGBA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3984 table
[MESA_FORMAT_RGBA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3985 table
[MESA_FORMAT_RGB_FLOAT32
] = _mesa_texstore_rgba_float32
;
3986 table
[MESA_FORMAT_RGB_FLOAT16
] = _mesa_texstore_rgba_float16
;
3987 table
[MESA_FORMAT_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3988 table
[MESA_FORMAT_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3989 table
[MESA_FORMAT_LUMINANCE_FLOAT32
] = _mesa_texstore_rgba_float32
;
3990 table
[MESA_FORMAT_LUMINANCE_FLOAT16
] = _mesa_texstore_rgba_float16
;
3991 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
] = _mesa_texstore_rgba_float32
;
3992 table
[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
] = _mesa_texstore_rgba_float16
;
3993 table
[MESA_FORMAT_INTENSITY_FLOAT32
] = _mesa_texstore_rgba_float32
;
3994 table
[MESA_FORMAT_INTENSITY_FLOAT16
] = _mesa_texstore_rgba_float16
;
3995 table
[MESA_FORMAT_R_FLOAT32
] = _mesa_texstore_rgba_float32
;
3996 table
[MESA_FORMAT_R_FLOAT16
] = _mesa_texstore_rgba_float16
;
3997 table
[MESA_FORMAT_RG_FLOAT32
] = _mesa_texstore_rgba_float32
;
3998 table
[MESA_FORMAT_RG_FLOAT16
] = _mesa_texstore_rgba_float16
;
3999 table
[MESA_FORMAT_DUDV8
] = _mesa_texstore_dudv8
;
4000 table
[MESA_FORMAT_SIGNED_R8
] = _mesa_texstore_snorm8
;
4001 table
[MESA_FORMAT_SIGNED_RG88_REV
] = _mesa_texstore_snorm88
;
4002 table
[MESA_FORMAT_SIGNED_RGBX8888
] = _mesa_texstore_signed_rgbx8888
;
4003 table
[MESA_FORMAT_SIGNED_RGBA8888
] = _mesa_texstore_signed_rgba8888
;
4004 table
[MESA_FORMAT_SIGNED_RGBA8888_REV
] = _mesa_texstore_signed_rgba8888
;
4005 table
[MESA_FORMAT_SIGNED_R16
] = _mesa_texstore_snorm16
;
4006 table
[MESA_FORMAT_SIGNED_GR1616
] = _mesa_texstore_snorm1616
;
4007 table
[MESA_FORMAT_SIGNED_RGB_16
] = _mesa_texstore_signed_rgba_16
;
4008 table
[MESA_FORMAT_SIGNED_RGBA_16
] = _mesa_texstore_signed_rgba_16
;
4009 table
[MESA_FORMAT_RGBA_16
] = _mesa_texstore_rgba_16
;
4010 table
[MESA_FORMAT_RED_RGTC1
] = _mesa_texstore_red_rgtc1
;
4011 table
[MESA_FORMAT_SIGNED_RED_RGTC1
] = _mesa_texstore_signed_red_rgtc1
;
4012 table
[MESA_FORMAT_RG_RGTC2
] = _mesa_texstore_rg_rgtc2
;
4013 table
[MESA_FORMAT_SIGNED_RG_RGTC2
] = _mesa_texstore_signed_rg_rgtc2
;
4014 table
[MESA_FORMAT_L_LATC1
] = _mesa_texstore_red_rgtc1
;
4015 table
[MESA_FORMAT_SIGNED_L_LATC1
] = _mesa_texstore_signed_red_rgtc1
;
4016 table
[MESA_FORMAT_LA_LATC2
] = _mesa_texstore_rg_rgtc2
;
4017 table
[MESA_FORMAT_SIGNED_LA_LATC2
] = _mesa_texstore_signed_rg_rgtc2
;
4018 table
[MESA_FORMAT_ETC1_RGB8
] = _mesa_texstore_etc1_rgb8
;
4019 table
[MESA_FORMAT_SIGNED_A8
] = _mesa_texstore_snorm8
;
4020 table
[MESA_FORMAT_SIGNED_L8
] = _mesa_texstore_snorm8
;
4021 table
[MESA_FORMAT_SIGNED_AL88
] = _mesa_texstore_snorm88
;
4022 table
[MESA_FORMAT_SIGNED_I8
] = _mesa_texstore_snorm8
;
4023 table
[MESA_FORMAT_SIGNED_A16
] = _mesa_texstore_snorm16
;
4024 table
[MESA_FORMAT_SIGNED_L16
] = _mesa_texstore_snorm16
;
4025 table
[MESA_FORMAT_SIGNED_AL1616
] = _mesa_texstore_snorm1616
;
4026 table
[MESA_FORMAT_SIGNED_I16
] = _mesa_texstore_snorm16
;
4027 table
[MESA_FORMAT_RGB9_E5_FLOAT
] = _mesa_texstore_rgb9_e5
;
4028 table
[MESA_FORMAT_R11_G11_B10_FLOAT
] = _mesa_texstore_r11_g11_b10f
;
4029 table
[MESA_FORMAT_Z32_FLOAT
] = _mesa_texstore_z32
;
4030 table
[MESA_FORMAT_Z32_FLOAT_X24S8
] = _mesa_texstore_z32f_x24s8
;
4032 table
[MESA_FORMAT_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4033 table
[MESA_FORMAT_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4034 table
[MESA_FORMAT_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4035 table
[MESA_FORMAT_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4036 table
[MESA_FORMAT_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4037 table
[MESA_FORMAT_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4039 table
[MESA_FORMAT_INTENSITY_UINT8
] = _mesa_texstore_rgba_uint8
;
4040 table
[MESA_FORMAT_INTENSITY_UINT16
] = _mesa_texstore_rgba_uint16
;
4041 table
[MESA_FORMAT_INTENSITY_UINT32
] = _mesa_texstore_rgba_uint32
;
4042 table
[MESA_FORMAT_INTENSITY_INT8
] = _mesa_texstore_rgba_int8
;
4043 table
[MESA_FORMAT_INTENSITY_INT16
] = _mesa_texstore_rgba_int16
;
4044 table
[MESA_FORMAT_INTENSITY_INT32
] = _mesa_texstore_rgba_int32
;
4046 table
[MESA_FORMAT_LUMINANCE_UINT8
] = _mesa_texstore_rgba_uint8
;
4047 table
[MESA_FORMAT_LUMINANCE_UINT16
] = _mesa_texstore_rgba_uint16
;
4048 table
[MESA_FORMAT_LUMINANCE_UINT32
] = _mesa_texstore_rgba_uint32
;
4049 table
[MESA_FORMAT_LUMINANCE_INT8
] = _mesa_texstore_rgba_int8
;
4050 table
[MESA_FORMAT_LUMINANCE_INT16
] = _mesa_texstore_rgba_int16
;
4051 table
[MESA_FORMAT_LUMINANCE_INT32
] = _mesa_texstore_rgba_int32
;
4053 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT8
] = _mesa_texstore_rgba_uint8
;
4054 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT16
] = _mesa_texstore_rgba_uint16
;
4055 table
[MESA_FORMAT_LUMINANCE_ALPHA_UINT32
] = _mesa_texstore_rgba_uint32
;
4056 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT8
] = _mesa_texstore_rgba_int8
;
4057 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT16
] = _mesa_texstore_rgba_int16
;
4058 table
[MESA_FORMAT_LUMINANCE_ALPHA_INT32
] = _mesa_texstore_rgba_int32
;
4060 table
[MESA_FORMAT_R_INT8
] = _mesa_texstore_rgba_int8
;
4061 table
[MESA_FORMAT_RG_INT8
] = _mesa_texstore_rgba_int8
;
4062 table
[MESA_FORMAT_RGB_INT8
] = _mesa_texstore_rgba_int8
;
4063 table
[MESA_FORMAT_RGBA_INT8
] = _mesa_texstore_rgba_int8
;
4064 table
[MESA_FORMAT_R_INT16
] = _mesa_texstore_rgba_int16
;
4065 table
[MESA_FORMAT_RG_INT16
] = _mesa_texstore_rgba_int16
;
4066 table
[MESA_FORMAT_RGB_INT16
] = _mesa_texstore_rgba_int16
;
4067 table
[MESA_FORMAT_RGBA_INT16
] = _mesa_texstore_rgba_int16
;
4068 table
[MESA_FORMAT_R_INT32
] = _mesa_texstore_rgba_int32
;
4069 table
[MESA_FORMAT_RG_INT32
] = _mesa_texstore_rgba_int32
;
4070 table
[MESA_FORMAT_RGB_INT32
] = _mesa_texstore_rgba_int32
;
4071 table
[MESA_FORMAT_RGBA_INT32
] = _mesa_texstore_rgba_int32
;
4073 table
[MESA_FORMAT_R_UINT8
] = _mesa_texstore_rgba_uint8
;
4074 table
[MESA_FORMAT_RG_UINT8
] = _mesa_texstore_rgba_uint8
;
4075 table
[MESA_FORMAT_RGB_UINT8
] = _mesa_texstore_rgba_uint8
;
4076 table
[MESA_FORMAT_RGBA_UINT8
] = _mesa_texstore_rgba_uint8
;
4077 table
[MESA_FORMAT_R_UINT16
] = _mesa_texstore_rgba_uint16
;
4078 table
[MESA_FORMAT_RG_UINT16
] = _mesa_texstore_rgba_uint16
;
4079 table
[MESA_FORMAT_RGB_UINT16
] = _mesa_texstore_rgba_uint16
;
4080 table
[MESA_FORMAT_RGBA_UINT16
] = _mesa_texstore_rgba_uint16
;
4081 table
[MESA_FORMAT_R_UINT32
] = _mesa_texstore_rgba_uint32
;
4082 table
[MESA_FORMAT_RG_UINT32
] = _mesa_texstore_rgba_uint32
;
4083 table
[MESA_FORMAT_RGB_UINT32
] = _mesa_texstore_rgba_uint32
;
4084 table
[MESA_FORMAT_RGBA_UINT32
] = _mesa_texstore_rgba_uint32
;
4086 table
[MESA_FORMAT_ARGB2101010_UINT
] = _mesa_texstore_argb2101010_uint
;
4087 initialized
= GL_TRUE
;
4090 ASSERT(table
[format
]);
4091 return table
[format
];
4096 * Store user data into texture memory.
4097 * Called via glTex[Sub]Image1/2/3D()
4100 _mesa_texstore(TEXSTORE_PARAMS
)
4102 StoreTexImageFunc storeImage
;
4105 storeImage
= _mesa_get_texstore_func(dstFormat
);
4107 success
= storeImage(ctx
, dims
, baseInternalFormat
,
4109 dstRowStride
, dstSlices
,
4110 srcWidth
, srcHeight
, srcDepth
,
4111 srcFormat
, srcType
, srcAddr
, srcPacking
);
4117 * Normally, we'll only _write_ texel data to a texture when we map it.
4118 * But if the user is providing depth or stencil values and the texture
4119 * image is a combined depth/stencil format, we'll actually read from
4120 * the texture buffer too (in order to insert the depth or stencil values.
4121 * \param userFormat the user-provided image format
4122 * \param texFormat the destination texture format
4125 get_read_write_mode(GLenum userFormat
, gl_format texFormat
)
4127 if ((userFormat
== GL_STENCIL_INDEX
|| userFormat
== GL_DEPTH_COMPONENT
)
4128 && _mesa_get_format_base_format(texFormat
) == GL_DEPTH_STENCIL
)
4129 return GL_MAP_READ_BIT
| GL_MAP_WRITE_BIT
;
4131 return GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
;
4136 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
4138 * The source of the image data may be user memory or a PBO. In the later
4139 * case, we'll map the PBO, copy from it, then unmap it.
4142 store_texsubimage(struct gl_context
*ctx
,
4143 struct gl_texture_image
*texImage
,
4144 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4145 GLint width
, GLint height
, GLint depth
,
4146 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4147 const struct gl_pixelstore_attrib
*packing
,
4151 const GLbitfield mapMode
= get_read_write_mode(format
, texImage
->TexFormat
);
4152 const GLenum target
= texImage
->TexObject
->Target
;
4153 GLboolean success
= GL_FALSE
;
4154 GLuint dims
, slice
, numSlices
= 1, sliceOffset
= 0;
4155 GLint srcImageStride
= 0;
4158 assert(xoffset
+ width
<= texImage
->Width
);
4159 assert(yoffset
+ height
<= texImage
->Height
);
4160 assert(zoffset
+ depth
<= texImage
->Depth
);
4166 case GL_TEXTURE_2D_ARRAY
:
4174 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4175 src
= (const GLubyte
*)
4176 _mesa_validate_pbo_teximage(ctx
, dims
, width
, height
, depth
,
4177 format
, type
, pixels
, packing
, caller
);
4181 /* compute slice info (and do some sanity checks) */
4184 case GL_TEXTURE_RECTANGLE
:
4185 case GL_TEXTURE_CUBE_MAP
:
4186 /* one image slice, nothing special needs to be done */
4189 assert(height
== 1);
4191 assert(yoffset
== 0);
4192 assert(zoffset
== 0);
4194 case GL_TEXTURE_1D_ARRAY
:
4196 assert(zoffset
== 0);
4198 sliceOffset
= yoffset
;
4201 srcImageStride
= _mesa_image_row_stride(packing
, width
, format
, type
);
4203 case GL_TEXTURE_2D_ARRAY
:
4205 sliceOffset
= zoffset
;
4208 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4212 /* we'll store 3D images as a series of slices */
4214 sliceOffset
= zoffset
;
4215 srcImageStride
= _mesa_image_image_stride(packing
, width
, height
,
4219 _mesa_warning(ctx
, "Unexpected target 0x%x in store_texsubimage()", target
);
4223 assert(numSlices
== 1 || srcImageStride
!= 0);
4225 for (slice
= 0; slice
< numSlices
; slice
++) {
4229 ctx
->Driver
.MapTextureImage(ctx
, texImage
,
4230 slice
+ sliceOffset
,
4231 xoffset
, yoffset
, width
, height
,
4232 mapMode
, &dstMap
, &dstRowStride
);
4234 /* Note: we're only storing a 2D (or 1D) slice at a time but we need
4235 * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
4236 * used for 3D images.
4238 success
= _mesa_texstore(ctx
, dims
, texImage
->_BaseFormat
,
4239 texImage
->TexFormat
,
4242 width
, height
, 1, /* w, h, d */
4243 format
, type
, src
, packing
);
4245 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, slice
+ sliceOffset
);
4248 src
+= srcImageStride
;
4255 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", caller
);
4257 _mesa_unmap_teximage_pbo(ctx
, packing
);
4263 * Fallback code for ctx->Driver.TexImage().
4264 * Basically, allocate storage for the texture image, then copy the
4265 * user's image into it.
4268 _mesa_store_teximage(struct gl_context
*ctx
,
4270 struct gl_texture_image
*texImage
,
4271 GLint internalFormat
,
4272 GLint width
, GLint height
, GLint depth
, GLint border
,
4273 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4274 const struct gl_pixelstore_attrib
*packing
)
4276 assert(dims
== 1 || dims
== 2 || dims
== 3);
4278 if (width
== 0 || height
== 0 || depth
== 0)
4281 /* allocate storage for texture data */
4282 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4283 width
, height
, depth
)) {
4284 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
4288 store_texsubimage(ctx
, texImage
,
4289 0, 0, 0, width
, height
, depth
,
4290 format
, type
, pixels
, packing
, "glTexImage");
4295 * Fallback for Driver.TexSubImage().
4298 _mesa_store_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4299 struct gl_texture_image
*texImage
,
4300 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4301 GLint width
, GLint height
, GLint depth
,
4302 GLenum format
, GLenum type
, const void *pixels
,
4303 const struct gl_pixelstore_attrib
*packing
)
4305 store_texsubimage(ctx
, texImage
,
4306 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
4307 format
, type
, pixels
, packing
, "glTexSubImage");
4312 * Fallback for Driver.CompressedTexImage()
4315 _mesa_store_compressed_teximage(struct gl_context
*ctx
, GLuint dims
,
4316 struct gl_texture_image
*texImage
,
4317 GLint internalFormat
,
4318 GLint width
, GLint height
, GLint depth
,
4320 GLsizei imageSize
, const GLvoid
*data
)
4322 /* only 2D compressed images are supported at this time */
4324 _mesa_problem(ctx
, "Unexpected glCompressedTexImage1D/3D call");
4328 /* This is pretty simple, because unlike the general texstore path we don't
4329 * have to worry about the usual image unpacking or image transfer
4333 ASSERT(texImage
->Width
> 0);
4334 ASSERT(texImage
->Height
> 0);
4335 ASSERT(texImage
->Depth
== 1);
4337 /* allocate storage for texture data */
4338 if (!ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
, texImage
->TexFormat
,
4339 width
, height
, 1)) {
4340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
4344 _mesa_store_compressed_texsubimage(ctx
, dims
, texImage
,
4346 width
, height
, depth
,
4347 texImage
->TexFormat
,
4353 * Fallback for Driver.CompressedTexSubImage()
4356 _mesa_store_compressed_texsubimage(struct gl_context
*ctx
, GLuint dims
,
4357 struct gl_texture_image
*texImage
,
4358 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4359 GLsizei width
, GLsizei height
, GLsizei depth
,
4361 GLsizei imageSize
, const GLvoid
*data
)
4363 GLint bytesPerRow
, dstRowStride
, srcRowStride
;
4367 const gl_format texFormat
= texImage
->TexFormat
;
4371 _mesa_problem(ctx
, "Unexpected 1D/3D compressed texsubimage call");
4375 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4377 /* these should have been caught sooner */
4378 ASSERT((width
% bw
) == 0 || width
< bw
);
4379 ASSERT((height
% bh
) == 0 || height
< bh
);
4380 ASSERT((xoffset
% bw
) == 0);
4381 ASSERT((yoffset
% bh
) == 0);
4383 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4384 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4386 "glCompressedTexSubImage2D");
4390 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4391 src
= (const GLubyte
*) data
;
4393 /* Map dest texture buffer */
4394 ctx
->Driver
.MapTextureImage(ctx
, texImage
, 0,
4395 xoffset
, yoffset
, width
, height
,
4396 GL_MAP_WRITE_BIT
| GL_MAP_INVALIDATE_RANGE_BIT
,
4397 &dstMap
, &dstRowStride
);
4400 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4401 rows
= (height
+ bh
- 1) / bh
; /* rows in blocks */
4403 /* copy rows of blocks */
4404 for (i
= 0; i
< rows
; i
++) {
4405 memcpy(dstMap
, src
, bytesPerRow
);
4406 dstMap
+= dstRowStride
;
4407 src
+= srcRowStride
;
4410 ctx
->Driver
.UnmapTextureImage(ctx
, texImage
, 0);
4413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexSubImage2D");
4416 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);